Vulkan: Remove RenderPassDescriptorVk

This patch removes RenderPassDescriptorVk completely and move the
function RecordBeginRenderPass to CommandBufferVk.cpp, which is
a part of preparation of removing RenderPassDescriptorBuilder from
Dawn.

BUG=dawn:6

Change-Id: Id666ef2f998fa65de93deb16afedb1d53d6b8bc0
Reviewed-on: https://dawn-review.googlesource.com/c/4540
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index d51eb5c..d7581f8 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -682,8 +682,6 @@
       "src/dawn_native/vulkan/QueueVk.h",
       "src/dawn_native/vulkan/RenderPassCache.cpp",
       "src/dawn_native/vulkan/RenderPassCache.h",
-      "src/dawn_native/vulkan/RenderPassDescriptorVk.cpp",
-      "src/dawn_native/vulkan/RenderPassDescriptorVk.h",
       "src/dawn_native/vulkan/RenderPipelineVk.cpp",
       "src/dawn_native/vulkan/RenderPipelineVk.h",
       "src/dawn_native/vulkan/SamplerVk.cpp",
diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp
index 13c818c..f94fb0f 100644
--- a/src/dawn_native/vulkan/CommandBufferVk.cpp
+++ b/src/dawn_native/vulkan/CommandBufferVk.cpp
@@ -19,8 +19,9 @@
 #include "dawn_native/vulkan/BufferVk.h"
 #include "dawn_native/vulkan/ComputePipelineVk.h"
 #include "dawn_native/vulkan/DeviceVk.h"
+#include "dawn_native/vulkan/FencedDeleter.h"
 #include "dawn_native/vulkan/PipelineLayoutVk.h"
-#include "dawn_native/vulkan/RenderPassDescriptorVk.h"
+#include "dawn_native/vulkan/RenderPassCache.h"
 #include "dawn_native/vulkan/RenderPipelineVk.h"
 #include "dawn_native/vulkan/TextureVk.h"
 
@@ -109,6 +110,100 @@
             std::bitset<kMaxBindGroups> mDirtySets;
         };
 
