diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-04-15 04:57:19 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-04-15 04:57:19 +0000 |
| commit | bf9177a31943fd4637778317c8d4f06ec9df39c3 (patch) | |
| tree | 1d1b9531babca5ab2545f039f0a6a5a08735cf10 /Graphics/GraphicsEngineVulkan | |
| parent | Added GLSL to SPIRV shader compilation (diff) | |
| download | DiligentCore-bf9177a31943fd4637778317c8d4f06ec9df39c3.tar.gz DiligentCore-bf9177a31943fd4637778317c8d4f06ec9df39c3.zip | |
Added vulkan shader module creation
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
7 files changed, 47 insertions, 7 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h index 4bd9d43d..a861700f 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h @@ -30,6 +30,7 @@ #include "ShaderVk.h" #include "ShaderBase.h" #include "ShaderResourceLayoutVk.h" +#include "VulkanUtilities/VulkanObjectWrappers.h" #ifdef _DEBUG # define VERIFY_SHADER_BINDINGS @@ -56,8 +57,12 @@ public: virtual IShaderVariable* GetShaderVariable(const Char* Name)override; + virtual VkShaderModule GetVkShaderModule()override final + { + return m_VkShaderModule; + } + /* - ID3DBlob* GetShaderByteCode(){return m_pShaderByteCode;} const std::shared_ptr<const ShaderResourcesVk>& GetShaderResources()const{return m_pShaderResources;} const ShaderResourceLayoutVk& GetConstResLayout()const{return m_StaticResLayout;} @@ -75,6 +80,7 @@ private: ShaderResourceLayoutVk m_StaticResLayout; ShaderResourceCacheVk m_ConstResCache; */ + VulkanUtilities::ShaderModuleWrapper m_VkShaderModule; }; } diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h index 901f42af..8dba0dd7 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanLogicalDevice.h @@ -72,6 +72,7 @@ namespace VulkanUtilities 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; + ShaderModuleWrapper CreateShaderModule (const VkShaderModuleCreateInfo &ShaderModuleCI, const char *DebugName = "")const; VkCommandBuffer AllocateVkCommandBuffer(const VkCommandBufferAllocateInfo &AllocInfo, const char *DebugName = "")const; @@ -84,6 +85,7 @@ namespace VulkanUtilities void ReleaseVulkanObject(RenderPassWrapper&& RenderPass)const; void ReleaseVulkanObject(DeviceMemoryWrapper&& Memory)const; void ReleaseVulkanObject(PipelineWrapper&& Pipeline)const; + void ReleaseVulkanObject(ShaderModuleWrapper&& ShaderModule)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 456b4853..7e749a70 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanObjectWrappers.h @@ -99,4 +99,5 @@ namespace VulkanUtilities using FenceWrapper = VulkanObjectWrapper<VkFence>; using RenderPassWrapper = VulkanObjectWrapper<VkRenderPass>; using PipelineWrapper = VulkanObjectWrapper<VkPipeline>; + using ShaderModuleWrapper = VulkanObjectWrapper<VkShaderModule>; } diff --git a/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h b/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h index e9fc51de..2f7acbda 100644 --- a/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/ShaderVk.h @@ -40,11 +40,8 @@ class IShaderVk : public IShader { public: - /// Returns a pointer to the ID3D12DeviceChild interface of the internal Direct3D12 object. - - /// The method does *NOT* call AddRef() on the returned interface, - /// so Release() must not be called. - //virtual ID3D12DeviceChild* GetD3D12Shader() = 0; + /// Returns Vulkan shader module handle + virtual VkShaderModule GetVkShaderModule() = 0; }; } diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 13d79d06..e18186ff 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -412,6 +412,7 @@ template void RenderDeviceVkImpl::SafeReleaseVkObject<VkImageView> (VulkanUti template void RenderDeviceVkImpl::SafeReleaseVkObject<VkDeviceMemory> (VulkanUtilities::DeviceMemoryWrapper &&Object); template void RenderDeviceVkImpl::SafeReleaseVkObject<VkRenderPass> (VulkanUtilities::RenderPassWrapper &&Object); template void RenderDeviceVkImpl::SafeReleaseVkObject<VkPipeline> (VulkanUtilities::PipelineWrapper &&Object); +template void RenderDeviceVkImpl::SafeReleaseVkObject<VkShaderModule> (VulkanUtilities::ShaderModuleWrapper &&Object); void RenderDeviceVkImpl::DiscardStaleVkObjects(Uint64 CmdListNumber, Uint64 FenceValue) diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index d012b1bc..507d3aea 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -43,12 +43,22 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl m_DummyShaderVar(*this), m_ConstResCache(ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources)*/ { - auto GLSLSource = BuildGLSLSourceString(CreationAttribs); + auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::glslang); auto SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str()); if(SPIRV.empty()) { LOG_ERROR_AND_THROW("Failed to compile shader"); } + + const auto &LogicalDevice = pRenderDeviceVk->GetLogicalDevice(); + VkShaderModuleCreateInfo ShaderModuleCI = {}; + ShaderModuleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + ShaderModuleCI.pNext = NULL; + ShaderModuleCI.flags = 0; + ShaderModuleCI.codeSize = SPIRV.size() * sizeof(unsigned int); + ShaderModuleCI.pCode = SPIRV.data(); + m_VkShaderModule = LogicalDevice.CreateShaderModule(ShaderModuleCI, m_Desc.Name); + /* // Load shader resources auto &Allocator = GetRawAllocator(); @@ -65,6 +75,8 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl ShaderVkImpl::~ShaderVkImpl() { + auto pDeviceVkImpl = ValidatedCast<RenderDeviceVkImpl>(GetDevice()); + pDeviceVkImpl->SafeReleaseVkObject(std::move(m_VkShaderModule)); } void ShaderVkImpl::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp index 70c0e671..c178d3d2 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanLogicalDevice.cpp @@ -235,6 +235,21 @@ namespace VulkanUtilities return PipelineWrapper{ GetSharedPtr(), std::move(vkPipeline) }; } + ShaderModuleWrapper VulkanLogicalDevice::CreateShaderModule(const VkShaderModuleCreateInfo &ShaderModuleCI, const char *DebugName)const + { + if (DebugName == nullptr) + DebugName = ""; + + VkShaderModule vkShaderModule = VK_NULL_HANDLE; + auto err = vkCreateShaderModule(m_VkDevice, &ShaderModuleCI, m_VkAllocator, &vkShaderModule); + CHECK_VK_ERROR_AND_THROW(err, "Failed to create Render Pass '", DebugName, '\''); + + if (DebugName != nullptr && *DebugName != 0) + VulkanUtilities::SetShaderModuleName(m_VkDevice, vkShaderModule, DebugName); + + return ShaderModuleWrapper{ GetSharedPtr(), std::move(vkShaderModule) }; + } + VkCommandBuffer VulkanLogicalDevice::AllocateVkCommandBuffer(const VkCommandBufferAllocateInfo &AllocInfo, const char *DebugName)const { @@ -305,6 +320,12 @@ namespace VulkanUtilities Pipeline.m_VkObject = VK_NULL_HANDLE; } + void VulkanLogicalDevice::ReleaseVulkanObject(ShaderModuleWrapper&& ShaderModule)const + { + vkDestroyShaderModule(m_VkDevice, ShaderModule.m_VkObject, m_VkAllocator); + ShaderModule.m_VkObject = VK_NULL_HANDLE; + } + VkMemoryRequirements VulkanLogicalDevice::GetBufferMemoryRequirements(VkBuffer vkBuffer)const { VkMemoryRequirements MemReqs = {}; |
