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,13 +78,11 @@ public:
78 78
         DKArray<uint32_t> indexData = { 0, 1, 2, 2, 3, 0 };
79 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 87
 		DKRenderPipelineDescriptor pipelineDescriptor;
90 88
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
@@ -135,25 +133,15 @@ public:
135 133
                 DKMatrix4 viewMatrix;
136 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 137
             if (uboBuffer)
140 138
             {
141 139
                 ubo.projectionMatrix = DKMatrix4::identity;
142 140
                 ubo.modelMatrix = DKMatrix4::identity;
143 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,13 +49,11 @@ public:
49 49
 		DKArray<uint32_t> indexData = { 0, 1, 2 };
50 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 58
 		DKRenderPipelineDescriptor pipelineDescriptor;
61 59
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
@@ -105,25 +103,15 @@ public:
105 103
                 DKMatrix4 viewMatrix;
106 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 107
             if (uboBuffer)
110 108
             {
111 109
                 ubo.projectionMatrix = DKMatrix4::identity;
112 110
                 ubo.modelMatrix = DKMatrix4::identity;
113 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