| 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 "GrVkPipeline.h" | 8 #include "GrVkPipeline.h" |
| 9 | 9 |
| 10 #include "GrGeometryProcessor.h" | 10 #include "GrGeometryProcessor.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); | 34 GR_STATIC_ASSERT(5 == kVec4ub_GrVertexAttribType); |
| 35 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType); | 35 GR_STATIC_ASSERT(6 == kVec2us_GrVertexAttribType); |
| 36 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFormats) == kGrVertexAttribTypeCount); | 36 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFormats) == kGrVertexAttribTypeCount); |
| 37 return kFormats[type]; | 37 return kFormats[type]; |
| 38 } | 38 } |
| 39 | 39 |
| 40 static void setup_vertex_input_state(const GrPrimitiveProcessor& primProc, | 40 static void setup_vertex_input_state(const GrPrimitiveProcessor& primProc, |
| 41 VkPipelineVertexInputStateCreateInfo* verte
xInputInfo, | 41 VkPipelineVertexInputStateCreateInfo* verte
xInputInfo, |
| 42 VkVertexInputBindingDescription* bindingDes
c, | 42 VkVertexInputBindingDescription* bindingDes
c, |
| 43 int maxBindingDescCount, | 43 int maxBindingDescCount, |
| 44 VkVertexInputAttributeDescription* attribut
eDesc, | 44 VkVertexInputAttributeDescription* attribut
eDesc) { |
| 45 int maxAttributeDescCount) { | |
| 46 // for now we have only one vertex buffer and one binding | 45 // for now we have only one vertex buffer and one binding |
| 47 memset(bindingDesc, 0, sizeof(VkVertexInputBindingDescription)); | 46 memset(bindingDesc, 0, sizeof(VkVertexInputBindingDescription)); |
| 48 bindingDesc->binding = 0; | 47 bindingDesc->binding = 0; |
| 49 bindingDesc->stride = (uint32_t)primProc.getVertexStride(); | 48 bindingDesc->stride = (uint32_t)primProc.getVertexStride(); |
| 50 bindingDesc->inputRate = VK_VERTEX_INPUT_RATE_VERTEX; | 49 bindingDesc->inputRate = VK_VERTEX_INPUT_RATE_VERTEX; |
| 51 | 50 |
| 52 // setup attribute descriptions | 51 // setup attribute descriptions |
| 53 int vaCount = primProc.numAttribs(); | 52 int vaCount = primProc.numAttribs(); |
| 54 SkASSERT(vaCount < maxAttributeDescCount); | |
| 55 if (vaCount > 0) { | 53 if (vaCount > 0) { |
| 56 size_t offset = 0; | 54 size_t offset = 0; |
| 57 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { | 55 for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { |
| 58 const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(at
tribIndex); | 56 const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(at
tribIndex); |
| 59 GrVertexAttribType attribType = attrib.fType; | 57 GrVertexAttribType attribType = attrib.fType; |
| 60 | 58 |
| 61 VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIn
dex]; | 59 VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIn
dex]; |
| 62 vkAttrib.location = attribIndex; // for now assume location = attrib
Index | 60 vkAttrib.location = attribIndex; // for now assume location = attrib
Index |
| 63 vkAttrib.binding = 0; // for now only one vertex buffer & binding | 61 vkAttrib.binding = 0; // for now only one vertex buffer & binding |
| 64 vkAttrib.format = attrib_type_to_vkformat(attribType); | 62 vkAttrib.format = attrib_type_to_vkformat(attribType); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 GrVkPipeline* GrVkPipeline::Create(GrVkGpu* gpu, const GrPipeline& pipeline, | 408 GrVkPipeline* GrVkPipeline::Create(GrVkGpu* gpu, const GrPipeline& pipeline, |
| 411 const GrPrimitiveProcessor& primProc, | 409 const GrPrimitiveProcessor& primProc, |
| 412 VkPipelineShaderStageCreateInfo* shaderStageI
nfo, | 410 VkPipelineShaderStageCreateInfo* shaderStageI
nfo, |
| 413 int shaderStageCount, | 411 int shaderStageCount, |
| 414 GrPrimitiveType primitiveType, | 412 GrPrimitiveType primitiveType, |
| 415 const GrVkRenderPass& renderPass, | 413 const GrVkRenderPass& renderPass, |
| 416 VkPipelineLayout layout, | 414 VkPipelineLayout layout, |
| 417 VkPipelineCache cache) { | 415 VkPipelineCache cache) { |
| 418 VkPipelineVertexInputStateCreateInfo vertexInputInfo; | 416 VkPipelineVertexInputStateCreateInfo vertexInputInfo; |
| 419 VkVertexInputBindingDescription bindingDesc; | 417 VkVertexInputBindingDescription bindingDesc; |
| 420 // TODO: allocate this based on VkPhysicalDeviceLimits::maxVertexInputAttrib
utes | 418 SkSTArray<16, VkVertexInputAttributeDescription> attributeDesc; |
| 421 static const int kMaxVertexAttributes = 16; | 419 SkASSERT(primProc.numAttribs() <= gpu->vkCaps().maxVertexAttributes()); |
| 422 static VkVertexInputAttributeDescription attributeDesc[kMaxVertexAttributes]
; | 420 VkVertexInputAttributeDescription* pAttribs = attributeDesc.push_back_n(prim
Proc.numAttribs()); |
| 423 setup_vertex_input_state(primProc, &vertexInputInfo, &bindingDesc, 1, | 421 setup_vertex_input_state(primProc, &vertexInputInfo, &bindingDesc, 1, pAttri
bs); |
| 424 attributeDesc, kMaxVertexAttributes); | |
| 425 | 422 |
| 426 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo; | 423 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo; |
| 427 setup_input_assembly_state(primitiveType, &inputAssemblyInfo); | 424 setup_input_assembly_state(primitiveType, &inputAssemblyInfo); |
| 428 | 425 |
| 429 VkPipelineDepthStencilStateCreateInfo depthStencilInfo; | 426 VkPipelineDepthStencilStateCreateInfo depthStencilInfo; |
| 430 setup_depth_stencil_state(gpu, pipeline.getStencil(), &depthStencilInfo); | 427 setup_depth_stencil_state(gpu, pipeline.getStencil(), &depthStencilInfo); |
| 431 | 428 |
| 432 GrRenderTarget* rt = pipeline.getRenderTarget(); | 429 GrRenderTarget* rt = pipeline.getRenderTarget(); |
| 433 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); | 430 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); |
| 434 VkPipelineViewportStateCreateInfo viewportInfo; | 431 VkPipelineViewportStateCreateInfo viewportInfo; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 549 } |
| 553 | 550 |
| 554 void GrVkPipeline::SetDynamicState(GrVkGpu* gpu, | 551 void GrVkPipeline::SetDynamicState(GrVkGpu* gpu, |
| 555 GrVkCommandBuffer* cmdBuffer, | 552 GrVkCommandBuffer* cmdBuffer, |
| 556 const GrPipeline& pipeline) { | 553 const GrPipeline& pipeline) { |
| 557 const GrRenderTarget& target = *pipeline.getRenderTarget(); | 554 const GrRenderTarget& target = *pipeline.getRenderTarget(); |
| 558 set_dynamic_scissor_state(gpu, cmdBuffer, pipeline, target); | 555 set_dynamic_scissor_state(gpu, cmdBuffer, pipeline, target); |
| 559 set_dynamic_viewport_state(gpu, cmdBuffer, target); | 556 set_dynamic_viewport_state(gpu, cmdBuffer, target); |
| 560 set_dynamic_blend_constant_state(gpu, cmdBuffer, pipeline); | 557 set_dynamic_blend_constant_state(gpu, cmdBuffer, pipeline); |
| 561 } | 558 } |
| OLD | NEW |