Vulkan: Implement ComputePipeline

This commit is contained in:
Corentin Wallez 2018-04-18 13:59:43 -04:00 committed by Corentin Wallez
parent 857a1cdb0e
commit 20aa6b9759
11 changed files with 119 additions and 9 deletions

View File

@ -302,6 +302,8 @@ if (NXT_ENABLE_VULKAN)
${VULKAN_DIR}/BufferVk.h ${VULKAN_DIR}/BufferVk.h
${VULKAN_DIR}/CommandBufferVk.cpp ${VULKAN_DIR}/CommandBufferVk.cpp
${VULKAN_DIR}/CommandBufferVk.h ${VULKAN_DIR}/CommandBufferVk.h
${VULKAN_DIR}/ComputePipelineVk.cpp
${VULKAN_DIR}/ComputePipelineVk.h
${VULKAN_DIR}/DepthStencilStateVk.cpp ${VULKAN_DIR}/DepthStencilStateVk.cpp
${VULKAN_DIR}/DepthStencilStateVk.h ${VULKAN_DIR}/DepthStencilStateVk.h
${VULKAN_DIR}/FencedDeleter.cpp ${VULKAN_DIR}/FencedDeleter.cpp

View File

@ -15,6 +15,7 @@
#include "backend/vulkan/BindGroupLayoutVk.h" #include "backend/vulkan/BindGroupLayoutVk.h"
#include "backend/vulkan/VulkanBackend.h" #include "backend/vulkan/VulkanBackend.h"
#include "common/BitSetIterator.h"
namespace backend { namespace vulkan { namespace backend { namespace vulkan {

View File

@ -14,12 +14,14 @@
#include "backend/vulkan/BindGroupVk.h" #include "backend/vulkan/BindGroupVk.h"
#include "BindGroupLayoutVk.h" #include "backend/vulkan/BindGroupLayoutVk.h"
#include "BufferVk.h" #include "backend/vulkan/BufferVk.h"
#include "FencedDeleter.h" #include "backend/vulkan/FencedDeleter.h"
#include "SamplerVk.h" #include "backend/vulkan/SamplerVk.h"
#include "TextureVk.h" #include "backend/vulkan/TextureVk.h"
#include "VulkanBackend.h" #include "backend/vulkan/VulkanBackend.h"
#include "common/BitSetIterator.h"
namespace backend { namespace vulkan { namespace backend { namespace vulkan {

View File

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

View File

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

View File

@ -17,6 +17,7 @@
#include "backend/vulkan/BlendStateVk.h" #include "backend/vulkan/BlendStateVk.h"
#include "backend/vulkan/BufferVk.h" #include "backend/vulkan/BufferVk.h"
#include "backend/vulkan/CommandBufferVk.h" #include "backend/vulkan/CommandBufferVk.h"
#include "backend/vulkan/ComputePipelineVk.h"
#include "backend/vulkan/DepthStencilStateVk.h" #include "backend/vulkan/DepthStencilStateVk.h"
#include "backend/vulkan/FramebufferVk.h" #include "backend/vulkan/FramebufferVk.h"
#include "backend/vulkan/InputStateVk.h" #include "backend/vulkan/InputStateVk.h"

View File

@ -18,6 +18,8 @@
#include "backend/vulkan/TextureVk.h" #include "backend/vulkan/TextureVk.h"
#include "backend/vulkan/VulkanBackend.h" #include "backend/vulkan/VulkanBackend.h"
#include <limits>
namespace backend { namespace vulkan { namespace backend { namespace vulkan {
namespace { namespace {

View File

@ -18,6 +18,8 @@
#include "backend/vulkan/FencedDeleter.h" #include "backend/vulkan/FencedDeleter.h"
#include "backend/vulkan/VulkanBackend.h" #include "backend/vulkan/VulkanBackend.h"
#include "common/BitSetIterator.h"
namespace backend { namespace vulkan { namespace backend { namespace vulkan {
PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder) PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder)

View File

@ -17,6 +17,7 @@
#include "backend/vulkan/FencedDeleter.h" #include "backend/vulkan/FencedDeleter.h"
#include "backend/vulkan/TextureVk.h" #include "backend/vulkan/TextureVk.h"
#include "backend/vulkan/VulkanBackend.h" #include "backend/vulkan/VulkanBackend.h"
#include "common/BitSetIterator.h"
namespace backend { namespace vulkan { namespace backend { namespace vulkan {

View File

@ -21,6 +21,7 @@
#include "backend/vulkan/BufferUploader.h" #include "backend/vulkan/BufferUploader.h"
#include "backend/vulkan/BufferVk.h" #include "backend/vulkan/BufferVk.h"
#include "backend/vulkan/CommandBufferVk.h" #include "backend/vulkan/CommandBufferVk.h"
#include "backend/vulkan/ComputePipelineVk.h"
#include "backend/vulkan/DepthStencilStateVk.h" #include "backend/vulkan/DepthStencilStateVk.h"
#include "backend/vulkan/FencedDeleter.h" #include "backend/vulkan/FencedDeleter.h"
#include "backend/vulkan/FramebufferVk.h" #include "backend/vulkan/FramebufferVk.h"

View File

@ -17,10 +17,8 @@
#include "nxt/nxtcpp.h" #include "nxt/nxtcpp.h"
#include "backend/ComputePipeline.h"
#include "backend/Device.h" #include "backend/Device.h"
#include "backend/Queue.h" #include "backend/Queue.h"
#include "backend/Sampler.h"
#include "backend/ToBackend.h" #include "backend/ToBackend.h"
#include "backend/vulkan/VulkanFunctions.h" #include "backend/vulkan/VulkanFunctions.h"
#include "backend/vulkan/VulkanInfo.h" #include "backend/vulkan/VulkanInfo.h"
@ -38,7 +36,7 @@ namespace backend { namespace vulkan {
class Buffer; class Buffer;
using BufferView = BufferViewBase; using BufferView = BufferViewBase;
class CommandBuffer; class CommandBuffer;
using ComputePipeline = ComputePipelineBase; class ComputePipeline;
class DepthStencilState; class DepthStencilState;
class Device; class Device;
class Framebuffer; class Framebuffer;