Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrVkPipeline.h" |
| 9 | |
| 10 | #include "GrGeometryProcessor.h" |
| 11 | #include "GrPipeline.h" |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 12 | #include "GrVkCommandBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 13 | #include "GrVkGpu.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 14 | #include "GrVkRenderTarget.h" |
| 15 | #include "GrVkUtil.h" |
| 16 | |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 17 | static inline VkFormat attrib_type_to_vkformat(GrVertexAttribType type) { |
| 18 | switch (type) { |
| 19 | case kFloat_GrVertexAttribType: |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 20 | case kHalf_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 21 | return VK_FORMAT_R32_SFLOAT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 22 | case kFloat2_GrVertexAttribType: |
| 23 | case kHalf2_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 24 | return VK_FORMAT_R32G32_SFLOAT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 25 | case kFloat3_GrVertexAttribType: |
| 26 | case kHalf3_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 27 | return VK_FORMAT_R32G32B32_SFLOAT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 28 | case kFloat4_GrVertexAttribType: |
| 29 | case kHalf4_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 30 | return VK_FORMAT_R32G32B32A32_SFLOAT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 31 | case kInt2_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 32 | return VK_FORMAT_R32G32_SINT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 33 | case kInt3_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 34 | return VK_FORMAT_R32G32B32_SINT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 35 | case kInt4_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 36 | return VK_FORMAT_R32G32B32A32_SINT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 37 | case kUByte_norm_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 38 | return VK_FORMAT_R8_UNORM; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 39 | case kUByte4_norm_GrVertexAttribType: |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 40 | return VK_FORMAT_R8G8B8A8_UNORM; |
Chris Dalton | a045eea | 2017-10-24 13:22:10 -0600 | [diff] [blame] | 41 | case kShort2_GrVertexAttribType: |
| 42 | return VK_FORMAT_R16G16_SINT; |
Ethan Nicholas | fa7ee24 | 2017-09-25 09:52:04 -0400 | [diff] [blame] | 43 | case kUShort2_GrVertexAttribType: |
Robert Phillips | 8296e75 | 2017-08-25 08:45:21 -0400 | [diff] [blame] | 44 | return VK_FORMAT_R16G16_UINT; |
Chris Dalton | a045eea | 2017-10-24 13:22:10 -0600 | [diff] [blame] | 45 | case kUShort2_norm_GrVertexAttribType: |
| 46 | return VK_FORMAT_R16G16_UNORM; |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 47 | case kInt_GrVertexAttribType: |
| 48 | return VK_FORMAT_R32_SINT; |
| 49 | case kUint_GrVertexAttribType: |
| 50 | return VK_FORMAT_R32_UINT; |
| 51 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 52 | SK_ABORT("Unknown vertex attrib type"); |
csmartdalton | b37cb23 | 2017-02-08 14:56:27 -0500 | [diff] [blame] | 53 | return VK_FORMAT_UNDEFINED; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static void setup_vertex_input_state(const GrPrimitiveProcessor& primProc, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 57 | VkPipelineVertexInputStateCreateInfo* vertexInputInfo, |
| 58 | SkSTArray<2, VkVertexInputBindingDescription, true>* bindingDescs, |
| 59 | VkVertexInputAttributeDescription* attributeDesc) { |
Kevin Lubick | 4284613 | 2018-01-05 10:11:11 -0500 | [diff] [blame] | 60 | uint32_t vertexBinding = 0, instanceBinding = 0; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 61 | |
| 62 | if (primProc.hasVertexAttribs()) { |
| 63 | vertexBinding = bindingDescs->count(); |
| 64 | bindingDescs->push_back() = { |
| 65 | vertexBinding, |
| 66 | (uint32_t) primProc.getVertexStride(), |
| 67 | VK_VERTEX_INPUT_RATE_VERTEX |
| 68 | }; |
| 69 | } |
| 70 | |
| 71 | if (primProc.hasInstanceAttribs()) { |
| 72 | instanceBinding = bindingDescs->count(); |
| 73 | bindingDescs->push_back() = { |
| 74 | instanceBinding, |
| 75 | (uint32_t) primProc.getInstanceStride(), |
| 76 | VK_VERTEX_INPUT_RATE_INSTANCE |
| 77 | }; |
| 78 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 79 | |
| 80 | // setup attribute descriptions |
| 81 | int vaCount = primProc.numAttribs(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 82 | if (vaCount > 0) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 83 | for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 84 | using InputRate = GrPrimitiveProcessor::Attribute::InputRate; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 85 | const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(attribIndex); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 86 | VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIndex]; |
| 87 | vkAttrib.location = attribIndex; // for now assume location = attribIndex |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 88 | vkAttrib.binding = InputRate::kPerInstance == attrib.fInputRate ? instanceBinding |
| 89 | : vertexBinding; |
| 90 | vkAttrib.format = attrib_type_to_vkformat(attrib.fType); |
| 91 | vkAttrib.offset = attrib.fOffsetInRecord; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | memset(vertexInputInfo, 0, sizeof(VkPipelineVertexInputStateCreateInfo)); |
| 96 | vertexInputInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 97 | vertexInputInfo->pNext = nullptr; |
| 98 | vertexInputInfo->flags = 0; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 99 | vertexInputInfo->vertexBindingDescriptionCount = bindingDescs->count(); |
| 100 | vertexInputInfo->pVertexBindingDescriptions = bindingDescs->begin(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 101 | vertexInputInfo->vertexAttributeDescriptionCount = vaCount; |
| 102 | vertexInputInfo->pVertexAttributeDescriptions = attributeDesc; |
| 103 | } |
| 104 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 105 | static VkPrimitiveTopology gr_primitive_type_to_vk_topology(GrPrimitiveType primitiveType) { |
| 106 | switch (primitiveType) { |
| 107 | case GrPrimitiveType::kTriangles: |
| 108 | return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; |
| 109 | case GrPrimitiveType::kTriangleStrip: |
| 110 | return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 111 | case GrPrimitiveType::kTriangleFan: |
| 112 | return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN; |
| 113 | case GrPrimitiveType::kPoints: |
| 114 | return VK_PRIMITIVE_TOPOLOGY_POINT_LIST; |
| 115 | case GrPrimitiveType::kLines: |
| 116 | return VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 117 | case GrPrimitiveType::kLineStrip: |
| 118 | return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP; |
| 119 | case GrPrimitiveType::kLinesAdjacency: |
| 120 | return VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY; |
| 121 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 122 | SK_ABORT("invalid GrPrimitiveType"); |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 123 | return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; |
| 124 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 125 | |
| 126 | static void setup_input_assembly_state(GrPrimitiveType primitiveType, |
| 127 | VkPipelineInputAssemblyStateCreateInfo* inputAssemblyInfo) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 128 | memset(inputAssemblyInfo, 0, sizeof(VkPipelineInputAssemblyStateCreateInfo)); |
| 129 | inputAssemblyInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 130 | inputAssemblyInfo->pNext = nullptr; |
| 131 | inputAssemblyInfo->flags = 0; |
| 132 | inputAssemblyInfo->primitiveRestartEnable = false; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 133 | inputAssemblyInfo->topology = gr_primitive_type_to_vk_topology(primitiveType); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 137 | static VkStencilOp stencil_op_to_vk_stencil_op(GrStencilOp op) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 138 | static const VkStencilOp gTable[] = { |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 139 | VK_STENCIL_OP_KEEP, // kKeep |
| 140 | VK_STENCIL_OP_ZERO, // kZero |
| 141 | VK_STENCIL_OP_REPLACE, // kReplace |
| 142 | VK_STENCIL_OP_INVERT, // kInvert |
| 143 | VK_STENCIL_OP_INCREMENT_AND_WRAP, // kIncWrap |
| 144 | VK_STENCIL_OP_DECREMENT_AND_WRAP, // kDecWrap |
| 145 | VK_STENCIL_OP_INCREMENT_AND_CLAMP, // kIncClamp |
| 146 | VK_STENCIL_OP_DECREMENT_AND_CLAMP, // kDecClamp |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 147 | }; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 148 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilOpCount); |
| 149 | GR_STATIC_ASSERT(0 == (int)GrStencilOp::kKeep); |
| 150 | GR_STATIC_ASSERT(1 == (int)GrStencilOp::kZero); |
| 151 | GR_STATIC_ASSERT(2 == (int)GrStencilOp::kReplace); |
| 152 | GR_STATIC_ASSERT(3 == (int)GrStencilOp::kInvert); |
| 153 | GR_STATIC_ASSERT(4 == (int)GrStencilOp::kIncWrap); |
| 154 | GR_STATIC_ASSERT(5 == (int)GrStencilOp::kDecWrap); |
| 155 | GR_STATIC_ASSERT(6 == (int)GrStencilOp::kIncClamp); |
| 156 | GR_STATIC_ASSERT(7 == (int)GrStencilOp::kDecClamp); |
| 157 | SkASSERT(op < (GrStencilOp)kGrStencilOpCount); |
| 158 | return gTable[(int)op]; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 159 | } |
| 160 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 161 | static VkCompareOp stencil_func_to_vk_compare_op(GrStencilTest test) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 162 | static const VkCompareOp gTable[] = { |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 163 | VK_COMPARE_OP_ALWAYS, // kAlways |
| 164 | VK_COMPARE_OP_NEVER, // kNever |
| 165 | VK_COMPARE_OP_GREATER, // kGreater |
| 166 | VK_COMPARE_OP_GREATER_OR_EQUAL, // kGEqual |
| 167 | VK_COMPARE_OP_LESS, // kLess |
| 168 | VK_COMPARE_OP_LESS_OR_EQUAL, // kLEqual |
| 169 | VK_COMPARE_OP_EQUAL, // kEqual |
| 170 | VK_COMPARE_OP_NOT_EQUAL, // kNotEqual |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 171 | }; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 172 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilTestCount); |
| 173 | GR_STATIC_ASSERT(0 == (int)GrStencilTest::kAlways); |
| 174 | GR_STATIC_ASSERT(1 == (int)GrStencilTest::kNever); |
| 175 | GR_STATIC_ASSERT(2 == (int)GrStencilTest::kGreater); |
| 176 | GR_STATIC_ASSERT(3 == (int)GrStencilTest::kGEqual); |
| 177 | GR_STATIC_ASSERT(4 == (int)GrStencilTest::kLess); |
| 178 | GR_STATIC_ASSERT(5 == (int)GrStencilTest::kLEqual); |
| 179 | GR_STATIC_ASSERT(6 == (int)GrStencilTest::kEqual); |
| 180 | GR_STATIC_ASSERT(7 == (int)GrStencilTest::kNotEqual); |
| 181 | SkASSERT(test < (GrStencilTest)kGrStencilTestCount); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 182 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 183 | return gTable[(int)test]; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 184 | } |
| 185 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 186 | static void setup_depth_stencil_state(const GrStencilSettings& stencilSettings, |
| 187 | VkPipelineDepthStencilStateCreateInfo* stencilInfo) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 188 | memset(stencilInfo, 0, sizeof(VkPipelineDepthStencilStateCreateInfo)); |
| 189 | stencilInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
| 190 | stencilInfo->pNext = nullptr; |
| 191 | stencilInfo->flags = 0; |
| 192 | // set depth testing defaults |
| 193 | stencilInfo->depthTestEnable = VK_FALSE; |
| 194 | stencilInfo->depthWriteEnable = VK_FALSE; |
| 195 | stencilInfo->depthCompareOp = VK_COMPARE_OP_ALWAYS; |
| 196 | stencilInfo->depthBoundsTestEnable = VK_FALSE; |
| 197 | stencilInfo->stencilTestEnable = !stencilSettings.isDisabled(); |
| 198 | if (!stencilSettings.isDisabled()) { |
| 199 | // Set front face |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 200 | const GrStencilSettings::Face& front = stencilSettings.front(); |
| 201 | stencilInfo->front.failOp = stencil_op_to_vk_stencil_op(front.fFailOp); |
| 202 | stencilInfo->front.passOp = stencil_op_to_vk_stencil_op(front.fPassOp); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 203 | stencilInfo->front.depthFailOp = stencilInfo->front.failOp; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 204 | stencilInfo->front.compareOp = stencil_func_to_vk_compare_op(front.fTest); |
| 205 | stencilInfo->front.compareMask = front.fTestMask; |
| 206 | stencilInfo->front.writeMask = front.fWriteMask; |
| 207 | stencilInfo->front.reference = front.fRef; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 208 | |
| 209 | // Set back face |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 210 | if (!stencilSettings.isTwoSided()) { |
| 211 | stencilInfo->back = stencilInfo->front; |
| 212 | } else { |
| 213 | const GrStencilSettings::Face& back = stencilSettings.back(); |
| 214 | stencilInfo->back.failOp = stencil_op_to_vk_stencil_op(back.fFailOp); |
| 215 | stencilInfo->back.passOp = stencil_op_to_vk_stencil_op(back.fPassOp); |
| 216 | stencilInfo->back.depthFailOp = stencilInfo->front.failOp; |
| 217 | stencilInfo->back.compareOp = stencil_func_to_vk_compare_op(back.fTest); |
| 218 | stencilInfo->back.compareMask = back.fTestMask; |
| 219 | stencilInfo->back.writeMask = back.fWriteMask; |
| 220 | stencilInfo->back.reference = back.fRef; |
| 221 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 222 | } |
| 223 | stencilInfo->minDepthBounds = 0.0f; |
| 224 | stencilInfo->maxDepthBounds = 1.0f; |
| 225 | } |
| 226 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 227 | static void setup_viewport_scissor_state(VkPipelineViewportStateCreateInfo* viewportInfo) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 228 | memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo)); |
| 229 | viewportInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 230 | viewportInfo->pNext = nullptr; |
| 231 | viewportInfo->flags = 0; |
| 232 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 233 | viewportInfo->viewportCount = 1; |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 234 | viewportInfo->pViewports = nullptr; // This is set dynamically |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 235 | |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 236 | viewportInfo->scissorCount = 1; |
| 237 | viewportInfo->pScissors = nullptr; // This is set dynamically |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 238 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 239 | SkASSERT(viewportInfo->viewportCount == viewportInfo->scissorCount); |
| 240 | } |
| 241 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 242 | static void setup_multisample_state(const GrPipeline& pipeline, |
| 243 | const GrPrimitiveProcessor& primProc, |
| 244 | const GrCaps* caps, |
| 245 | VkPipelineMultisampleStateCreateInfo* multisampleInfo) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 246 | memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo)); |
| 247 | multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 248 | multisampleInfo->pNext = nullptr; |
| 249 | multisampleInfo->flags = 0; |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 250 | int numSamples = pipeline.proxy()->numColorSamples(); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 251 | SkAssertResult(GrSampleCountToVkSampleCount(numSamples, |
| 252 | &multisampleInfo->rasterizationSamples)); |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 253 | float sampleShading = primProc.getSampleShading(); |
| 254 | SkASSERT(sampleShading == 0.0f || caps->sampleShadingSupport()); |
| 255 | multisampleInfo->sampleShadingEnable = sampleShading > 0.0f; |
| 256 | multisampleInfo->minSampleShading = sampleShading; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 257 | multisampleInfo->pSampleMask = nullptr; |
| 258 | multisampleInfo->alphaToCoverageEnable = VK_FALSE; |
| 259 | multisampleInfo->alphaToOneEnable = VK_FALSE; |
| 260 | } |
| 261 | |
| 262 | static VkBlendFactor blend_coeff_to_vk_blend(GrBlendCoeff coeff) { |
| 263 | static const VkBlendFactor gTable[] = { |
| 264 | VK_BLEND_FACTOR_ZERO, // kZero_GrBlendCoeff |
| 265 | VK_BLEND_FACTOR_ONE, // kOne_GrBlendCoeff |
| 266 | VK_BLEND_FACTOR_SRC_COLOR, // kSC_GrBlendCoeff |
| 267 | VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR, // kISC_GrBlendCoeff |
| 268 | VK_BLEND_FACTOR_DST_COLOR, // kDC_GrBlendCoeff |
| 269 | VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR, // kIDC_GrBlendCoeff |
| 270 | VK_BLEND_FACTOR_SRC_ALPHA, // kSA_GrBlendCoeff |
| 271 | VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // kISA_GrBlendCoeff |
| 272 | VK_BLEND_FACTOR_DST_ALPHA, // kDA_GrBlendCoeff |
| 273 | VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA, // kIDA_GrBlendCoeff |
| 274 | VK_BLEND_FACTOR_CONSTANT_COLOR, // kConstC_GrBlendCoeff |
| 275 | VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR, // kIConstC_GrBlendCoeff |
| 276 | VK_BLEND_FACTOR_CONSTANT_ALPHA, // kConstA_GrBlendCoeff |
| 277 | VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA, // kIConstA_GrBlendCoeff |
| 278 | VK_BLEND_FACTOR_SRC1_COLOR, // kS2C_GrBlendCoeff |
| 279 | VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR, // kIS2C_GrBlendCoeff |
| 280 | VK_BLEND_FACTOR_SRC1_ALPHA, // kS2A_GrBlendCoeff |
| 281 | VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA, // kIS2A_GrBlendCoeff |
| 282 | |
| 283 | }; |
| 284 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrBlendCoeffCnt); |
| 285 | GR_STATIC_ASSERT(0 == kZero_GrBlendCoeff); |
| 286 | GR_STATIC_ASSERT(1 == kOne_GrBlendCoeff); |
| 287 | GR_STATIC_ASSERT(2 == kSC_GrBlendCoeff); |
| 288 | GR_STATIC_ASSERT(3 == kISC_GrBlendCoeff); |
| 289 | GR_STATIC_ASSERT(4 == kDC_GrBlendCoeff); |
| 290 | GR_STATIC_ASSERT(5 == kIDC_GrBlendCoeff); |
| 291 | GR_STATIC_ASSERT(6 == kSA_GrBlendCoeff); |
| 292 | GR_STATIC_ASSERT(7 == kISA_GrBlendCoeff); |
| 293 | GR_STATIC_ASSERT(8 == kDA_GrBlendCoeff); |
| 294 | GR_STATIC_ASSERT(9 == kIDA_GrBlendCoeff); |
| 295 | GR_STATIC_ASSERT(10 == kConstC_GrBlendCoeff); |
| 296 | GR_STATIC_ASSERT(11 == kIConstC_GrBlendCoeff); |
| 297 | GR_STATIC_ASSERT(12 == kConstA_GrBlendCoeff); |
| 298 | GR_STATIC_ASSERT(13 == kIConstA_GrBlendCoeff); |
| 299 | GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff); |
| 300 | GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); |
| 301 | GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); |
| 302 | GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); |
| 303 | |
| 304 | SkASSERT((unsigned)coeff < kGrBlendCoeffCnt); |
| 305 | return gTable[coeff]; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | static VkBlendOp blend_equation_to_vk_blend_op(GrBlendEquation equation) { |
| 310 | static const VkBlendOp gTable[] = { |
| 311 | VK_BLEND_OP_ADD, // kAdd_GrBlendEquation |
| 312 | VK_BLEND_OP_SUBTRACT, // kSubtract_GrBlendEquation |
| 313 | VK_BLEND_OP_REVERSE_SUBTRACT, // kReverseSubtract_GrBlendEquation |
| 314 | }; |
| 315 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kFirstAdvancedGrBlendEquation); |
| 316 | GR_STATIC_ASSERT(0 == kAdd_GrBlendEquation); |
| 317 | GR_STATIC_ASSERT(1 == kSubtract_GrBlendEquation); |
| 318 | GR_STATIC_ASSERT(2 == kReverseSubtract_GrBlendEquation); |
| 319 | |
| 320 | SkASSERT((unsigned)equation < kGrBlendCoeffCnt); |
| 321 | return gTable[equation]; |
| 322 | } |
| 323 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 324 | static bool blend_coeff_refs_constant(GrBlendCoeff coeff) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 325 | static const bool gCoeffReferencesBlendConst[] = { |
| 326 | false, |
| 327 | false, |
| 328 | false, |
| 329 | false, |
| 330 | false, |
| 331 | false, |
| 332 | false, |
| 333 | false, |
| 334 | false, |
| 335 | false, |
| 336 | true, |
| 337 | true, |
| 338 | true, |
| 339 | true, |
| 340 | |
| 341 | // extended blend coeffs |
| 342 | false, |
| 343 | false, |
| 344 | false, |
| 345 | false, |
| 346 | }; |
| 347 | return gCoeffReferencesBlendConst[coeff]; |
| 348 | GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendConst)); |
| 349 | // Individual enum asserts already made in blend_coeff_to_vk_blend |
| 350 | } |
| 351 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 352 | static void setup_color_blend_state(const GrPipeline& pipeline, |
| 353 | VkPipelineColorBlendStateCreateInfo* colorBlendInfo, |
| 354 | VkPipelineColorBlendAttachmentState* attachmentState) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 355 | GrXferProcessor::BlendInfo blendInfo; |
| 356 | pipeline.getXferProcessor().getBlendInfo(&blendInfo); |
| 357 | |
| 358 | GrBlendEquation equation = blendInfo.fEquation; |
| 359 | GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
| 360 | GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
| 361 | bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquation == equation) && |
| 362 | kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff; |
| 363 | |
| 364 | memset(attachmentState, 0, sizeof(VkPipelineColorBlendAttachmentState)); |
| 365 | attachmentState->blendEnable = !blendOff; |
| 366 | if (!blendOff) { |
| 367 | attachmentState->srcColorBlendFactor = blend_coeff_to_vk_blend(srcCoeff); |
| 368 | attachmentState->dstColorBlendFactor = blend_coeff_to_vk_blend(dstCoeff); |
| 369 | attachmentState->colorBlendOp = blend_equation_to_vk_blend_op(equation); |
| 370 | attachmentState->srcAlphaBlendFactor = blend_coeff_to_vk_blend(srcCoeff); |
| 371 | attachmentState->dstAlphaBlendFactor = blend_coeff_to_vk_blend(dstCoeff); |
| 372 | attachmentState->alphaBlendOp = blend_equation_to_vk_blend_op(equation); |
| 373 | } |
egdaniel | 3d5d9ac | 2016-03-01 12:56:15 -0800 | [diff] [blame] | 374 | |
| 375 | if (!blendInfo.fWriteColor) { |
| 376 | attachmentState->colorWriteMask = 0; |
| 377 | } else { |
| 378 | attachmentState->colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | |
| 379 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; |
| 380 | } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 381 | |
| 382 | memset(colorBlendInfo, 0, sizeof(VkPipelineColorBlendStateCreateInfo)); |
| 383 | colorBlendInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 384 | colorBlendInfo->pNext = nullptr; |
| 385 | colorBlendInfo->flags = 0; |
| 386 | colorBlendInfo->logicOpEnable = VK_FALSE; |
| 387 | colorBlendInfo->attachmentCount = 1; |
| 388 | colorBlendInfo->pAttachments = attachmentState; |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 389 | // colorBlendInfo->blendConstants is set dynamically |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 390 | } |
| 391 | |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 392 | static void setup_raster_state(const GrPipeline& pipeline, |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 393 | const GrCaps* caps, |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 394 | VkPipelineRasterizationStateCreateInfo* rasterInfo) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 395 | memset(rasterInfo, 0, sizeof(VkPipelineRasterizationStateCreateInfo)); |
| 396 | rasterInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 397 | rasterInfo->pNext = nullptr; |
| 398 | rasterInfo->flags = 0; |
| 399 | rasterInfo->depthClampEnable = VK_FALSE; |
| 400 | rasterInfo->rasterizerDiscardEnable = VK_FALSE; |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 401 | rasterInfo->polygonMode = caps->wireframeMode() ? VK_POLYGON_MODE_LINE |
| 402 | : VK_POLYGON_MODE_FILL; |
Brian Salomon | f086167 | 2017-05-08 11:10:10 -0400 | [diff] [blame] | 403 | rasterInfo->cullMode = VK_CULL_MODE_NONE; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 404 | rasterInfo->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 405 | rasterInfo->depthBiasEnable = VK_FALSE; |
| 406 | rasterInfo->depthBiasConstantFactor = 0.0f; |
| 407 | rasterInfo->depthBiasClamp = 0.0f; |
| 408 | rasterInfo->depthBiasSlopeFactor = 0.0f; |
| 409 | rasterInfo->lineWidth = 1.0f; |
| 410 | } |
| 411 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 412 | static void setup_dynamic_state(VkPipelineDynamicStateCreateInfo* dynamicInfo, |
| 413 | VkDynamicState* dynamicStates) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 414 | memset(dynamicInfo, 0, sizeof(VkPipelineDynamicStateCreateInfo)); |
| 415 | dynamicInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 416 | dynamicInfo->pNext = VK_NULL_HANDLE; |
| 417 | dynamicInfo->flags = 0; |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 418 | dynamicStates[0] = VK_DYNAMIC_STATE_VIEWPORT; |
| 419 | dynamicStates[1] = VK_DYNAMIC_STATE_SCISSOR; |
| 420 | dynamicStates[2] = VK_DYNAMIC_STATE_BLEND_CONSTANTS; |
| 421 | dynamicInfo->dynamicStateCount = 3; |
| 422 | dynamicInfo->pDynamicStates = dynamicStates; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | GrVkPipeline* GrVkPipeline::Create(GrVkGpu* gpu, const GrPipeline& pipeline, |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 426 | const GrStencilSettings& stencil, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 427 | const GrPrimitiveProcessor& primProc, |
| 428 | VkPipelineShaderStageCreateInfo* shaderStageInfo, |
| 429 | int shaderStageCount, |
| 430 | GrPrimitiveType primitiveType, |
| 431 | const GrVkRenderPass& renderPass, |
jvanverth | 03509ea | 2016-03-02 13:19:47 -0800 | [diff] [blame] | 432 | VkPipelineLayout layout, |
| 433 | VkPipelineCache cache) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 434 | VkPipelineVertexInputStateCreateInfo vertexInputInfo; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 435 | SkSTArray<2, VkVertexInputBindingDescription, true> bindingDescs; |
egdaniel | b05df0f | 2016-06-27 07:15:20 -0700 | [diff] [blame] | 436 | SkSTArray<16, VkVertexInputAttributeDescription> attributeDesc; |
| 437 | SkASSERT(primProc.numAttribs() <= gpu->vkCaps().maxVertexAttributes()); |
| 438 | VkVertexInputAttributeDescription* pAttribs = attributeDesc.push_back_n(primProc.numAttribs()); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 439 | setup_vertex_input_state(primProc, &vertexInputInfo, &bindingDescs, pAttribs); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 440 | |
| 441 | VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo; |
| 442 | setup_input_assembly_state(primitiveType, &inputAssemblyInfo); |
| 443 | |
| 444 | VkPipelineDepthStencilStateCreateInfo depthStencilInfo; |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 445 | setup_depth_stencil_state(stencil, &depthStencilInfo); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 446 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 447 | VkPipelineViewportStateCreateInfo viewportInfo; |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 448 | setup_viewport_scissor_state(&viewportInfo); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 449 | |
| 450 | VkPipelineMultisampleStateCreateInfo multisampleInfo; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 451 | setup_multisample_state(pipeline, primProc, gpu->caps(), &multisampleInfo); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 452 | |
| 453 | // We will only have one color attachment per pipeline. |
| 454 | VkPipelineColorBlendAttachmentState attachmentStates[1]; |
| 455 | VkPipelineColorBlendStateCreateInfo colorBlendInfo; |
egdaniel | ec44099 | 2016-09-13 09:54:11 -0700 | [diff] [blame] | 456 | setup_color_blend_state(pipeline, &colorBlendInfo, attachmentStates); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 457 | |
| 458 | VkPipelineRasterizationStateCreateInfo rasterInfo; |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 459 | setup_raster_state(pipeline, gpu->caps(), &rasterInfo); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 460 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 461 | VkDynamicState dynamicStates[3]; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 462 | VkPipelineDynamicStateCreateInfo dynamicInfo; |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 463 | setup_dynamic_state(&dynamicInfo, dynamicStates); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 464 | |
| 465 | VkGraphicsPipelineCreateInfo pipelineCreateInfo; |
| 466 | memset(&pipelineCreateInfo, 0, sizeof(VkGraphicsPipelineCreateInfo)); |
| 467 | pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 468 | pipelineCreateInfo.pNext = nullptr; |
| 469 | pipelineCreateInfo.flags = 0; |
| 470 | pipelineCreateInfo.stageCount = shaderStageCount; |
| 471 | pipelineCreateInfo.pStages = shaderStageInfo; |
| 472 | pipelineCreateInfo.pVertexInputState = &vertexInputInfo; |
| 473 | pipelineCreateInfo.pInputAssemblyState = &inputAssemblyInfo; |
| 474 | pipelineCreateInfo.pTessellationState = nullptr; |
| 475 | pipelineCreateInfo.pViewportState = &viewportInfo; |
| 476 | pipelineCreateInfo.pRasterizationState = &rasterInfo; |
| 477 | pipelineCreateInfo.pMultisampleState = &multisampleInfo; |
| 478 | pipelineCreateInfo.pDepthStencilState = &depthStencilInfo; |
| 479 | pipelineCreateInfo.pColorBlendState = &colorBlendInfo; |
| 480 | pipelineCreateInfo.pDynamicState = &dynamicInfo; |
| 481 | pipelineCreateInfo.layout = layout; |
| 482 | pipelineCreateInfo.renderPass = renderPass.vkRenderPass(); |
| 483 | pipelineCreateInfo.subpass = 0; |
| 484 | pipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE; |
| 485 | pipelineCreateInfo.basePipelineIndex = -1; |
| 486 | |
| 487 | VkPipeline vkPipeline; |
| 488 | VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateGraphicsPipelines(gpu->device(), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 489 | cache, 1, |
| 490 | &pipelineCreateInfo, |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 491 | nullptr, &vkPipeline)); |
| 492 | if (err) { |
Greg Daniel | 5ba448c | 2018-02-26 13:30:47 -0500 | [diff] [blame^] | 493 | SkDebugf("Failed to create pipeline. Error: %d\n", err); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 494 | return nullptr; |
| 495 | } |
| 496 | |
| 497 | return new GrVkPipeline(vkPipeline); |
| 498 | } |
| 499 | |
| 500 | void GrVkPipeline::freeGPUData(const GrVkGpu* gpu) const { |
| 501 | GR_VK_CALL(gpu->vkInterface(), DestroyPipeline(gpu->device(), fPipeline, nullptr)); |
| 502 | } |
| 503 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 504 | void GrVkPipeline::SetDynamicScissorRectState(GrVkGpu* gpu, |
| 505 | GrVkCommandBuffer* cmdBuffer, |
| 506 | const GrRenderTarget* renderTarget, |
| 507 | GrSurfaceOrigin rtOrigin, |
| 508 | SkIRect scissorRect) { |
| 509 | if (!scissorRect.intersect(SkIRect::MakeWH(renderTarget->width(), renderTarget->height()))) { |
| 510 | scissorRect.setEmpty(); |
| 511 | } |
| 512 | |
| 513 | VkRect2D scissor; |
| 514 | scissor.offset.x = scissorRect.fLeft; |
| 515 | scissor.extent.width = scissorRect.width(); |
| 516 | if (kTopLeft_GrSurfaceOrigin == rtOrigin) { |
| 517 | scissor.offset.y = scissorRect.fTop; |
| 518 | } else { |
| 519 | SkASSERT(kBottomLeft_GrSurfaceOrigin == rtOrigin); |
| 520 | scissor.offset.y = renderTarget->height() - scissorRect.fBottom; |
| 521 | } |
| 522 | scissor.extent.height = scissorRect.height(); |
| 523 | |
| 524 | SkASSERT(scissor.offset.x >= 0); |
| 525 | SkASSERT(scissor.offset.y >= 0); |
| 526 | cmdBuffer->setScissor(gpu, 0, 1, &scissor); |
| 527 | } |
| 528 | |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 529 | void GrVkPipeline::SetDynamicViewportState(GrVkGpu* gpu, |
| 530 | GrVkCommandBuffer* cmdBuffer, |
| 531 | const GrRenderTarget* renderTarget) { |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 532 | // We always use one viewport the size of the RT |
| 533 | VkViewport viewport; |
| 534 | viewport.x = 0.0f; |
| 535 | viewport.y = 0.0f; |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 536 | viewport.width = SkIntToScalar(renderTarget->width()); |
| 537 | viewport.height = SkIntToScalar(renderTarget->height()); |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 538 | viewport.minDepth = 0.0f; |
| 539 | viewport.maxDepth = 1.0f; |
| 540 | cmdBuffer->setViewport(gpu, 0, 1, &viewport); |
| 541 | } |
| 542 | |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 543 | void GrVkPipeline::SetDynamicBlendConstantState(GrVkGpu* gpu, |
| 544 | GrVkCommandBuffer* cmdBuffer, |
| 545 | GrPixelConfig pixelConfig, |
| 546 | const GrXferProcessor& xferProcessor) { |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 547 | GrXferProcessor::BlendInfo blendInfo; |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 548 | xferProcessor.getBlendInfo(&blendInfo); |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 549 | GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
| 550 | GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
| 551 | float floatColors[4]; |
| 552 | if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoeff)) { |
Greg Daniel | 6c9f101 | 2017-05-11 09:20:59 -0400 | [diff] [blame] | 553 | // Swizzle the blend to match what the shader will output. |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 554 | const GrSwizzle& swizzle = gpu->caps()->shaderCaps()->configOutputSwizzle(pixelConfig); |
Greg Daniel | 6c9f101 | 2017-05-11 09:20:59 -0400 | [diff] [blame] | 555 | GrColor blendConst = swizzle.applyTo(blendInfo.fBlendConstant); |
| 556 | GrColorToRGBAFloat(blendConst, floatColors); |
egdaniel | 470d77a | 2016-03-18 12:50:27 -0700 | [diff] [blame] | 557 | } else { |
| 558 | memset(floatColors, 0, 4 * sizeof(float)); |
| 559 | } |
| 560 | cmdBuffer->setBlendConstants(gpu, floatColors); |
| 561 | } |