| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrVkRenderPass.h" | 8 #include "GrVkRenderPass.h" |
| 9 | 9 |
| 10 #include "GrProcessor.h" | 10 #include "GrProcessor.h" |
| 11 #include "GrVkFramebuffer.h" | 11 #include "GrVkFramebuffer.h" |
| 12 #include "GrVkGpu.h" | 12 #include "GrVkGpu.h" |
| 13 #include "GrVkRenderTarget.h" | 13 #include "GrVkRenderTarget.h" |
| 14 #include "GrVkUtil.h" | 14 #include "GrVkUtil.h" |
| 15 | 15 |
| 16 void setup_simple_vk_attachment_description(VkAttachmentDescription* attachment, | 16 typedef GrVkRenderPass::AttachmentsDescriptor::AttachmentDesc AttachmentDesc; |
| 17 VkFormat format, | 17 |
| 18 uint32_t samples, | 18 void setup_vk_attachment_description(VkAttachmentDescription* attachment, |
| 19 VkImageLayout layout) { | 19 const AttachmentDesc& desc, |
| 20 VkImageLayout layout) { |
| 20 attachment->flags = 0; | 21 attachment->flags = 0; |
| 21 attachment->format = format; | 22 attachment->format = desc.fFormat; |
| 22 SkAssertResult(GrSampleCountToVkSampleCount(samples, &attachment->samples)); | 23 SkAssertResult(GrSampleCountToVkSampleCount(desc.fSamples, &attachment->samp
les)); |
| 23 attachment->loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; | 24 switch (layout) { |
| 24 attachment->storeOp = VK_ATTACHMENT_STORE_OP_STORE; | 25 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 25 attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; | 26 attachment->loadOp = desc.fLoadOp; |
| 26 attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; | 27 attachment->storeOp = desc.fStoreOp; |
| 28 attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 29 attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 30 break; |
| 31 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 32 attachment->loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 33 attachment->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 34 attachment->stencilLoadOp = desc.fLoadOp; |
| 35 attachment->stencilStoreOp = desc.fStoreOp; |
| 36 break; |
| 37 default: |
| 38 SkFAIL("Unexpected attachment layout"); |
| 39 } |
| 40 |
| 27 attachment->initialLayout = layout; | 41 attachment->initialLayout = layout; |
| 28 attachment->finalLayout = layout; | 42 attachment->finalLayout = layout; |
| 29 } | 43 } |
| 30 | 44 |
| 31 void GrVkRenderPass::initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& targ
et) { | 45 void GrVkRenderPass::initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& targ
et) { |
| 32 // Get attachment information from render target. This includes which attach
ments the render | 46 // Get attachment information from render target. This includes which attach
ments the render |
| 33 // target has (color, resolve, stencil) and the attachments format and sampl
e count. | 47 // target has (color, resolve, stencil) and the attachments format and sampl
e count. |
| 34 target.getAttachmentsDescriptor(&fAttachmentsDescriptor, &fAttachmentFlags); | 48 target.getAttachmentsDescriptor(&fAttachmentsDescriptor, &fAttachmentFlags); |
| 35 | 49 |
| 36 uint32_t numAttachments = fAttachmentsDescriptor.fAttachmentCount; | 50 uint32_t numAttachments = fAttachmentsDescriptor.fAttachmentCount; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 // Go through each of the attachment types (color, resolve, stencil) and set
the necessary | 63 // Go through each of the attachment types (color, resolve, stencil) and set
the necessary |
| 50 // on the various Vk structs. | 64 // on the various Vk structs. |
| 51 VkSubpassDescription subpassDesc; | 65 VkSubpassDescription subpassDesc; |
| 52 memset(&subpassDesc, 0, sizeof(VkSubpassDescription)); | 66 memset(&subpassDesc, 0, sizeof(VkSubpassDescription)); |
| 53 subpassDesc.flags = 0; | 67 subpassDesc.flags = 0; |
| 54 subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; | 68 subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 55 subpassDesc.inputAttachmentCount = 0; | 69 subpassDesc.inputAttachmentCount = 0; |
| 56 subpassDesc.pInputAttachments = nullptr; | 70 subpassDesc.pInputAttachments = nullptr; |
| 57 if (fAttachmentFlags & kColor_AttachmentFlag) { | 71 if (fAttachmentFlags & kColor_AttachmentFlag) { |
| 58 // set up color attachment | 72 // set up color attachment |
| 59 setup_simple_vk_attachment_description(&attachments[currentAttachment], | 73 setup_vk_attachment_description(&attachments[currentAttachment], |
| 60 fAttachmentsDescriptor.fColor.fFo
rmat, | 74 fAttachmentsDescriptor.fColor, |
| 61 fAttachmentsDescriptor.fColor.fSa
mples, | 75 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
); |
| 62 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_
OPTIMAL); | |
| 63 // setup subpass use of attachment | 76 // setup subpass use of attachment |
| 64 colorRef.attachment = currentAttachment++; | 77 colorRef.attachment = currentAttachment++; |
| 65 colorRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; | 78 colorRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 66 subpassDesc.colorAttachmentCount = 1; | 79 subpassDesc.colorAttachmentCount = 1; |
| 67 } else { | 80 } else { |
| 68 // I don't think there should ever be a time where we don't have a color
attachment | 81 // I don't think there should ever be a time where we don't have a color
attachment |
| 69 SkASSERT(false); | 82 SkASSERT(false); |
| 70 colorRef.attachment = VK_ATTACHMENT_UNUSED; | 83 colorRef.attachment = VK_ATTACHMENT_UNUSED; |
| 71 colorRef.layout = VK_IMAGE_LAYOUT_UNDEFINED; | 84 colorRef.layout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 72 subpassDesc.colorAttachmentCount = 0; | 85 subpassDesc.colorAttachmentCount = 0; |
| 73 } | 86 } |
| 74 subpassDesc.pColorAttachments = &colorRef; | 87 subpassDesc.pColorAttachments = &colorRef; |
| 75 | 88 |
| 76 if (fAttachmentFlags & kResolve_AttachmentFlag) { | 89 if (fAttachmentFlags & kResolve_AttachmentFlag) { |
| 77 // set up resolve attachment | 90 // set up resolve attachment |
| 78 setup_simple_vk_attachment_description(&attachments[currentAttachment], | 91 setup_vk_attachment_description(&attachments[currentAttachment], |
| 79 fAttachmentsDescriptor.fResolve.f
Format, | 92 fAttachmentsDescriptor.fResolve, |
| 80 fAttachmentsDescriptor.fResolve.f
Samples, | 93 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
); |
| 81 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_
OPTIMAL); | |
| 82 // setup subpass use of attachment | 94 // setup subpass use of attachment |
| 83 resolveRef.attachment = currentAttachment++; | 95 resolveRef.attachment = currentAttachment++; |
| 84 // I'm really not sure what the layout should be for the resolve texture
s. | 96 // I'm really not sure what the layout should be for the resolve texture
s. |
| 85 resolveRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; | 97 resolveRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 86 subpassDesc.pResolveAttachments = &resolveRef; | 98 subpassDesc.pResolveAttachments = &resolveRef; |
| 87 } else { | 99 } else { |
| 88 subpassDesc.pResolveAttachments = nullptr; | 100 subpassDesc.pResolveAttachments = nullptr; |
| 89 } | 101 } |
| 90 | 102 |
| 91 if (fAttachmentFlags & kStencil_AttachmentFlag) { | 103 if (fAttachmentFlags & kStencil_AttachmentFlag) { |
| 92 // set up stencil attachment | 104 // set up stencil attachment |
| 93 setup_simple_vk_attachment_description(&attachments[currentAttachment], | 105 setup_vk_attachment_description(&attachments[currentAttachment], |
| 94 fAttachmentsDescriptor.fStencil.f
Format, | 106 fAttachmentsDescriptor.fStencil, |
| 95 fAttachmentsDescriptor.fStencil.f
Samples, | 107 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT
_OPTIMAL); |
| 96 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATT
ACHMENT_OPTIMAL); | |
| 97 // setup subpass use of attachment | 108 // setup subpass use of attachment |
| 98 stencilRef.attachment = currentAttachment++; | 109 stencilRef.attachment = currentAttachment++; |
| 99 stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; | 110 stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 100 } else { | 111 } else { |
| 101 stencilRef.attachment = VK_ATTACHMENT_UNUSED; | 112 stencilRef.attachment = VK_ATTACHMENT_UNUSED; |
| 102 stencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED; | 113 stencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 103 } | 114 } |
| 104 subpassDesc.pDepthStencilAttachment = &stencilRef; | 115 subpassDesc.pDepthStencilAttachment = &stencilRef; |
| 105 | 116 |
| 106 subpassDesc.preserveAttachmentCount = 0; | 117 subpassDesc.preserveAttachmentCount = 0; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 bool GrVkRenderPass::isCompatible(const GrVkRenderTarget& target) const { | 206 bool GrVkRenderPass::isCompatible(const GrVkRenderTarget& target) const { |
| 196 AttachmentsDescriptor desc; | 207 AttachmentsDescriptor desc; |
| 197 AttachmentFlags flags; | 208 AttachmentFlags flags; |
| 198 target.getAttachmentsDescriptor(&desc, &flags); | 209 target.getAttachmentsDescriptor(&desc, &flags); |
| 199 | 210 |
| 200 if (flags != fAttachmentFlags) { | 211 if (flags != fAttachmentFlags) { |
| 201 return false; | 212 return false; |
| 202 } | 213 } |
| 203 | 214 |
| 204 if (fAttachmentFlags & kColor_AttachmentFlag) { | 215 if (fAttachmentFlags & kColor_AttachmentFlag) { |
| 205 if (fAttachmentsDescriptor.fColor != desc.fColor) { | 216 if (!fAttachmentsDescriptor.fColor.isCompatible(desc.fColor)) { |
| 206 return false; | 217 return false; |
| 207 } | 218 } |
| 208 } | 219 } |
| 209 if (fAttachmentFlags & kResolve_AttachmentFlag) { | 220 if (fAttachmentFlags & kResolve_AttachmentFlag) { |
| 210 if (fAttachmentsDescriptor.fResolve != desc.fResolve) { | 221 if (!fAttachmentsDescriptor.fResolve.isCompatible(desc.fResolve)) { |
| 211 return false; | 222 return false; |
| 212 } | 223 } |
| 213 } | 224 } |
| 214 if (fAttachmentFlags & kStencil_AttachmentFlag) { | 225 if (fAttachmentFlags & kStencil_AttachmentFlag) { |
| 215 if (fAttachmentsDescriptor.fStencil != desc.fStencil) { | 226 if (!fAttachmentsDescriptor.fStencil.isCompatible(desc.fStencil)) { |
| 216 return false; | 227 return false; |
| 217 } | 228 } |
| 218 } | 229 } |
| 219 | 230 |
| 220 return true; | 231 return true; |
| 221 } | 232 } |
| 222 | 233 |
| 223 void GrVkRenderPass::genKey(GrProcessorKeyBuilder* b) const { | 234 void GrVkRenderPass::genKey(GrProcessorKeyBuilder* b) const { |
| 224 b->add32(fAttachmentFlags); | 235 b->add32(fAttachmentFlags); |
| 225 if (fAttachmentFlags & kColor_AttachmentFlag) { | 236 if (fAttachmentFlags & kColor_AttachmentFlag) { |
| 226 b->add32(fAttachmentsDescriptor.fColor.fFormat); | 237 b->add32(fAttachmentsDescriptor.fColor.fFormat); |
| 227 b->add32(fAttachmentsDescriptor.fColor.fSamples); | 238 b->add32(fAttachmentsDescriptor.fColor.fSamples); |
| 228 } | 239 } |
| 229 if (fAttachmentFlags & kResolve_AttachmentFlag) { | 240 if (fAttachmentFlags & kResolve_AttachmentFlag) { |
| 230 b->add32(fAttachmentsDescriptor.fResolve.fFormat); | 241 b->add32(fAttachmentsDescriptor.fResolve.fFormat); |
| 231 b->add32(fAttachmentsDescriptor.fResolve.fSamples); | 242 b->add32(fAttachmentsDescriptor.fResolve.fSamples); |
| 232 } | 243 } |
| 233 if (fAttachmentFlags & kStencil_AttachmentFlag) { | 244 if (fAttachmentFlags & kStencil_AttachmentFlag) { |
| 234 b->add32(fAttachmentsDescriptor.fStencil.fFormat); | 245 b->add32(fAttachmentsDescriptor.fStencil.fFormat); |
| 235 b->add32(fAttachmentsDescriptor.fStencil.fSamples); | 246 b->add32(fAttachmentsDescriptor.fStencil.fSamples); |
| 236 } | 247 } |
| 237 } | 248 } |
| OLD | NEW |