Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "GrVkProgram.h" | 8 #include "GrVkProgram.h" |
| 9 | 9 |
| 10 #include "GrPipeline.h" | 10 #include "GrPipeline.h" |
| 11 #include "GrVkCommandBuffer.h" | 11 #include "GrVkCommandBuffer.h" |
| 12 #include "GrVkDescriptorPool.h" | 12 #include "GrVkDescriptorPool.h" |
| 13 #include "GrVkGpu.h" | 13 #include "GrVkGpu.h" |
| 14 #include "GrVkImageView.h" | 14 #include "GrVkImageView.h" |
| 15 #include "GrVkMemory.h" | 15 #include "GrVkMemory.h" |
| 16 #include "GrVkPipeline.h" | 16 #include "GrVkPipeline.h" |
| 17 #include "GrVkRenderTarget.h" | |
| 17 #include "GrVkSampler.h" | 18 #include "GrVkSampler.h" |
| 18 #include "GrVkTexture.h" | 19 #include "GrVkTexture.h" |
| 19 #include "GrVkUniformBuffer.h" | 20 #include "GrVkUniformBuffer.h" |
| 20 #include "glsl/GrGLSLFragmentProcessor.h" | 21 #include "glsl/GrGLSLFragmentProcessor.h" |
| 21 #include "glsl/GrGLSLGeometryProcessor.h" | 22 #include "glsl/GrGLSLGeometryProcessor.h" |
| 22 #include "glsl/GrGLSLXferProcessor.h" | 23 #include "glsl/GrGLSLXferProcessor.h" |
| 23 | 24 |
| 24 GrVkProgram::GrVkProgram(GrVkGpu* gpu, | 25 GrVkProgram::GrVkProgram(GrVkGpu* gpu, |
| 26 const GrVkProgram::PipelineDesc& desc, | |
| 25 GrVkPipeline* pipeline, | 27 GrVkPipeline* pipeline, |
| 26 VkPipelineLayout layout, | 28 VkPipelineLayout layout, |
| 27 VkDescriptorSetLayout dsLayout[2], | 29 VkDescriptorSetLayout dsLayout[2], |
| 28 const BuiltinUniformHandles& builtinUniformHandles, | 30 const BuiltinUniformHandles& builtinUniformHandles, |
| 29 const UniformInfoArray& uniforms, | 31 const UniformInfoArray& uniforms, |
| 30 uint32_t vertexUniformSize, | 32 uint32_t vertexUniformSize, |
| 31 uint32_t fragmentUniformSize, | 33 uint32_t fragmentUniformSize, |
| 32 uint32_t numSamplers, | 34 uint32_t numSamplers, |
| 33 GrGLSLPrimitiveProcessor* geometryProcessor, | 35 GrGLSLPrimitiveProcessor* geometryProcessor, |
| 34 GrGLSLXferProcessor* xferProcessor, | 36 GrGLSLXferProcessor* xferProcessor, |
| 35 const GrGLSLFragProcs& fragmentProcessors) | 37 const GrGLSLFragProcs& fragmentProcessors) |
| 36 : fPipeline(pipeline) | 38 : fPipeline(pipeline) |
| 37 , fPipelineLayout(layout) | 39 , fPipelineLayout(layout) |
| 38 , fBuiltinUniformHandles(builtinUniformHandles) | 40 , fBuiltinUniformHandles(builtinUniformHandles) |
| 39 , fGeometryProcessor(geometryProcessor) | 41 , fGeometryProcessor(geometryProcessor) |
| 40 , fXferProcessor(xferProcessor) | 42 , fXferProcessor(xferProcessor) |
| 41 , fFragmentProcessors(fragmentProcessors) | 43 , fFragmentProcessors(fragmentProcessors) |
| 44 , fPipelineDesc(desc) | |
| 42 , fProgramDataManager(uniforms, vertexUniformSize, fragmentUniformSize) | 45 , fProgramDataManager(uniforms, vertexUniformSize, fragmentUniformSize) |
| 43 , fSamplerPoolManager(dsLayout[GrVkUniformHandler::kSamplerDescSet], | 46 , fSamplerPoolManager(dsLayout[GrVkUniformHandler::kSamplerDescSet], |
| 44 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, numSamplers , gpu) | 47 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, numSamplers , gpu) |
| 45 , fUniformPoolManager(dsLayout[GrVkUniformHandler::kUniformBufferDescSet], | 48 , fUniformPoolManager(dsLayout[GrVkUniformHandler::kUniformBufferDescSet], |
| 46 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2, gpu) { | 49 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2, gpu) { |
| 47 fSamplers.setReserve(numSamplers); | 50 fSamplers.setReserve(numSamplers); |
| 48 fTextureViews.setReserve(numSamplers); | 51 fTextureViews.setReserve(numSamplers); |
| 49 fTextures.setReserve(numSamplers); | 52 fTextures.setReserve(numSamplers); |
| 50 | 53 |
| 51 fDescriptorSets[0] = VK_NULL_HANDLE; | 54 fDescriptorSets[0] = VK_NULL_HANDLE; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; | 221 descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 219 descriptorWrites[0].pNext = nullptr; | 222 descriptorWrites[0].pNext = nullptr; |
| 220 descriptorWrites[0].dstSet = fDescriptorSets[1]; | 223 descriptorWrites[0].dstSet = fDescriptorSets[1]; |
| 221 descriptorWrites[0].dstBinding = GrVkUniformHandler::kVertexBinding; | 224 descriptorWrites[0].dstBinding = GrVkUniformHandler::kVertexBinding; |
| 222 descriptorWrites[0].dstArrayElement = 0; | 225 descriptorWrites[0].dstArrayElement = 0; |
| 223 descriptorWrites[0].descriptorCount = 1; | 226 descriptorWrites[0].descriptorCount = 1; |
| 224 descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; | 227 descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 225 descriptorWrites[0].pImageInfo = nullptr; | 228 descriptorWrites[0].pImageInfo = nullptr; |
| 226 descriptorWrites[0].pBufferInfo = &vertBufferInfo; | 229 descriptorWrites[0].pBufferInfo = &vertBufferInfo; |
| 227 descriptorWrites[0].pTexelBufferView = nullptr; | 230 descriptorWrites[0].pTexelBufferView = nullptr; |
| 231 | |
| 232 fVertexUniformBuffer->addMemoryBarrier(gpu, | |
| 233 VK_ACCESS_HOST_WRITE_BIT, | |
| 234 VK_ACCESS_UNIFORM_READ_BIT, | |
| 235 VK_PIPELINE_STAGE_HOST_BIT, | |
| 236 VK_PIPELINE_STAGE_VERTEX_SHADER_B IT, | |
| 237 false); | |
| 228 } | 238 } |
| 229 | 239 |
| 230 VkDescriptorBufferInfo fragBufferInfo; | 240 VkDescriptorBufferInfo fragBufferInfo; |
| 231 // Fragment Uniform Buffer | 241 // Fragment Uniform Buffer |
| 232 if (fFragmentUniformBuffer.get()) { | 242 if (fFragmentUniformBuffer.get()) { |
| 233 if (0 == uniformBindingUpdateCount) { | 243 if (0 == uniformBindingUpdateCount) { |
| 234 firstUniformWrite = 1; | 244 firstUniformWrite = 1; |
| 235 } | 245 } |
| 236 ++uniformBindingUpdateCount; | 246 ++uniformBindingUpdateCount; |
| 237 memset(&fragBufferInfo, 0, sizeof(VkDescriptorBufferInfo)); | 247 memset(&fragBufferInfo, 0, sizeof(VkDescriptorBufferInfo)); |
| 238 fragBufferInfo.buffer = fFragmentUniformBuffer->buffer(); | 248 fragBufferInfo.buffer = fFragmentUniformBuffer->buffer(); |
| 239 fragBufferInfo.offset = 0; | 249 fragBufferInfo.offset = 0; |
| 240 fragBufferInfo.range = fFragmentUniformBuffer->size(); | 250 fragBufferInfo.range = fFragmentUniformBuffer->size(); |
| 241 | 251 |
| 242 descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; | 252 descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 243 descriptorWrites[1].pNext = nullptr; | 253 descriptorWrites[1].pNext = nullptr; |
| 244 descriptorWrites[1].dstSet = fDescriptorSets[1]; | 254 descriptorWrites[1].dstSet = fDescriptorSets[1]; |
| 245 descriptorWrites[1].dstBinding = GrVkUniformHandler::kFragBinding;; | 255 descriptorWrites[1].dstBinding = GrVkUniformHandler::kFragBinding;; |
| 246 descriptorWrites[1].dstArrayElement = 0; | 256 descriptorWrites[1].dstArrayElement = 0; |
| 247 descriptorWrites[1].descriptorCount = 1; | 257 descriptorWrites[1].descriptorCount = 1; |
| 248 descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; | 258 descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 249 descriptorWrites[1].pImageInfo = nullptr; | 259 descriptorWrites[1].pImageInfo = nullptr; |
| 250 descriptorWrites[1].pBufferInfo = &fragBufferInfo; | 260 descriptorWrites[1].pBufferInfo = &fragBufferInfo; |
| 251 descriptorWrites[1].pTexelBufferView = nullptr; | 261 descriptorWrites[1].pTexelBufferView = nullptr; |
| 262 | |
| 263 fFragmentUniformBuffer->addMemoryBarrier(gpu, | |
| 264 VK_ACCESS_HOST_WRITE_BIT, | |
| 265 VK_ACCESS_UNIFORM_READ_BIT, | |
| 266 VK_PIPELINE_STAGE_HOST_BIT, | |
| 267 VK_PIPELINE_STAGE_FRAGMENT_SHAD ER_BIT, | |
| 268 false); | |
| 252 } | 269 } |
| 253 | 270 |
| 254 if (uniformBindingUpdateCount) { | 271 if (uniformBindingUpdateCount) { |
| 255 GR_VK_CALL(gpu->vkInterface(), UpdateDescriptorSets(gpu->device(), | 272 GR_VK_CALL(gpu->vkInterface(), UpdateDescriptorSets(gpu->device(), |
| 256 uniformBindingUpdate Count, | 273 uniformBindingUpdate Count, |
| 257 &descriptorWrites[fi rstUniformWrite], | 274 &descriptorWrites[fi rstUniformWrite], |
| 258 0, nullptr)); | 275 0, nullptr)); |
| 259 } | 276 } |
| 260 } | 277 } |
| 261 | 278 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 } | 421 } |
| 405 fCurrentDescriptorSet++; | 422 fCurrentDescriptorSet++; |
| 406 | 423 |
| 407 VkDescriptorSetAllocateInfo dsAllocateInfo; | 424 VkDescriptorSetAllocateInfo dsAllocateInfo; |
| 408 memset(&dsAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo)); | 425 memset(&dsAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo)); |
| 409 dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; | 426 dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 410 dsAllocateInfo.pNext = nullptr; | 427 dsAllocateInfo.pNext = nullptr; |
| 411 dsAllocateInfo.descriptorPool = fPool->descPool(); | 428 dsAllocateInfo.descriptorPool = fPool->descPool(); |
| 412 dsAllocateInfo.descriptorSetCount = 1; | 429 dsAllocateInfo.descriptorSetCount = 1; |
| 413 dsAllocateInfo.pSetLayouts = &fDescLayout; | 430 dsAllocateInfo.pSetLayouts = &fDescLayout; |
| 414 | |
| 415 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), AllocateDescriptorSets(gpu->device() , | 431 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), AllocateDescriptorSets(gpu->device() , |
| 416 &dsAllocateIn fo, | 432 &dsAllocateIn fo, |
| 417 ds)); | 433 ds)); |
| 418 } | 434 } |
| 419 | 435 |
| 420 void GrVkProgram::DescriptorPoolManager::freeGPUResources(const GrVkGpu* gpu) { | 436 void GrVkProgram::DescriptorPoolManager::freeGPUResources(const GrVkGpu* gpu) { |
| 421 if (fDescLayout) { | 437 if (fDescLayout) { |
| 422 GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorSetLayout(gpu->device(), fDescLayout, | 438 GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorSetLayout(gpu->device(), fDescLayout, |
| 423 nullptr)); | 439 nullptr)); |
| 424 fDescLayout = VK_NULL_HANDLE; | 440 fDescLayout = VK_NULL_HANDLE; |
| 425 } | 441 } |
| 426 | 442 |
| 427 if (fPool) { | 443 if (fPool) { |
| 428 fPool->unref(gpu); | 444 fPool->unref(gpu); |
| 429 fPool = nullptr; | 445 fPool = nullptr; |
| 430 } | 446 } |
| 431 } | 447 } |
| 432 | 448 |
| 433 void GrVkProgram::DescriptorPoolManager::abandonGPUResources() { | 449 void GrVkProgram::DescriptorPoolManager::abandonGPUResources() { |
| 434 fDescLayout = VK_NULL_HANDLE; | 450 fDescLayout = VK_NULL_HANDLE; |
| 435 if (fPool) { | 451 if (fPool) { |
| 436 fPool->unrefAndAbandon(); | 452 fPool->unrefAndAbandon(); |
| 437 fPool = nullptr; | 453 fPool = nullptr; |
| 438 } | 454 } |
| 439 } | 455 } |
| 456 | |
| 457 uint32_t get_blend_info_key(const GrPipeline& pipeline) { | |
| 458 GrXferProcessor::BlendInfo blendInfo; | |
| 459 pipeline.getXferProcessor().getBlendInfo(&blendInfo); | |
| 460 | |
| 461 static const uint32_t kBlendWriteShift = 1; | |
| 462 static const uint32_t kBlendCoeffShift = 5; | |
| 463 GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << kBlendCoeffShift)); | |
| 464 GR_STATIC_ASSERT(kFirstAdvancedGrBlendEquation - 1 < 4); | |
| 465 | |
| 466 uint32_t key = blendInfo.fWriteColor; | |
| 467 key |= (blendInfo.fSrcBlend << kBlendWriteShift); | |
| 468 key |= (blendInfo.fDstBlend << (kBlendWriteShift + kBlendCoeffShift)); | |
| 469 key |= (blendInfo.fEquation << (kBlendWriteShift + 2 * kBlendCoeffShift)); | |
| 470 | |
| 471 return key; | |
| 472 } | |
| 473 | |
| 474 void GrVkProgram::BuildVkKey(const GrPipeline& pipeline, GrPrimitiveType primiti veType, | |
| 475 SkTArray<unsigned char, true>* key) { | |
|
bsalomon
2016/03/22 14:00:33
uint8_t in the class and unsigned char here
egdaniel
2016/03/22 20:06:14
Done.
| |
| 476 // Save room for the key length and key header | |
| 477 key->reset(); | |
| 478 key->push_back_n(kData_KeyOffset); | |
| 479 | |
| 480 GrProcessorKeyBuilder b(key); | |
| 481 | |
| 482 GrVkRenderTarget* vkRT = (GrVkRenderTarget*)pipeline.getRenderTarget(); | |
| 483 vkRT->simpleRenderPass()->genKey(&b); | |
| 484 | |
| 485 pipeline.getStencil().genKey(&b); | |
| 486 | |
| 487 SkASSERT(sizeof(GrPipelineBuilder::DrawFace) <= sizeof(uint32_t)); | |
| 488 b.add32(pipeline.getDrawFace()); | |
| 489 | |
| 490 b.add32(get_blend_info_key(pipeline)); | |
| 491 | |
| 492 b.add32(primitiveType); | |
| 493 | |
| 494 // Set key length | |
| 495 int keyLength = key->count(); | |
| 496 SkASSERT(0 == (keyLength % 4)); | |
| 497 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength); | |
| 498 } | |
| OLD | NEW |