| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 inputAssemblyInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_C
REATE_INFO; | 93 inputAssemblyInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_C
REATE_INFO; |
| 94 inputAssemblyInfo->pNext = nullptr; | 94 inputAssemblyInfo->pNext = nullptr; |
| 95 inputAssemblyInfo->flags = 0; | 95 inputAssemblyInfo->flags = 0; |
| 96 inputAssemblyInfo->primitiveRestartEnable = false; | 96 inputAssemblyInfo->primitiveRestartEnable = false; |
| 97 inputAssemblyInfo->topology = gPrimitiveType2VkTopology[primitiveType]; | 97 inputAssemblyInfo->topology = gPrimitiveType2VkTopology[primitiveType]; |
| 98 } | 98 } |
| 99 | 99 |
| 100 | 100 |
| 101 VkStencilOp stencil_op_to_vk_stencil_op(GrStencilOp op) { | 101 VkStencilOp stencil_op_to_vk_stencil_op(GrStencilOp op) { |
| 102 static const VkStencilOp gTable[] = { | 102 static const VkStencilOp gTable[] = { |
| 103 VK_STENCIL_OP_KEEP, // kKeep | 103 VK_STENCIL_OP_KEEP, // kKeep_StencilOp |
| 104 VK_STENCIL_OP_ZERO, // kZero | 104 VK_STENCIL_OP_REPLACE, // kReplace_StencilOp |
| 105 VK_STENCIL_OP_REPLACE, // kReplace | 105 VK_STENCIL_OP_INCREMENT_AND_WRAP, // kIncWrap_StencilOp |
| 106 VK_STENCIL_OP_INVERT, // kInvert | 106 VK_STENCIL_OP_INCREMENT_AND_CLAMP, // kIncClamp_StencilOp |
| 107 VK_STENCIL_OP_INCREMENT_AND_WRAP, // kIncWrap | 107 VK_STENCIL_OP_DECREMENT_AND_WRAP, // kDecWrap_StencilOp |
| 108 VK_STENCIL_OP_DECREMENT_AND_WRAP, // kDecWrap | 108 VK_STENCIL_OP_DECREMENT_AND_CLAMP, // kDecClamp_StencilOp |
| 109 VK_STENCIL_OP_INCREMENT_AND_CLAMP, // kIncClamp | 109 VK_STENCIL_OP_ZERO, // kZero_StencilOp |
| 110 VK_STENCIL_OP_DECREMENT_AND_CLAMP, // kDecClamp | 110 VK_STENCIL_OP_INVERT, // kInvert_StencilOp |
| 111 }; | 111 }; |
| 112 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilOpCount); | 112 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCnt); |
| 113 GR_STATIC_ASSERT(0 == (int)GrStencilOp::kKeep); | 113 GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
| 114 GR_STATIC_ASSERT(1 == (int)GrStencilOp::kZero); | 114 GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
| 115 GR_STATIC_ASSERT(2 == (int)GrStencilOp::kReplace); | 115 GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
| 116 GR_STATIC_ASSERT(3 == (int)GrStencilOp::kInvert); | 116 GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
| 117 GR_STATIC_ASSERT(4 == (int)GrStencilOp::kIncWrap); | 117 GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
| 118 GR_STATIC_ASSERT(5 == (int)GrStencilOp::kDecWrap); | 118 GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
| 119 GR_STATIC_ASSERT(6 == (int)GrStencilOp::kIncClamp); | 119 GR_STATIC_ASSERT(6 == kZero_StencilOp); |
| 120 GR_STATIC_ASSERT(7 == (int)GrStencilOp::kDecClamp); | 120 GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
| 121 SkASSERT(op < (GrStencilOp)kGrStencilOpCount); | 121 SkASSERT((unsigned)op < kStencilOpCnt); |
| 122 return gTable[(int)op]; | 122 return gTable[op]; |
| 123 } | 123 } |
| 124 | 124 |
| 125 VkCompareOp stencil_func_to_vk_compare_op(GrStencilTest test) { | 125 VkCompareOp stencil_func_to_vk_compare_op(GrStencilFunc basicFunc) { |
| 126 static const VkCompareOp gTable[] = { | 126 static const VkCompareOp gTable[] = { |
| 127 VK_COMPARE_OP_ALWAYS, // kAlways | 127 VK_COMPARE_OP_ALWAYS, // kAlways_StencilFunc |
| 128 VK_COMPARE_OP_NEVER, // kNever | 128 VK_COMPARE_OP_NEVER, // kNever_StencilFunc |
| 129 VK_COMPARE_OP_GREATER, // kGreater | 129 VK_COMPARE_OP_GREATER, // kGreater_StencilFunc |
| 130 VK_COMPARE_OP_GREATER_OR_EQUAL, // kGEqual | 130 VK_COMPARE_OP_GREATER_OR_EQUAL, // kGEqual_StencilFunc |
| 131 VK_COMPARE_OP_LESS, // kLess | 131 VK_COMPARE_OP_LESS, // kLess_StencilFunc |
| 132 VK_COMPARE_OP_LESS_OR_EQUAL, // kLEqual | 132 VK_COMPARE_OP_LESS_OR_EQUAL, // kLEqual_StencilFunc, |
| 133 VK_COMPARE_OP_EQUAL, // kEqual | 133 VK_COMPARE_OP_EQUAL, // kEqual_StencilFunc, |
| 134 VK_COMPARE_OP_NOT_EQUAL, // kNotEqual | 134 VK_COMPARE_OP_NOT_EQUAL, // kNotEqual_StencilFunc, |
| 135 }; | 135 }; |
| 136 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilTestCount); | 136 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kBasicStencilFuncCnt); |
| 137 GR_STATIC_ASSERT(0 == (int)GrStencilTest::kAlways); | 137 GR_STATIC_ASSERT(0 == kAlways_StencilFunc); |
| 138 GR_STATIC_ASSERT(1 == (int)GrStencilTest::kNever); | 138 GR_STATIC_ASSERT(1 == kNever_StencilFunc); |
| 139 GR_STATIC_ASSERT(2 == (int)GrStencilTest::kGreater); | 139 GR_STATIC_ASSERT(2 == kGreater_StencilFunc); |
| 140 GR_STATIC_ASSERT(3 == (int)GrStencilTest::kGEqual); | 140 GR_STATIC_ASSERT(3 == kGEqual_StencilFunc); |
| 141 GR_STATIC_ASSERT(4 == (int)GrStencilTest::kLess); | 141 GR_STATIC_ASSERT(4 == kLess_StencilFunc); |
| 142 GR_STATIC_ASSERT(5 == (int)GrStencilTest::kLEqual); | 142 GR_STATIC_ASSERT(5 == kLEqual_StencilFunc); |
| 143 GR_STATIC_ASSERT(6 == (int)GrStencilTest::kEqual); | 143 GR_STATIC_ASSERT(6 == kEqual_StencilFunc); |
| 144 GR_STATIC_ASSERT(7 == (int)GrStencilTest::kNotEqual); | 144 GR_STATIC_ASSERT(7 == kNotEqual_StencilFunc); |
| 145 SkASSERT(test < (GrStencilTest)kGrStencilTestCount); | 145 SkASSERT((unsigned)basicFunc < kBasicStencilFuncCnt); |
| 146 | 146 |
| 147 return gTable[(int)test]; | 147 return gTable[basicFunc]; |
| 148 } | 148 } |
| 149 | 149 |
| 150 void setup_depth_stencil_state(const GrVkGpu* gpu, | 150 void setup_depth_stencil_state(const GrVkGpu* gpu, |
| 151 const GrStencilSettings& stencilSettings, | 151 const GrStencilSettings& stencilSettings, |
| 152 VkPipelineDepthStencilStateCreateInfo* stencilInf
o) { | 152 VkPipelineDepthStencilStateCreateInfo* stencilInf
o) { |
| 153 memset(stencilInfo, 0, sizeof(VkPipelineDepthStencilStateCreateInfo)); | 153 memset(stencilInfo, 0, sizeof(VkPipelineDepthStencilStateCreateInfo)); |
| 154 stencilInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_I
NFO; | 154 stencilInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_I
NFO; |
| 155 stencilInfo->pNext = nullptr; | 155 stencilInfo->pNext = nullptr; |
| 156 stencilInfo->flags = 0; | 156 stencilInfo->flags = 0; |
| 157 // set depth testing defaults | 157 // set depth testing defaults |
| 158 stencilInfo->depthTestEnable = VK_FALSE; | 158 stencilInfo->depthTestEnable = VK_FALSE; |
| 159 stencilInfo->depthWriteEnable = VK_FALSE; | 159 stencilInfo->depthWriteEnable = VK_FALSE; |
| 160 stencilInfo->depthCompareOp = VK_COMPARE_OP_ALWAYS; | 160 stencilInfo->depthCompareOp = VK_COMPARE_OP_ALWAYS; |
| 161 stencilInfo->depthBoundsTestEnable = VK_FALSE; | 161 stencilInfo->depthBoundsTestEnable = VK_FALSE; |
| 162 stencilInfo->stencilTestEnable = !stencilSettings.isDisabled(); | 162 stencilInfo->stencilTestEnable = !stencilSettings.isDisabled(); |
| 163 if (!stencilSettings.isDisabled()) { | 163 if (!stencilSettings.isDisabled()) { |
| 164 // Set front face | 164 // Set front face |
| 165 const GrStencilSettings::Face& front = stencilSettings.front(); | 165 GrStencilSettings::Face face = GrStencilSettings::kFront_Face; |
| 166 stencilInfo->front.failOp = stencil_op_to_vk_stencil_op(front.fFailOp); | 166 stencilInfo->front.failOp = stencil_op_to_vk_stencil_op(stencilSettings.
failOp(face)); |
| 167 stencilInfo->front.passOp = stencil_op_to_vk_stencil_op(front.fPassOp); | 167 stencilInfo->front.passOp = stencil_op_to_vk_stencil_op(stencilSettings.
passOp(face)); |
| 168 stencilInfo->front.depthFailOp = stencilInfo->front.failOp; | 168 stencilInfo->front.depthFailOp = stencilInfo->front.failOp; |
| 169 stencilInfo->front.compareOp = stencil_func_to_vk_compare_op(front.fTest
); | 169 stencilInfo->front.compareOp = stencil_func_to_vk_compare_op(stencilSett
ings.func(face)); |
| 170 stencilInfo->front.compareMask = front.fTestMask; | 170 stencilInfo->front.compareMask = stencilSettings.funcMask(face); |
| 171 stencilInfo->front.writeMask = front.fWriteMask; | 171 stencilInfo->front.writeMask = stencilSettings.writeMask(face); |
| 172 stencilInfo->front.reference = front.fRef; | 172 stencilInfo->front.reference = stencilSettings.funcRef(face); |
| 173 | 173 |
| 174 // Set back face | 174 // Set back face |
| 175 if (!stencilSettings.isTwoSided()) { | 175 face = GrStencilSettings::kBack_Face; |
| 176 stencilInfo->back = stencilInfo->front; | 176 stencilInfo->back.failOp = stencil_op_to_vk_stencil_op(stencilSettings.f
ailOp(face)); |
| 177 } else { | 177 stencilInfo->back.passOp = stencil_op_to_vk_stencil_op(stencilSettings.p
assOp(face)); |
| 178 const GrStencilSettings::Face& back = stencilSettings.back(); | 178 stencilInfo->back.depthFailOp = stencilInfo->front.failOp; |
| 179 stencilInfo->back.failOp = stencil_op_to_vk_stencil_op(back.fFailOp)
; | 179 stencilInfo->back.compareOp = stencil_func_to_vk_compare_op(stencilSetti
ngs.func(face)); |
| 180 stencilInfo->back.passOp = stencil_op_to_vk_stencil_op(back.fPassOp)
; | 180 stencilInfo->back.compareMask = stencilSettings.funcMask(face); |
| 181 stencilInfo->back.depthFailOp = stencilInfo->front.failOp; | 181 stencilInfo->back.writeMask = stencilSettings.writeMask(face); |
| 182 stencilInfo->back.compareOp = stencil_func_to_vk_compare_op(back.fTe
st); | 182 stencilInfo->back.reference = stencilSettings.funcRef(face); |
| 183 stencilInfo->back.compareMask = back.fTestMask; | |
| 184 stencilInfo->back.writeMask = back.fWriteMask; | |
| 185 stencilInfo->back.reference = back.fRef; | |
| 186 } | |
| 187 } | 183 } |
| 188 stencilInfo->minDepthBounds = 0.0f; | 184 stencilInfo->minDepthBounds = 0.0f; |
| 189 stencilInfo->maxDepthBounds = 1.0f; | 185 stencilInfo->maxDepthBounds = 1.0f; |
| 190 } | 186 } |
| 191 | 187 |
| 192 void setup_viewport_scissor_state(const GrVkGpu* gpu, | 188 void setup_viewport_scissor_state(const GrVkGpu* gpu, |
| 193 const GrPipeline& pipeline, | 189 const GrPipeline& pipeline, |
| 194 const GrVkRenderTarget* vkRT, | 190 const GrVkRenderTarget* vkRT, |
| 195 VkPipelineViewportStateCreateInfo* viewportInf
o) { | 191 VkPipelineViewportStateCreateInfo* viewportInf
o) { |
| 196 memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo)); | 192 memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo)); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 548 } |
| 553 | 549 |
| 554 void GrVkPipeline::SetDynamicState(GrVkGpu* gpu, | 550 void GrVkPipeline::SetDynamicState(GrVkGpu* gpu, |
| 555 GrVkCommandBuffer* cmdBuffer, | 551 GrVkCommandBuffer* cmdBuffer, |
| 556 const GrPipeline& pipeline) { | 552 const GrPipeline& pipeline) { |
| 557 const GrRenderTarget& target = *pipeline.getRenderTarget(); | 553 const GrRenderTarget& target = *pipeline.getRenderTarget(); |
| 558 set_dynamic_scissor_state(gpu, cmdBuffer, pipeline, target); | 554 set_dynamic_scissor_state(gpu, cmdBuffer, pipeline, target); |
| 559 set_dynamic_viewport_state(gpu, cmdBuffer, target); | 555 set_dynamic_viewport_state(gpu, cmdBuffer, target); |
| 560 set_dynamic_blend_constant_state(gpu, cmdBuffer, pipeline); | 556 set_dynamic_blend_constant_state(gpu, cmdBuffer, pipeline); |
| 561 } | 557 } |
| OLD | NEW |