Browse Source

DKGpuBuffer persistent mapping 으로 변경

Hongtae Kim 5 years ago
parent
commit
9046bbaba5
2 changed files with 14 additions and 38 deletions
  1. 7
    19
      Samples/Texture/Texture.cpp
  2. 7
    19
      Samples/Triangle/Triangle.cpp

+ 7
- 19
Samples/Texture/Texture.cpp View File

78
         DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
78
         DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
79
 		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
79
 		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
80
 
80
 
81
-		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
82
-		memcpy(vertexBuffer->Lock(), vertexData, vertexBufferSize);
83
-		vertexBuffer->Unlock();
81
+		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
82
+		memcpy(vertexBuffer->Contents(), vertexData, vertexBufferSize);
84
 
83
 
85
-		DKObject<DKGpuBuffer> indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
86
-		memcpy(indexBuffer->Lock(), indexData, indexBufferSize);
87
-		indexBuffer->Unlock();
84
+		DKObject<DKGpuBuffer> indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
85
+		memcpy(indexBuffer->Contents(), indexData, indexBufferSize);
88
 
86
 
89
 		DKRenderPipelineDescriptor pipelineDescriptor;
87
 		DKRenderPipelineDescriptor pipelineDescriptor;
90
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
88
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
135
                 DKMatrix4 viewMatrix;
133
                 DKMatrix4 viewMatrix;
136
             } ubo;
134
             } ubo;
137
 
135
 
138
-            DKObject<DKGpuBuffer> uboBuffer = device->CreateBuffer(sizeof(ubo), DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
136
+            DKObject<DKGpuBuffer> uboBuffer = device->CreateBuffer(sizeof(ubo), DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
139
             if (uboBuffer)
137
             if (uboBuffer)
140
             {
138
             {
141
                 ubo.projectionMatrix = DKMatrix4::identity;
139
                 ubo.projectionMatrix = DKMatrix4::identity;
142
                 ubo.modelMatrix = DKMatrix4::identity;
140
                 ubo.modelMatrix = DKMatrix4::identity;
143
                 ubo.viewMatrix = DKMatrix4::identity;
141
                 ubo.viewMatrix = DKMatrix4::identity;
144
 
142
 
145
-                void* p = uboBuffer->Lock(0);
146
-                if (p)
147
-                {
148
-                    memcpy(p, &ubo, sizeof(ubo));
149
-                    uboBuffer->Unlock();
150
-
151
-                    bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
152
-                }
153
-                else
154
-                {
155
-                    DKLogE("GpuBuffer Lock failed!");
156
-                }
143
+                memcpy(uboBuffer->Contents(), &ubo, sizeof(ubo));
144
+                bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
157
             }
145
             }
158
         }
146
         }
159
 
147
 

+ 7
- 19
Samples/Triangle/Triangle.cpp View File

49
 		DKArray<uint32_t> indexData = { 0, 1, 2 };
49
 		DKArray<uint32_t> indexData = { 0, 1, 2 };
50
 		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
50
 		uint32_t indexBufferSize = indexData.Count() * sizeof(uint32_t);
51
 
51
 
52
-		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
53
-		memcpy(vertexBuffer->Lock(), vertexData, vertexBufferSize);
54
-		vertexBuffer->Unlock();
52
+		DKObject<DKGpuBuffer> vertexBuffer = device->CreateBuffer(vertexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
53
+		memcpy(vertexBuffer->Contents(), vertexData, vertexBufferSize);
55
 
54
 
56
-		DKObject<DKGpuBuffer> indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
57
-		memcpy(indexBuffer->Lock(), indexData, indexBufferSize);
58
-		indexBuffer->Unlock();
55
+		DKObject<DKGpuBuffer> indexBuffer = device->CreateBuffer(indexBufferSize, DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
56
+		memcpy(indexBuffer->Contents(), indexData, indexBufferSize);
59
 
57
 
60
 		DKRenderPipelineDescriptor pipelineDescriptor;
58
 		DKRenderPipelineDescriptor pipelineDescriptor;
61
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
59
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
105
                 DKMatrix4 viewMatrix;
103
                 DKMatrix4 viewMatrix;
106
             } ubo;
104
             } ubo;
107
 
105
 
108
-            DKObject<DKGpuBuffer> uboBuffer = device->CreateBuffer(sizeof(ubo), DKGpuBuffer::StorageModeShared, DKCpuCacheModeDefault);
106
+            DKObject<DKGpuBuffer> uboBuffer = device->CreateBuffer(sizeof(ubo), DKGpuBuffer::StorageModeShared, DKCpuCacheModeReadWrite);
109
             if (uboBuffer)
107
             if (uboBuffer)
110
             {
108
             {
111
                 ubo.projectionMatrix = DKMatrix4::identity;
109
                 ubo.projectionMatrix = DKMatrix4::identity;
112
                 ubo.modelMatrix = DKMatrix4::identity;
110
                 ubo.modelMatrix = DKMatrix4::identity;
113
                 ubo.viewMatrix = DKMatrix4::identity;
111
                 ubo.viewMatrix = DKMatrix4::identity;
114
 
112
 
115
-                void* p = uboBuffer->Lock(0);
116
-                if (p)
117
-                {
118
-                    memcpy(p, &ubo, sizeof(ubo));
119
-                    uboBuffer->Unlock();
120
-
121
-                    bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
122
-                }
123
-                else
124
-                {
125
-                    DKLogE("GpuBuffer Lock failed!");
126
-                }
113
+                memcpy(uboBuffer->Contents(), &ubo, sizeof(ubo));
114
+                bindSet->SetBuffer(0, uboBuffer, 0, sizeof(ubo));
127
             }
115
             }
128
         }
116
         }
129
 
117