diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-10-26 04:25:09 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-10-26 04:25:09 +0000 |
| commit | c430a7906d1320172539494e331a823aa52f8ea3 (patch) | |
| tree | 41b2f4d18d39d14c065cc81aa3c6f7ac842926af /Graphics/GraphicsEngineVulkan | |
| parent | Fixed https://github.com/DiligentGraphics/DiligentCore/issues/37 (build error... (diff) | |
| parent | Added HLSL definitions to SPIRV compiler + fixed bug in SPIRV shader resources (diff) | |
| download | DiligentCore-c430a7906d1320172539494e331a823aa52f8ea3.tar.gz DiligentCore-c430a7906d1320172539494e331a823aa52f8ea3.zip | |
Merge branch 'hlsl_glslang'
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
4 files changed, 154 insertions, 54 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h index 3ce40f5b..dc72d609 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h @@ -144,9 +144,15 @@ public: VkResource& operator = (const VkResource&) = delete; VkResource& operator = (VkResource&&) = delete; + static constexpr const Uint32 CacheOffsetBits = 24; + static constexpr const Uint32 SamplerIndBits = 8; + static constexpr const Uint32 InvalidSamplerInd = (1 << SamplerIndBits)-1; + const Uint16 Binding; const Uint16 DescriptorSet; - const Uint32 CacheOffset; // Offset from the beginning of the cached descriptor set + const Uint32 CacheOffset : CacheOffsetBits; // Offset from the beginning of the cached descriptor set + const Uint32 SamplerInd : SamplerIndBits; // When using combined texture samplers, index of the separate sampler + // assigned to separate image const SPIRVShaderResourceAttribs& SpirvAttribs; const ShaderResourceLayoutVk& ParentResLayout; @@ -154,15 +160,19 @@ public: const SPIRVShaderResourceAttribs& _SpirvAttribs, uint32_t _Binding, uint32_t _DescriptorSet, - Uint32 _CacheOffset)noexcept : + Uint32 _CacheOffset, + Uint32 _SamplerInd)noexcept : Binding (static_cast<decltype(Binding)>(_Binding)), DescriptorSet (static_cast<decltype(DescriptorSet)>(_DescriptorSet)), CacheOffset (_CacheOffset), + SamplerInd (_SamplerInd), SpirvAttribs (_SpirvAttribs), ParentResLayout (_ParentLayout) { - VERIFY(_Binding <= std::numeric_limits<decltype(Binding)>::max(), "Binding (", _Binding, ") exceeds representable max value", std::numeric_limits<decltype(Binding)>::max() ); - VERIFY(_DescriptorSet <= std::numeric_limits<decltype(DescriptorSet)>::max(), "Descriptor set (", _DescriptorSet, ") exceeds representable max value", std::numeric_limits<decltype(DescriptorSet)>::max()); + VERIFY(_CacheOffset < (1 << CacheOffsetBits), "Cache offset (", _CacheOffset, ") exceeds max representable value ", (1 << CacheOffsetBits) ); + VERIFY(_SamplerInd < (1 << SamplerIndBits), "Sampler index (", _SamplerInd, ") exceeds max representable value ", (1 << SamplerIndBits) ); + VERIFY(_Binding <= std::numeric_limits<decltype(Binding)>::max(), "Binding (", _Binding, ") exceeds max representable value ", std::numeric_limits<decltype(Binding)>::max() ); + VERIFY(_DescriptorSet <= std::numeric_limits<decltype(DescriptorSet)>::max(), "Descriptor set (", _DescriptorSet, ") exceeds max representable value ", std::numeric_limits<decltype(DescriptorSet)>::max()); } // Checks if a resource is bound in ResourceCache at the given ArrayIndex @@ -193,11 +203,13 @@ public: ShaderResourceCacheVk::Resource& DstRes, VkDescriptorSet vkDescrSet, Uint32 ArrayInd)const; - + + template<typename TCacheSampler> void CacheImage(IDeviceObject* pTexView, ShaderResourceCacheVk::Resource& DstRes, VkDescriptorSet vkDescrSet, - Uint32 ArrayInd)const; + Uint32 ArrayInd, + TCacheSampler CacheSampler)const; void CacheSeparateSampler(IDeviceObject* pSampler, ShaderResourceCacheVk::Resource& DstRes, @@ -242,6 +254,8 @@ public: return Resources[GetResourceOffset(VarType,r)]; } + bool IsUsingSeparateSamplers()const {return !m_pResources->IsUsingCombinedSamplers();} + private: Uint32 GetResourceOffset(SHADER_VARIABLE_TYPE VarType, Uint32 r)const { @@ -276,6 +290,8 @@ private: const SHADER_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes); + Uint32 FindAssignedSampler(const SPIRVShaderResourceAttribs& SepImg, Uint32 CurrResourceCount)const; + IObject& m_Owner; const VulkanUtilities::VulkanLogicalDevice& m_LogicalDevice; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index fc986cf7..9bc21a7e 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -68,7 +68,7 @@ void ShaderResourceLayoutVk::AllocateMemory(std::shared_ptr<const SPIRVShaderRes m_pResources->ProcessResources( AllowedVarTypes, NumAllowedTypes, - [&](const SPIRVShaderResourceAttribs &ResAttribs, Uint32) + [&](const SPIRVShaderResourceAttribs& ResAttribs, Uint32) { VERIFY_EXPR(IsAllowedType(ResAttribs.VarType, AllowedTypeBits)); VERIFY( Uint32{m_NumResources[ResAttribs.VarType]} + 1 <= Uint32{std::numeric_limits<Uint16>::max()}, "Number of resources exceeds max representable value"); @@ -104,13 +104,21 @@ void ShaderResourceLayoutVk::InitializeStaticResourceLayout(std::shared_ptr<cons m_pResources->ProcessResources( &AllowedVarType, 1, - [&](const SPIRVShaderResourceAttribs &Attribs, Uint32) + [&](const SPIRVShaderResourceAttribs& Attribs, Uint32) { Uint32 Binding = Attribs.Type; Uint32 DescriptorSet = 0; Uint32 CacheOffset = StaticResCacheSize; StaticResCacheSize += Attribs.ArraySize; - ::new (&GetResource(Attribs.VarType, CurrResInd[Attribs.VarType]++)) VkResource(*this, Attribs, Binding, DescriptorSet, CacheOffset); + + Uint32 SamplerInd = VkResource::InvalidSamplerInd; + if (Attribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage) + { + // Separate samplers are enumerated before separate images, so the sampler + // assigned to this separate image must already be created. + SamplerInd = FindAssignedSampler(Attribs, CurrResInd[Attribs.VarType]); + } + ::new (&GetResource(Attribs.VarType, CurrResInd[Attribs.VarType]++)) VkResource(*this, Attribs, Binding, DescriptorSet, CacheOffset, SamplerInd); } ); @@ -148,10 +156,11 @@ void ShaderResourceLayoutVk::Initialize(Uint32 NumShaders, std::unordered_map<Uint32, std::pair<Uint32, Uint32>> dbgBindings_CacheOffsets; #endif - auto AddResource = [&](Uint32 ShaderInd, - ShaderResourceLayoutVk& ResLayout, - const SPIRVShaderResources& Resources, - const SPIRVShaderResourceAttribs& Attribs) + auto AddResource = [&](Uint32 ShaderInd, + ShaderResourceLayoutVk& ResLayout, + const SPIRVShaderResources& Resources, + const SPIRVShaderResourceAttribs& Attribs, + Uint32 SamplerInd = VkResource::InvalidSamplerInd) { Uint32 Binding = 0; Uint32 DescriptorSet = 0; @@ -179,7 +188,7 @@ void ShaderResourceLayoutVk::Initialize(Uint32 NumShaders, #endif auto& ResInd = CurrResInd[ShaderInd][Attribs.VarType]; - ::new (&ResLayout.GetResource(Attribs.VarType, ResInd++)) VkResource(ResLayout, Attribs, Binding, DescriptorSet, CacheOffset); + ::new (&ResLayout.GetResource(Attribs.VarType, ResInd++)) VkResource(ResLayout, Attribs, Binding, DescriptorSet, CacheOffset, SamplerInd); }; // First process uniform buffers for all shader stages to make sure all UBs go first in every descriptor set @@ -220,41 +229,48 @@ void ShaderResourceLayoutVk::Initialize(Uint32 NumShaders, Resources.ProcessResources( AllowedVarTypes, NumAllowedTypes, - [&](const SPIRVShaderResourceAttribs &UB, Uint32) + [&](const SPIRVShaderResourceAttribs& UB, Uint32) { + VERIFY_EXPR(UB.Type == SPIRVShaderResourceAttribs::ResourceType::UniformBuffer); VERIFY_EXPR(IsAllowedType(UB.VarType, AllowedTypeBits)); // Skip }, [&](const SPIRVShaderResourceAttribs& SB, Uint32) { + VERIFY_EXPR(SB.Type == SPIRVShaderResourceAttribs::ResourceType::StorageBuffer); VERIFY_EXPR(IsAllowedType(SB.VarType, AllowedTypeBits)); // Skip }, - [&](const SPIRVShaderResourceAttribs &Img, Uint32) + [&](const SPIRVShaderResourceAttribs& Img, Uint32) { + VERIFY_EXPR(Img.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage || Img.Type == SPIRVShaderResourceAttribs::ResourceType::StorageTexelBuffer); VERIFY_EXPR(IsAllowedType(Img.VarType, AllowedTypeBits)); AddResource(s, Layout, Resources, Img); }, - [&](const SPIRVShaderResourceAttribs &SmplImg, Uint32) + [&](const SPIRVShaderResourceAttribs& SmplImg, Uint32) { + VERIFY_EXPR(SmplImg.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage || SmplImg.Type == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer); VERIFY_EXPR(IsAllowedType(SmplImg.VarType, AllowedTypeBits)); AddResource(s, Layout, Resources, SmplImg); }, - [&](const SPIRVShaderResourceAttribs &AC, Uint32) + [&](const SPIRVShaderResourceAttribs& AC, Uint32) { + VERIFY_EXPR(AC.Type == SPIRVShaderResourceAttribs::ResourceType::AtomicCounter); VERIFY_EXPR(IsAllowedType(AC.VarType, AllowedTypeBits)); AddResource(s, Layout, Resources, AC); }, - [&](const SPIRVShaderResourceAttribs &SepImg, Uint32) - { - VERIFY_EXPR(IsAllowedType(SepImg.VarType, AllowedTypeBits)); - AddResource(s, Layout, Resources, SepImg); - }, - - [&](const SPIRVShaderResourceAttribs &SepSmpl, Uint32) + [&](const SPIRVShaderResourceAttribs& SepSmpl, Uint32) { + VERIFY_EXPR(SepSmpl.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler); VERIFY_EXPR(IsAllowedType(SepSmpl.VarType, AllowedTypeBits)); AddResource(s, Layout, Resources, SepSmpl); + }, + [&](const SPIRVShaderResourceAttribs& SepImg, Uint32) + { + VERIFY_EXPR(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage); + VERIFY_EXPR(IsAllowedType(SepImg.VarType, AllowedTypeBits)); + Uint32 SamplerInd = Layout.FindAssignedSampler(SepImg, CurrResInd[s][SepImg.VarType]); + AddResource(s, Layout, Resources, SepImg, SamplerInd); } ); } @@ -271,11 +287,43 @@ void ShaderResourceLayoutVk::Initialize(Uint32 NumShaders, #endif } + +Uint32 ShaderResourceLayoutVk::FindAssignedSampler(const SPIRVShaderResourceAttribs& SepImg, Uint32 CurrResourceCount)const +{ + VERIFY_EXPR(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage); + + Uint32 SamplerInd = VkResource::InvalidSamplerInd; + if (m_pResources->IsUsingCombinedSamplers() && SepImg.ValidSepSamplerAssigned()) + { + const auto& SepSampler = m_pResources->GetSepSmplr(SepImg.SepSmplrOrImgInd); + DEV_CHECK_ERR(SepImg.VarType == SepSampler.VarType, + "The type (", GetShaderVariableTypeLiteralName(SepImg.VarType),") of separate image variable '", SepImg.Name, + "' is not consistent with the type (", GetShaderVariableTypeLiteralName(SepSampler.VarType), + ") of the separate sampler '", SepSampler.Name, "' that is assigned to it."); + + for (SamplerInd = 0; SamplerInd < CurrResourceCount; ++SamplerInd) + { + const auto& Res = GetResource(SepSampler.VarType, SamplerInd); + if (Res.SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler && + strcmp(Res.SpirvAttribs.Name, SepSampler.Name) == 0) + { + break; + } + } + if (SamplerInd == CurrResourceCount) + { + LOG_ERROR("Unable to find separate sampler '", SepSampler.Name, "' assigned to separate image '", SepImg.Name, "' in the list of already created resources. This seems to be a bug."); + SamplerInd = VkResource::InvalidSamplerInd; + } + } + return SamplerInd; +} + #define LOG_RESOURCE_BINDING_ERROR(ResType, pResource, VarName, ShaderName, ...)\ -{ \ - const auto &ResName = pResource->GetDesc().Name; \ - LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " \"", ResName, "\" to variable \"", VarName, \ - "\" in shader \"", ShaderName, "\". ", __VA_ARGS__ ); \ +{ \ + const auto &ResName = pResource->GetDesc().Name; \ + LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " '", ResName, "' to variable '", VarName, \ + "' in shader '", ShaderName, "'. ", __VA_ARGS__ ); \ } void ShaderResourceLayoutVk::VkResource::UpdateDescriptorHandle(VkDescriptorSet vkDescrSet, @@ -319,7 +367,7 @@ bool ShaderResourceLayoutVk::VkResource::UpdateCachedResource(ShaderResourceCach if (DstRes.pObject != pResource) { auto VarTypeStr = GetShaderVariableTypeLiteralName(SpirvAttribs.VarType); - LOG_ERROR_MESSAGE("Non-null resource is already bound to ", VarTypeStr, " shader variable \"", SpirvAttribs.GetPrintName(ArrayInd), "\" in shader \"", ParentResLayout.GetShaderName(), "\". Attempring to bind another resource is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic."); + LOG_ERROR_MESSAGE("Non-null resource is already bound to ", VarTypeStr, " shader variable '", SpirvAttribs.GetPrintName(ArrayInd), "' in shader '", ParentResLayout.GetShaderName(), "'. Attempring to bind another resource is an error and will be ignored. Use another shader resource binding instance or label the variable as dynamic."); } // Do not update resource if one is already bound unless it is dynamic. This may be @@ -441,20 +489,23 @@ void ShaderResourceLayoutVk::VkResource::CacheTexelBuffer(IDeviceObject* } } +template<typename TCacheSampler> void ShaderResourceLayoutVk::VkResource::CacheImage(IDeviceObject* pTexView, ShaderResourceCacheVk::Resource& DstRes, VkDescriptorSet vkDescrSet, - Uint32 ArrayInd)const + Uint32 ArrayInd, + TCacheSampler CacheSampler)const { - VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage || + VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage || SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage || SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage, "Storage image, separate image or sampled image resource is expected"); if (UpdateCachedResource(DstRes, ArrayInd, pTexView, IID_TextureViewVk, "texture view") ) { -#ifdef DEVELOPMENT + // We can do RawPtr here safely since UpdateCachedResource() returned true auto* pTexViewVk = DstRes.pObject.RawPtr<TextureViewVkImpl>(); +#ifdef DEVELOPMENT const auto ViewType = pTexViewVk->GetDesc().ViewType; const bool IsStorageImage = SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage; const auto dbgExpectedViewType = IsStorageImage ? TEXTURE_VIEW_UNORDERED_ACCESS : TEXTURE_VIEW_SHADER_RESOURCE; @@ -472,7 +523,7 @@ void ShaderResourceLayoutVk::VkResource::CacheImage(IDeviceObject* { if(pTexViewVk->GetSampler() == nullptr) { - LOG_RESOURCE_BINDING_ERROR("resource", pTexView, SpirvAttribs.GetPrintName(ArrayInd), ParentResLayout.GetShaderName(), "No sampler assigned to texture view."); + LOG_RESOURCE_BINDING_ERROR("resource", pTexView, SpirvAttribs.GetPrintName(ArrayInd), ParentResLayout.GetShaderName(), "No sampler assigned to texture view '", pTexViewVk->GetDesc().Name, "'"); } } #endif @@ -484,6 +535,24 @@ void ShaderResourceLayoutVk::VkResource::CacheImage(IDeviceObject* VkDescriptorImageInfo DescrImgInfo = DstRes.GetImageDescriptorWriteInfo(SpirvAttribs.StaticSamplerInd >= 0); UpdateDescriptorHandle(vkDescrSet, ArrayInd, &DescrImgInfo, nullptr, nullptr); } + + if (SamplerInd != InvalidSamplerInd) + { + VERIFY_EXPR(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage); + VERIFY_EXPR(SpirvAttribs.StaticSamplerInd < 0); + auto* pSampler = pTexViewVk->GetSampler(); + const auto& SamplerAttribs = ParentResLayout.GetResource(SpirvAttribs.VarType, SamplerInd); + if (pSampler != nullptr) + { + CacheSampler(SamplerAttribs, pSampler); + } + else + { + LOG_ERROR_MESSAGE( "Failed to bind sampler to sampler variable '", SamplerAttribs.SpirvAttribs.Name, + "' assigned to separate image '", SpirvAttribs.GetPrintName(ArrayInd), "' in shader '", + ParentResLayout.GetShaderName(), "': no sampler is set in texture view '", pTexViewVk->GetDesc().Name, '\''); \ + } + } } } @@ -554,7 +623,17 @@ void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject *pObj, Uint3 case SPIRVShaderResourceAttribs::ResourceType::StorageImage: case SPIRVShaderResourceAttribs::ResourceType::SeparateImage: case SPIRVShaderResourceAttribs::ResourceType::SampledImage: - CacheImage(pObj, DstRes, vkDescrSet, ArrayIndex); + CacheImage(pObj, DstRes, vkDescrSet, ArrayIndex, + [&](const VkResource& SeparateSampler, ISampler* pSampler) + { + DEV_CHECK_ERR(SeparateSampler.SpirvAttribs.ArraySize == 1 || SeparateSampler.SpirvAttribs.ArraySize == SpirvAttribs.ArraySize, + "Array size (", SeparateSampler.SpirvAttribs.ArraySize,") of separate sampler variable '", + SeparateSampler.SpirvAttribs.Name, "' must be one or same as the array size (", SpirvAttribs.ArraySize, + ") of separate image variable '", SpirvAttribs.Name, "' it is assigned to"); + Uint32 SamplerArrInd = SeparateSampler.SpirvAttribs.ArraySize == 0 ? ArrayIndex : 0; + SeparateSampler.BindResource(pSampler, SamplerArrInd, ResourceCache); + } + ); break; case SPIRVShaderResourceAttribs::ResourceType::SeparateSampler: @@ -577,7 +656,7 @@ void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject *pObj, Uint3 { if (DstRes.pObject && SpirvAttribs.VarType != SHADER_VARIABLE_TYPE_DYNAMIC) { - LOG_ERROR_MESSAGE( "Shader variable \"", SpirvAttribs.Name, "\" in shader \"", ParentResLayout.GetShaderName(), "\" is not dynamic but being unbound. This is an error and may cause unpredicted behavior. Use another shader resource binding instance or label shader variable as dynamic if you need to bind another resource." ); + LOG_ERROR_MESSAGE( "Shader variable '", SpirvAttribs.Name, "' in shader '", ParentResLayout.GetShaderName(), "' is not dynamic but being unbound. This is an error and may cause unpredicted behavior. Use another shader resource binding instance or label shader variable as dynamic if you need to bind another resource." ); } DstRes.pObject.Release(); @@ -628,7 +707,7 @@ void ShaderResourceLayoutVk::InitializeStaticResources(const ShaderResourceLayou auto SrcOffset = SrcRes.CacheOffset + ArrInd; IDeviceObject* pObject = SrcResourceCache.GetDescriptorSet(SrcRes.DescriptorSet).GetResource(SrcOffset).pObject; if (!pObject) - LOG_ERROR_MESSAGE("No resource assigned to static shader variable \"", SrcRes.SpirvAttribs.GetPrintName(ArrInd), "\" in shader \"", GetShaderName(), "\"."); + LOG_ERROR_MESSAGE("No resource assigned to static shader variable '", SrcRes.SpirvAttribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'."); auto DstOffset = DstRes.CacheOffset + ArrInd; IDeviceObject* pCachedResource = DstResourceCache.GetDescriptorSet(DstRes.DescriptorSet).GetResource(DstOffset).pObject; @@ -659,7 +738,7 @@ void ShaderResourceLayoutVk::dvpVerifyBindings(const ShaderResourceCacheVk& Reso if(CachedRes.pObject == nullptr && !(Res.SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler && Res.SpirvAttribs.StaticSamplerInd >= 0)) { - LOG_ERROR_MESSAGE("No resource is bound to ", GetShaderVariableTypeLiteralName(Res.SpirvAttribs.VarType), " variable \"", Res.SpirvAttribs.GetPrintName(ArrInd), "\" in shader \"", GetShaderName(), "\""); + LOG_ERROR_MESSAGE("No resource is bound to ", GetShaderVariableTypeLiteralName(Res.SpirvAttribs.VarType), " variable '", Res.SpirvAttribs.GetPrintName(ArrInd), "' in shader '", GetShaderName(), "'"); } #ifdef _DEBUG auto vkDescSet = CachedDescrSet.GetVkDescriptorSet(); diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 10ca267f..e27445f9 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -28,22 +28,27 @@ #include "RenderDeviceVkImpl.h" #include "DataBlobImpl.h" #include "GLSLSourceBuilder.h" -#include "GLSL2SPIRV.h" - -using namespace Diligent; +#include "SPIRVUtils.h" namespace Diligent { - ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pRenderDeviceVk, const ShaderCreationAttribs& CreationAttribs) : - TShaderBase(pRefCounters, pRenderDeviceVk, CreationAttribs.Desc), - m_StaticResLayout(*this, pRenderDeviceVk->GetLogicalDevice()), - m_StaticResCache(ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources), - m_StaticVarsMgr(*this) + TShaderBase (pRefCounters, pRenderDeviceVk, CreationAttribs.Desc), + m_StaticResLayout (*this, pRenderDeviceVk->GetLogicalDevice()), + m_StaticResCache (ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources), + m_StaticVarsMgr (*this) { - auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::glslang, "#define TARGET_API_VULKAN 1\n"); - m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), CreationAttribs.ppCompilerOutput); + if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL) + { + m_SPIRV = HLSLtoSPIRV(CreationAttribs, CreationAttribs.ppCompilerOutput); + } + else + { + auto GLSLSource = BuildGLSLSourceString(CreationAttribs, TargetGLSLCompiler::glslang, "#define TARGET_API_VULKAN 1\n"); + m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), static_cast<int>(GLSLSource.length()), CreationAttribs.ppCompilerOutput); + } + if (m_SPIRV.empty()) { LOG_ERROR_AND_THROW("Failed to compile shader"); @@ -51,16 +56,16 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* // We cannot create shader module here because resource bindings are assigned when // pipeline state is created - + // Load shader resources - auto &Allocator = GetRawAllocator(); - auto *pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources)); - auto *pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc); + auto& Allocator = GetRawAllocator(); + auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources)); + auto* pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr); m_pShaderResources.reset(pResources, STDDeleterRawMem<SPIRVShaderResources>(Allocator)); m_StaticResLayout.InitializeStaticResourceLayout(m_pShaderResources, GetRawAllocator(), m_StaticResCache); // m_StaticResLayout only contains static resources, so reference all of them - m_StaticVarsMgr.Initialize(m_StaticResLayout, GetRawAllocator(), nullptr, 0, m_StaticResCache); + m_StaticVarsMgr.Initialize(m_StaticResLayout, GetRawAllocator(), nullptr, 0, m_StaticResCache); } ShaderVkImpl::~ShaderVkImpl() diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp index f084577f..b7f992f4 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanInstance.cpp @@ -26,7 +26,7 @@ #include "VulkanErrors.h" #include "VulkanUtilities/VulkanInstance.h" #include "VulkanUtilities/VulkanDebug.h" -#include "GLSL2SPIRV.h" +#include "SPIRVUtils.h" namespace VulkanUtilities { |
