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

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

Powered by Google App Engine
This is Rietveld 408576698