Track clear counts in vulkan render passes
authorGreg Daniel <egdaniel@google.com>
Mon, 23 Jan 2017 16:04:45 +0000 (11:04 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 23 Jan 2017 18:52:25 +0000 (18:52 +0000)
Though not required by spec, the validation layers have started spitting
out warnings if the clearValueCount in BeginRenderPass is greater than
the number of attachments actually being cleared. This just adds tracking
of the count to appease the validation layers.

BUG=skia:

Change-Id: Iac6500df3ed5ad3f5df5f045c6e533bb021857aa
Reviewed-on: https://skia-review.googlesource.com/7401
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>

src/gpu/vk/GrVkCommandBuffer.cpp
src/gpu/vk/GrVkCommandBuffer.h
src/gpu/vk/GrVkCopyManager.cpp
src/gpu/vk/GrVkGpu.cpp
src/gpu/vk/GrVkRenderPass.cpp
src/gpu/vk/GrVkRenderPass.h

index 91acf98..b1d20e2 100644 (file)
@@ -345,7 +345,6 @@ void GrVkPrimaryCommandBuffer::end(const GrVkGpu* gpu) {
 
 void GrVkPrimaryCommandBuffer::beginRenderPass(const GrVkGpu* gpu,
                                                const GrVkRenderPass* renderPass,
-                                               uint32_t clearCount,
                                                const VkClearValue* clearValues,
                                                const GrVkRenderTarget& target,
                                                const SkIRect& bounds,
@@ -365,7 +364,7 @@ void GrVkPrimaryCommandBuffer::beginRenderPass(const GrVkGpu* gpu,
     beginInfo.renderPass = renderPass->vkRenderPass();
     beginInfo.framebuffer = target.framebuffer()->framebuffer();
     beginInfo.renderArea = renderArea;
-    beginInfo.clearValueCount = clearCount;
+    beginInfo.clearValueCount = renderPass->clearValueCount();
     beginInfo.pClearValues = clearValues;
 
     VkSubpassContents contents = forSecondaryCB ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS
index 8020c7d..e28df44 100644 (file)
@@ -210,7 +210,6 @@ public:
     // in the render pass.
     void beginRenderPass(const GrVkGpu* gpu,
                          const GrVkRenderPass* renderPass,
-                         uint32_t clearCount,
                          const VkClearValue* clearValues,
                          const GrVkRenderTarget& target,
                          const SkIRect& bounds,
index b1f8f2a..269ec5e 100644 (file)
@@ -320,7 +320,7 @@ bool GrVkCopyManager::copySurfaceAsDraw(GrVkGpu* gpu,
     SkASSERT(renderPass->isCompatible(*rt->simpleRenderPass()));
 
 
-    cmdBuffer->beginRenderPass(gpu, renderPass, 0, nullptr, *rt, bounds, false);
+    cmdBuffer->beginRenderPass(gpu, renderPass, nullptr, *rt, bounds, false);
     cmdBuffer->bindPipeline(gpu, pipeline);
 
     // Uniform DescriptorSet, Sampler DescriptorSet, and vertex shader uniformBuffer
index b94a379..9bb4c57 100644 (file)
@@ -1838,10 +1838,7 @@ void GrVkGpu::submitSecondaryCommandBuffer(GrVkSecondaryCommandBuffer* buffer,
         pBounds = &adjustedBounds;
     }
 
-    // Currently it is fine for us to always pass in 1 for the clear count even if no attachment
-    // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment
-    // which is always at the first attachment.
-    fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, *pBounds, true);
+    fCurrentCmdBuffer->beginRenderPass(this, renderPass, colorClear, *target, *pBounds, true);
     fCurrentCmdBuffer->executeCommands(this, buffer);
     fCurrentCmdBuffer->endRenderPass(this);
 
index ee2d3d9..a6a6afb 100644 (file)
@@ -84,6 +84,10 @@ void GrVkRenderPass::init(const GrVkGpu* gpu,
         colorRef.attachment = currentAttachment++;
         colorRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
         subpassDesc.colorAttachmentCount = 1;
+
+        if (VK_ATTACHMENT_LOAD_OP_CLEAR == colorOp.fLoadOp) {
+            fClearValueCount++;
+        }
     } else {
         // I don't think there should ever be a time where we don't have a color attachment
         SkASSERT(false);
@@ -102,6 +106,9 @@ void GrVkRenderPass::init(const GrVkGpu* gpu,
         // setup subpass use of attachment
         stencilRef.attachment = currentAttachment++;
         stencilRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+        if (VK_ATTACHMENT_LOAD_OP_CLEAR == stencilOp.fLoadOp) {
+            fClearValueCount++;
+        }
     } else {
         stencilRef.attachment = VK_ATTACHMENT_UNUSED;
         stencilRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
@@ -147,7 +154,7 @@ void GrVkRenderPass::init(const GrVkGpu* gpu,
 }
 
 void GrVkRenderPass::init(const GrVkGpu* gpu,
-                          const GrVkRenderTarget& target, 
+                          const GrVkRenderTarget& target,
                           const LoadStoreOps& colorOp,
                           const LoadStoreOps& stencilOp) {
     // Get attachment information from render target. This includes which attachments the render
@@ -183,29 +190,6 @@ bool GrVkRenderPass::stencilAttachmentIndex(uint32_t* index) const {
     return false;
 }
 
-void GrVkRenderPass::getBeginInfo(const GrVkRenderTarget& target,
-                                  VkRenderPassBeginInfo* beginInfo,
-                                  VkSubpassContents* contents) const {
-    SkASSERT(this->isCompatible(target));
-
-    VkRect2D renderArea;
-    renderArea.offset = { 0, 0 };
-    renderArea.extent = { (uint32_t)target.width(), (uint32_t)target.height() };
-
-    memset(beginInfo, 0, sizeof(VkRenderPassBeginInfo));
-    beginInfo->sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
-    beginInfo->pNext = nullptr;
-    beginInfo->renderPass = fRenderPass;
-    beginInfo->framebuffer = target.framebuffer()->framebuffer();
-    beginInfo->renderArea = renderArea;
-    beginInfo->clearValueCount = 0;
-    beginInfo->pClearValues = nullptr;
-
-    // Currently just assuming no secondary cmd buffers. This value will need to be update if we
-    // have them.
-    *contents = VK_SUBPASS_CONTENTS_INLINE;
-}
-
 bool GrVkRenderPass::isCompatible(const AttachmentsDescriptor& desc,
                                   const AttachmentFlags& flags) const {
     if (flags != fAttachmentFlags) {
index d59b5fa..b3b6092 100644 (file)
@@ -20,7 +20,7 @@ class GrVkRenderTarget;
 
 class GrVkRenderPass : public GrVkResource {
 public:
-    GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE) {}
+    GrVkRenderPass() : INHERITED(), fRenderPass(VK_NULL_HANDLE), fClearValueCount(0) {}
 
     struct LoadStoreOps {
         VkAttachmentLoadOp  fLoadOp;
@@ -89,16 +89,6 @@ public:
     bool colorAttachmentIndex(uint32_t* index) const;
     bool stencilAttachmentIndex(uint32_t* index) const;
 
-    // Sets the VkRenderPassBeginInfo and VkRenderPassContents need to begin a render pass.
-    // TODO: In the future I expect this function will also take an optional render area instead of
-    // defaulting to the entire render target.
-    // TODO: Figure out if load clear values should be passed into this function or should be stored
-    // on the GrVkRenderPass at create time since we'll know at that point if we want to do a load
-    // clear.
-    void getBeginInfo(const GrVkRenderTarget& target,
-                      VkRenderPassBeginInfo* beginInfo,
-                      VkSubpassContents* contents) const;
-
     // Returns whether or not the structure of a RenderTarget matches that of the VkRenderPass in
     // this object. Specifically this compares that the number of attachments, format of
     // attachments, and sample counts are all the same. This function is used in the creation of
@@ -114,6 +104,11 @@ public:
 
     const VkExtent2D& granularity() const { return fGranularity; }
 
+    // Returns the number of clear colors needed to begin this render pass. Currently this will
+    // either only be 0 or 1 since we only ever clear the color attachment.
+    uint32_t clearValueCount() const { return fClearValueCount; }
+
+
     void genKey(GrProcessorKeyBuilder* b) const;
 
 #ifdef SK_TRACE_VK_RESOURCES
@@ -137,6 +132,7 @@ private:
     AttachmentFlags       fAttachmentFlags;
     AttachmentsDescriptor fAttachmentsDescriptor;
     VkExtent2D            fGranularity;
+    uint32_t              fClearValueCount;
 
     typedef GrVkResource INHERITED;
 };