From a47df897d30a8fdacc28235ab708ac4b28748eae Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 14 Apr 2018 21:08:00 -0700 Subject: Added GLSL to SPIRV shader compilation --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 1 + Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h | 2 +- Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 12 ++++++++++-- .../src/VulkanUtilities/VulkanInstance.cpp | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index bf8a78ea..5d417d8a 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -158,6 +158,7 @@ set(PRIVATE_DEPENDENCIES Common TargetPlatform GraphicsEngine + GLSLTools ) if(PLATFORM_WIN32) diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h index 904ae379..4bd9d43d 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h @@ -47,7 +47,7 @@ class ShaderVkImpl : public ShaderBase public: typedef ShaderBase TShaderBase; - ShaderVkImpl(IReferenceCounters *pRefCounters, class RenderDeviceVkImpl *pRenderDeviceVk, const ShaderCreationAttribs &ShaderCreationAttribs); + ShaderVkImpl(IReferenceCounters *pRefCounters, class RenderDeviceVkImpl *pRenderDeviceVk, const ShaderCreationAttribs &CreationAttribs); ~ShaderVkImpl(); //virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 0b96448c..d012b1bc 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -26,6 +26,8 @@ #include "ShaderVkImpl.h" #include "RenderDeviceVkImpl.h" #include "DataBlobImpl.h" +#include "GLSLSourceBuilder.h" +#include "GLSL2SPIRV.h" //#include "D3DShaderResourceLoader.h" using namespace Diligent; @@ -34,13 +36,19 @@ namespace Diligent { -ShaderVkImpl::ShaderVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl *pRenderDeviceVk, const ShaderCreationAttribs &ShaderCreationAttribs) : - TShaderBase(pRefCounters, pRenderDeviceVk, ShaderCreationAttribs.Desc)/*, +ShaderVkImpl::ShaderVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl *pRenderDeviceVk, const ShaderCreationAttribs &CreationAttribs) : + TShaderBase(pRefCounters, pRenderDeviceVk, CreationAttribs.Desc)/*, ShaderD3DBase(ShaderCreationAttribs), m_StaticResLayout(*this, GetRawAllocator()), m_DummyShaderVar(*this), m_ConstResCache(ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources)*/ { + auto GLSLSource = BuildGLSLSourceString(CreationAttribs); + auto SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str()); + if(SPIRV.empty()) + { + LOG_ERROR_AND_THROW("Failed to compile shader"); + } /* // Load shader resources auto &Allocator = GetRawAllocator(); diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp index a47c0ec0..a8e34a82 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp @@ -26,6 +26,7 @@ #include "VulkanErrors.h" #include "VulkanUtilities/VulkanInstance.h" #include "VulkanUtilities/VulkanDebug.h" +#include "GLSL2SPIRV.h" namespace VulkanUtilities { @@ -186,6 +187,8 @@ namespace VulkanUtilities CHECK_VK_ERROR(err, "Failed to enumerate physical devices"); VERIFY_EXPR(m_PhysicalDevices.size() == PhysicalDeviceCount); } + + Diligent::InitializeGlslang(); } VulkanInstance::~VulkanInstance() @@ -195,6 +198,8 @@ namespace VulkanUtilities VulkanUtilities::FreeDebugCallback(m_VkInstance); } vkDestroyInstance(m_VkInstance, m_pVkAllocator); + + Diligent::FinalizeGlslang(); } VkPhysicalDevice VulkanInstance::SelectPhysicalDevice() -- cgit v1.2.3