From 7747661dff6c6c45cca54bd81521de5f96842331 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 12 Apr 2018 18:54:00 -0700 Subject: Vulkan: working on pipeline state initialization --- .../include/PipelineStateVkImpl.h | 2 +- .../include/VulkanUtilities/VulkanLogicalDevice.h | 5 ++- .../include/VulkanUtilities/VulkanObjectWrappers.h | 3 ++ .../src/RenderDeviceVkImpl.cpp | 13 +++---- .../src/VulkanTypeConversions.cpp | 8 +++-- .../src/VulkanUtilities/VulkanDebug.cpp | 2 +- .../src/VulkanUtilities/VulkanLogicalDevice.cpp | 40 ++++++++++++++++++++++ 7 files changed, 61 insertions(+), 12 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h index 65e9eb3d..8142ce5c 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h @@ -89,7 +89,6 @@ private: void ParseShaderResourceLayout(IShader *pShader); /// Vk device - CComPtr m_pVkPSO; RootSignature m_RootSig; DummyShaderVariable m_DummyVar; @@ -127,6 +126,7 @@ private: std::unique_ptr > m_pDefaultShaderResBinding; #endif VulkanUtilities::RenderPassWrapper m_RenderPass; + VulkanUtilities::PipelineWrapper m_Pipeline; }; diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h index 48f6d660..901f42af 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h @@ -70,7 +70,9 @@ namespace VulkanUtilities FenceWrapper CreateFence (const VkFenceCreateInfo &FenceCI, const char *DebugName = "")const; RenderPassWrapper CreateRenderPass (const VkRenderPassCreateInfo &RenderPassCI,const char *DebugName = "")const; DeviceMemoryWrapper AllocateDeviceMemory(const VkMemoryAllocateInfo &AllocInfo, const char *DebugName = "")const; - + PipelineWrapper CreateComputePipeline (const VkComputePipelineCreateInfo &PipelineCI, VkPipelineCache cache, const char *DebugName = "")const; + PipelineWrapper CreateGraphicsPipeline(const VkGraphicsPipelineCreateInfo &PipelineCI, VkPipelineCache cache, const char *DebugName = "")const; + VkCommandBuffer AllocateVkCommandBuffer(const VkCommandBufferAllocateInfo &AllocInfo, const char *DebugName = "")const; void ReleaseVulkanObject(CommandPoolWrapper&& CmdPool)const; @@ -81,6 +83,7 @@ namespace VulkanUtilities void ReleaseVulkanObject(FenceWrapper&& Fence)const; void ReleaseVulkanObject(RenderPassWrapper&& RenderPass)const; void ReleaseVulkanObject(DeviceMemoryWrapper&& Memory)const; + void ReleaseVulkanObject(PipelineWrapper&& Pipeline)const; VkMemoryRequirements GetBufferMemoryRequirements(VkBuffer vkBuffer)const; VkMemoryRequirements GetImageMemoryRequirements (VkImage vkImage )const; diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h index 745f6b9d..456b4853 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h @@ -34,6 +34,8 @@ namespace VulkanUtilities class VulkanObjectWrapper { public: + using VkObjectType = VulkanObjectType; + VulkanObjectWrapper() : m_pLogicalDevice(nullptr), m_VkObject(VK_NULL_HANDLE) @@ -96,4 +98,5 @@ namespace VulkanUtilities using DeviceMemoryWrapper = VulkanObjectWrapper; using FenceWrapper = VulkanObjectWrapper; using RenderPassWrapper = VulkanObjectWrapper; + using PipelineWrapper = VulkanObjectWrapper; } diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 84917dbb..13d79d06 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -405,12 +405,13 @@ void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::VulkanObjectWrappe m_StaleVkObjects.emplace_back(m_NextCmdListNumber, new StaleVulkanObject(std::move(vkObject)) ); } -template void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::BufferWrapper &&Object); -template void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::BufferViewWrapper &&Object); -template void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::ImageWrapper &&Object); -template void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::ImageViewWrapper &&Object); -template void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::DeviceMemoryWrapper &&Object); -template void RenderDeviceVkImpl::SafeReleaseVkObject(VulkanUtilities::RenderPassWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::BufferWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::BufferViewWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::ImageWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::ImageViewWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::DeviceMemoryWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::RenderPassWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject (VulkanUtilities::PipelineWrapper &&Object); void RenderDeviceVkImpl::DiscardStaleVkObjects(Uint64 CmdListNumber, Uint64 FenceValue) diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 0454cfb4..ad28c1c4 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -666,7 +666,9 @@ VkPipelineRasterizationStateCreateInfo RasterizerStateDesc_To_VkRasterizationSta RSStateCI.depthBiasConstantFactor = static_cast(RasterizerDesc.DepthBias); // a scalar factor controlling the constant depth value added to each fragment. RSStateCI.depthBiasClamp = RasterizerDesc.DepthBiasClamp; // maximum (or minimum) depth bias of a fragment. RSStateCI.depthBiasSlopeFactor = RasterizerDesc.SlopeScaledDepthBias; // a scalar factor applied to a fragment’s slope in depth bias calculations. - RSStateCI.lineWidth = 1.f; + RSStateCI.lineWidth = 1.f; // If the wide lines feature is not enabled, and no element of the pDynamicStates member of + // pDynamicState is VK_DYNAMIC_STATE_LINE_WIDTH, the lineWidth member of + // pRasterizationState must be 1.0 (9.2) return RSStateCI; } @@ -745,8 +747,8 @@ VkPipelineDepthStencilStateCreateInfo DepthStencilStateDesc_To_VkDepthStencilSt DSStateCI.stencilTestEnable = DepthStencilDesc.StencilEnable; DSStateCI.front = StencilOpDescToVkStencilOpState(DepthStencilDesc.FrontFace, DepthStencilDesc.StencilReadMask, DepthStencilDesc.StencilWriteMask); DSStateCI.back = StencilOpDescToVkStencilOpState(DepthStencilDesc.BackFace, DepthStencilDesc.StencilReadMask, DepthStencilDesc.StencilWriteMask); - DSStateCI.minDepthBounds = -FLT_MAX; - DSStateCI.maxDepthBounds = +FLT_MAX; + DSStateCI.minDepthBounds = 0; + DSStateCI.maxDepthBounds = 1; return DSStateCI; } diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp index f9b8ec58..9e80f530 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanDebug.cpp @@ -124,7 +124,7 @@ namespace VulkanUtilities void SetObjectName(VkDevice device, uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name) { // Check for valid function pointer (may not be present if not running in a debugging application) - if (pfnDebugMarkerSetObjectName != VK_NULL_HANDLE) + if (pfnDebugMarkerSetObjectName != VK_NULL_HANDLE && name != nullptr && *name != 0) { VkDebugMarkerObjectNameInfoEXT nameInfo = {}; nameInfo.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT; diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp index 23471e99..70c0e671 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp @@ -201,6 +201,40 @@ namespace VulkanUtilities return DeviceMemoryWrapper{ GetSharedPtr(), std::move(vkDeviceMem) }; } + PipelineWrapper VulkanLogicalDevice::CreateComputePipeline(const VkComputePipelineCreateInfo &PipelineCI, + VkPipelineCache cache, + const char *DebugName)const + { + if (DebugName == nullptr) + DebugName = ""; + + VkPipeline vkPipeline = VK_NULL_HANDLE; + auto err = vkCreateComputePipelines(m_VkDevice, cache, 1, &PipelineCI, m_VkAllocator, &vkPipeline); + CHECK_VK_ERROR_AND_THROW(err, "Failed to create compute pipeline '", DebugName, '\''); + + if (DebugName != nullptr && *DebugName != 0) + VulkanUtilities::SetPipelineName(m_VkDevice, vkPipeline, DebugName); + + return PipelineWrapper{ GetSharedPtr(), std::move(vkPipeline) }; + } + + PipelineWrapper VulkanLogicalDevice::CreateGraphicsPipeline(const VkGraphicsPipelineCreateInfo &PipelineCI, + VkPipelineCache cache, + const char *DebugName)const + { + if (DebugName == nullptr) + DebugName = ""; + + VkPipeline vkPipeline = VK_NULL_HANDLE; + auto err = vkCreateGraphicsPipelines(m_VkDevice, cache, 1, &PipelineCI, m_VkAllocator, &vkPipeline); + CHECK_VK_ERROR_AND_THROW(err, "Failed to create Graphics pipeline '", DebugName, '\''); + + if (DebugName != nullptr && *DebugName != 0) + VulkanUtilities::SetPipelineName(m_VkDevice, vkPipeline, DebugName); + + return PipelineWrapper{ GetSharedPtr(), std::move(vkPipeline) }; + } + VkCommandBuffer VulkanLogicalDevice::AllocateVkCommandBuffer(const VkCommandBufferAllocateInfo &AllocInfo, const char *DebugName)const { @@ -265,6 +299,12 @@ namespace VulkanUtilities Memory.m_VkObject = VK_NULL_HANDLE; } + void VulkanLogicalDevice::ReleaseVulkanObject(PipelineWrapper&& Pipeline)const + { + vkDestroyPipeline(m_VkDevice, Pipeline.m_VkObject, m_VkAllocator); + Pipeline.m_VkObject = VK_NULL_HANDLE; + } + VkMemoryRequirements VulkanLogicalDevice::GetBufferMemoryRequirements(VkBuffer vkBuffer)const { VkMemoryRequirements MemReqs = {}; -- cgit v1.2.3