Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: src/gpu/vk/GrVkPipelineState.cpp

Issue 1864303002: Switch uniforms to be descriptor set 0 in Vulkan (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrVkPipelineState.h" 8 #include "GrVkPipelineState.h"
9 9
10 #include "GrPipeline.h" 10 #include "GrPipeline.h"
(...skipping 19 matching lines...) Expand all
30 const BuiltinUniformHandles& builtinUniform Handles, 30 const BuiltinUniformHandles& builtinUniform Handles,
31 const UniformInfoArray& uniforms, 31 const UniformInfoArray& uniforms,
32 uint32_t vertexUniformSize, 32 uint32_t vertexUniformSize,
33 uint32_t fragmentUniformSize, 33 uint32_t fragmentUniformSize,
34 uint32_t numSamplers, 34 uint32_t numSamplers,
35 GrGLSLPrimitiveProcessor* geometryProcessor , 35 GrGLSLPrimitiveProcessor* geometryProcessor ,
36 GrGLSLXferProcessor* xferProcessor, 36 GrGLSLXferProcessor* xferProcessor,
37 const GrGLSLFragProcs& fragmentProcessors) 37 const GrGLSLFragProcs& fragmentProcessors)
38 : fPipeline(pipeline) 38 : fPipeline(pipeline)
39 , fPipelineLayout(layout) 39 , fPipelineLayout(layout)
40 , fStartDS(SK_MaxS32)
41 , fDSCount(0)
40 , fBuiltinUniformHandles(builtinUniformHandles) 42 , fBuiltinUniformHandles(builtinUniformHandles)
41 , fGeometryProcessor(geometryProcessor) 43 , fGeometryProcessor(geometryProcessor)
42 , fXferProcessor(xferProcessor) 44 , fXferProcessor(xferProcessor)
43 , fFragmentProcessors(fragmentProcessors) 45 , fFragmentProcessors(fragmentProcessors)
44 , fDesc(desc) 46 , fDesc(desc)
45 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize) 47 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize)
46 , fSamplerPoolManager(dsLayout[GrVkUniformHandler::kSamplerDescSet], 48 , fSamplerPoolManager(dsLayout[GrVkUniformHandler::kSamplerDescSet],
47 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, numSamplers , gpu) 49 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, numSamplers , gpu)
48 , fUniformPoolManager(dsLayout[GrVkUniformHandler::kUniformBufferDescSet], 50 , fUniformPoolManager(dsLayout[GrVkUniformHandler::kUniformBufferDescSet],
49 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2, gpu) { 51 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
52 (vertexUniformSize || fragmentUniformSize) ? 2 : 0, gp u) {
50 fSamplers.setReserve(numSamplers); 53 fSamplers.setReserve(numSamplers);
51 fTextureViews.setReserve(numSamplers); 54 fTextureViews.setReserve(numSamplers);
52 fTextures.setReserve(numSamplers); 55 fTextures.setReserve(numSamplers);
53 56
54 fDescriptorSets[0] = VK_NULL_HANDLE; 57 fDescriptorSets[0] = VK_NULL_HANDLE;
55 fDescriptorSets[1] = VK_NULL_HANDLE; 58 fDescriptorSets[1] = VK_NULL_HANDLE;
56 59
57 // Currently we are always binding a descriptor set for uniform buffers. 60 // Currently we are always binding a descriptor set for uniform buffers.
58 fStartDS = GrVkUniformHandler::kUniformBufferDescSet; 61 if (vertexUniformSize || fragmentUniformSize) {
59 fDSCount = 1; 62 fDSCount++;
63 fStartDS = GrVkUniformHandler::kUniformBufferDescSet;
64 }
60 if (numSamplers) { 65 if (numSamplers) {
61 fDSCount++; 66 fDSCount++;
62 fStartDS = SkTMin(fStartDS, (int)GrVkUniformHandler::kSamplerDescSet); 67 fStartDS = SkTMin(fStartDS, (int)GrVkUniformHandler::kSamplerDescSet);
63 } 68 }
64 69
65 fVertexUniformBuffer.reset(GrVkUniformBuffer::Create(gpu, vertexUniformSize, true)); 70 fVertexUniformBuffer.reset(GrVkUniformBuffer::Create(gpu, vertexUniformSize, true));
66 fFragmentUniformBuffer.reset(GrVkUniformBuffer::Create(gpu, fragmentUniformS ize, true)); 71 fFragmentUniformBuffer.reset(GrVkUniformBuffer::Create(gpu, fragmentUniformS ize, true));
67 72
68 fNumSamplers = numSamplers; 73 fNumSamplers = numSamplers;
69 } 74 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 append_texture_bindings(processor, &textureBindings); 187 append_texture_bindings(processor, &textureBindings);
183 } 188 }
184 189
185 fXferProcessor->setData(fDataManager, pipeline.getXferProcessor()); 190 fXferProcessor->setData(fDataManager, pipeline.getXferProcessor());
186 append_texture_bindings(pipeline.getXferProcessor(), &textureBindings); 191 append_texture_bindings(pipeline.getXferProcessor(), &textureBindings);
187 192
188 // Get new descriptor sets 193 // Get new descriptor sets
189 if (fNumSamplers) { 194 if (fNumSamplers) {
190 fSamplerPoolManager.getNewDescriptorSet(gpu, 195 fSamplerPoolManager.getNewDescriptorSet(gpu,
191 &fDescriptorSets[GrVkUniformHandler ::kSamplerDescSet]); 196 &fDescriptorSets[GrVkUniformHandler ::kSamplerDescSet]);
197 this->writeSamplers(gpu, textureBindings);
192 } 198 }
193 fUniformPoolManager.getNewDescriptorSet(gpu, 199
200
201 if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) {
202 fUniformPoolManager.getNewDescriptorSet(gpu,
194 &fDescriptorSets[GrVkUniformHandler::kUni formBufferDescSet]); 203 &fDescriptorSets[GrVkUniformHandler::kUni formBufferDescSet]);
195 204 this->writeUniformBuffers(gpu);
196 this->writeUniformBuffers(gpu); 205 }
197
198 this->writeSamplers(gpu, textureBindings);
199 } 206 }
200 207
201 void GrVkPipelineState::writeUniformBuffers(const GrVkGpu* gpu) { 208 void GrVkPipelineState::writeUniformBuffers(const GrVkGpu* gpu) {
202 fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragmentUnifor mBuffer); 209 fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragmentUnifor mBuffer);
203 210
204 VkWriteDescriptorSet descriptorWrites[2]; 211 VkWriteDescriptorSet descriptorWrites[2];
205 memset(descriptorWrites, 0, 2 * sizeof(VkWriteDescriptorSet)); 212 memset(descriptorWrites, 0, 2 * sizeof(VkWriteDescriptorSet));
206 213
207 uint32_t firstUniformWrite = 0; 214 uint32_t firstUniformWrite = 0;
208 uint32_t uniformBindingUpdateCount = 0; 215 uint32_t uniformBindingUpdateCount = 0;
209 216
210 VkDescriptorBufferInfo vertBufferInfo; 217 VkDescriptorBufferInfo vertBufferInfo;
211 // Vertex Uniform Buffer 218 // Vertex Uniform Buffer
212 if (fVertexUniformBuffer.get()) { 219 if (fVertexUniformBuffer.get()) {
213 ++uniformBindingUpdateCount; 220 ++uniformBindingUpdateCount;
214 memset(&vertBufferInfo, 0, sizeof(VkDescriptorBufferInfo)); 221 memset(&vertBufferInfo, 0, sizeof(VkDescriptorBufferInfo));
215 vertBufferInfo.buffer = fVertexUniformBuffer->buffer(); 222 vertBufferInfo.buffer = fVertexUniformBuffer->buffer();
216 vertBufferInfo.offset = 0; 223 vertBufferInfo.offset = 0;
217 vertBufferInfo.range = fVertexUniformBuffer->size(); 224 vertBufferInfo.range = fVertexUniformBuffer->size();
218 225
219 descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; 226 descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
220 descriptorWrites[0].pNext = nullptr; 227 descriptorWrites[0].pNext = nullptr;
221 descriptorWrites[0].dstSet = fDescriptorSets[1]; 228 descriptorWrites[0].dstSet = fDescriptorSets[GrVkUniformHandler::kUnifor mBufferDescSet];
222 descriptorWrites[0].dstBinding = GrVkUniformHandler::kVertexBinding; 229 descriptorWrites[0].dstBinding = GrVkUniformHandler::kVertexBinding;
223 descriptorWrites[0].dstArrayElement = 0; 230 descriptorWrites[0].dstArrayElement = 0;
224 descriptorWrites[0].descriptorCount = 1; 231 descriptorWrites[0].descriptorCount = 1;
225 descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 232 descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
226 descriptorWrites[0].pImageInfo = nullptr; 233 descriptorWrites[0].pImageInfo = nullptr;
227 descriptorWrites[0].pBufferInfo = &vertBufferInfo; 234 descriptorWrites[0].pBufferInfo = &vertBufferInfo;
228 descriptorWrites[0].pTexelBufferView = nullptr; 235 descriptorWrites[0].pTexelBufferView = nullptr;
229 236
230 fVertexUniformBuffer->addMemoryBarrier(gpu, 237 fVertexUniformBuffer->addMemoryBarrier(gpu,
231 VK_ACCESS_HOST_WRITE_BIT, 238 VK_ACCESS_HOST_WRITE_BIT,
(...skipping 10 matching lines...) Expand all
242 firstUniformWrite = 1; 249 firstUniformWrite = 1;
243 } 250 }
244 ++uniformBindingUpdateCount; 251 ++uniformBindingUpdateCount;
245 memset(&fragBufferInfo, 0, sizeof(VkDescriptorBufferInfo)); 252 memset(&fragBufferInfo, 0, sizeof(VkDescriptorBufferInfo));
246 fragBufferInfo.buffer = fFragmentUniformBuffer->buffer(); 253 fragBufferInfo.buffer = fFragmentUniformBuffer->buffer();
247 fragBufferInfo.offset = 0; 254 fragBufferInfo.offset = 0;
248 fragBufferInfo.range = fFragmentUniformBuffer->size(); 255 fragBufferInfo.range = fFragmentUniformBuffer->size();
249 256
250 descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; 257 descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
251 descriptorWrites[1].pNext = nullptr; 258 descriptorWrites[1].pNext = nullptr;
252 descriptorWrites[1].dstSet = fDescriptorSets[1]; 259 descriptorWrites[1].dstSet = fDescriptorSets[GrVkUniformHandler::kUnifor mBufferDescSet];
253 descriptorWrites[1].dstBinding = GrVkUniformHandler::kFragBinding;; 260 descriptorWrites[1].dstBinding = GrVkUniformHandler::kFragBinding;;
254 descriptorWrites[1].dstArrayElement = 0; 261 descriptorWrites[1].dstArrayElement = 0;
255 descriptorWrites[1].descriptorCount = 1; 262 descriptorWrites[1].descriptorCount = 1;
256 descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 263 descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
257 descriptorWrites[1].pImageInfo = nullptr; 264 descriptorWrites[1].pImageInfo = nullptr;
258 descriptorWrites[1].pBufferInfo = &fragBufferInfo; 265 descriptorWrites[1].pBufferInfo = &fragBufferInfo;
259 descriptorWrites[1].pTexelBufferView = nullptr; 266 descriptorWrites[1].pTexelBufferView = nullptr;
260 267
261 fFragmentUniformBuffer->addMemoryBarrier(gpu, 268 fFragmentUniformBuffer->addMemoryBarrier(gpu,
262 VK_ACCESS_HOST_WRITE_BIT, 269 VK_ACCESS_HOST_WRITE_BIT,
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 494
488 b.add32(get_blend_info_key(pipeline)); 495 b.add32(get_blend_info_key(pipeline));
489 496
490 b.add32(primitiveType); 497 b.add32(primitiveType);
491 498
492 // Set key length 499 // Set key length
493 int keyLength = key->count(); 500 int keyLength = key->count();
494 SkASSERT(0 == (keyLength % 4)); 501 SkASSERT(0 == (keyLength % 4));
495 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength); 502 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength);
496 } 503 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698