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

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

Issue 2035853002: Add support for finding/creating general GrVkRenderPass from the VkResourceProvider. (Closed) Base URL: https://skia.googlesource.com/skia.git@renderPass
Patch Set: nits Created 4 years, 6 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/GrVkRenderPass.h ('k') | src/gpu/vk/GrVkRenderTarget.h » ('j') | 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 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 typedef GrVkRenderPass::AttachmentsDescriptor::AttachmentDesc AttachmentDesc; 16 typedef GrVkRenderPass::AttachmentsDescriptor::AttachmentDesc AttachmentDesc;
17 17
18 void setup_vk_attachment_description(VkAttachmentDescription* attachment, 18 void setup_vk_attachment_description(VkAttachmentDescription* attachment,
19 const AttachmentDesc& desc, 19 const AttachmentDesc& desc,
20 VkImageLayout layout) { 20 VkImageLayout layout) {
21 attachment->flags = 0; 21 attachment->flags = 0;
22 attachment->format = desc.fFormat; 22 attachment->format = desc.fFormat;
23 SkAssertResult(GrSampleCountToVkSampleCount(desc.fSamples, &attachment->samp les)); 23 SkAssertResult(GrSampleCountToVkSampleCount(desc.fSamples, &attachment->samp les));
24 switch (layout) { 24 switch (layout) {
25 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: 25 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
26 attachment->loadOp = desc.fLoadOp; 26 attachment->loadOp = desc.fLoadStoreOps.fLoadOp;
27 attachment->storeOp = desc.fStoreOp; 27 attachment->storeOp = desc.fLoadStoreOps.fStoreOp;
28 attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 28 attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
29 attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 29 attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
30 break; 30 break;
31 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: 31 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
32 attachment->loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 32 attachment->loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
33 attachment->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 33 attachment->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
34 attachment->stencilLoadOp = desc.fLoadOp; 34 attachment->stencilLoadOp = desc.fLoadStoreOps.fLoadOp;
35 attachment->stencilStoreOp = desc.fStoreOp; 35 attachment->stencilStoreOp = desc.fLoadStoreOps.fStoreOp;
36 break; 36 break;
37 default: 37 default:
38 SkFAIL("Unexpected attachment layout"); 38 SkFAIL("Unexpected attachment layout");
39 } 39 }
40 40
41 attachment->initialLayout = layout; 41 attachment->initialLayout = layout;
42 attachment->finalLayout = layout; 42 attachment->finalLayout = layout;
43 } 43 }
44 44
45 void GrVkRenderPass::initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& targ et) { 45 void GrVkRenderPass::initSimple(const GrVkGpu* gpu, const GrVkRenderTarget& targ et) {
46 // Get attachment information from render target. This includes which attach ments the render 46 static const GrVkRenderPass::LoadStoreOps kBasicLoadStoreOps(VK_ATTACHMENT_L OAD_OP_LOAD,
47 // target has (color, resolve, stencil) and the attachments format and sampl e count. 47 VK_ATTACHMENT_S TORE_OP_STORE);
48 target.getAttachmentsDescriptor(&fAttachmentsDescriptor, &fAttachmentFlags);
49 48
49 this->init(gpu, target, kBasicLoadStoreOps, kBasicLoadStoreOps, kBasicLoadSt oreOps);
50 }
51
52 void GrVkRenderPass::init(const GrVkGpu* gpu,
53 const LoadStoreOps& colorOp,
54 const LoadStoreOps& resolveOp,
55 const LoadStoreOps& stencilOp) {
50 uint32_t numAttachments = fAttachmentsDescriptor.fAttachmentCount; 56 uint32_t numAttachments = fAttachmentsDescriptor.fAttachmentCount;
51 // Attachment descriptions to be set on the render pass 57 // Attachment descriptions to be set on the render pass
52 SkTArray<VkAttachmentDescription> attachments(numAttachments); 58 SkTArray<VkAttachmentDescription> attachments(numAttachments);
53 attachments.reset(numAttachments); 59 attachments.reset(numAttachments);
54 memset(attachments.begin(), 0, numAttachments*sizeof(VkAttachmentDescription )); 60 memset(attachments.begin(), 0, numAttachments * sizeof(VkAttachmentDescripti on));
55 61
56 // Refs to attachments on the render pass (as described by teh VkAttachmentD escription above), 62 // Refs to attachments on the render pass (as described by teh VkAttachmentD escription above),
57 // that are used by the subpass. 63 // that are used by the subpass.
58 VkAttachmentReference colorRef; 64 VkAttachmentReference colorRef;
59 VkAttachmentReference resolveRef; 65 VkAttachmentReference resolveRef;
60 VkAttachmentReference stencilRef; 66 VkAttachmentReference stencilRef;
61 uint32_t currentAttachment = 0; 67 uint32_t currentAttachment = 0;
62 68
63 // Go through each of the attachment types (color, resolve, stencil) and set the necessary 69 // Go through each of the attachment types (color, resolve, stencil) and set the necessary
64 // on the various Vk structs. 70 // on the various Vk structs.
65 VkSubpassDescription subpassDesc; 71 VkSubpassDescription subpassDesc;
66 memset(&subpassDesc, 0, sizeof(VkSubpassDescription)); 72 memset(&subpassDesc, 0, sizeof(VkSubpassDescription));
67 subpassDesc.flags = 0; 73 subpassDesc.flags = 0;
68 subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; 74 subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
69 subpassDesc.inputAttachmentCount = 0; 75 subpassDesc.inputAttachmentCount = 0;
70 subpassDesc.pInputAttachments = nullptr; 76 subpassDesc.pInputAttachments = nullptr;
71 if (fAttachmentFlags & kColor_AttachmentFlag) { 77 if (fAttachmentFlags & kColor_AttachmentFlag) {
72 // set up color attachment 78 // set up color attachment
79 fAttachmentsDescriptor.fColor.fLoadStoreOps = colorOp;
73 setup_vk_attachment_description(&attachments[currentAttachment], 80 setup_vk_attachment_description(&attachments[currentAttachment],
74 fAttachmentsDescriptor.fColor, 81 fAttachmentsDescriptor.fColor,
75 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ); 82 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL );
76 // setup subpass use of attachment 83 // setup subpass use of attachment
77 colorRef.attachment = currentAttachment++; 84 colorRef.attachment = currentAttachment++;
78 colorRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 85 colorRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
79 subpassDesc.colorAttachmentCount = 1; 86 subpassDesc.colorAttachmentCount = 1;
80 } else { 87 } else {
81 // I don't think there should ever be a time where we don't have a color attachment 88 // I don't think there should ever be a time where we don't have a color attachment
82 SkASSERT(false); 89 SkASSERT(false);
83 colorRef.attachment = VK_ATTACHMENT_UNUSED; 90 colorRef.attachment = VK_ATTACHMENT_UNUSED;
84 colorRef.layout = VK_IMAGE_LAYOUT_UNDEFINED; 91 colorRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
85 subpassDesc.colorAttachmentCount = 0; 92 subpassDesc.colorAttachmentCount = 0;
86 } 93 }
87 subpassDesc.pColorAttachments = &colorRef; 94 subpassDesc.pColorAttachments = &colorRef;
88 95
89 if (fAttachmentFlags & kResolve_AttachmentFlag) { 96 if (fAttachmentFlags & kResolve_AttachmentFlag) {
90 // set up resolve attachment 97 // set up resolve attachment
98 fAttachmentsDescriptor.fResolve.fLoadStoreOps = resolveOp;
91 setup_vk_attachment_description(&attachments[currentAttachment], 99 setup_vk_attachment_description(&attachments[currentAttachment],
92 fAttachmentsDescriptor.fResolve, 100 fAttachmentsDescriptor.fResolve,
93 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ); 101 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL );
94 // setup subpass use of attachment 102 // setup subpass use of attachment
95 resolveRef.attachment = currentAttachment++; 103 resolveRef.attachment = currentAttachment++;
96 // I'm really not sure what the layout should be for the resolve texture s. 104 // I'm really not sure what the layout should be for the resolve texture s.
97 resolveRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 105 resolveRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
98 subpassDesc.pResolveAttachments = &resolveRef; 106 subpassDesc.pResolveAttachments = &resolveRef;
99 } else { 107 } else {
100 subpassDesc.pResolveAttachments = nullptr; 108 subpassDesc.pResolveAttachments = nullptr;
101 } 109 }
102 110
103 if (fAttachmentFlags & kStencil_AttachmentFlag) { 111 if (fAttachmentFlags & kStencil_AttachmentFlag) {
104 // set up stencil attachment 112 // set up stencil attachment
113 fAttachmentsDescriptor.fStencil.fLoadStoreOps = stencilOp;
105 setup_vk_attachment_description(&attachments[currentAttachment], 114 setup_vk_attachment_description(&attachments[currentAttachment],
106 fAttachmentsDescriptor.fStencil, 115 fAttachmentsDescriptor.fStencil,
107 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT _OPTIMAL); 116 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT _OPTIMAL);
108 // setup subpass use of attachment 117 // setup subpass use of attachment
109 stencilRef.attachment = currentAttachment++; 118 stencilRef.attachment = currentAttachment++;
110 stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; 119 stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
111 } else { 120 } else {
112 stencilRef.attachment = VK_ATTACHMENT_UNUSED; 121 stencilRef.attachment = VK_ATTACHMENT_UNUSED;
113 stencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED; 122 stencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
114 } 123 }
(...skipping 16 matching lines...) Expand all
131 createInfo.pSubpasses = &subpassDesc; 140 createInfo.pSubpasses = &subpassDesc;
132 createInfo.dependencyCount = 0; 141 createInfo.dependencyCount = 0;
133 createInfo.pDependencies = nullptr; 142 createInfo.pDependencies = nullptr;
134 143
135 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateRenderPass(gpu->device(), 144 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateRenderPass(gpu->device(),
136 &createInfo, 145 &createInfo,
137 nullptr, 146 nullptr,
138 &fRenderPass)); 147 &fRenderPass));
139 } 148 }
140 149
150 void GrVkRenderPass::init(const GrVkGpu* gpu,
151 const GrVkRenderPass& compatibleRenderPass,
152 const LoadStoreOps& colorOp,
153 const LoadStoreOps& resolveOp,
154 const LoadStoreOps& stencilOp) {
155 fAttachmentFlags = compatibleRenderPass.fAttachmentFlags;
156 fAttachmentsDescriptor = compatibleRenderPass.fAttachmentsDescriptor;
157 this->init(gpu, colorOp, resolveOp, stencilOp);
158 }
159
160 void GrVkRenderPass::init(const GrVkGpu* gpu,
161 const GrVkRenderTarget& target,
162 const LoadStoreOps& colorOp,
163 const LoadStoreOps& resolveOp,
164 const LoadStoreOps& stencilOp) {
165 // Get attachment information from render target. This includes which attach ments the render
166 // target has (color, resolve, stencil) and the attachments format and sampl e count.
167 target.getAttachmentsDescriptor(&fAttachmentsDescriptor, &fAttachmentFlags);
168 this->init(gpu, colorOp, resolveOp, stencilOp);
169 }
170
141 void GrVkRenderPass::freeGPUData(const GrVkGpu* gpu) const { 171 void GrVkRenderPass::freeGPUData(const GrVkGpu* gpu) const {
142 GR_VK_CALL(gpu->vkInterface(), DestroyRenderPass(gpu->device(), fRenderPass, nullptr)); 172 GR_VK_CALL(gpu->vkInterface(), DestroyRenderPass(gpu->device(), fRenderPass, nullptr));
143 } 173 }
144 174
145 // Works under the assumption that color attachment will always be the first att achment in our 175 // Works under the assumption that color attachment will always be the first att achment in our
146 // attachment array if it exists. 176 // attachment array if it exists.
147 bool GrVkRenderPass::colorAttachmentIndex(uint32_t* index) const { 177 bool GrVkRenderPass::colorAttachmentIndex(uint32_t* index) const {
148 *index = 0; 178 *index = 0;
149 if (fAttachmentFlags & kColor_AttachmentFlag) { 179 if (fAttachmentFlags & kColor_AttachmentFlag) {
150 return true; 180 return true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 254 }
225 if (fAttachmentFlags & kStencil_AttachmentFlag) { 255 if (fAttachmentFlags & kStencil_AttachmentFlag) {
226 if (!fAttachmentsDescriptor.fStencil.isCompatible(desc.fStencil)) { 256 if (!fAttachmentsDescriptor.fStencil.isCompatible(desc.fStencil)) {
227 return false; 257 return false;
228 } 258 }
229 } 259 }
230 260
231 return true; 261 return true;
232 } 262 }
233 263
264 bool GrVkRenderPass::equalLoadStoreOps(const LoadStoreOps& colorOps,
265 const LoadStoreOps& resolveOps,
266 const LoadStoreOps& stencilOps) const {
267 if (fAttachmentFlags & kColor_AttachmentFlag) {
268 if (fAttachmentsDescriptor.fColor.fLoadStoreOps != colorOps) {
269 return false;
270 }
271 }
272 if (fAttachmentFlags & kResolve_AttachmentFlag) {
273 if (fAttachmentsDescriptor.fResolve.fLoadStoreOps != resolveOps) {
274 return false;
275 }
276 }
277 if (fAttachmentFlags & kStencil_AttachmentFlag) {
278 if (fAttachmentsDescriptor.fStencil.fLoadStoreOps != stencilOps) {
279 return false;
280 }
281 }
282 return true;
283 }
284
234 void GrVkRenderPass::genKey(GrProcessorKeyBuilder* b) const { 285 void GrVkRenderPass::genKey(GrProcessorKeyBuilder* b) const {
235 b->add32(fAttachmentFlags); 286 b->add32(fAttachmentFlags);
236 if (fAttachmentFlags & kColor_AttachmentFlag) { 287 if (fAttachmentFlags & kColor_AttachmentFlag) {
237 b->add32(fAttachmentsDescriptor.fColor.fFormat); 288 b->add32(fAttachmentsDescriptor.fColor.fFormat);
238 b->add32(fAttachmentsDescriptor.fColor.fSamples); 289 b->add32(fAttachmentsDescriptor.fColor.fSamples);
239 } 290 }
240 if (fAttachmentFlags & kResolve_AttachmentFlag) { 291 if (fAttachmentFlags & kResolve_AttachmentFlag) {
241 b->add32(fAttachmentsDescriptor.fResolve.fFormat); 292 b->add32(fAttachmentsDescriptor.fResolve.fFormat);
242 b->add32(fAttachmentsDescriptor.fResolve.fSamples); 293 b->add32(fAttachmentsDescriptor.fResolve.fSamples);
243 } 294 }
244 if (fAttachmentFlags & kStencil_AttachmentFlag) { 295 if (fAttachmentFlags & kStencil_AttachmentFlag) {
245 b->add32(fAttachmentsDescriptor.fStencil.fFormat); 296 b->add32(fAttachmentsDescriptor.fStencil.fFormat);
246 b->add32(fAttachmentsDescriptor.fStencil.fSamples); 297 b->add32(fAttachmentsDescriptor.fStencil.fSamples);
247 } 298 }
248 } 299 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkRenderPass.h ('k') | src/gpu/vk/GrVkRenderTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698