1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "src/gpu/vk/GrVkRenderPass.h"
9
10 #include "src/gpu/GrProcessor.h"
11 #include "src/gpu/vk/GrVkFramebuffer.h"
12 #include "src/gpu/vk/GrVkGpu.h"
13 #include "src/gpu/vk/GrVkRenderTarget.h"
14 #include "src/gpu/vk/GrVkUtil.h"
15
16 typedef GrVkRenderPass::AttachmentsDescriptor::AttachmentDesc AttachmentDesc;
17
setup_vk_attachment_description(VkAttachmentDescription * attachment,const AttachmentDesc & desc,VkImageLayout startLayout,VkImageLayout endLayout)18 void setup_vk_attachment_description(VkAttachmentDescription* attachment,
19 const AttachmentDesc& desc,
20 VkImageLayout startLayout,
21 VkImageLayout endLayout) {
22 attachment->flags = 0;
23 attachment->format = desc.fFormat;
24 SkAssertResult(GrSampleCountToVkSampleCount(desc.fSamples, &attachment->samples));
25 switch (startLayout) {
26 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
27 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
28 case VK_IMAGE_LAYOUT_GENERAL:
29 attachment->loadOp = desc.fLoadStoreOps.fLoadOp;
30 attachment->storeOp = desc.fLoadStoreOps.fStoreOp;
31 attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
32 attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
33 break;
34 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
35 attachment->loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
36 attachment->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
37 attachment->stencilLoadOp = desc.fLoadStoreOps.fLoadOp;
38 attachment->stencilStoreOp = desc.fLoadStoreOps.fStoreOp;
39 break;
40 default:
41 SK_ABORT("Unexpected attachment layout");
42 }
43
44 attachment->initialLayout = startLayout;
45 attachment->finalLayout = endLayout == VK_IMAGE_LAYOUT_UNDEFINED ? startLayout : endLayout;
46 }
47
CreateSimple(GrVkGpu * gpu,AttachmentsDescriptor * attachmentsDescriptor,AttachmentFlags attachmentFlags,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve)48 GrVkRenderPass* GrVkRenderPass::CreateSimple(GrVkGpu* gpu,
49 AttachmentsDescriptor* attachmentsDescriptor,
50 AttachmentFlags attachmentFlags,
51 SelfDependencyFlags selfDepFlags,
52 LoadFromResolve loadFromResolve) {
53 static const GrVkRenderPass::LoadStoreOps kBasicLoadStoreOps(VK_ATTACHMENT_LOAD_OP_LOAD,
54 VK_ATTACHMENT_STORE_OP_STORE);
55 switch (loadFromResolve) {
56 case LoadFromResolve::kNo:
57 return Create(gpu, attachmentFlags, attachmentsDescriptor, kBasicLoadStoreOps,
58 kBasicLoadStoreOps, kBasicLoadStoreOps, selfDepFlags, loadFromResolve);
59 case LoadFromResolve::kLoad: {
60 static const GrVkRenderPass::LoadStoreOps kDiscardLoadStoreOps(
61 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE);
62 return Create(gpu, attachmentFlags, attachmentsDescriptor, kDiscardLoadStoreOps,
63 kBasicLoadStoreOps, kBasicLoadStoreOps, selfDepFlags, loadFromResolve);
64 }
65 }
66 SkUNREACHABLE;
67 }
68
Create(GrVkGpu * gpu,const GrVkRenderPass & compatibleRenderPass,const LoadStoreOps & colorOp,const LoadStoreOps & resolveOp,const LoadStoreOps & stencilOp)69 GrVkRenderPass* GrVkRenderPass::Create(GrVkGpu* gpu,
70 const GrVkRenderPass& compatibleRenderPass,
71 const LoadStoreOps& colorOp,
72 const LoadStoreOps& resolveOp,
73 const LoadStoreOps& stencilOp) {
74 AttachmentFlags attachmentFlags = compatibleRenderPass.fAttachmentFlags;
75 AttachmentsDescriptor attachmentsDescriptor = compatibleRenderPass.fAttachmentsDescriptor;
76 SelfDependencyFlags selfDepFlags = compatibleRenderPass.fSelfDepFlags;
77 LoadFromResolve loadFromResolve = compatibleRenderPass.fLoadFromResolve;
78 return Create(gpu, attachmentFlags, &attachmentsDescriptor, colorOp, resolveOp, stencilOp,
79 selfDepFlags, loadFromResolve);
80 }
81
Create(GrVkGpu * gpu,AttachmentFlags attachmentFlags,AttachmentsDescriptor * attachmentsDescriptor,const LoadStoreOps & colorOp,const LoadStoreOps & resolveOp,const LoadStoreOps & stencilOp,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve)82 GrVkRenderPass* GrVkRenderPass::Create(GrVkGpu* gpu,
83 AttachmentFlags attachmentFlags,
84 AttachmentsDescriptor* attachmentsDescriptor,
85 const LoadStoreOps& colorOp,
86 const LoadStoreOps& resolveOp,
87 const LoadStoreOps& stencilOp,
88 SelfDependencyFlags selfDepFlags,
89 LoadFromResolve loadFromResolve) {
90 SkASSERT(!SkToBool(selfDepFlags & SelfDependencyFlags::kForNonCoherentAdvBlend) ||
91 gpu->caps()->advancedBlendEquationSupport());
92 SkASSERT(!SkToBool(selfDepFlags & SelfDependencyFlags::kForInputAttachment) ||
93 gpu->caps()->textureBarrierSupport());
94
95 // If we have a resolve attachment, we will always do a resolve into it. Thus it doesn't make
96 // sense not to store the resolve attachment at the end of the render pass.
97 //
98 // Currently today (when not using discardable msaa images) we load and store the the msaa image
99 // and then use the copy resolve command to handle the resolving. If instead we moved to doing
100 // the resolving at the end of the last render pass, we would probably want a separate flag
101 // for having a resolve attachment versus actually doing the resolving. This would allow us to
102 // use the same VkPiplines for render passes where we resolve and those we don't since each will
103 // always have the resolve attachment. The actual resolving or not does not affect render pass
104 // compatibility if there is only one sub pass, just the presence of the attachment or not.
105 SkASSERT(!SkToBool(attachmentFlags & kResolve_AttachmentFlag) ||
106 resolveOp.fStoreOp == VK_ATTACHMENT_STORE_OP_STORE);
107
108 SkASSERT(loadFromResolve == LoadFromResolve::kNo ||
109 (SkToBool(attachmentFlags & kColor_AttachmentFlag) &&
110 SkToBool(attachmentFlags & kResolve_AttachmentFlag)));
111
112 #ifdef SK_DEBUG
113 if (loadFromResolve == LoadFromResolve::kLoad) {
114 // If we are loading the resolve image into the msaa color attachment then we should not be
115 // loading or storing the msaa attachment. Additionally we need to make sure we are loading
116 // the resolve so it can be copied into the msaa color attachment.
117 SkASSERT(colorOp.fLoadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE);
118 SkASSERT(colorOp.fStoreOp == VK_ATTACHMENT_STORE_OP_DONT_CARE);
119 SkASSERT(resolveOp.fLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD);
120 }
121 #endif
122
123 uint32_t numAttachments = attachmentsDescriptor->fAttachmentCount;
124 // Attachment descriptions to be set on the render pass
125 SkTArray<VkAttachmentDescription> attachments(numAttachments);
126 attachments.reset(numAttachments);
127 memset(attachments.begin(), 0, numAttachments * sizeof(VkAttachmentDescription));
128
129 // Refs to attachments on the render pass (as described by the VkAttachmentDescription above),
130 // that are used by the subpass.
131 VkAttachmentReference colorRef;
132 VkAttachmentReference resolveRef;
133 VkAttachmentReference resolveLoadInputRef;
134 VkAttachmentReference stencilRef;
135 uint32_t currentAttachment = 0;
136
137 // Go through each of the attachment types (color, stencil) and set the necessary
138 // on the various Vk structs.
139 VkSubpassDescription subpassDescs[2];
140 memset(subpassDescs, 0, 2*sizeof(VkSubpassDescription));
141 const int mainSubpass = loadFromResolve == LoadFromResolve::kLoad ? 1 : 0;
142 VkSubpassDescription& subpassDescMain = subpassDescs[mainSubpass];
143 subpassDescMain.flags = 0;
144 subpassDescMain.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
145 subpassDescMain.inputAttachmentCount = 0;
146 subpassDescMain.pInputAttachments = nullptr;
147 subpassDescMain.pResolveAttachments = nullptr;
148
149 uint32_t clearValueCount = 0;
150
151 VkSubpassDependency dependencies[2];
152 int currentDependency = 0;
153 bool skipSetSubpassDep = false;
154
155 if (attachmentFlags & kColor_AttachmentFlag) {
156 // set up color attachment
157 bool needsGeneralLayout = SkToBool(selfDepFlags & SelfDependencyFlags::kForInputAttachment);
158 VkImageLayout layout = needsGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL
159 : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
160
161 attachmentsDescriptor->fColor.fLoadStoreOps = colorOp;
162
163 setup_vk_attachment_description(&attachments[currentAttachment],
164 attachmentsDescriptor->fColor,
165 layout, layout);
166 // setup subpass use of attachment
167 colorRef.attachment = currentAttachment++;
168 colorRef.layout = layout;
169 subpassDescMain.colorAttachmentCount = 1;
170
171 if (selfDepFlags != SelfDependencyFlags::kNone) {
172 VkSubpassDependency& dependency = dependencies[currentDependency++];
173 dependency.srcSubpass = mainSubpass;
174 dependency.dstSubpass = mainSubpass;
175 dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
176 dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
177 dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
178 dependency.dstStageMask = 0;
179 dependency.dstAccessMask = 0;
180
181 if (selfDepFlags & SelfDependencyFlags::kForNonCoherentAdvBlend) {
182 // If we have coherent support we shouldn't be needing a self dependency
183 SkASSERT(!gpu->caps()->advancedCoherentBlendEquationSupport());
184 dependency.dstStageMask |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
185 dependency.dstAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT;
186 }
187 if (selfDepFlags & SelfDependencyFlags::kForInputAttachment) {
188 SkASSERT(gpu->vkCaps().maxInputAttachmentDescriptors());
189
190 subpassDescMain.inputAttachmentCount = 1;
191 subpassDescMain.pInputAttachments = &colorRef;
192
193 dependency.dstStageMask |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
194 dependency.dstAccessMask |= VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
195 skipSetSubpassDep = true;
196 }
197 }
198
199 if (VK_ATTACHMENT_LOAD_OP_CLEAR == colorOp.fLoadOp) {
200 clearValueCount = colorRef.attachment + 1;
201 }
202 } else {
203 // I don't think there should ever be a time where we don't have a color attachment
204 SkASSERT(false);
205 SkASSERT(selfDepFlags == SelfDependencyFlags::kNone);
206 colorRef.attachment = VK_ATTACHMENT_UNUSED;
207 colorRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
208 subpassDescMain.colorAttachmentCount = 0;
209 }
210
211 subpassDescMain.pColorAttachments = &colorRef;
212
213 if (attachmentFlags & kResolve_AttachmentFlag) {
214 attachmentsDescriptor->fResolve.fLoadStoreOps = resolveOp;
215
216 VkImageLayout layout = loadFromResolve == LoadFromResolve::kLoad
217 ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
218 : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
219
220 setup_vk_attachment_description(&attachments[currentAttachment],
221 attachmentsDescriptor->fResolve,
222 layout,
223 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
224
225 // setup main subpass use of attachment
226 resolveRef.attachment = currentAttachment++;
227 resolveRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
228
229 subpassDescMain.pResolveAttachments = &resolveRef;
230
231 // Setup the load subpass and set subpass dependendcies
232 if (loadFromResolve == LoadFromResolve::kLoad) {
233 resolveLoadInputRef.attachment = resolveRef.attachment;
234 resolveLoadInputRef.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
235
236 // The load subpass will always be the first
237 VkSubpassDescription& subpassDescLoad = subpassDescs[0];
238 subpassDescLoad.flags = 0;
239 subpassDescLoad.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
240 subpassDescLoad.inputAttachmentCount = 1;
241 subpassDescLoad.pInputAttachments = &resolveLoadInputRef;
242 subpassDescLoad.colorAttachmentCount = 1;
243 subpassDescLoad.pColorAttachments = &colorRef;
244 subpassDescLoad.pResolveAttachments = nullptr;
245 subpassDescLoad.pDepthStencilAttachment = nullptr;
246 subpassDescLoad.preserveAttachmentCount = 0;
247 subpassDescLoad.pPreserveAttachments = nullptr;
248
249 VkSubpassDependency& dependency = dependencies[currentDependency++];
250 dependency.srcSubpass = 0;
251 dependency.dstSubpass = mainSubpass;
252 dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
253 dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
254 dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
255 dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
256 dependency.dstAccessMask =
257 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
258 }
259 }
260
261
262 if (attachmentFlags & kStencil_AttachmentFlag) {
263 // set up stencil attachment
264 attachmentsDescriptor->fStencil.fLoadStoreOps = stencilOp;
265 setup_vk_attachment_description(&attachments[currentAttachment],
266 attachmentsDescriptor->fStencil,
267 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
268 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
269 // setup subpass use of attachment
270 stencilRef.attachment = currentAttachment++;
271 stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
272 if (VK_ATTACHMENT_LOAD_OP_CLEAR == stencilOp.fLoadOp) {
273 clearValueCount = std::max(clearValueCount, stencilRef.attachment + 1);
274 }
275 } else {
276 stencilRef.attachment = VK_ATTACHMENT_UNUSED;
277 stencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
278 }
279 subpassDescMain.pDepthStencilAttachment = &stencilRef;
280
281 subpassDescMain.preserveAttachmentCount = 0;
282 subpassDescMain.pPreserveAttachments = nullptr;
283
284 SkASSERT(numAttachments == currentAttachment);
285
286 uint32_t subpassCount = loadFromResolve == LoadFromResolve::kLoad ? 2 : 1;
287
288 // Create the VkRenderPass compatible with the attachment descriptions above
289 VkRenderPassCreateInfo createInfo;
290 memset(&createInfo, 0, sizeof(VkRenderPassCreateInfo));
291 createInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
292 createInfo.pNext = nullptr;
293 createInfo.flags = 0;
294 createInfo.attachmentCount = numAttachments;
295 createInfo.pAttachments = attachments.begin();
296 createInfo.subpassCount = subpassCount;
297 createInfo.pSubpasses = subpassDescs;
298 // skipSetSubpassDep is a non-specification operation
299 if (skipSetSubpassDep && currentDependency == 1) {
300 createInfo.dependencyCount = 0;
301 createInfo.pDependencies = nullptr;
302 } else {
303 createInfo.dependencyCount = currentDependency;
304 createInfo.pDependencies = dependencies;
305 }
306
307 VkResult result;
308 VkRenderPass renderPass;
309 GR_VK_CALL_RESULT(gpu, result, CreateRenderPass(gpu->device(),
310 &createInfo,
311 nullptr,
312 &renderPass));
313 if (result != VK_SUCCESS) {
314 return nullptr;
315 }
316
317 VkExtent2D granularity;
318 // Get granularity for this render pass
319 GR_VK_CALL(gpu->vkInterface(), GetRenderAreaGranularity(gpu->device(),
320 renderPass,
321 &granularity));
322
323 return new GrVkRenderPass(gpu, renderPass, attachmentFlags, *attachmentsDescriptor,
324 selfDepFlags, loadFromResolve, granularity, clearValueCount);
325 }
326
GrVkRenderPass(const GrVkGpu * gpu,VkRenderPass renderPass,AttachmentFlags flags,const AttachmentsDescriptor & descriptor,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve,const VkExtent2D & granularity,uint32_t clearValueCount)327 GrVkRenderPass::GrVkRenderPass(const GrVkGpu* gpu, VkRenderPass renderPass, AttachmentFlags flags,
328 const AttachmentsDescriptor& descriptor,
329 SelfDependencyFlags selfDepFlags,
330 LoadFromResolve loadFromResolve,
331 const VkExtent2D& granularity, uint32_t clearValueCount)
332 : INHERITED(gpu)
333 , fRenderPass(renderPass)
334 , fAttachmentFlags(flags)
335 , fAttachmentsDescriptor(descriptor)
336 , fSelfDepFlags(selfDepFlags)
337 , fLoadFromResolve(loadFromResolve)
338 , fGranularity(granularity)
339 , fClearValueCount(clearValueCount) {
340 }
341
freeGPUData() const342 void GrVkRenderPass::freeGPUData() const {
343 if (!(fAttachmentFlags & kExternal_AttachmentFlag)) {
344 GR_VK_CALL(fGpu->vkInterface(), DestroyRenderPass(fGpu->device(), fRenderPass, nullptr));
345 }
346 }
347
colorAttachmentIndex(uint32_t * index) const348 bool GrVkRenderPass::colorAttachmentIndex(uint32_t* index) const {
349 *index = fColorAttachmentIndex;
350 if ((fAttachmentFlags & kColor_AttachmentFlag) ||
351 (fAttachmentFlags & kExternal_AttachmentFlag)) {
352 return true;
353 }
354 return false;
355 }
356
357 // Works under the assumption that stencil attachment will always be after the color and resolve
358 // attachments.
stencilAttachmentIndex(uint32_t * index) const359 bool GrVkRenderPass::stencilAttachmentIndex(uint32_t* index) const {
360 *index = 0;
361 if (fAttachmentFlags & kColor_AttachmentFlag) {
362 ++(*index);
363 }
364 if (fAttachmentFlags & kStencil_AttachmentFlag) {
365 return true;
366 }
367 return false;
368 }
369
isCompatible(const AttachmentsDescriptor & desc,const AttachmentFlags & flags,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve) const370 bool GrVkRenderPass::isCompatible(const AttachmentsDescriptor& desc,
371 const AttachmentFlags& flags,
372 SelfDependencyFlags selfDepFlags,
373 LoadFromResolve loadFromResolve) const {
374 SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
375 if (flags != fAttachmentFlags) {
376 return false;
377 }
378
379 if (fAttachmentFlags & kColor_AttachmentFlag) {
380 if (!fAttachmentsDescriptor.fColor.isCompatible(desc.fColor)) {
381 return false;
382 }
383 }
384 if (fAttachmentFlags & kResolve_AttachmentFlag) {
385 if (!fAttachmentsDescriptor.fResolve.isCompatible(desc.fResolve)) {
386 return false;
387 }
388 }
389 if (fAttachmentFlags & kStencil_AttachmentFlag) {
390 if (!fAttachmentsDescriptor.fStencil.isCompatible(desc.fStencil)) {
391 return false;
392 }
393 }
394
395 if (fSelfDepFlags != selfDepFlags) {
396 return false;
397 }
398
399 if (fLoadFromResolve != loadFromResolve) {
400 return false;
401 }
402
403 return true;
404 }
405
isCompatible(GrVkRenderTarget * target,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve) const406 bool GrVkRenderPass::isCompatible(GrVkRenderTarget* target,
407 SelfDependencyFlags selfDepFlags,
408 LoadFromResolve loadFromResolve) const {
409 SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
410
411 AttachmentsDescriptor desc;
412 AttachmentFlags flags;
413 target->getAttachmentsDescriptor(&desc, &flags, this->hasResolveAttachment(),
414 this->hasStencilAttachment());
415
416 return this->isCompatible(desc, flags, selfDepFlags, loadFromResolve);
417 }
418
isCompatible(const GrVkRenderPass & renderPass) const419 bool GrVkRenderPass::isCompatible(const GrVkRenderPass& renderPass) const {
420 SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
421 return this->isCompatible(renderPass.fAttachmentsDescriptor, renderPass.fAttachmentFlags,
422 renderPass.fSelfDepFlags, renderPass.fLoadFromResolve);
423 }
424
isCompatibleExternalRP(VkRenderPass renderPass) const425 bool GrVkRenderPass::isCompatibleExternalRP(VkRenderPass renderPass) const {
426 SkASSERT(fAttachmentFlags & kExternal_AttachmentFlag);
427 return fRenderPass == renderPass;
428 }
429
equalLoadStoreOps(const LoadStoreOps & colorOps,const LoadStoreOps & resolveOps,const LoadStoreOps & stencilOps) const430 bool GrVkRenderPass::equalLoadStoreOps(const LoadStoreOps& colorOps,
431 const LoadStoreOps& resolveOps,
432 const LoadStoreOps& stencilOps) const {
433 SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
434 if (fAttachmentFlags & kColor_AttachmentFlag) {
435 if (fAttachmentsDescriptor.fColor.fLoadStoreOps != colorOps) {
436 return false;
437 }
438 }
439 if (fAttachmentFlags & kResolve_AttachmentFlag) {
440 if (fAttachmentsDescriptor.fResolve.fLoadStoreOps != resolveOps) {
441 return false;
442 }
443 }
444 if (fAttachmentFlags & kStencil_AttachmentFlag) {
445 if (fAttachmentsDescriptor.fStencil.fLoadStoreOps != stencilOps) {
446 return false;
447 }
448 }
449 return true;
450 }
451
genKey(GrProcessorKeyBuilder * b) const452 void GrVkRenderPass::genKey(GrProcessorKeyBuilder* b) const {
453 GenKey(b, fAttachmentFlags, fAttachmentsDescriptor, fSelfDepFlags,
454 fLoadFromResolve, (uint64_t)fRenderPass);
455 }
456
GenKey(GrProcessorKeyBuilder * b,AttachmentFlags attachmentFlags,const AttachmentsDescriptor & attachmentsDescriptor,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve,uint64_t externalRenderPass)457 void GrVkRenderPass::GenKey(GrProcessorKeyBuilder* b,
458 AttachmentFlags attachmentFlags,
459 const AttachmentsDescriptor& attachmentsDescriptor,
460 SelfDependencyFlags selfDepFlags,
461 LoadFromResolve loadFromResolve,
462 uint64_t externalRenderPass) {
463 b->add32(attachmentFlags);
464 if (attachmentFlags & kColor_AttachmentFlag) {
465 b->add32(attachmentsDescriptor.fColor.fFormat);
466 b->add32(attachmentsDescriptor.fColor.fSamples);
467 }
468 if (attachmentFlags & kResolve_AttachmentFlag) {
469 b->add32(attachmentsDescriptor.fResolve.fFormat);
470 b->add32(attachmentsDescriptor.fResolve.fSamples);
471 }
472 if (attachmentFlags & kStencil_AttachmentFlag) {
473 b->add32(attachmentsDescriptor.fStencil.fFormat);
474 b->add32(attachmentsDescriptor.fStencil.fSamples);
475 }
476
477 uint32_t extraFlags = (uint32_t)selfDepFlags;
478 SkASSERT(extraFlags < (1 << 30));
479 SkASSERT((uint32_t)loadFromResolve <= 2);
480 extraFlags |= ((uint32_t)loadFromResolve << 30);
481
482 b->add32(extraFlags);
483
484 if (attachmentFlags & kExternal_AttachmentFlag) {
485 SkASSERT(!(attachmentFlags & ~kExternal_AttachmentFlag));
486 b->add32((uint32_t)(externalRenderPass & 0xFFFFFFFF));
487 b->add32((uint32_t)(externalRenderPass>>32));
488 }
489 }
490