Vulkan: Create dummy pipeline layouts

This commit is contained in:
Corentin Wallez 2018-01-09 04:37:02 -08:00 committed by Corentin Wallez
parent 47155a3555
commit aeaffcf8fc
9 changed files with 115 additions and 7 deletions

View File

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

View File

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

View File

@ -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<VkBuffer> mBuffersToDelete;
SerialQueue<VkDeviceMemory> mMemoriesToDelete;
SerialQueue<VkImage> mImagesToDelete;
SerialQueue<VkPipelineLayout> mPipelineLayoutsToDelete;
};
}} // namespace backend::vulkan

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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