diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-05-05 22:46:25 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-05-05 22:46:25 +0000 |
| commit | 86500467cbf998df13f3644c1e04040ce2dd5907 (patch) | |
| tree | 16f299b3bda4cfc8b7f0afcdb93bd11ec3c839d7 /Graphics | |
| parent | Fixed GLSL shader compilation to generate bindings and descriptor sets; updat... (diff) | |
| download | DiligentCore-86500467cbf998df13f3644c1e04040ce2dd5907.tar.gz DiligentCore-86500467cbf998df13f3644c1e04040ce2dd5907.zip | |
Added shader variable type parsing in Vulkan
Diffstat (limited to 'Graphics')
| -rw-r--r-- | Graphics/GLSLTools/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | Graphics/GLSLTools/include/SPIRVShaderResources.h | 7 | ||||
| -rw-r--r-- | Graphics/GLSLTools/src/SPIRVShaderResources.cpp | 29 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceObjectBase.h | 2 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 2 |
5 files changed, 31 insertions, 10 deletions
diff --git a/Graphics/GLSLTools/CMakeLists.txt b/Graphics/GLSLTools/CMakeLists.txt index 32cd107a..46392807 100644 --- a/Graphics/GLSLTools/CMakeLists.txt +++ b/Graphics/GLSLTools/CMakeLists.txt @@ -28,6 +28,7 @@ PUBLIC include PRIVATE ../HLSL2GLSLConverterLib/include + ../GraphicsEngine/include ) target_link_libraries(GLSLTools diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.h b/Graphics/GLSLTools/include/SPIRVShaderResources.h index 9d952a97..df853933 100644 --- a/Graphics/GLSLTools/include/SPIRVShaderResources.h +++ b/Graphics/GLSLTools/include/SPIRVShaderResources.h @@ -116,7 +116,12 @@ struct SPIRVShaderResourceAttribs class SPIRVShaderResources { public: - SPIRVShaderResources(IMemoryAllocator &Allocator, SHADER_TYPE ShaderType, std::vector<uint32_t> spirv_binary); + SPIRVShaderResources(IMemoryAllocator &Allocator, + SHADER_TYPE ShaderType, + std::vector<uint32_t> spirv_binary, + SHADER_VARIABLE_TYPE DefaultVariableType, + const ShaderVariableDesc *VariableDesc, + Uint32 NumVars); // Copies specified types of resources from another ShaderResources objects // Only resources listed in AllowedVarTypes are copied diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp index 1e2a5865..854f6582 100644 --- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp +++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp @@ -23,6 +23,7 @@ #include "SPIRVShaderResources.h" #include "spirv_cross.hpp" +#include "ShaderBase.h" namespace Diligent { @@ -73,7 +74,12 @@ SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const spirv_cross::Compil { } -SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator &Allocator, SHADER_TYPE ShaderType, std::vector<uint32_t> spirv_binary) : +SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator &Allocator, + SHADER_TYPE ShaderType, + std::vector<uint32_t> spirv_binary, + SHADER_VARIABLE_TYPE DefaultVariableType, + const ShaderVariableDesc *VariableDesc, + Uint32 NumVars) : m_MemoryBuffer(nullptr, STDDeleterRawMem<void>(Allocator)), m_ShaderType(ShaderType) { @@ -95,37 +101,44 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator &Allocator, SHADER_T Uint32 CurrUB = 0, CurrSB = 0, CurrImg = 0, CurrSmplImg = 0, CurrAC = 0, CurrSepImg = 0, CurrSepSmpl = 0; for (const auto &UB : resources.uniform_buffers) { - new (&GetUB(CurrUB++)) SPIRVShaderResourceAttribs(Compiler, UB, SPIRVShaderResourceAttribs::ResourceType::UniformBuffer, SHADER_VARIABLE_TYPE_STATIC); + auto VarType = GetShaderVariableType(UB.name.c_str(), DefaultVariableType, VariableDesc, NumVars); + new (&GetUB(CurrUB++)) SPIRVShaderResourceAttribs(Compiler, UB, SPIRVShaderResourceAttribs::ResourceType::UniformBuffer, VarType); } for (const auto &SB : resources.storage_buffers) { - new (&GetSB(CurrSB++)) SPIRVShaderResourceAttribs(Compiler, SB, SPIRVShaderResourceAttribs::ResourceType::StorageBuffer, SHADER_VARIABLE_TYPE_STATIC); + auto VarType = GetShaderVariableType(SB.name.c_str(), DefaultVariableType, VariableDesc, NumVars); + new (&GetSB(CurrSB++)) SPIRVShaderResourceAttribs(Compiler, SB, SPIRVShaderResourceAttribs::ResourceType::StorageBuffer, VarType); } for (const auto &SmplImg : resources.sampled_images) { - new (&GetSmplImg(CurrSmplImg++)) SPIRVShaderResourceAttribs(Compiler, SmplImg, SPIRVShaderResourceAttribs::ResourceType::SampledImage, SHADER_VARIABLE_TYPE_STATIC); + auto VarType = GetShaderVariableType(SmplImg.name.c_str(), DefaultVariableType, VariableDesc, NumVars); + new (&GetSmplImg(CurrSmplImg++)) SPIRVShaderResourceAttribs(Compiler, SmplImg, SPIRVShaderResourceAttribs::ResourceType::SampledImage, VarType); } for (const auto &Img : resources.storage_images) { - new (&GetImg(CurrImg++)) SPIRVShaderResourceAttribs(Compiler, Img, SPIRVShaderResourceAttribs::ResourceType::StorageImage, SHADER_VARIABLE_TYPE_STATIC); + auto VarType = GetShaderVariableType(Img.name.c_str(), DefaultVariableType, VariableDesc, NumVars); + new (&GetImg(CurrImg++)) SPIRVShaderResourceAttribs(Compiler, Img, SPIRVShaderResourceAttribs::ResourceType::StorageImage, VarType); } for (const auto &AC : resources.atomic_counters) { - new (&GetAC(CurrAC++)) SPIRVShaderResourceAttribs(Compiler, AC, SPIRVShaderResourceAttribs::ResourceType::AtomicCounter, SHADER_VARIABLE_TYPE_STATIC); + auto VarType = GetShaderVariableType(AC.name.c_str(), DefaultVariableType, VariableDesc, NumVars); + new (&GetAC(CurrAC++)) SPIRVShaderResourceAttribs(Compiler, AC, SPIRVShaderResourceAttribs::ResourceType::AtomicCounter, VarType); } for (const auto &SepImg : resources.separate_images) { - new (&GetSepImg(CurrSepImg++)) SPIRVShaderResourceAttribs(Compiler, SepImg, SPIRVShaderResourceAttribs::ResourceType::SeparateImage, SHADER_VARIABLE_TYPE_STATIC); + auto VarType = GetShaderVariableType(SepImg.name.c_str(), DefaultVariableType, VariableDesc, NumVars); + new (&GetSepImg(CurrSepImg++)) SPIRVShaderResourceAttribs(Compiler, SepImg, SPIRVShaderResourceAttribs::ResourceType::SeparateImage, VarType); } for (const auto &SepSam : resources.separate_samplers) { - new (&GetSepSmpl(CurrSepSmpl++)) SPIRVShaderResourceAttribs(Compiler, SepSam, SPIRVShaderResourceAttribs::ResourceType::SeparateSampler, SHADER_VARIABLE_TYPE_STATIC); + auto VarType = GetShaderVariableType(SepSam.name.c_str(), DefaultVariableType, VariableDesc, NumVars); + new (&GetSepSmpl(CurrSepSmpl++)) SPIRVShaderResourceAttribs(Compiler, SepSam, SPIRVShaderResourceAttribs::ResourceType::SeparateSampler, VarType); } VERIFY_EXPR(CurrUB == GetNumUBs()); diff --git a/Graphics/GraphicsEngine/include/DeviceObjectBase.h b/Graphics/GraphicsEngine/include/DeviceObjectBase.h index af5fed00..09368cf4 100644 --- a/Graphics/GraphicsEngine/include/DeviceObjectBase.h +++ b/Graphics/GraphicsEngine/include/DeviceObjectBase.h @@ -26,9 +26,11 @@ /// \file /// Implementation of the Diligent::DeviceObjectBase template class +#include "RefCntAutoPtr.h" #include "ObjectBase.h" #include "UniqueIdentifier.h" + namespace Diligent { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 73c97870..64084135 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -62,7 +62,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters *pRefCounters, RenderDeviceVkImpl // Load shader resources auto &Allocator = GetRawAllocator(); auto *pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources)); - auto *pResources = new (pRawMem) SPIRVShaderResources(Allocator, m_Desc.ShaderType, std::move(SPIRV)); + auto *pResources = new (pRawMem) SPIRVShaderResources(Allocator, m_Desc.ShaderType, std::move(SPIRV), m_Desc.DefaultVariableType, m_Desc.VariableDesc, m_Desc.NumVariables); m_pShaderResources.reset(pResources, STDDeleterRawMem<SPIRVShaderResources>(Allocator)); /* |
