From 20aa6b97599575550799340868e9268e42327f01 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 18 Apr 2018 13:59:43 -0400 Subject: [PATCH] Vulkan: Implement ComputePipeline --- src/backend/CMakeLists.txt | 2 + src/backend/vulkan/BindGroupLayoutVk.cpp | 1 + src/backend/vulkan/BindGroupVk.cpp | 14 +++-- src/backend/vulkan/ComputePipelineVk.cpp | 60 ++++++++++++++++++++ src/backend/vulkan/ComputePipelineVk.h | 40 +++++++++++++ src/backend/vulkan/GeneratedCodeIncludes.h | 1 + src/backend/vulkan/NativeSwapChainImplVk.cpp | 2 + src/backend/vulkan/PipelineLayoutVk.cpp | 2 + src/backend/vulkan/RenderPassVk.cpp | 1 + src/backend/vulkan/VulkanBackend.cpp | 1 + src/backend/vulkan/VulkanBackend.h | 4 +- 11 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 src/backend/vulkan/ComputePipelineVk.cpp create mode 100644 src/backend/vulkan/ComputePipelineVk.h diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt index 5be8d19ea5..77c7d5a551 100644 --- a/src/backend/CMakeLists.txt +++ b/src/backend/CMakeLists.txt @@ -302,6 +302,8 @@ if (NXT_ENABLE_VULKAN) ${VULKAN_DIR}/BufferVk.h ${VULKAN_DIR}/CommandBufferVk.cpp ${VULKAN_DIR}/CommandBufferVk.h + ${VULKAN_DIR}/ComputePipelineVk.cpp + ${VULKAN_DIR}/ComputePipelineVk.h ${VULKAN_DIR}/DepthStencilStateVk.cpp ${VULKAN_DIR}/DepthStencilStateVk.h ${VULKAN_DIR}/FencedDeleter.cpp diff --git a/src/backend/vulkan/BindGroupLayoutVk.cpp b/src/backend/vulkan/BindGroupLayoutVk.cpp index 49f3fd52c4..5a4c0b6517 100644 --- a/src/backend/vulkan/BindGroupLayoutVk.cpp +++ b/src/backend/vulkan/BindGroupLayoutVk.cpp @@ -15,6 +15,7 @@ #include "backend/vulkan/BindGroupLayoutVk.h" #include "backend/vulkan/VulkanBackend.h" +#include "common/BitSetIterator.h" namespace backend { namespace vulkan { diff --git a/src/backend/vulkan/BindGroupVk.cpp b/src/backend/vulkan/BindGroupVk.cpp index 93783ad606..b38efac0ed 100644 --- a/src/backend/vulkan/BindGroupVk.cpp +++ b/src/backend/vulkan/BindGroupVk.cpp @@ -14,12 +14,14 @@ #include "backend/vulkan/BindGroupVk.h" -#include "BindGroupLayoutVk.h" -#include "BufferVk.h" -#include "FencedDeleter.h" -#include "SamplerVk.h" -#include "TextureVk.h" -#include "VulkanBackend.h" +#include "backend/vulkan/BindGroupLayoutVk.h" +#include "backend/vulkan/BufferVk.h" +#include "backend/vulkan/FencedDeleter.h" +#include "backend/vulkan/SamplerVk.h" +#include "backend/vulkan/TextureVk.h" +#include "backend/vulkan/VulkanBackend.h" + +#include "common/BitSetIterator.h" namespace backend { namespace vulkan { diff --git a/src/backend/vulkan/ComputePipelineVk.cpp b/src/backend/vulkan/ComputePipelineVk.cpp new file mode 100644 index 0000000000..aaa3aa4406 --- /dev/null +++ b/src/backend/vulkan/ComputePipelineVk.cpp @@ -0,0 +1,60 @@ +// Copyright 2018 The NXT 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 "backend/vulkan/ComputePipelineVk.h" + +#include "backend/vulkan/FencedDeleter.h" +#include "backend/vulkan/PipelineLayoutVk.h" +#include "backend/vulkan/ShaderModuleVk.h" +#include "backend/vulkan/VulkanBackend.h" + +namespace backend { namespace vulkan { + + ComputePipeline::ComputePipeline(ComputePipelineBuilder* builder) + : ComputePipelineBase(builder), mDevice(ToBackend(builder->GetDevice())) { + VkComputePipelineCreateInfo createInfo; + createInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + createInfo.pNext = nullptr; + createInfo.flags = 0; + createInfo.layout = ToBackend(GetLayout())->GetHandle(); + createInfo.basePipelineHandle = VK_NULL_HANDLE; + createInfo.basePipelineIndex = -1; + + const auto& stageInfo = builder->GetStageInfo(nxt::ShaderStage::Compute); + createInfo.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + createInfo.stage.pNext = nullptr; + createInfo.stage.flags = 0; + createInfo.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; + createInfo.stage.module = ToBackend(stageInfo.module)->GetHandle(); + createInfo.stage.pName = stageInfo.entryPoint.c_str(); + createInfo.stage.pSpecializationInfo = nullptr; + + if (mDevice->fn.CreateComputePipelines(mDevice->GetVkDevice(), VK_NULL_HANDLE, 1, + &createInfo, nullptr, &mHandle) != VK_SUCCESS) { + ASSERT(false); + } + } + + ComputePipeline::~ComputePipeline() { + if (mHandle != VK_NULL_HANDLE) { + mDevice->GetFencedDeleter()->DeleteWhenUnused(mHandle); + mHandle = VK_NULL_HANDLE; + } + } + + VkPipeline ComputePipeline::GetHandle() const { + return mHandle; + } + +}} // namespace backend::vulkan diff --git a/src/backend/vulkan/ComputePipelineVk.h b/src/backend/vulkan/ComputePipelineVk.h new file mode 100644 index 0000000000..8afd96c0ff --- /dev/null +++ b/src/backend/vulkan/ComputePipelineVk.h @@ -0,0 +1,40 @@ +// Copyright 2018 The NXT 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 BACKEND_VULKAN_COMPUTEPIPELINEVK_H_ +#define BACKEND_VULKAN_COMPUTEPIPELINEVK_H_ + +#include "backend/ComputePipeline.h" + +#include "common/vulkan_platform.h" + +namespace backend { namespace vulkan { + + class Device; + + class ComputePipeline : public ComputePipelineBase { + public: + ComputePipeline(ComputePipelineBuilder* builder); + ~ComputePipeline(); + + VkPipeline GetHandle() const; + + private: + VkPipeline mHandle = VK_NULL_HANDLE; + Device* mDevice = nullptr; + }; + +}} // namespace backend::vulkan + +#endif // BACKEND_VULKAN_COMPUTEPIPELINEVK_H_ diff --git a/src/backend/vulkan/GeneratedCodeIncludes.h b/src/backend/vulkan/GeneratedCodeIncludes.h index 41811f8050..23b44890fc 100644 --- a/src/backend/vulkan/GeneratedCodeIncludes.h +++ b/src/backend/vulkan/GeneratedCodeIncludes.h @@ -17,6 +17,7 @@ #include "backend/vulkan/BlendStateVk.h" #include "backend/vulkan/BufferVk.h" #include "backend/vulkan/CommandBufferVk.h" +#include "backend/vulkan/ComputePipelineVk.h" #include "backend/vulkan/DepthStencilStateVk.h" #include "backend/vulkan/FramebufferVk.h" #include "backend/vulkan/InputStateVk.h" diff --git a/src/backend/vulkan/NativeSwapChainImplVk.cpp b/src/backend/vulkan/NativeSwapChainImplVk.cpp index a5f10f0f2e..a595ff0a65 100644 --- a/src/backend/vulkan/NativeSwapChainImplVk.cpp +++ b/src/backend/vulkan/NativeSwapChainImplVk.cpp @@ -18,6 +18,8 @@ #include "backend/vulkan/TextureVk.h" #include "backend/vulkan/VulkanBackend.h" +#include + namespace backend { namespace vulkan { namespace { diff --git a/src/backend/vulkan/PipelineLayoutVk.cpp b/src/backend/vulkan/PipelineLayoutVk.cpp index 49119ef6c8..d59b2b6822 100644 --- a/src/backend/vulkan/PipelineLayoutVk.cpp +++ b/src/backend/vulkan/PipelineLayoutVk.cpp @@ -18,6 +18,8 @@ #include "backend/vulkan/FencedDeleter.h" #include "backend/vulkan/VulkanBackend.h" +#include "common/BitSetIterator.h" + namespace backend { namespace vulkan { PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder) diff --git a/src/backend/vulkan/RenderPassVk.cpp b/src/backend/vulkan/RenderPassVk.cpp index df175ad194..d1d35b99e7 100644 --- a/src/backend/vulkan/RenderPassVk.cpp +++ b/src/backend/vulkan/RenderPassVk.cpp @@ -17,6 +17,7 @@ #include "backend/vulkan/FencedDeleter.h" #include "backend/vulkan/TextureVk.h" #include "backend/vulkan/VulkanBackend.h" +#include "common/BitSetIterator.h" namespace backend { namespace vulkan { diff --git a/src/backend/vulkan/VulkanBackend.cpp b/src/backend/vulkan/VulkanBackend.cpp index 732f3a4031..ad2b064279 100644 --- a/src/backend/vulkan/VulkanBackend.cpp +++ b/src/backend/vulkan/VulkanBackend.cpp @@ -21,6 +21,7 @@ #include "backend/vulkan/BufferUploader.h" #include "backend/vulkan/BufferVk.h" #include "backend/vulkan/CommandBufferVk.h" +#include "backend/vulkan/ComputePipelineVk.h" #include "backend/vulkan/DepthStencilStateVk.h" #include "backend/vulkan/FencedDeleter.h" #include "backend/vulkan/FramebufferVk.h" diff --git a/src/backend/vulkan/VulkanBackend.h b/src/backend/vulkan/VulkanBackend.h index 41c79a11c6..9612bab6a4 100644 --- a/src/backend/vulkan/VulkanBackend.h +++ b/src/backend/vulkan/VulkanBackend.h @@ -17,10 +17,8 @@ #include "nxt/nxtcpp.h" -#include "backend/ComputePipeline.h" #include "backend/Device.h" #include "backend/Queue.h" -#include "backend/Sampler.h" #include "backend/ToBackend.h" #include "backend/vulkan/VulkanFunctions.h" #include "backend/vulkan/VulkanInfo.h" @@ -38,7 +36,7 @@ namespace backend { namespace vulkan { class Buffer; using BufferView = BufferViewBase; class CommandBuffer; - using ComputePipeline = ComputePipelineBase; + class ComputePipeline; class DepthStencilState; class Device; class Framebuffer;