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

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

Issue 2336763002: Lots of little cleanup improvements to Vulkan (Closed)
Patch Set: [ Created 4 years, 3 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
« no previous file with comments | « src/gpu/vk/GrVkGpuCommandBuffer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "GrVkPipeline.h" 8 #include "GrVkPipeline.h"
9 9
10 #include "GrGeometryProcessor.h" 10 #include "GrGeometryProcessor.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 memset(inputAssemblyInfo, 0, sizeof(VkPipelineInputAssemblyStateCreateInfo)) ; 89 memset(inputAssemblyInfo, 0, sizeof(VkPipelineInputAssemblyStateCreateInfo)) ;
90 inputAssemblyInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_C REATE_INFO; 90 inputAssemblyInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_C REATE_INFO;
91 inputAssemblyInfo->pNext = nullptr; 91 inputAssemblyInfo->pNext = nullptr;
92 inputAssemblyInfo->flags = 0; 92 inputAssemblyInfo->flags = 0;
93 inputAssemblyInfo->primitiveRestartEnable = false; 93 inputAssemblyInfo->primitiveRestartEnable = false;
94 inputAssemblyInfo->topology = gPrimitiveType2VkTopology[primitiveType]; 94 inputAssemblyInfo->topology = gPrimitiveType2VkTopology[primitiveType];
95 } 95 }
96 96
97 97
98 VkStencilOp stencil_op_to_vk_stencil_op(GrStencilOp op) { 98 static VkStencilOp stencil_op_to_vk_stencil_op(GrStencilOp op) {
99 static const VkStencilOp gTable[] = { 99 static const VkStencilOp gTable[] = {
100 VK_STENCIL_OP_KEEP, // kKeep 100 VK_STENCIL_OP_KEEP, // kKeep
101 VK_STENCIL_OP_ZERO, // kZero 101 VK_STENCIL_OP_ZERO, // kZero
102 VK_STENCIL_OP_REPLACE, // kReplace 102 VK_STENCIL_OP_REPLACE, // kReplace
103 VK_STENCIL_OP_INVERT, // kInvert 103 VK_STENCIL_OP_INVERT, // kInvert
104 VK_STENCIL_OP_INCREMENT_AND_WRAP, // kIncWrap 104 VK_STENCIL_OP_INCREMENT_AND_WRAP, // kIncWrap
105 VK_STENCIL_OP_DECREMENT_AND_WRAP, // kDecWrap 105 VK_STENCIL_OP_DECREMENT_AND_WRAP, // kDecWrap
106 VK_STENCIL_OP_INCREMENT_AND_CLAMP, // kIncClamp 106 VK_STENCIL_OP_INCREMENT_AND_CLAMP, // kIncClamp
107 VK_STENCIL_OP_DECREMENT_AND_CLAMP, // kDecClamp 107 VK_STENCIL_OP_DECREMENT_AND_CLAMP, // kDecClamp
108 }; 108 };
109 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilOpCount); 109 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilOpCount);
110 GR_STATIC_ASSERT(0 == (int)GrStencilOp::kKeep); 110 GR_STATIC_ASSERT(0 == (int)GrStencilOp::kKeep);
111 GR_STATIC_ASSERT(1 == (int)GrStencilOp::kZero); 111 GR_STATIC_ASSERT(1 == (int)GrStencilOp::kZero);
112 GR_STATIC_ASSERT(2 == (int)GrStencilOp::kReplace); 112 GR_STATIC_ASSERT(2 == (int)GrStencilOp::kReplace);
113 GR_STATIC_ASSERT(3 == (int)GrStencilOp::kInvert); 113 GR_STATIC_ASSERT(3 == (int)GrStencilOp::kInvert);
114 GR_STATIC_ASSERT(4 == (int)GrStencilOp::kIncWrap); 114 GR_STATIC_ASSERT(4 == (int)GrStencilOp::kIncWrap);
115 GR_STATIC_ASSERT(5 == (int)GrStencilOp::kDecWrap); 115 GR_STATIC_ASSERT(5 == (int)GrStencilOp::kDecWrap);
116 GR_STATIC_ASSERT(6 == (int)GrStencilOp::kIncClamp); 116 GR_STATIC_ASSERT(6 == (int)GrStencilOp::kIncClamp);
117 GR_STATIC_ASSERT(7 == (int)GrStencilOp::kDecClamp); 117 GR_STATIC_ASSERT(7 == (int)GrStencilOp::kDecClamp);
118 SkASSERT(op < (GrStencilOp)kGrStencilOpCount); 118 SkASSERT(op < (GrStencilOp)kGrStencilOpCount);
119 return gTable[(int)op]; 119 return gTable[(int)op];
120 } 120 }
121 121
122 VkCompareOp stencil_func_to_vk_compare_op(GrStencilTest test) { 122 static VkCompareOp stencil_func_to_vk_compare_op(GrStencilTest test) {
123 static const VkCompareOp gTable[] = { 123 static const VkCompareOp gTable[] = {
124 VK_COMPARE_OP_ALWAYS, // kAlways 124 VK_COMPARE_OP_ALWAYS, // kAlways
125 VK_COMPARE_OP_NEVER, // kNever 125 VK_COMPARE_OP_NEVER, // kNever
126 VK_COMPARE_OP_GREATER, // kGreater 126 VK_COMPARE_OP_GREATER, // kGreater
127 VK_COMPARE_OP_GREATER_OR_EQUAL, // kGEqual 127 VK_COMPARE_OP_GREATER_OR_EQUAL, // kGEqual
128 VK_COMPARE_OP_LESS, // kLess 128 VK_COMPARE_OP_LESS, // kLess
129 VK_COMPARE_OP_LESS_OR_EQUAL, // kLEqual 129 VK_COMPARE_OP_LESS_OR_EQUAL, // kLEqual
130 VK_COMPARE_OP_EQUAL, // kEqual 130 VK_COMPARE_OP_EQUAL, // kEqual
131 VK_COMPARE_OP_NOT_EQUAL, // kNotEqual 131 VK_COMPARE_OP_NOT_EQUAL, // kNotEqual
132 }; 132 };
133 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilTestCount); 133 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kGrStencilTestCount);
134 GR_STATIC_ASSERT(0 == (int)GrStencilTest::kAlways); 134 GR_STATIC_ASSERT(0 == (int)GrStencilTest::kAlways);
135 GR_STATIC_ASSERT(1 == (int)GrStencilTest::kNever); 135 GR_STATIC_ASSERT(1 == (int)GrStencilTest::kNever);
136 GR_STATIC_ASSERT(2 == (int)GrStencilTest::kGreater); 136 GR_STATIC_ASSERT(2 == (int)GrStencilTest::kGreater);
137 GR_STATIC_ASSERT(3 == (int)GrStencilTest::kGEqual); 137 GR_STATIC_ASSERT(3 == (int)GrStencilTest::kGEqual);
138 GR_STATIC_ASSERT(4 == (int)GrStencilTest::kLess); 138 GR_STATIC_ASSERT(4 == (int)GrStencilTest::kLess);
139 GR_STATIC_ASSERT(5 == (int)GrStencilTest::kLEqual); 139 GR_STATIC_ASSERT(5 == (int)GrStencilTest::kLEqual);
140 GR_STATIC_ASSERT(6 == (int)GrStencilTest::kEqual); 140 GR_STATIC_ASSERT(6 == (int)GrStencilTest::kEqual);
141 GR_STATIC_ASSERT(7 == (int)GrStencilTest::kNotEqual); 141 GR_STATIC_ASSERT(7 == (int)GrStencilTest::kNotEqual);
142 SkASSERT(test < (GrStencilTest)kGrStencilTestCount); 142 SkASSERT(test < (GrStencilTest)kGrStencilTestCount);
143 143
144 return gTable[(int)test]; 144 return gTable[(int)test];
145 } 145 }
146 146
147 void setup_depth_stencil_state(const GrVkGpu* gpu, 147 static void setup_depth_stencil_state(const GrStencilSettings& stencilSettings,
148 const GrStencilSettings& stencilSettings, 148 VkPipelineDepthStencilStateCreateInfo* ste ncilInfo) {
149 VkPipelineDepthStencilStateCreateInfo* stencilInf o) {
150 memset(stencilInfo, 0, sizeof(VkPipelineDepthStencilStateCreateInfo)); 149 memset(stencilInfo, 0, sizeof(VkPipelineDepthStencilStateCreateInfo));
151 stencilInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_I NFO; 150 stencilInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_I NFO;
152 stencilInfo->pNext = nullptr; 151 stencilInfo->pNext = nullptr;
153 stencilInfo->flags = 0; 152 stencilInfo->flags = 0;
154 // set depth testing defaults 153 // set depth testing defaults
155 stencilInfo->depthTestEnable = VK_FALSE; 154 stencilInfo->depthTestEnable = VK_FALSE;
156 stencilInfo->depthWriteEnable = VK_FALSE; 155 stencilInfo->depthWriteEnable = VK_FALSE;
157 stencilInfo->depthCompareOp = VK_COMPARE_OP_ALWAYS; 156 stencilInfo->depthCompareOp = VK_COMPARE_OP_ALWAYS;
158 stencilInfo->depthBoundsTestEnable = VK_FALSE; 157 stencilInfo->depthBoundsTestEnable = VK_FALSE;
159 stencilInfo->stencilTestEnable = !stencilSettings.isDisabled(); 158 stencilInfo->stencilTestEnable = !stencilSettings.isDisabled();
(...skipping 19 matching lines...) Expand all
179 stencilInfo->back.compareOp = stencil_func_to_vk_compare_op(back.fTe st); 178 stencilInfo->back.compareOp = stencil_func_to_vk_compare_op(back.fTe st);
180 stencilInfo->back.compareMask = back.fTestMask; 179 stencilInfo->back.compareMask = back.fTestMask;
181 stencilInfo->back.writeMask = back.fWriteMask; 180 stencilInfo->back.writeMask = back.fWriteMask;
182 stencilInfo->back.reference = back.fRef; 181 stencilInfo->back.reference = back.fRef;
183 } 182 }
184 } 183 }
185 stencilInfo->minDepthBounds = 0.0f; 184 stencilInfo->minDepthBounds = 0.0f;
186 stencilInfo->maxDepthBounds = 1.0f; 185 stencilInfo->maxDepthBounds = 1.0f;
187 } 186 }
188 187
189 void setup_viewport_scissor_state(const GrVkGpu* gpu, 188 static void setup_viewport_scissor_state(VkPipelineViewportStateCreateInfo* view portInfo) {
190 const GrPipeline& pipeline,
191 const GrVkRenderTarget* vkRT,
192 VkPipelineViewportStateCreateInfo* viewportInf o) {
193 memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo)); 189 memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo));
194 viewportInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; 190 viewportInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
195 viewportInfo->pNext = nullptr; 191 viewportInfo->pNext = nullptr;
196 viewportInfo->flags = 0; 192 viewportInfo->flags = 0;
197 193
198 viewportInfo->viewportCount = 1; 194 viewportInfo->viewportCount = 1;
199 viewportInfo->pViewports = nullptr; // This is set dynamically 195 viewportInfo->pViewports = nullptr; // This is set dynamically
200 196
201 viewportInfo->scissorCount = 1; 197 viewportInfo->scissorCount = 1;
202 viewportInfo->pScissors = nullptr; // This is set dynamically 198 viewportInfo->pScissors = nullptr; // This is set dynamically
203 199
204 SkASSERT(viewportInfo->viewportCount == viewportInfo->scissorCount); 200 SkASSERT(viewportInfo->viewportCount == viewportInfo->scissorCount);
205 } 201 }
206 202
207 void setup_multisample_state(const GrPipeline& pipeline, 203 static void setup_multisample_state(const GrPipeline& pipeline,
208 const GrPrimitiveProcessor& primProc, 204 const GrPrimitiveProcessor& primProc,
209 const GrCaps* caps, 205 const GrCaps* caps,
210 VkPipelineMultisampleStateCreateInfo* multisampleIn fo) { 206 VkPipelineMultisampleStateCreateInfo* multis ampleInfo) {
211 memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo)); 207 memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo));
212 multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE _INFO; 208 multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE _INFO;
213 multisampleInfo->pNext = nullptr; 209 multisampleInfo->pNext = nullptr;
214 multisampleInfo->flags = 0; 210 multisampleInfo->flags = 0;
215 int numSamples = pipeline.getRenderTarget()->numColorSamples(); 211 int numSamples = pipeline.getRenderTarget()->numColorSamples();
216 SkAssertResult(GrSampleCountToVkSampleCount(numSamples, 212 SkAssertResult(GrSampleCountToVkSampleCount(numSamples,
217 &multisampleInfo->rasterizationSamples)); 213 &multisampleInfo->rasterizationSamples));
218 float sampleShading = primProc.getSampleShading(); 214 float sampleShading = primProc.getSampleShading();
219 SkASSERT(sampleShading == 0.0f || caps->sampleShadingSupport()); 215 SkASSERT(sampleShading == 0.0f || caps->sampleShadingSupport());
220 multisampleInfo->sampleShadingEnable = sampleShading > 0.0f; 216 multisampleInfo->sampleShadingEnable = sampleShading > 0.0f;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 }; 275 };
280 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kFirstAdvancedGrBlendEquation); 276 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kFirstAdvancedGrBlendEquation);
281 GR_STATIC_ASSERT(0 == kAdd_GrBlendEquation); 277 GR_STATIC_ASSERT(0 == kAdd_GrBlendEquation);
282 GR_STATIC_ASSERT(1 == kSubtract_GrBlendEquation); 278 GR_STATIC_ASSERT(1 == kSubtract_GrBlendEquation);
283 GR_STATIC_ASSERT(2 == kReverseSubtract_GrBlendEquation); 279 GR_STATIC_ASSERT(2 == kReverseSubtract_GrBlendEquation);
284 280
285 SkASSERT((unsigned)equation < kGrBlendCoeffCnt); 281 SkASSERT((unsigned)equation < kGrBlendCoeffCnt);
286 return gTable[equation]; 282 return gTable[equation];
287 } 283 }
288 284
289 bool blend_coeff_refs_constant(GrBlendCoeff coeff) { 285 static bool blend_coeff_refs_constant(GrBlendCoeff coeff) {
290 static const bool gCoeffReferencesBlendConst[] = { 286 static const bool gCoeffReferencesBlendConst[] = {
291 false, 287 false,
292 false, 288 false,
293 false, 289 false,
294 false, 290 false,
295 false, 291 false,
296 false, 292 false,
297 false, 293 false,
298 false, 294 false,
299 false, 295 false,
300 false, 296 false,
301 true, 297 true,
302 true, 298 true,
303 true, 299 true,
304 true, 300 true,
305 301
306 // extended blend coeffs 302 // extended blend coeffs
307 false, 303 false,
308 false, 304 false,
309 false, 305 false,
310 false, 306 false,
311 }; 307 };
312 return gCoeffReferencesBlendConst[coeff]; 308 return gCoeffReferencesBlendConst[coeff];
313 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendCon st)); 309 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendCon st));
314 // Individual enum asserts already made in blend_coeff_to_vk_blend 310 // Individual enum asserts already made in blend_coeff_to_vk_blend
315 } 311 }
316 312
317 void setup_color_blend_state(const GrVkGpu* gpu, 313 static void setup_color_blend_state(const GrPipeline& pipeline,
318 const GrPipeline& pipeline, 314 VkPipelineColorBlendStateCreateInfo* colorBl endInfo,
319 VkPipelineColorBlendStateCreateInfo* colorBlendInfo , 315 VkPipelineColorBlendAttachmentState* attachm entState) {
320 VkPipelineColorBlendAttachmentState* attachmentStat e) {
321 GrXferProcessor::BlendInfo blendInfo; 316 GrXferProcessor::BlendInfo blendInfo;
322 pipeline.getXferProcessor().getBlendInfo(&blendInfo); 317 pipeline.getXferProcessor().getBlendInfo(&blendInfo);
323 318
324 GrBlendEquation equation = blendInfo.fEquation; 319 GrBlendEquation equation = blendInfo.fEquation;
325 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; 320 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
326 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; 321 GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
327 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) && 322 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) &&
328 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff; 323 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff;
329 324
330 memset(attachmentState, 0, sizeof(VkPipelineColorBlendAttachmentState)); 325 memset(attachmentState, 0, sizeof(VkPipelineColorBlendAttachmentState));
(...skipping 17 matching lines...) Expand all
348 memset(colorBlendInfo, 0, sizeof(VkPipelineColorBlendStateCreateInfo)); 343 memset(colorBlendInfo, 0, sizeof(VkPipelineColorBlendStateCreateInfo));
349 colorBlendInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_ INFO; 344 colorBlendInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_ INFO;
350 colorBlendInfo->pNext = nullptr; 345 colorBlendInfo->pNext = nullptr;
351 colorBlendInfo->flags = 0; 346 colorBlendInfo->flags = 0;
352 colorBlendInfo->logicOpEnable = VK_FALSE; 347 colorBlendInfo->logicOpEnable = VK_FALSE;
353 colorBlendInfo->attachmentCount = 1; 348 colorBlendInfo->attachmentCount = 1;
354 colorBlendInfo->pAttachments = attachmentState; 349 colorBlendInfo->pAttachments = attachmentState;
355 // colorBlendInfo->blendConstants is set dynamically 350 // colorBlendInfo->blendConstants is set dynamically
356 } 351 }
357 352
358 VkCullModeFlags draw_face_to_vk_cull_mode(GrDrawFace drawFace) { 353 static VkCullModeFlags draw_face_to_vk_cull_mode(GrDrawFace drawFace) {
359 // Assumes that we've set the front face to be ccw 354 // Assumes that we've set the front face to be ccw
360 static const VkCullModeFlags gTable[] = { 355 static const VkCullModeFlags gTable[] = {
361 VK_CULL_MODE_NONE, // kBoth_DrawFace 356 VK_CULL_MODE_NONE, // kBoth_DrawFace
362 VK_CULL_MODE_BACK_BIT, // kCCW_DrawFace, cull back face 357 VK_CULL_MODE_BACK_BIT, // kCCW_DrawFace, cull back face
363 VK_CULL_MODE_FRONT_BIT, // kCW_DrawFace, cull front face 358 VK_CULL_MODE_FRONT_BIT, // kCW_DrawFace, cull front face
364 }; 359 };
365 GR_STATIC_ASSERT(0 == (int)GrDrawFace::kBoth); 360 GR_STATIC_ASSERT(0 == (int)GrDrawFace::kBoth);
366 GR_STATIC_ASSERT(1 == (int)GrDrawFace::kCCW); 361 GR_STATIC_ASSERT(1 == (int)GrDrawFace::kCCW);
367 GR_STATIC_ASSERT(2 == (int)GrDrawFace::kCW); 362 GR_STATIC_ASSERT(2 == (int)GrDrawFace::kCW);
368 SkASSERT(-1 < (int)drawFace && (int)drawFace <= 2); 363 SkASSERT(-1 < (int)drawFace && (int)drawFace <= 2);
369 364
370 return gTable[(int)drawFace]; 365 return gTable[(int)drawFace];
371 } 366 }
372 367
373 void setup_raster_state(const GrVkGpu* gpu, 368 static void setup_raster_state(const GrPipeline& pipeline,
374 const GrPipeline& pipeline, 369 VkPipelineRasterizationStateCreateInfo* rasterInf o) {
375 VkPipelineRasterizationStateCreateInfo* rasterInfo) {
376 memset(rasterInfo, 0, sizeof(VkPipelineRasterizationStateCreateInfo)); 370 memset(rasterInfo, 0, sizeof(VkPipelineRasterizationStateCreateInfo));
377 rasterInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_IN FO; 371 rasterInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_IN FO;
378 rasterInfo->pNext = nullptr; 372 rasterInfo->pNext = nullptr;
379 rasterInfo->flags = 0; 373 rasterInfo->flags = 0;
380 rasterInfo->depthClampEnable = VK_FALSE; 374 rasterInfo->depthClampEnable = VK_FALSE;
381 rasterInfo->rasterizerDiscardEnable = VK_FALSE; 375 rasterInfo->rasterizerDiscardEnable = VK_FALSE;
382 rasterInfo->polygonMode = VK_POLYGON_MODE_FILL; 376 rasterInfo->polygonMode = VK_POLYGON_MODE_FILL;
383 rasterInfo->cullMode = draw_face_to_vk_cull_mode(pipeline.getDrawFace()); 377 rasterInfo->cullMode = draw_face_to_vk_cull_mode(pipeline.getDrawFace());
384 rasterInfo->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; 378 rasterInfo->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
385 rasterInfo->depthBiasEnable = VK_FALSE; 379 rasterInfo->depthBiasEnable = VK_FALSE;
386 rasterInfo->depthBiasConstantFactor = 0.0f; 380 rasterInfo->depthBiasConstantFactor = 0.0f;
387 rasterInfo->depthBiasClamp = 0.0f; 381 rasterInfo->depthBiasClamp = 0.0f;
388 rasterInfo->depthBiasSlopeFactor = 0.0f; 382 rasterInfo->depthBiasSlopeFactor = 0.0f;
389 rasterInfo->lineWidth = 1.0f; 383 rasterInfo->lineWidth = 1.0f;
390 } 384 }
391 385
392 void setup_dynamic_state(const GrVkGpu* gpu, 386 static void setup_dynamic_state(VkPipelineDynamicStateCreateInfo* dynamicInfo,
393 const GrPipeline& pipeline, 387 VkDynamicState* dynamicStates) {
394 VkPipelineDynamicStateCreateInfo* dynamicInfo,
395 VkDynamicState* dynamicStates) {
396 memset(dynamicInfo, 0, sizeof(VkPipelineDynamicStateCreateInfo)); 388 memset(dynamicInfo, 0, sizeof(VkPipelineDynamicStateCreateInfo));
397 dynamicInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; 389 dynamicInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
398 dynamicInfo->pNext = VK_NULL_HANDLE; 390 dynamicInfo->pNext = VK_NULL_HANDLE;
399 dynamicInfo->flags = 0; 391 dynamicInfo->flags = 0;
400 dynamicStates[0] = VK_DYNAMIC_STATE_VIEWPORT; 392 dynamicStates[0] = VK_DYNAMIC_STATE_VIEWPORT;
401 dynamicStates[1] = VK_DYNAMIC_STATE_SCISSOR; 393 dynamicStates[1] = VK_DYNAMIC_STATE_SCISSOR;
402 dynamicStates[2] = VK_DYNAMIC_STATE_BLEND_CONSTANTS; 394 dynamicStates[2] = VK_DYNAMIC_STATE_BLEND_CONSTANTS;
403 dynamicInfo->dynamicStateCount = 3; 395 dynamicInfo->dynamicStateCount = 3;
404 dynamicInfo->pDynamicStates = dynamicStates; 396 dynamicInfo->pDynamicStates = dynamicStates;
405 } 397 }
(...skipping 10 matching lines...) Expand all
416 VkVertexInputBindingDescription bindingDesc; 408 VkVertexInputBindingDescription bindingDesc;
417 SkSTArray<16, VkVertexInputAttributeDescription> attributeDesc; 409 SkSTArray<16, VkVertexInputAttributeDescription> attributeDesc;
418 SkASSERT(primProc.numAttribs() <= gpu->vkCaps().maxVertexAttributes()); 410 SkASSERT(primProc.numAttribs() <= gpu->vkCaps().maxVertexAttributes());
419 VkVertexInputAttributeDescription* pAttribs = attributeDesc.push_back_n(prim Proc.numAttribs()); 411 VkVertexInputAttributeDescription* pAttribs = attributeDesc.push_back_n(prim Proc.numAttribs());
420 setup_vertex_input_state(primProc, &vertexInputInfo, &bindingDesc, 1, pAttri bs); 412 setup_vertex_input_state(primProc, &vertexInputInfo, &bindingDesc, 1, pAttri bs);
421 413
422 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo; 414 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo;
423 setup_input_assembly_state(primitiveType, &inputAssemblyInfo); 415 setup_input_assembly_state(primitiveType, &inputAssemblyInfo);
424 416
425 VkPipelineDepthStencilStateCreateInfo depthStencilInfo; 417 VkPipelineDepthStencilStateCreateInfo depthStencilInfo;
426 setup_depth_stencil_state(gpu, pipeline.getStencil(), &depthStencilInfo); 418 setup_depth_stencil_state(pipeline.getStencil(), &depthStencilInfo);
427 419
428 GrRenderTarget* rt = pipeline.getRenderTarget();
429 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt);
430 VkPipelineViewportStateCreateInfo viewportInfo; 420 VkPipelineViewportStateCreateInfo viewportInfo;
431 setup_viewport_scissor_state(gpu, pipeline, vkRT, &viewportInfo); 421 setup_viewport_scissor_state(&viewportInfo);
432 422
433 VkPipelineMultisampleStateCreateInfo multisampleInfo; 423 VkPipelineMultisampleStateCreateInfo multisampleInfo;
434 setup_multisample_state(pipeline, primProc, gpu->caps(), &multisampleInfo); 424 setup_multisample_state(pipeline, primProc, gpu->caps(), &multisampleInfo);
435 425
436 // We will only have one color attachment per pipeline. 426 // We will only have one color attachment per pipeline.
437 VkPipelineColorBlendAttachmentState attachmentStates[1]; 427 VkPipelineColorBlendAttachmentState attachmentStates[1];
438 VkPipelineColorBlendStateCreateInfo colorBlendInfo; 428 VkPipelineColorBlendStateCreateInfo colorBlendInfo;
439 setup_color_blend_state(gpu, pipeline, &colorBlendInfo, attachmentStates); 429 setup_color_blend_state(pipeline, &colorBlendInfo, attachmentStates);
440 430
441 VkPipelineRasterizationStateCreateInfo rasterInfo; 431 VkPipelineRasterizationStateCreateInfo rasterInfo;
442 setup_raster_state(gpu, pipeline, &rasterInfo); 432 setup_raster_state(pipeline, &rasterInfo);
443 433
444 VkDynamicState dynamicStates[3]; 434 VkDynamicState dynamicStates[3];
445 VkPipelineDynamicStateCreateInfo dynamicInfo; 435 VkPipelineDynamicStateCreateInfo dynamicInfo;
446 setup_dynamic_state(gpu, pipeline, &dynamicInfo, dynamicStates); 436 setup_dynamic_state(&dynamicInfo, dynamicStates);
447 437
448 VkGraphicsPipelineCreateInfo pipelineCreateInfo; 438 VkGraphicsPipelineCreateInfo pipelineCreateInfo;
449 memset(&pipelineCreateInfo, 0, sizeof(VkGraphicsPipelineCreateInfo)); 439 memset(&pipelineCreateInfo, 0, sizeof(VkGraphicsPipelineCreateInfo));
450 pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; 440 pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
451 pipelineCreateInfo.pNext = nullptr; 441 pipelineCreateInfo.pNext = nullptr;
452 pipelineCreateInfo.flags = 0; 442 pipelineCreateInfo.flags = 0;
453 pipelineCreateInfo.stageCount = shaderStageCount; 443 pipelineCreateInfo.stageCount = shaderStageCount;
454 pipelineCreateInfo.pStages = shaderStageInfo; 444 pipelineCreateInfo.pStages = shaderStageInfo;
455 pipelineCreateInfo.pVertexInputState = &vertexInputInfo; 445 pipelineCreateInfo.pVertexInputState = &vertexInputInfo;
456 pipelineCreateInfo.pInputAssemblyState = &inputAssemblyInfo; 446 pipelineCreateInfo.pInputAssemblyState = &inputAssemblyInfo;
(...skipping 19 matching lines...) Expand all
476 return nullptr; 466 return nullptr;
477 } 467 }
478 468
479 return new GrVkPipeline(vkPipeline); 469 return new GrVkPipeline(vkPipeline);
480 } 470 }
481 471
482 void GrVkPipeline::freeGPUData(const GrVkGpu* gpu) const { 472 void GrVkPipeline::freeGPUData(const GrVkGpu* gpu) const {
483 GR_VK_CALL(gpu->vkInterface(), DestroyPipeline(gpu->device(), fPipeline, nul lptr)); 473 GR_VK_CALL(gpu->vkInterface(), DestroyPipeline(gpu->device(), fPipeline, nul lptr));
484 } 474 }
485 475
486 void set_dynamic_scissor_state(GrVkGpu* gpu, 476 static void set_dynamic_scissor_state(GrVkGpu* gpu,
487 GrVkCommandBuffer* cmdBuffer, 477 GrVkCommandBuffer* cmdBuffer,
488 const GrPipeline& pipeline, 478 const GrPipeline& pipeline,
489 const GrRenderTarget& target) { 479 const GrRenderTarget& target) {
490 // We always use one scissor and if it is disabled we just make it the size of the RT 480 // We always use one scissor and if it is disabled we just make it the size of the RT
491 const GrScissorState& scissorState = pipeline.getScissorState(); 481 const GrScissorState& scissorState = pipeline.getScissorState();
492 VkRect2D scissor; 482 VkRect2D scissor;
493 if (scissorState.enabled() && 483 if (scissorState.enabled() &&
494 !scissorState.rect().contains(0, 0, target.width(), target.height())) { 484 !scissorState.rect().contains(0, 0, target.width(), target.height())) {
495 // This all assumes the scissorState has previously been clipped to the device space render 485 // This all assumes the scissorState has previously been clipped to the device space render
496 // target. 486 // target.
497 scissor.offset.x = SkTMax(scissorState.rect().fLeft, 0); 487 scissor.offset.x = SkTMax(scissorState.rect().fLeft, 0);
498 scissor.extent.width = scissorState.rect().width(); 488 scissor.extent.width = scissorState.rect().width();
499 if (kTopLeft_GrSurfaceOrigin == target.origin()) { 489 if (kTopLeft_GrSurfaceOrigin == target.origin()) {
500 scissor.offset.y = scissorState.rect().fTop; 490 scissor.offset.y = scissorState.rect().fTop;
501 } else { 491 } else {
502 SkASSERT(kBottomLeft_GrSurfaceOrigin == target.origin()); 492 SkASSERT(kBottomLeft_GrSurfaceOrigin == target.origin());
503 scissor.offset.y = target.height() - scissorState.rect().fBottom; 493 scissor.offset.y = target.height() - scissorState.rect().fBottom;
504 } 494 }
505 scissor.offset.y = SkTMax(scissor.offset.y, 0); 495 scissor.offset.y = SkTMax(scissor.offset.y, 0);
506 scissor.extent.height = scissorState.rect().height(); 496 scissor.extent.height = scissorState.rect().height();
507 497
508 SkASSERT(scissor.offset.x >= 0); 498 SkASSERT(scissor.offset.x >= 0);
509 SkASSERT(scissor.offset.y >= 0); 499 SkASSERT(scissor.offset.y >= 0);
510 } else { 500 } else {
511 scissor.extent.width = target.width(); 501 scissor.extent.width = target.width();
512 scissor.extent.height = target.height(); 502 scissor.extent.height = target.height();
513 scissor.offset.x = 0; 503 scissor.offset.x = 0;
514 scissor.offset.y = 0; 504 scissor.offset.y = 0;
515 } 505 }
516 cmdBuffer->setScissor(gpu, 0, 1, &scissor); 506 cmdBuffer->setScissor(gpu, 0, 1, &scissor);
517 } 507 }
518 508
519 void set_dynamic_viewport_state(GrVkGpu* gpu, 509 static void set_dynamic_viewport_state(GrVkGpu* gpu,
520 GrVkCommandBuffer* cmdBuffer, 510 GrVkCommandBuffer* cmdBuffer,
521 const GrRenderTarget& target) { 511 const GrRenderTarget& target) {
522 // We always use one viewport the size of the RT 512 // We always use one viewport the size of the RT
523 VkViewport viewport; 513 VkViewport viewport;
524 viewport.x = 0.0f; 514 viewport.x = 0.0f;
525 viewport.y = 0.0f; 515 viewport.y = 0.0f;
526 viewport.width = SkIntToScalar(target.width()); 516 viewport.width = SkIntToScalar(target.width());
527 viewport.height = SkIntToScalar(target.height()); 517 viewport.height = SkIntToScalar(target.height());
528 viewport.minDepth = 0.0f; 518 viewport.minDepth = 0.0f;
529 viewport.maxDepth = 1.0f; 519 viewport.maxDepth = 1.0f;
530 cmdBuffer->setViewport(gpu, 0, 1, &viewport); 520 cmdBuffer->setViewport(gpu, 0, 1, &viewport);
531 } 521 }
532 522
533 void set_dynamic_blend_constant_state(GrVkGpu* gpu, 523 static void set_dynamic_blend_constant_state(GrVkGpu* gpu,
534 GrVkCommandBuffer* cmdBuffer, 524 GrVkCommandBuffer* cmdBuffer,
535 const GrPipeline& pipeline) { 525 const GrPipeline& pipeline) {
536 GrXferProcessor::BlendInfo blendInfo; 526 GrXferProcessor::BlendInfo blendInfo;
537 pipeline.getXferProcessor().getBlendInfo(&blendInfo); 527 pipeline.getXferProcessor().getBlendInfo(&blendInfo);
538 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; 528 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
539 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; 529 GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
540 float floatColors[4]; 530 float floatColors[4];
541 if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoef f)) { 531 if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoef f)) {
542 GrColorToRGBAFloat(blendInfo.fBlendConstant, floatColors); 532 GrColorToRGBAFloat(blendInfo.fBlendConstant, floatColors);
543 } else { 533 } else {
544 memset(floatColors, 0, 4 * sizeof(float)); 534 memset(floatColors, 0, 4 * sizeof(float));
545 } 535 }
546 cmdBuffer->setBlendConstants(gpu, floatColors); 536 cmdBuffer->setBlendConstants(gpu, floatColors);
547 } 537 }
548 538
549 void GrVkPipeline::SetDynamicState(GrVkGpu* gpu, 539 void GrVkPipeline::SetDynamicState(GrVkGpu* gpu,
550 GrVkCommandBuffer* cmdBuffer, 540 GrVkCommandBuffer* cmdBuffer,
551 const GrPipeline& pipeline) { 541 const GrPipeline& pipeline) {
552 const GrRenderTarget& target = *pipeline.getRenderTarget(); 542 const GrRenderTarget& target = *pipeline.getRenderTarget();
553 set_dynamic_scissor_state(gpu, cmdBuffer, pipeline, target); 543 set_dynamic_scissor_state(gpu, cmdBuffer, pipeline, target);
554 set_dynamic_viewport_state(gpu, cmdBuffer, target); 544 set_dynamic_viewport_state(gpu, cmdBuffer, target);
555 set_dynamic_blend_constant_state(gpu, cmdBuffer, pipeline); 545 set_dynamic_blend_constant_state(gpu, cmdBuffer, pipeline);
556 } 546 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkGpuCommandBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698