diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt index 2d6d63a16a..e27a6c3260 100644 --- a/src/backend/CMakeLists.txt +++ b/src/backend/CMakeLists.txt @@ -299,6 +299,8 @@ if (NXT_ENABLE_VULKAN) ${VULKAN_DIR}/FencedDeleter.h ${VULKAN_DIR}/MemoryAllocator.cpp ${VULKAN_DIR}/MemoryAllocator.h + ${VULKAN_DIR}/PipelineLayoutVk.cpp + ${VULKAN_DIR}/PipelineLayoutVk.h ${VULKAN_DIR}/TextureVk.cpp ${VULKAN_DIR}/TextureVk.h ${VULKAN_DIR}/VulkanBackend.cpp diff --git a/src/backend/vulkan/FencedDeleter.cpp b/src/backend/vulkan/FencedDeleter.cpp index b5e4788234..7d920bf435 100644 --- a/src/backend/vulkan/FencedDeleter.cpp +++ b/src/backend/vulkan/FencedDeleter.cpp @@ -38,22 +38,33 @@ namespace backend { namespace vulkan { mImagesToDelete.Enqueue(image, mDevice->GetSerial()); } + void FencedDeleter::DeleteWhenUnused(VkPipelineLayout layout) { + mPipelineLayoutsToDelete.Enqueue(layout, mDevice->GetSerial()); + } + void FencedDeleter::Tick(Serial completedSerial) { + VkDevice vkDevice = mDevice->GetVkDevice(); + // Buffers and images must be deleted before memories because it is invalid to free memory // that still have resources bound to it. for (VkBuffer buffer : mBuffersToDelete.IterateUpTo(completedSerial)) { - mDevice->fn.DestroyBuffer(mDevice->GetVkDevice(), buffer, nullptr); + mDevice->fn.DestroyBuffer(vkDevice, buffer, nullptr); } mBuffersToDelete.ClearUpTo(completedSerial); for (VkImage image : mImagesToDelete.IterateUpTo(completedSerial)) { - mDevice->fn.DestroyImage(mDevice->GetVkDevice(), image, nullptr); + mDevice->fn.DestroyImage(vkDevice, image, nullptr); } mImagesToDelete.ClearUpTo(completedSerial); for (VkDeviceMemory memory : mMemoriesToDelete.IterateUpTo(completedSerial)) { - mDevice->fn.FreeMemory(mDevice->GetVkDevice(), memory, nullptr); + mDevice->fn.FreeMemory(vkDevice, memory, nullptr); } mMemoriesToDelete.ClearUpTo(completedSerial); + + for (VkPipelineLayout layout : mPipelineLayoutsToDelete.IterateUpTo(completedSerial)) { + mDevice->fn.DestroyPipelineLayout(vkDevice, layout, nullptr); + } + mPipelineLayoutsToDelete.ClearUpTo(completedSerial); } }} // namespace backend::vulkan diff --git a/src/backend/vulkan/FencedDeleter.h b/src/backend/vulkan/FencedDeleter.h index abb93065ee..7299ce4417 100644 --- a/src/backend/vulkan/FencedDeleter.h +++ b/src/backend/vulkan/FencedDeleter.h @@ -30,6 +30,7 @@ namespace backend { namespace vulkan { void DeleteWhenUnused(VkBuffer buffer); void DeleteWhenUnused(VkDeviceMemory memory); void DeleteWhenUnused(VkImage image); + void DeleteWhenUnused(VkPipelineLayout layout); void Tick(Serial completedSerial); @@ -38,6 +39,7 @@ namespace backend { namespace vulkan { SerialQueue mBuffersToDelete; SerialQueue mMemoriesToDelete; SerialQueue mImagesToDelete; + SerialQueue mPipelineLayoutsToDelete; }; }} // namespace backend::vulkan diff --git a/src/backend/vulkan/GeneratedCodeIncludes.h b/src/backend/vulkan/GeneratedCodeIncludes.h index 875acfeaf9..661b9d82c1 100644 --- a/src/backend/vulkan/GeneratedCodeIncludes.h +++ b/src/backend/vulkan/GeneratedCodeIncludes.h @@ -14,5 +14,6 @@ #include "backend/vulkan/BufferVk.h" #include "backend/vulkan/CommandBufferVk.h" +#include "backend/vulkan/PipelineLayoutVk.h" #include "backend/vulkan/TextureVk.h" #include "backend/vulkan/VulkanBackend.h" diff --git a/src/backend/vulkan/PipelineLayoutVk.cpp b/src/backend/vulkan/PipelineLayoutVk.cpp new file mode 100644 index 0000000000..9284cb7735 --- /dev/null +++ b/src/backend/vulkan/PipelineLayoutVk.cpp @@ -0,0 +1,52 @@ +// 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/PipelineLayoutVk.h" + +#include "backend/vulkan/FencedDeleter.h" +#include "backend/vulkan/VulkanBackend.h" + +namespace backend { namespace vulkan { + + PipelineLayout::PipelineLayout(PipelineLayoutBuilder* builder) + : PipelineLayoutBase(builder), mDevice(ToBackend(builder->GetDevice())) { + // Create an empty pipeline layout for now + // TODO(cwallez@chromium.org): Add support for descriptor sets, figure out push constants + VkPipelineLayoutCreateInfo createInfo; + createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + createInfo.pNext = nullptr; + createInfo.flags = 0; + createInfo.setLayoutCount = 0; + createInfo.pSetLayouts = nullptr; + createInfo.pushConstantRangeCount = 0; + createInfo.pPushConstantRanges = nullptr; + + if (mDevice->fn.CreatePipelineLayout(mDevice->GetVkDevice(), &createInfo, nullptr, + &mHandle) != VK_SUCCESS) { + ASSERT(false); + } + } + + PipelineLayout::~PipelineLayout() { + if (mHandle != VK_NULL_HANDLE) { + mDevice->GetFencedDeleter()->DeleteWhenUnused(mHandle); + mHandle = VK_NULL_HANDLE; + } + } + + VkPipelineLayout PipelineLayout::GetHandle() const { + return mHandle; + } + +}} // namespace backend::vulkan diff --git a/src/backend/vulkan/PipelineLayoutVk.h b/src/backend/vulkan/PipelineLayoutVk.h new file mode 100644 index 0000000000..c042c0a4fa --- /dev/null +++ b/src/backend/vulkan/PipelineLayoutVk.h @@ -0,0 +1,41 @@ +// 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_PIPELINELAYOUTVK_H_ +#define BACKEND_VULKAN_PIPELINELAYOUTVK_H_ + +#include "backend/PipelineLayout.h" + +#include "backend/vulkan/vulkan_platform.h" + +namespace backend { namespace vulkan { + + class Device; + + class PipelineLayout : public PipelineLayoutBase { + public: + PipelineLayout(PipelineLayoutBuilder* builder); + ~PipelineLayout(); + + VkPipelineLayout GetHandle() const; + + private: + VkPipelineLayout mHandle = VK_NULL_HANDLE; + + Device* mDevice = nullptr; + }; + +}} // namespace backend::vulkan + +#endif // BACKEND_VULKAN_PIPELINELAYOUTVK_H_ diff --git a/src/backend/vulkan/TextureVk.cpp b/src/backend/vulkan/TextureVk.cpp index 2aea70d3a3..49dfb41294 100644 --- a/src/backend/vulkan/TextureVk.cpp +++ b/src/backend/vulkan/TextureVk.cpp @@ -1,4 +1,4 @@ -// Copyright 2017 The NXT Authors +// 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. diff --git a/src/backend/vulkan/VulkanBackend.cpp b/src/backend/vulkan/VulkanBackend.cpp index 362ee40b2c..16c02cc99f 100644 --- a/src/backend/vulkan/VulkanBackend.cpp +++ b/src/backend/vulkan/VulkanBackend.cpp @@ -19,6 +19,7 @@ #include "backend/vulkan/BufferVk.h" #include "backend/vulkan/CommandBufferVk.h" #include "backend/vulkan/FencedDeleter.h" +#include "backend/vulkan/PipelineLayoutVk.h" #include "backend/vulkan/TextureVk.h" #include "common/Platform.h" diff --git a/src/backend/vulkan/VulkanBackend.h b/src/backend/vulkan/VulkanBackend.h index ec72abd69c..cbb481ed9a 100644 --- a/src/backend/vulkan/VulkanBackend.h +++ b/src/backend/vulkan/VulkanBackend.h @@ -25,14 +25,12 @@ #include "backend/Device.h" #include "backend/Framebuffer.h" #include "backend/InputState.h" -#include "backend/PipelineLayout.h" #include "backend/Queue.h" #include "backend/RenderPass.h" #include "backend/RenderPipeline.h" #include "backend/Sampler.h" #include "backend/ShaderModule.h" #include "backend/SwapChain.h" -#include "backend/Texture.h" #include "backend/ToBackend.h" #include "backend/vulkan/VulkanFunctions.h" #include "backend/vulkan/VulkanInfo.h" @@ -55,7 +53,7 @@ namespace backend { namespace vulkan { class Device; using Framebuffer = FramebufferBase; using InputState = InputStateBase; - using PipelineLayout = PipelineLayoutBase; + class PipelineLayout; class Queue; using RenderPass = RenderPassBase; using RenderPipeline = RenderPipelineBase;