+        void RecordBeginRenderPass(VkCommandBuffer commands,
+                                   Device* device,
+                                   RenderPassDescriptorBase* renderPass) {
+            // Query a VkRenderPass from the cache
+            VkRenderPass renderPassVK = VK_NULL_HANDLE;
+            {
+                RenderPassCacheQuery query;
+
+                for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) {
+                    const auto& attachmentInfo = renderPass->GetColorAttachment(i);
+                    query.SetColor(i, attachmentInfo.view->GetTexture()->GetFormat(),
+                                   attachmentInfo.loadOp);
+                }
+
+                if (renderPass->HasDepthStencilAttachment()) {
+                    const auto& attachmentInfo = renderPass->GetDepthStencilAttachment();
+                    query.SetDepthStencil(attachmentInfo.view->GetTexture()->GetFormat(),
+                                          attachmentInfo.depthLoadOp, attachmentInfo.stencilLoadOp);
+                }
+
+                renderPassVK = device->GetRenderPassCache()->GetRenderPass(query);
+            }
+
+            // Create a framebuffer that will be used once for the render pass and gather the clear
+            // values for the attachments at the same time.
+            std::array<VkClearValue, kMaxColorAttachments + 1> clearValues;
+            VkFramebuffer framebuffer = VK_NULL_HANDLE;
+            uint32_t attachmentCount = 0;
+            {
+                // Fill in the attachment info that will be chained in the framebuffer create info.
+                std::array<VkImageView, kMaxColorAttachments + 1> attachments;
+
+                for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) {
+                    auto& attachmentInfo = renderPass->GetColorAttachment(i);
+                    TextureView* view = ToBackend(attachmentInfo.view.Get());
+
+                    attachments[attachmentCount] = view->GetHandle();
+
+                    clearValues[attachmentCount].color.float32[0] = attachmentInfo.clearColor[0];
+                    clearValues[attachmentCount].color.float32[1] = attachmentInfo.clearColor[1];
+                    clearValues[attachmentCount].color.float32[2] = attachmentInfo.clearColor[2];
+                    clearValues[attachmentCount].color.float32[3] = attachmentInfo.clearColor[3];
+
+                    attachmentCount++;
+                }
+
+                if (renderPass->HasDepthStencilAttachment()) {
+                    auto& attachmentInfo = renderPass->GetDepthStencilAttachment();
+                    TextureView* view = ToBackend(attachmentInfo.view.Get());
+
+                    attachments[attachmentCount] = view->GetHandle();
+
+                    clearValues[attachmentCount].depthStencil.depth = attachmentInfo.clearDepth;
+                    clearValues[attachmentCount].depthStencil.stencil = attachmentInfo.clearStencil;
+
+                    attachmentCount++;
+                }
+
+                // Chain attachments and create the framebuffer
+                VkFramebufferCreateInfo createInfo;
+                createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+                createInfo.pNext = nullptr;
+                createInfo.flags = 0;
+                createInfo.renderPass = renderPassVK;
+                createInfo.attachmentCount = attachmentCount;
+                createInfo.pAttachments = attachments.data();
+                createInfo.width = renderPass->GetWidth();
+                createInfo.height = renderPass->GetHeight();
+                createInfo.layers = 1;
+
+                if (device->fn.CreateFramebuffer(device->GetVkDevice(), &createInfo, nullptr,
+                                                 &framebuffer) != VK_SUCCESS) {
+                    ASSERT(false);
+                }
+
+                // We don't reuse VkFramebuffers so mark the framebuffer for deletion as soon as the
+                // commands currently being recorded are finished.
+                device->GetFencedDeleter()->DeleteWhenUnused(framebuffer);
+            }
+
+            VkRenderPassBeginInfo beginInfo;
+            beginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
+            beginInfo.pNext = nullptr;
+            beginInfo.renderPass = renderPassVK;
+            beginInfo.framebuffer = framebuffer;
+            beginInfo.renderArea.offset.x = 0;
+            beginInfo.renderArea.offset.y = 0;
+            beginInfo.renderArea.extent.width = renderPass->GetWidth();
+            beginInfo.renderArea.extent.height = renderPass->GetHeight();
+            beginInfo.clearValueCount = attachmentCount;
+            beginInfo.pClearValues = clearValues.data();
+
+            device->fn.CmdBeginRenderPass(commands, &beginInfo, VK_SUBPASS_CONTENTS_INLINE);
+        }
     }  // anonymous namespace
 
     CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
