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>
This commit is contained in:
Jiawei Shao 2019-02-13 19:53:58 +00:00 committed by Commit Bot service account
parent 0e6dad0a7d
commit 1809ff7423
8 changed files with 101 additions and 172 deletions

View File

@ -682,8 +682,6 @@ source_set("libdawn_native_sources") {
"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",

View File

@ -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 @@ namespace dawn_native { namespace vulkan {
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 @@ namespace dawn_native { namespace vulkan {
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
{

View File

@ -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 @@ namespace dawn_native { namespace vulkan {
private:
void RecordComputePass(VkCommandBuffer commands);
void RecordRenderPass(VkCommandBuffer commands, RenderPassDescriptor* renderPass);
void RecordRenderPass(VkCommandBuffer commands, RenderPassDescriptorBase* renderPass);
CommandIterator mCommands;
};

View File

@ -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"

View File

@ -29,7 +29,7 @@ namespace dawn_native { namespace vulkan {
class InputState;
class PipelineLayout;
class Queue;
class RenderPassDescriptor;
using RenderPassDescriptor = RenderPassDescriptorBase;
class RenderPipeline;
class Sampler;
class ShaderModule;

View File

@ -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

View File

@ -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_

View File

@ -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"