Refactor creation of GrVkRenderPasses to make them move general

This change is a refactorization to open up more flexable use for render passes
in the future. Once we start bundling draw calls into a single render pass we
will need to start using specific load and store ops instead of the default
currently of load and store everything.

We still will need to simply get a compatible render pass for creation of framebuffers
and pipeline objects. These render passes don't need to know load and store ops. Thus
in this change, I'm defaulting the "compatible" render pass to always be the one
which both loads and stores. All other load/store combinations will be created lazily
when requested for a specific draw (future change).

The CompatibleRPHandle is a way for us to avoid analysing the RenderTarget every time
we want to get a new GrVkRenderPass.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1977403002

Review-Url: https://codereview.chromium.org/1977403002
diff --git a/src/gpu/vk/GrVkRenderPass.cpp b/src/gpu/vk/GrVkRenderPass.cpp
index 1aedab4..c56bafa 100644
--- a/src/gpu/vk/GrVkRenderPass.cpp
+++ b/src/gpu/vk/GrVkRenderPass.cpp
@@ -13,17 +13,31 @@
 #include "GrVkRenderTarget.h"
 #include "GrVkUtil.h"
 
-void setup_simple_vk_attachment_description(VkAttachmentDescription* attachment,
-                                            VkFormat format,
-                                            uint32_t samples,
-                                            VkImageLayout layout) {
+typedef GrVkRenderPass::AttachmentsDescriptor::AttachmentDesc AttachmentDesc;
+
+void setup_vk_attachment_description(VkAttachmentDescription* attachment,
+                                     const AttachmentDesc& desc,
+                                     VkImageLayout layout) {
     attachment->flags = 0;
-    attachment->format = format;
-    SkAssertResult(GrSampleCountToVkSampleCount(samples, &attachment->samples));
-    attachment->loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
-    attachment->storeOp = VK_ATTACHMENT_STORE_OP_STORE;
-    attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
-    attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
+    attachment->format = desc.fFormat;
+    SkAssertResult(GrSampleCountToVkSampleCount(desc.fSamples, &attachment->samples));
+    switch (layout) {
+        case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
+            attachment->loadOp = desc.fLoadOp;
+            attachment->storeOp = desc.fStoreOp;
+            attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+            attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+            break;
+        case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
+            attachment->loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+            attachment->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+            attachment->stencilLoadOp = desc.fLoadOp;
+            attachment->stencilStoreOp = desc.fStoreOp;
+            break;
+        default:
+            SkFAIL("Unexpected attachment layout");
+    }
+
     attachment->initialLayout = layout;
     attachment->finalLayout = layout;
 }
@@ -56,10 +70,9 @@
     subpassDesc.pInputAttachments = nullptr;
     if (fAttachmentFlags & kColor_AttachmentFlag) {
         // set up color attachment
-        setup_simple_vk_attachment_description(&attachments[currentAttachment],
-                                               fAttachmentsDescriptor.fColor.fFormat,
-                                               fAttachmentsDescriptor.fColor.fSamples,
-                                               VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
+        setup_vk_attachment_description(&attachments[currentAttachment],
+                                        fAttachmentsDescriptor.fColor,
+                                        VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
         // setup subpass use of attachment
         colorRef.attachment = currentAttachment++;
         colorRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
@@ -75,10 +88,9 @@
 
     if (fAttachmentFlags & kResolve_AttachmentFlag) {
         // set up resolve attachment
-        setup_simple_vk_attachment_description(&attachments[currentAttachment],
-                                               fAttachmentsDescriptor.fResolve.fFormat,
-                                               fAttachmentsDescriptor.fResolve.fSamples,
-                                               VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
+        setup_vk_attachment_description(&attachments[currentAttachment],
+                                        fAttachmentsDescriptor.fResolve,
+                                        VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
         // setup subpass use of attachment
         resolveRef.attachment = currentAttachment++;
         // I'm really not sure what the layout should be for the resolve textures.
@@ -90,10 +102,9 @@
 
     if (fAttachmentFlags & kStencil_AttachmentFlag) {
         // set up stencil attachment
-        setup_simple_vk_attachment_description(&attachments[currentAttachment],
-                                               fAttachmentsDescriptor.fStencil.fFormat,
-                                               fAttachmentsDescriptor.fStencil.fSamples,
-                                               VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
+        setup_vk_attachment_description(&attachments[currentAttachment],
+                                        fAttachmentsDescriptor.fStencil,
+                                        VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
         // setup subpass use of attachment
         stencilRef.attachment = currentAttachment++;
         stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
@@ -202,17 +213,17 @@
     }
 
     if (fAttachmentFlags & kColor_AttachmentFlag) {
-        if (fAttachmentsDescriptor.fColor != desc.fColor) {
+        if (!fAttachmentsDescriptor.fColor.isCompatible(desc.fColor)) {
             return false;
         }
     }
     if (fAttachmentFlags & kResolve_AttachmentFlag) {
-        if (fAttachmentsDescriptor.fResolve != desc.fResolve) {
+        if (!fAttachmentsDescriptor.fResolve.isCompatible(desc.fResolve)) {
             return false;
         }
     }
     if (fAttachmentFlags & kStencil_AttachmentFlag) {
-        if (fAttachmentsDescriptor.fStencil != desc.fStencil) {
+        if (!fAttachmentsDescriptor.fStencil.isCompatible(desc.fStencil)) {
             return false;
         }
     }