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" |
11 #include "GrPipeline.h" | 11 #include "GrPipeline.h" |
12 | 12 #include "GrVkCommandBuffer.h" |
13 #include "GrVkGpu.h" | 13 #include "GrVkGpu.h" |
14 #include "GrVkProgramDesc.h" | 14 #include "GrVkProgramDesc.h" |
15 #include "GrVkRenderTarget.h" | 15 #include "GrVkRenderTarget.h" |
16 #include "GrVkUtil.h" | 16 #include "GrVkUtil.h" |
17 | 17 |
18 static inline const VkFormat& attrib_type_to_vkformat(GrVertexAttribType type) { | 18 static inline const VkFormat& attrib_type_to_vkformat(GrVertexAttribType type) { |
19 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); | 19 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
20 static const VkFormat kFormats[kGrVertexAttribTypeCount] = { | 20 static const VkFormat kFormats[kGrVertexAttribTypeCount] = { |
21 VK_FORMAT_R32_SFLOAT, // kFloat_GrVertexAttribType | 21 VK_FORMAT_R32_SFLOAT, // kFloat_GrVertexAttribType |
22 VK_FORMAT_R32G32_SFLOAT, // kVec2f_GrVertexAttribType | 22 VK_FORMAT_R32G32_SFLOAT, // kVec2f_GrVertexAttribType |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 stencilInfo->back.writeMask = stencilSettings.writeMask(face); | 181 stencilInfo->back.writeMask = stencilSettings.writeMask(face); |
182 stencilInfo->back.reference = stencilSettings.funcRef(face); | 182 stencilInfo->back.reference = stencilSettings.funcRef(face); |
183 } | 183 } |
184 stencilInfo->minDepthBounds = 0.0f; | 184 stencilInfo->minDepthBounds = 0.0f; |
185 stencilInfo->maxDepthBounds = 1.0f; | 185 stencilInfo->maxDepthBounds = 1.0f; |
186 } | 186 } |
187 | 187 |
188 void setup_viewport_scissor_state(const GrVkGpu* gpu, | 188 void setup_viewport_scissor_state(const GrVkGpu* gpu, |
189 const GrPipeline& pipeline, | 189 const GrPipeline& pipeline, |
190 const GrVkRenderTarget* vkRT, | 190 const GrVkRenderTarget* vkRT, |
191 VkPipelineViewportStateCreateInfo* viewportInf o, | 191 VkPipelineViewportStateCreateInfo* viewportInf o) { |
192 VkViewport* viewport, | |
193 VkRect2D* scissor) { | |
194 memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo)); | 192 memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo)); |
195 viewportInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; | 193 viewportInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
196 viewportInfo->pNext = nullptr; | 194 viewportInfo->pNext = nullptr; |
197 viewportInfo->flags = 0; | 195 viewportInfo->flags = 0; |
198 | 196 |
199 viewport->x = 0.0f; | |
200 viewport->y = 0.0f; | |
201 viewport->width = SkIntToScalar(vkRT->width()); | |
202 viewport->height = SkIntToScalar(vkRT->height()); | |
203 viewport->minDepth = 0.0f; | |
204 viewport->maxDepth = 1.0f; | |
205 viewportInfo->viewportCount = 1; | 197 viewportInfo->viewportCount = 1; |
206 viewportInfo->pViewports = viewport; | 198 viewportInfo->pViewports = nullptr; // This is set dynamically |
207 | 199 |
208 const GrScissorState& scissorState = pipeline.getScissorState(); | 200 viewportInfo->scissorCount = 1; |
209 if (scissorState.enabled() && | 201 viewportInfo->pScissors = nullptr; // This is set dynamically |
210 !scissorState.rect().contains(0, 0, vkRT->width(), vkRT->height())) { | |
211 // This all assumes the scissorState has previously been clipped to the device space render | |
212 // target. | |
213 scissor->offset.x = scissorState.rect().fLeft; | |
214 scissor->extent.width = scissorState.rect().width(); | |
215 if (kTopLeft_GrSurfaceOrigin == vkRT->origin()) { | |
216 scissor->offset.y = scissorState.rect().fTop; | |
217 } else { | |
218 SkASSERT(kBottomLeft_GrSurfaceOrigin == vkRT->origin()); | |
219 scissor->offset.y = vkRT->height() - scissorState.rect().fBottom; | |
220 } | |
221 scissor->extent.height = scissorState.rect().height(); | |
222 | 202 |
223 viewportInfo->scissorCount = 1; | |
224 viewportInfo->pScissors = scissor; | |
225 SkASSERT(scissor->offset.x >= 0); | |
226 SkASSERT(scissor->offset.x + scissor->extent.width <= (uint32_t)vkRT->wi dth()); | |
227 SkASSERT(scissor->offset.y >= 0); | |
228 SkASSERT(scissor->offset.y + scissor->extent.height <= (uint32_t)vkRT->h eight()); | |
229 } else { | |
230 scissor->extent.width = vkRT->width(); | |
231 scissor->extent.height = vkRT->height(); | |
232 scissor->offset.x = 0; | |
233 scissor->offset.y = 0; | |
234 viewportInfo->scissorCount = 1; | |
235 viewportInfo->pScissors = scissor; | |
236 } | |
237 SkASSERT(viewportInfo->viewportCount == viewportInfo->scissorCount); | 203 SkASSERT(viewportInfo->viewportCount == viewportInfo->scissorCount); |
238 } | 204 } |
239 | 205 |
240 void setup_multisample_state(const GrPipeline& pipeline, | 206 void setup_multisample_state(const GrPipeline& pipeline, |
241 VkPipelineMultisampleStateCreateInfo* multisampleIn fo) { | 207 VkPipelineMultisampleStateCreateInfo* multisampleIn fo) { |
242 memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo)); | 208 memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo)); |
243 multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE _INFO; | 209 multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE _INFO; |
244 multisampleInfo->pNext = nullptr; | 210 multisampleInfo->pNext = nullptr; |
245 multisampleInfo->flags = 0; | 211 multisampleInfo->flags = 0; |
246 int numSamples = pipeline.getRenderTarget()->numColorSamples(); | 212 int numSamples = pipeline.getRenderTarget()->numColorSamples(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 false, | 305 false, |
340 }; | 306 }; |
341 return gCoeffReferencesBlendConst[coeff]; | 307 return gCoeffReferencesBlendConst[coeff]; |
342 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendCon st)); | 308 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendCon st)); |
343 // Individual enum asserts already made in blend_coeff_to_vk_blend | 309 // Individual enum asserts already made in blend_coeff_to_vk_blend |
344 } | 310 } |
345 | 311 |
346 void setup_color_blend_state(const GrVkGpu* gpu, | 312 void setup_color_blend_state(const GrVkGpu* gpu, |
347 const GrPipeline& pipeline, | 313 const GrPipeline& pipeline, |
348 VkPipelineColorBlendStateCreateInfo* colorBlendInfo , | 314 VkPipelineColorBlendStateCreateInfo* colorBlendInfo , |
349 VkPipelineColorBlendAttachmentState* attachmentStat e) { | 315 VkPipelineColorBlendAttachmentState* attachmentStat e, |
316 bool* usesBlendConstant) { | |
350 GrXferProcessor::BlendInfo blendInfo; | 317 GrXferProcessor::BlendInfo blendInfo; |
351 pipeline.getXferProcessor().getBlendInfo(&blendInfo); | 318 pipeline.getXferProcessor().getBlendInfo(&blendInfo); |
352 | 319 |
353 GrBlendEquation equation = blendInfo.fEquation; | 320 GrBlendEquation equation = blendInfo.fEquation; |
354 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; | 321 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
355 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; | 322 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
356 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) && | 323 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) && |
357 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff; | 324 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff; |
358 | 325 |
359 memset(attachmentState, 0, sizeof(VkPipelineColorBlendAttachmentState)); | 326 memset(attachmentState, 0, sizeof(VkPipelineColorBlendAttachmentState)); |
(...skipping 14 matching lines...) Expand all Loading... | |
374 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_CO MPONENT_A_BIT; | 341 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_CO MPONENT_A_BIT; |
375 } | 342 } |
376 | 343 |
377 memset(colorBlendInfo, 0, sizeof(VkPipelineColorBlendStateCreateInfo)); | 344 memset(colorBlendInfo, 0, sizeof(VkPipelineColorBlendStateCreateInfo)); |
378 colorBlendInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_ INFO; | 345 colorBlendInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_ INFO; |
379 colorBlendInfo->pNext = nullptr; | 346 colorBlendInfo->pNext = nullptr; |
380 colorBlendInfo->flags = 0; | 347 colorBlendInfo->flags = 0; |
381 colorBlendInfo->logicOpEnable = VK_FALSE; | 348 colorBlendInfo->logicOpEnable = VK_FALSE; |
382 colorBlendInfo->attachmentCount = 1; | 349 colorBlendInfo->attachmentCount = 1; |
383 colorBlendInfo->pAttachments = attachmentState; | 350 colorBlendInfo->pAttachments = attachmentState; |
384 if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoef f)) { | 351 // colorBlendInfo->blendConstants is set dynamically |
jvanverth1
2016/03/18 15:02:26
SkASSERT(usesBlendConstant);
egdaniel
2016/03/18 19:29:58
removed
| |
385 GrColorToRGBAFloat(blendInfo.fBlendConstant, colorBlendInfo->blendConsta nts); | 352 *usesBlendConstant = blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs _constant(dstCoeff); |
386 } | |
387 } | 353 } |
388 | 354 |
389 VkCullModeFlags draw_face_to_vk_cull_mode(GrPipelineBuilder::DrawFace drawFace) { | 355 VkCullModeFlags draw_face_to_vk_cull_mode(GrPipelineBuilder::DrawFace drawFace) { |
390 // Assumes that we've set the front face to be ccw | 356 // Assumes that we've set the front face to be ccw |
391 static const VkCullModeFlags gTable[] = { | 357 static const VkCullModeFlags gTable[] = { |
392 VK_CULL_MODE_NONE, // kBoth_DrawFace | 358 VK_CULL_MODE_NONE, // kBoth_DrawFace |
393 VK_CULL_MODE_BACK_BIT, // kCCW_DrawFace, cull back face | 359 VK_CULL_MODE_BACK_BIT, // kCCW_DrawFace, cull back face |
394 VK_CULL_MODE_FRONT_BIT, // kCW_DrawFace, cull front face | 360 VK_CULL_MODE_FRONT_BIT, // kCW_DrawFace, cull front face |
395 }; | 361 }; |
396 GR_STATIC_ASSERT(0 == GrPipelineBuilder::kBoth_DrawFace); | 362 GR_STATIC_ASSERT(0 == GrPipelineBuilder::kBoth_DrawFace); |
(...skipping 18 matching lines...) Expand all Loading... | |
415 rasterInfo->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; | 381 rasterInfo->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
416 rasterInfo->depthBiasEnable = VK_FALSE; | 382 rasterInfo->depthBiasEnable = VK_FALSE; |
417 rasterInfo->depthBiasConstantFactor = 0.0f; | 383 rasterInfo->depthBiasConstantFactor = 0.0f; |
418 rasterInfo->depthBiasClamp = 0.0f; | 384 rasterInfo->depthBiasClamp = 0.0f; |
419 rasterInfo->depthBiasSlopeFactor = 0.0f; | 385 rasterInfo->depthBiasSlopeFactor = 0.0f; |
420 rasterInfo->lineWidth = 1.0f; | 386 rasterInfo->lineWidth = 1.0f; |
421 } | 387 } |
422 | 388 |
423 void setup_dynamic_state(const GrVkGpu* gpu, | 389 void setup_dynamic_state(const GrVkGpu* gpu, |
424 const GrPipeline& pipeline, | 390 const GrPipeline& pipeline, |
425 VkPipelineDynamicStateCreateInfo* dynamicInfo) { | 391 bool usingBlendConstant, |
392 VkPipelineDynamicStateCreateInfo* dynamicInfo, | |
393 VkDynamicState* dynamicStates) { | |
426 memset(dynamicInfo, 0, sizeof(VkPipelineDynamicStateCreateInfo)); | 394 memset(dynamicInfo, 0, sizeof(VkPipelineDynamicStateCreateInfo)); |
427 dynamicInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; | 395 dynamicInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
428 // TODO: mask out any state we might want to set dynamically | 396 dynamicInfo->pNext = VK_NULL_HANDLE; |
429 dynamicInfo->dynamicStateCount = 0; | 397 dynamicInfo->flags = 0; |
398 dynamicStates[0] = VK_DYNAMIC_STATE_VIEWPORT; | |
399 dynamicStates[1] = VK_DYNAMIC_STATE_SCISSOR; | |
400 dynamicStates[2] = VK_DYNAMIC_STATE_BLEND_CONSTANTS; | |
401 // If we aren't using the blend constant we don't set it on the command buff er where is an error | |
jvanverth1
2016/03/18 15:02:26
This comment is a little confusing. Suggestion: "I
egdaniel
2016/03/18 19:29:58
always using dynamic blendConstant now
| |
402 // if you say you are using it here. | |
403 dynamicInfo->dynamicStateCount = usingBlendConstant ? 3 : 2; | |
404 dynamicInfo->pDynamicStates = dynamicStates; | |
430 } | 405 } |
431 | 406 |
432 GrVkPipeline* GrVkPipeline::Create(GrVkGpu* gpu, const GrPipeline& pipeline, | 407 GrVkPipeline* GrVkPipeline::Create(GrVkGpu* gpu, const GrPipeline& pipeline, |
433 const GrPrimitiveProcessor& primProc, | 408 const GrPrimitiveProcessor& primProc, |
434 VkPipelineShaderStageCreateInfo* shaderStageI nfo, | 409 VkPipelineShaderStageCreateInfo* shaderStageI nfo, |
435 int shaderStageCount, | 410 int shaderStageCount, |
436 GrPrimitiveType primitiveType, | 411 GrPrimitiveType primitiveType, |
437 const GrVkRenderPass& renderPass, | 412 const GrVkRenderPass& renderPass, |
438 VkPipelineLayout layout, | 413 VkPipelineLayout layout, |
439 VkPipelineCache cache) { | 414 VkPipelineCache cache) { |
440 VkPipelineVertexInputStateCreateInfo vertexInputInfo; | 415 VkPipelineVertexInputStateCreateInfo vertexInputInfo; |
441 VkVertexInputBindingDescription bindingDesc; | 416 VkVertexInputBindingDescription bindingDesc; |
442 // TODO: allocate this based on VkPhysicalDeviceLimits::maxVertexInputAttrib utes | 417 // TODO: allocate this based on VkPhysicalDeviceLimits::maxVertexInputAttrib utes |
443 static const int kMaxVertexAttributes = 16; | 418 static const int kMaxVertexAttributes = 16; |
444 static VkVertexInputAttributeDescription attributeDesc[kMaxVertexAttributes] ; | 419 static VkVertexInputAttributeDescription attributeDesc[kMaxVertexAttributes] ; |
445 setup_vertex_input_state(primProc, &vertexInputInfo, &bindingDesc, 1, | 420 setup_vertex_input_state(primProc, &vertexInputInfo, &bindingDesc, 1, |
446 attributeDesc, kMaxVertexAttributes); | 421 attributeDesc, kMaxVertexAttributes); |
447 | 422 |
448 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo; | 423 VkPipelineInputAssemblyStateCreateInfo inputAssemblyInfo; |
449 setup_input_assembly_state(primitiveType, &inputAssemblyInfo); | 424 setup_input_assembly_state(primitiveType, &inputAssemblyInfo); |
450 | 425 |
451 VkPipelineDepthStencilStateCreateInfo depthStencilInfo; | 426 VkPipelineDepthStencilStateCreateInfo depthStencilInfo; |
452 setup_depth_stencil_state(gpu, pipeline.getStencil(), &depthStencilInfo); | 427 setup_depth_stencil_state(gpu, pipeline.getStencil(), &depthStencilInfo); |
453 | 428 |
454 GrRenderTarget* rt = pipeline.getRenderTarget(); | 429 GrRenderTarget* rt = pipeline.getRenderTarget(); |
455 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); | 430 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(rt); |
456 VkPipelineViewportStateCreateInfo viewportInfo; | 431 VkPipelineViewportStateCreateInfo viewportInfo; |
457 VkViewport viewport; | 432 setup_viewport_scissor_state(gpu, pipeline, vkRT, &viewportInfo); |
458 VkRect2D scissor; | |
459 setup_viewport_scissor_state(gpu, pipeline, vkRT, &viewportInfo, &viewport, &scissor); | |
460 | 433 |
461 VkPipelineMultisampleStateCreateInfo multisampleInfo; | 434 VkPipelineMultisampleStateCreateInfo multisampleInfo; |
462 setup_multisample_state(pipeline, &multisampleInfo); | 435 setup_multisample_state(pipeline, &multisampleInfo); |
463 | 436 |
464 // We will only have one color attachment per pipeline. | 437 // We will only have one color attachment per pipeline. |
465 VkPipelineColorBlendAttachmentState attachmentStates[1]; | 438 VkPipelineColorBlendAttachmentState attachmentStates[1]; |
466 VkPipelineColorBlendStateCreateInfo colorBlendInfo; | 439 VkPipelineColorBlendStateCreateInfo colorBlendInfo; |
467 setup_color_blend_state(gpu, pipeline, &colorBlendInfo, attachmentStates); | 440 bool usesBlendConstant; |
441 setup_color_blend_state(gpu, pipeline, &colorBlendInfo, attachmentStates, &u sesBlendConstant); | |
468 | 442 |
469 VkPipelineRasterizationStateCreateInfo rasterInfo; | 443 VkPipelineRasterizationStateCreateInfo rasterInfo; |
470 setup_raster_state(gpu, pipeline, &rasterInfo); | 444 setup_raster_state(gpu, pipeline, &rasterInfo); |
471 | 445 |
446 VkDynamicState dynamicStates[3]; | |
472 VkPipelineDynamicStateCreateInfo dynamicInfo; | 447 VkPipelineDynamicStateCreateInfo dynamicInfo; |
473 setup_dynamic_state(gpu, pipeline, &dynamicInfo); | 448 setup_dynamic_state(gpu, pipeline, usesBlendConstant, &dynamicInfo, dynamicS tates); |
474 | 449 |
475 VkGraphicsPipelineCreateInfo pipelineCreateInfo; | 450 VkGraphicsPipelineCreateInfo pipelineCreateInfo; |
476 memset(&pipelineCreateInfo, 0, sizeof(VkGraphicsPipelineCreateInfo)); | 451 memset(&pipelineCreateInfo, 0, sizeof(VkGraphicsPipelineCreateInfo)); |
477 pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; | 452 pipelineCreateInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
478 pipelineCreateInfo.pNext = nullptr; | 453 pipelineCreateInfo.pNext = nullptr; |
479 pipelineCreateInfo.flags = 0; | 454 pipelineCreateInfo.flags = 0; |
480 pipelineCreateInfo.stageCount = shaderStageCount; | 455 pipelineCreateInfo.stageCount = shaderStageCount; |
481 pipelineCreateInfo.pStages = shaderStageInfo; | 456 pipelineCreateInfo.pStages = shaderStageInfo; |
482 pipelineCreateInfo.pVertexInputState = &vertexInputInfo; | 457 pipelineCreateInfo.pVertexInputState = &vertexInputInfo; |
483 pipelineCreateInfo.pInputAssemblyState = &inputAssemblyInfo; | 458 pipelineCreateInfo.pInputAssemblyState = &inputAssemblyInfo; |
(...skipping 20 matching lines...) Expand all Loading... | |
504 } | 479 } |
505 | 480 |
506 return new GrVkPipeline(vkPipeline); | 481 return new GrVkPipeline(vkPipeline); |
507 } | 482 } |
508 | 483 |
509 void GrVkPipeline::freeGPUData(const GrVkGpu* gpu) const { | 484 void GrVkPipeline::freeGPUData(const GrVkGpu* gpu) const { |
510 GR_VK_CALL(gpu->vkInterface(), DestroyPipeline(gpu->device(), fPipeline, nul lptr)); | 485 GR_VK_CALL(gpu->vkInterface(), DestroyPipeline(gpu->device(), fPipeline, nul lptr)); |
511 } | 486 } |
512 | 487 |
513 | 488 |
489 void set_dynamic_scissor_state(GrVkGpu* gpu, | |
490 GrVkCommandBuffer* cmdBuffer, | |
491 const GrPipeline& pipeline, | |
492 const GrRenderTarget& target) { | |
493 // We always use one scissor and if it is disabled we just make it the size of the RT | |
494 const GrScissorState& scissorState = pipeline.getScissorState(); | |
495 VkRect2D scissor; | |
496 if (scissorState.enabled() && | |
497 !scissorState.rect().contains(0, 0, target.width(), target.height())) { | |
498 // This all assumes the scissorState has previously been clipped to the device space render | |
499 // target. | |
500 scissor.offset.x = scissorState.rect().fLeft; | |
501 scissor.extent.width = scissorState.rect().width(); | |
502 if (kTopLeft_GrSurfaceOrigin == target.origin()) { | |
503 scissor.offset.y = scissorState.rect().fTop; | |
504 } else { | |
505 SkASSERT(kBottomLeft_GrSurfaceOrigin == target.origin()); | |
506 scissor.offset.y = target.height() - scissorState.rect().fBottom; | |
507 } | |
508 scissor.extent.height = scissorState.rect().height(); | |
509 | |
510 SkASSERT(scissor.offset.x >= 0); | |
511 SkASSERT(scissor.offset.x + scissor.extent.width <= (uint32_t)target.wid th()); | |
512 SkASSERT(scissor.offset.y >= 0); | |
513 SkASSERT(scissor.offset.y + scissor.extent.height <= (uint32_t)target.he ight()); | |
514 } else { | |
515 scissor.extent.width = target.width(); | |
516 scissor.extent.height = target.height(); | |
517 scissor.offset.x = 0; | |
518 scissor.offset.y = 0; | |
519 } | |
520 cmdBuffer->setScissor(gpu, 0, 1, &scissor); | |
521 } | |
522 | |
523 void set_dynamic_viewport_state(GrVkGpu* gpu, | |
524 GrVkCommandBuffer* cmdBuffer, | |
525 const GrRenderTarget& target) { | |
526 // We always use one viewport the size of the RT | |
527 VkViewport viewport; | |
528 viewport.x = 0.0f; | |
529 viewport.y = 0.0f; | |
530 viewport.width = SkIntToScalar(target.width()); | |
531 viewport.height = SkIntToScalar(target.height()); | |
532 viewport.minDepth = 0.0f; | |
533 viewport.maxDepth = 1.0f; | |
534 cmdBuffer->setViewport(gpu, 0, 1, &viewport); | |
535 } | |
536 | |
537 void set_dynamic_blend_constant_state(GrVkGpu* gpu, | |
538 GrVkCommandBuffer* cmdBuffer, | |
539 const GrPipeline& pipeline) { | |
540 GrXferProcessor::BlendInfo blendInfo; | |
541 pipeline.getXferProcessor().getBlendInfo(&blendInfo); | |
542 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; | |
543 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; | |
544 if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoef f)) { | |
545 float floatColors[4]; | |
546 GrColorToRGBAFloat(blendInfo.fBlendConstant, floatColors); | |
547 cmdBuffer->setBlendConstants(gpu, floatColors); | |
548 } | |
549 } | |
550 | |
551 | |
552 | |
553 void GrVkPipeline::SetDynamicState(GrVkGpu* gpu, | |
554 GrVkCommandBuffer* cmdBuffer, | |
555 const GrPipeline& pipeline) { | |
556 const GrRenderTarget& target = *pipeline.getRenderTarget(); | |
557 set_dynamic_scissor_state(gpu, cmdBuffer, pipeline, target); | |
jvanverth1
2016/03/18 15:02:26
This is fine for now, but when you add the change
egdaniel
2016/03/18 19:29:58
added caching
| |
558 set_dynamic_viewport_state(gpu, cmdBuffer, target); | |
559 set_dynamic_blend_constant_state(gpu, cmdBuffer, pipeline); | |
560 } | |
OLD | NEW |