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