• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
154     if (attachmentFlags & kColor_AttachmentFlag) {
155         // set up color attachment
156         bool needsGeneralLayout = SkToBool(selfDepFlags & SelfDependencyFlags::kForInputAttachment);
157         VkImageLayout layout = needsGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL
158                                                   : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
159 
160         attachmentsDescriptor->fColor.fLoadStoreOps = colorOp;
161 
162         setup_vk_attachment_description(&attachments[currentAttachment],
163                                         attachmentsDescriptor->fColor,
164                                         layout, layout);
165         // setup subpass use of attachment
166         colorRef.attachment = currentAttachment++;
167         colorRef.layout = layout;
168         subpassDescMain.colorAttachmentCount = 1;
169 
170         if (selfDepFlags != SelfDependencyFlags::kNone) {
171             VkSubpassDependency& dependency = dependencies[currentDependency++];
172             dependency.srcSubpass = mainSubpass;
173             dependency.dstSubpass = mainSubpass;
174             dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
175             dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
176             dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
177             dependency.dstStageMask = 0;
178             dependency.dstAccessMask = 0;
179 
180             if (selfDepFlags & SelfDependencyFlags::kForNonCoherentAdvBlend) {
181                 // If we have coherent support we shouldn't be needing a self dependency
182                 SkASSERT(!gpu->caps()->advancedCoherentBlendEquationSupport());
183                 dependency.dstStageMask |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
184                 dependency.dstAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT;
185             }
186             if (selfDepFlags & SelfDependencyFlags::kForInputAttachment) {
187                 SkASSERT(gpu->vkCaps().maxInputAttachmentDescriptors());
188 
189                 subpassDescMain.inputAttachmentCount = 1;
190                 subpassDescMain.pInputAttachments = &colorRef;
191 
192                 dependency.dstStageMask |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
193                 dependency.dstAccessMask |= VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
194             }
195         }
196 
197         if (VK_ATTACHMENT_LOAD_OP_CLEAR == colorOp.fLoadOp) {
198             clearValueCount = colorRef.attachment + 1;
199         }
200     } else {
201         // I don't think there should ever be a time where we don't have a color attachment
202         SkASSERT(false);
203         SkASSERT(selfDepFlags == SelfDependencyFlags::kNone);
204         colorRef.attachment = VK_ATTACHMENT_UNUSED;
205         colorRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
206         subpassDescMain.colorAttachmentCount = 0;
207     }
208 
209     subpassDescMain.pColorAttachments = &colorRef;
210 
211     if (attachmentFlags & kResolve_AttachmentFlag) {
212         attachmentsDescriptor->fResolve.fLoadStoreOps = resolveOp;
213 
214         VkImageLayout layout = loadFromResolve == LoadFromResolve::kLoad
215                                        ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
216                                        : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
217 
218         setup_vk_attachment_description(&attachments[currentAttachment],
219                                         attachmentsDescriptor->fResolve,
220                                         layout,
221                                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
222 
223         // setup main subpass use of attachment
224         resolveRef.attachment = currentAttachment++;
225         resolveRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
226 
227         subpassDescMain.pResolveAttachments = &resolveRef;
228 
229         // Setup the load subpass and set subpass dependendcies
230         if (loadFromResolve == LoadFromResolve::kLoad) {
231             resolveLoadInputRef.attachment = resolveRef.attachment;
232             resolveLoadInputRef.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
233 
234             // The load subpass will always be the first
235             VkSubpassDescription& subpassDescLoad = subpassDescs[0];
236             subpassDescLoad.flags = 0;
237             subpassDescLoad.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
238             subpassDescLoad.inputAttachmentCount = 1;
239             subpassDescLoad.pInputAttachments = &resolveLoadInputRef;
240             subpassDescLoad.colorAttachmentCount = 1;
241             subpassDescLoad.pColorAttachments = &colorRef;
242             subpassDescLoad.pResolveAttachments = nullptr;
243             subpassDescLoad.pDepthStencilAttachment = nullptr;
244             subpassDescLoad.preserveAttachmentCount = 0;
245             subpassDescLoad.pPreserveAttachments = nullptr;
246 
247             VkSubpassDependency& dependency = dependencies[currentDependency++];
248             dependency.srcSubpass = 0;
249             dependency.dstSubpass = mainSubpass;
250             dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
251             dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
252             dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
253             dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
254             dependency.dstAccessMask =
255                     VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
256         }
257     }
258 
259 
260     if (attachmentFlags & kStencil_AttachmentFlag) {
261         // set up stencil attachment
262         attachmentsDescriptor->fStencil.fLoadStoreOps = stencilOp;
263         setup_vk_attachment_description(&attachments[currentAttachment],
264                                         attachmentsDescriptor->fStencil,
265                                         VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
266                                         VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
267         // setup subpass use of attachment
268         stencilRef.attachment = currentAttachment++;
269         stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
270         if (VK_ATTACHMENT_LOAD_OP_CLEAR == stencilOp.fLoadOp) {
271             clearValueCount = std::max(clearValueCount, stencilRef.attachment + 1);
272         }
273     } else {
274         stencilRef.attachment = VK_ATTACHMENT_UNUSED;
275         stencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
276     }
277     subpassDescMain.pDepthStencilAttachment = &stencilRef;
278 
279     subpassDescMain.preserveAttachmentCount = 0;
280     subpassDescMain.pPreserveAttachments = nullptr;
281 
282     SkASSERT(numAttachments == currentAttachment);
283 
284     uint32_t subpassCount = loadFromResolve == LoadFromResolve::kLoad ? 2 : 1;
285 
286     // Create the VkRenderPass compatible with the attachment descriptions above
287     VkRenderPassCreateInfo createInfo;
288     memset(&createInfo, 0, sizeof(VkRenderPassCreateInfo));
289     createInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
290     createInfo.pNext = nullptr;
291     createInfo.flags = 0;
292     createInfo.attachmentCount = numAttachments;
293     createInfo.pAttachments = attachments.begin();
294     createInfo.subpassCount = subpassCount;
295     createInfo.pSubpasses = subpassDescs;
296     createInfo.dependencyCount = currentDependency;
297     createInfo.pDependencies = dependencies;
298 
299     VkResult result;
300     VkRenderPass renderPass;
301     GR_VK_CALL_RESULT(gpu, result, CreateRenderPass(gpu->device(),
302                                                     &createInfo,
303                                                     nullptr,
304                                                     &renderPass));
305     if (result != VK_SUCCESS) {
306         return nullptr;
307     }
308 
309     VkExtent2D granularity;
310     // Get granularity for this render pass
311     GR_VK_CALL(gpu->vkInterface(), GetRenderAreaGranularity(gpu->device(),
312                                                             renderPass,
313                                                             &granularity));
314 
315     return new GrVkRenderPass(gpu, renderPass, attachmentFlags, *attachmentsDescriptor,
316                               selfDepFlags, loadFromResolve, granularity, clearValueCount);
317 }
318 
GrVkRenderPass(const GrVkGpu * gpu,VkRenderPass renderPass,AttachmentFlags flags,const AttachmentsDescriptor & descriptor,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve,const VkExtent2D & granularity,uint32_t clearValueCount)319 GrVkRenderPass::GrVkRenderPass(const GrVkGpu* gpu, VkRenderPass renderPass, AttachmentFlags flags,
320                                const AttachmentsDescriptor& descriptor,
321                                SelfDependencyFlags selfDepFlags,
322                                LoadFromResolve loadFromResolve,
323                                const VkExtent2D& granularity, uint32_t clearValueCount)
324         : INHERITED(gpu)
325         , fRenderPass(renderPass)
326         , fAttachmentFlags(flags)
327         , fAttachmentsDescriptor(descriptor)
328         , fSelfDepFlags(selfDepFlags)
329         , fLoadFromResolve(loadFromResolve)
330         , fGranularity(granularity)
331         , fClearValueCount(clearValueCount) {
332 }
333 
freeGPUData() const334 void GrVkRenderPass::freeGPUData() const {
335     if (!(fAttachmentFlags & kExternal_AttachmentFlag)) {
336         GR_VK_CALL(fGpu->vkInterface(), DestroyRenderPass(fGpu->device(), fRenderPass, nullptr));
337     }
338 }
339 
colorAttachmentIndex(uint32_t * index) const340 bool GrVkRenderPass::colorAttachmentIndex(uint32_t* index) const {
341     *index = fColorAttachmentIndex;
342     if ((fAttachmentFlags & kColor_AttachmentFlag) ||
343         (fAttachmentFlags & kExternal_AttachmentFlag)) {
344         return true;
345     }
346     return false;
347 }
348 
349 // Works under the assumption that stencil attachment will always be after the color and resolve
350 // attachments.
stencilAttachmentIndex(uint32_t * index) const351 bool GrVkRenderPass::stencilAttachmentIndex(uint32_t* index) const {
352     *index = 0;
353     if (fAttachmentFlags & kColor_AttachmentFlag) {
354         ++(*index);
355     }
356     if (fAttachmentFlags & kStencil_AttachmentFlag) {
357         return true;
358     }
359     return false;
360 }
361 
isCompatible(const AttachmentsDescriptor & desc,const AttachmentFlags & flags,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve) const362 bool GrVkRenderPass::isCompatible(const AttachmentsDescriptor& desc,
363                                   const AttachmentFlags& flags,
364                                   SelfDependencyFlags selfDepFlags,
365                                   LoadFromResolve loadFromResolve) const {
366     SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
367     if (flags != fAttachmentFlags) {
368         return false;
369     }
370 
371     if (fAttachmentFlags & kColor_AttachmentFlag) {
372         if (!fAttachmentsDescriptor.fColor.isCompatible(desc.fColor)) {
373             return false;
374         }
375     }
376     if (fAttachmentFlags & kResolve_AttachmentFlag) {
377         if (!fAttachmentsDescriptor.fResolve.isCompatible(desc.fResolve)) {
378             return false;
379         }
380     }
381     if (fAttachmentFlags & kStencil_AttachmentFlag) {
382         if (!fAttachmentsDescriptor.fStencil.isCompatible(desc.fStencil)) {
383             return false;
384         }
385     }
386 
387     if (fSelfDepFlags != selfDepFlags) {
388         return false;
389     }
390 
391     if (fLoadFromResolve != loadFromResolve) {
392         return false;
393     }
394 
395     return true;
396 }
397 
isCompatible(GrVkRenderTarget * target,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve) const398 bool GrVkRenderPass::isCompatible(GrVkRenderTarget* target,
399                                   SelfDependencyFlags selfDepFlags,
400                                   LoadFromResolve loadFromResolve) const {
401     SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
402 
403     AttachmentsDescriptor desc;
404     AttachmentFlags flags;
405     target->getAttachmentsDescriptor(&desc, &flags, this->hasResolveAttachment(),
406                                      this->hasStencilAttachment());
407 
408     return this->isCompatible(desc, flags, selfDepFlags, loadFromResolve);
409 }
410 
isCompatible(const GrVkRenderPass & renderPass) const411 bool GrVkRenderPass::isCompatible(const GrVkRenderPass& renderPass) const {
412     SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
413     return this->isCompatible(renderPass.fAttachmentsDescriptor, renderPass.fAttachmentFlags,
414                               renderPass.fSelfDepFlags, renderPass.fLoadFromResolve);
415 }
416 
isCompatibleExternalRP(VkRenderPass renderPass) const417 bool GrVkRenderPass::isCompatibleExternalRP(VkRenderPass renderPass) const {
418     SkASSERT(fAttachmentFlags & kExternal_AttachmentFlag);
419     return fRenderPass == renderPass;
420 }
421 
equalLoadStoreOps(const LoadStoreOps & colorOps,const LoadStoreOps & resolveOps,const LoadStoreOps & stencilOps) const422 bool GrVkRenderPass::equalLoadStoreOps(const LoadStoreOps& colorOps,
423                                        const LoadStoreOps& resolveOps,
424                                        const LoadStoreOps& stencilOps) const {
425     SkASSERT(!(fAttachmentFlags & kExternal_AttachmentFlag));
426     if (fAttachmentFlags & kColor_AttachmentFlag) {
427         if (fAttachmentsDescriptor.fColor.fLoadStoreOps != colorOps) {
428             return false;
429         }
430     }
431     if (fAttachmentFlags & kResolve_AttachmentFlag) {
432         if (fAttachmentsDescriptor.fResolve.fLoadStoreOps != resolveOps) {
433             return false;
434         }
435     }
436     if (fAttachmentFlags & kStencil_AttachmentFlag) {
437         if (fAttachmentsDescriptor.fStencil.fLoadStoreOps != stencilOps) {
438             return false;
439         }
440     }
441     return true;
442 }
443 
genKey(GrProcessorKeyBuilder * b) const444 void GrVkRenderPass::genKey(GrProcessorKeyBuilder* b) const {
445     GenKey(b, fAttachmentFlags, fAttachmentsDescriptor, fSelfDepFlags,
446            fLoadFromResolve, (uint64_t)fRenderPass);
447 }
448 
GenKey(GrProcessorKeyBuilder * b,AttachmentFlags attachmentFlags,const AttachmentsDescriptor & attachmentsDescriptor,SelfDependencyFlags selfDepFlags,LoadFromResolve loadFromResolve,uint64_t externalRenderPass)449 void GrVkRenderPass::GenKey(GrProcessorKeyBuilder* b,
450                             AttachmentFlags attachmentFlags,
451                             const AttachmentsDescriptor& attachmentsDescriptor,
452                             SelfDependencyFlags selfDepFlags,
453                             LoadFromResolve loadFromResolve,
454                             uint64_t externalRenderPass) {
455     b->add32(attachmentFlags);
456     if (attachmentFlags & kColor_AttachmentFlag) {
457         b->add32(attachmentsDescriptor.fColor.fFormat);
458         b->add32(attachmentsDescriptor.fColor.fSamples);
459     }
460     if (attachmentFlags & kResolve_AttachmentFlag) {
461         b->add32(attachmentsDescriptor.fResolve.fFormat);
462         b->add32(attachmentsDescriptor.fResolve.fSamples);
463     }
464     if (attachmentFlags & kStencil_AttachmentFlag) {
465         b->add32(attachmentsDescriptor.fStencil.fFormat);
466         b->add32(attachmentsDescriptor.fStencil.fSamples);
467     }
468 
469     uint32_t extraFlags = (uint32_t)selfDepFlags;
470     SkASSERT(extraFlags < (1 << 30));
471     SkASSERT((uint32_t)loadFromResolve <= 2);
472     extraFlags |= ((uint32_t)loadFromResolve << 30);
473 
474     b->add32(extraFlags);
475 
476     if (attachmentFlags & kExternal_AttachmentFlag) {
477         SkASSERT(!(attachmentFlags & ~kExternal_AttachmentFlag));
478         b->add32((uint32_t)(externalRenderPass & 0xFFFFFFFF));
479         b->add32((uint32_t)(externalRenderPass>>32));
480     }
481 }
482