@@ -270,10 +365,10 @@
         UNREACHABLE();
     }
     void CommandBuffer::RecordRenderPass(VkCommandBuffer commands,
-                                         RenderPassDescriptor* renderPass) {
+                                         RenderPassDescriptorBase* renderPass) {
         Device* device = ToBackend(GetDevice());
 
-        renderPass->RecordBeginRenderPass(commands);
+        RecordBeginRenderPass(commands, device, renderPass);
 
         // Set the default value for the dynamic state
         {
diff --git a/src/dawn_native/vulkan/CommandBufferVk.h b/src/dawn_native/vulkan/CommandBufferVk.h
index 2ca5a62..61d0236 100644
--- a/src/dawn_native/vulkan/CommandBufferVk.h
+++ b/src/dawn_native/vulkan/CommandBufferVk.h
@@ -16,13 +16,12 @@
 #define DAWNNATIVE_VULKAN_COMMANDBUFFERVK_H_
 
 #include "dawn_native/CommandBuffer.h"
+#include "dawn_native/RenderPassDescriptor.h"
 
 #include "common/vulkan_platform.h"
 
 namespace dawn_native { namespace vulkan {
 
-    class RenderPassDescriptor;
-
     class CommandBuffer : public CommandBufferBase {
       public:
         CommandBuffer(CommandBufferBuilder* builder);
@@ -32,7 +31,7 @@
 
       private:
         void RecordComputePass(VkCommandBuffer commands);
-        void RecordRenderPass(VkCommandBuffer commands, RenderPassDescriptor* renderPass);
+        void RecordRenderPass(VkCommandBuffer commands, RenderPassDescriptorBase* renderPass);
 
         CommandIterator mCommands;
     };
diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp
index 8fcd392..5d1949d 100644
--- a/src/dawn_native/vulkan/DeviceVk.cpp
+++ b/src/dawn_native/vulkan/DeviceVk.cpp
@@ -31,7 +31,6 @@
 #include "dawn_native/vulkan/PipelineLayoutVk.h"
 #include "dawn_native/vulkan/QueueVk.h"
 #include "dawn_native/vulkan/RenderPassCache.h"
-#include "dawn_native/vulkan/RenderPassDescriptorVk.h"
 #include "dawn_native/vulkan/RenderPipelineVk.h"
 #include "dawn_native/vulkan/SamplerVk.h"
 #include "dawn_native/vulkan/ShaderModuleVk.h"
diff --git a/src/dawn_native/vulkan/Forward.h b/src/dawn_native/vulkan/Forward.h
index 5e6cac6..53da58d 100644
--- a/src/dawn_native/vulkan/Forward.h
+++ b/src/dawn_native/vulkan/Forward.h
@@ -29,7 +29,7 @@
     class InputState;
     class PipelineLayout;
     class Queue;
-    class RenderPassDescriptor;
+    using RenderPassDescriptor = RenderPassDescriptorBase;
     class RenderPipeline;
     class Sampler;
     class ShaderModule;
diff --git a/src/dawn_native/vulkan/RenderPassDescriptorVk.cpp b/src/dawn_native/vulkan/RenderPassDescriptorVk.cpp
deleted file mode 100644
index a0f6d35..0000000
--- a/src/dawn_native/vulkan/RenderPassDescriptorVk.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2018 The Dawn Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "dawn_native/vulkan/RenderPassDescriptorVk.h"
-
-#include "common/BitSetIterator.h"
-#include "dawn_native/vulkan/DeviceVk.h"
-#include "dawn_native/vulkan/FencedDeleter.h"
-#include "dawn_native/vulkan/RenderPassCache.h"
-#include "dawn_native/vulkan/TextureVk.h"
-
-namespace dawn_native { namespace vulkan {
-
-    RenderPassDescriptor::RenderPassDescriptor(RenderPassDescriptorBuilder* builder)
-        : RenderPassDescriptorBase(builder), mDevice(ToBackend(builder->GetDevice())) {
-    }
-
-    void RenderPassDescriptor::RecordBeginRenderPass(VkCommandBuffer commands) {
-        // Query a VkRenderPass from the cache
-        VkRenderPass renderPass = VK_NULL_HANDLE;
-        {
-            RenderPassCacheQuery query;
-
-            for (uint32_t i : IterateBitSet(GetColorAttachmentMask())) {
-                const auto& attachmentInfo = GetColorAttachment(i);
-                query.SetColor(i, attachmentInfo.view->GetTexture()->GetFormat(),
-                               attachmentInfo.loadOp);
-            }
-
-            if (HasDepthStencilAttachment()) {
-                const auto& attachmentInfo = GetDepthStencilAttachment();
-                query.SetDepthStencil(attachmentInfo.view->GetTexture()->GetFormat(),
-                                      attachmentInfo.depthLoadOp, attachmentInfo.stencilLoadOp);
-            }
-
-            renderPass = mDevice->GetRenderPassCache()->GetRenderPass(query);
-        }
-
-        // Create a framebuffer that will be used once for the render pass and gather the clear
-        // values for the attachments at the same time.
-        std::array<VkClearValue, kMaxColorAttachments + 1> clearValues;
-        VkFramebuffer framebuffer = VK_NULL_HANDLE;
-        uint32_t attachmentCount = 0;
-        {
-            // Fill in the attachment info that will be chained in the framebuffer create info.
-            std::array<VkImageView, kMaxColorAttachments + 1> attachments;
-
-            for (uint32_t i : IterateBitSet(GetColorAttachmentMask())) {
-                auto& attachmentInfo = GetColorAttachment(i);
-                TextureView* view = ToBackend(attachmentInfo.view.Get());
-
-                attachments[attachmentCount] = view->GetHandle();
-
-                clearValues[attachmentCount].color.float32[0] = attachmentInfo.clearColor[0];
-                clearValues[attachmentCount].color.float32[1] = attachmentInfo.clearColor[1];
-                clearValues[attachmentCount].color.float32[2] = attachmentInfo.clearColor[2];
-                clearValues[attachmentCount].color.float32[3] = attachmentInfo.clearColor[3];
-
-                attachmentCount++;
-            }
-
-            if (HasDepthStencilAttachment()) {
-                auto& attachmentInfo = GetDepthStencilAttachment();
-                TextureView* view = ToBackend(attachmentInfo.view.Get());
-
-                attachments[attachmentCount] = view->GetHandle();
-
-                clearValues[attachmentCount].depthStencil.depth = attachmentInfo.clearDepth;
-                clearValues[attachmentCount].depthStencil.stencil = attachmentInfo.clearStencil;
-
-                attachmentCount++;
-            }
-
-            // Chain attachments and create the framebuffer
-            VkFramebufferCreateInfo createInfo;
-            createInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
-            createInfo.pNext = nullptr;
-            createInfo.flags = 0;
-            createInfo.renderPass = renderPass;
-            createInfo.attachmentCount = attachmentCount;
-            createInfo.pAttachments = attachments.data();
-            createInfo.width = GetWidth();
-            createInfo.height = GetHeight();
-            createInfo.layers = 1;
-
-            if (mDevice->fn.CreateFramebuffer(mDevice->GetVkDevice(), &createInfo, nullptr,
-                                              &framebuffer) != VK_SUCCESS) {
-                ASSERT(false);
-            }
-
-            // We don't reuse VkFramebuffers so mark the framebuffer for deletion as soon as the
-            // commands currently being recorded are finished.
-            mDevice->GetFencedDeleter()->DeleteWhenUnused(framebuffer);
-        }
-
-        VkRenderPassBeginInfo beginInfo;
-        beginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
-        beginInfo.pNext = nullptr;
-        beginInfo.renderPass = renderPass;
-        beginInfo.framebuffer = framebuffer;
-        beginInfo.renderArea.offset.x = 0;
-        beginInfo.renderArea.offset.y = 0;
-        beginInfo.renderArea.extent.width = GetWidth();
-        beginInfo.renderArea.extent.height = GetHeight();
-        beginInfo.clearValueCount = attachmentCount;
-        beginInfo.pClearValues = clearValues.data();
-
-        mDevice->fn.CmdBeginRenderPass(commands, &beginInfo, VK_SUBPASS_CONTENTS_INLINE);
-    }
-
-}}  // namespace dawn_native::vulkan
diff --git a/src/dawn_native/vulkan/RenderPassDescriptorVk.h b/src/dawn_native/vulkan/RenderPassDescriptorVk.h
deleted file mode 100644
index 07b65b6..0000000
--- a/src/dawn_native/vulkan/RenderPassDescriptorVk.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2018 The Dawn Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef DAWNNATIVE_VULKAN_RENDERPASSDESCRIPTORVK_H_
-#define DAWNNATIVE_VULKAN_RENDERPASSDESCRIPTORVK_H_
-
-#include "dawn_native/RenderPassDescriptor.h"
-
-#include "common/vulkan_platform.h"
-
-namespace dawn_native { namespace vulkan {
-
-    class Device;
-
-    class RenderPassDescriptor : public RenderPassDescriptorBase {
-      public:
-        RenderPassDescriptor(RenderPassDescriptorBuilder* builder);
-
-        // Compute all the arguments for, and record the vkCmdBeginRenderPass command.
-        void RecordBeginRenderPass(VkCommandBuffer commands);
-
-      private:
-        Device* mDevice = nullptr;
-    };
-
-}}  // namespace dawn_native::vulkan
-
-#endif  // DAWNNATIVE_VULKAN_RENDERPASSDESCRIPTORVK_H_
diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp
index 02f12fb..c7e024b 100644
--- a/src/dawn_native/vulkan/RenderPipelineVk.cpp
+++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp
@@ -19,7 +19,6 @@
 #include "dawn_native/vulkan/InputStateVk.h"
 #include "dawn_native/vulkan/PipelineLayoutVk.h"
 #include "dawn_native/vulkan/RenderPassCache.h"
-#include "dawn_native/vulkan/RenderPassDescriptorVk.h"
 #include "dawn_native/vulkan/ShaderModuleVk.h"
 #include "dawn_native/vulkan/UtilsVulkan.h"