diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-01 17:53:55 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-01 17:53:55 +0000 |
| commit | 0865ee3b7b5d4558e2cea100e615b8ce39b3aa91 (patch) | |
| tree | f65a689829afcdeda1e7c863dbc3e84c9b373720 /Graphics/GraphicsEngineVulkan | |
| parent | Renamed PipelineLayoutDesc to PipelineResourceLayoutDesc (diff) | |
| download | DiligentCore-0865ee3b7b5d4558e2cea100e615b8ce39b3aa91.tar.gz DiligentCore-0865ee3b7b5d4558e2cea100e615b8ce39b3aa91.zip | |
Fixed a number of issue with resource binding
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
6 files changed, 61 insertions, 33 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h index 5fd6f520..b9f0ea10 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h @@ -208,7 +208,10 @@ public: bool IsImmutableSamplerAssigned() const { - VERIFY_EXPR(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage); + VERIFY(ImmutableSamplerAssigned == 0 || + SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage || + SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler, + "Immutable sampler can only be assigned to a sampled image or separate sampler"); return ImmutableSamplerAssigned != 0; } diff --git a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp index 305f04ef..4ae8243e 100644 --- a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp +++ b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp @@ -104,13 +104,13 @@ namespace Diligent std::array<RefCntAutoPtr<IPipelineState>, 4> GenerateMipsVkHelper::CreatePSOs(TEXTURE_FORMAT Fmt) { - ShaderCreateInfo CSCreateAttribs; + ShaderCreateInfo CSCreateInfo; std::array<RefCntAutoPtr<IPipelineState>, 4> PSOs; - CSCreateAttribs.Source = g_GenerateMipsCSSource; - CSCreateAttribs.EntryPoint = "main"; - CSCreateAttribs.SourceLanguage = SHADER_SOURCE_LANGUAGE_GLSL; - CSCreateAttribs.Desc.ShaderType = SHADER_TYPE_COMPUTE; + CSCreateInfo.Source = g_GenerateMipsCSSource; + CSCreateInfo.EntryPoint = "main"; + CSCreateInfo.SourceLanguage = SHADER_SOURCE_LANGUAGE_GLSL; + CSCreateInfo.Desc.ShaderType = SHADER_TYPE_COMPUTE; const auto& FmtAttribs = GetTextureFormatAttribs(Fmt); bool IsGamma = FmtAttribs.ComponentType == COMPONENT_TYPE_UNORM_SRGB; @@ -125,7 +125,7 @@ namespace Diligent Macros.AddShaderMacro("IMG_FORMAT", GlFmt.data()); Macros.Finalize(); - CSCreateAttribs.Macros = Macros; + CSCreateInfo.Macros = Macros; std::stringstream name_ss; name_ss << "Generate mips " << GlFmt.data(); @@ -138,10 +138,10 @@ namespace Diligent default: UNEXPECTED("Unexpected value"); } auto name = name_ss.str(); - CSCreateAttribs.Desc.Name = name.c_str(); + CSCreateInfo.Desc.Name = name.c_str(); RefCntAutoPtr<IShader> pCS; - m_DeviceVkImpl.CreateShader(CSCreateAttribs, &pCS); + m_DeviceVkImpl.CreateShader(CSCreateInfo, &pCS); PipelineStateDesc PSODesc; PSODesc.IsComputePipeline = true; PSODesc.Name = name.c_str(); diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp index 7ce29a6f..ef7fd8ec 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp @@ -373,6 +373,9 @@ void PipelineLayout::AllocateResourceSlot(const SPIRVShaderResourceAttribs& ResA Uint32& OffsetInCache, std::vector<uint32_t>& SPIRV) { + VERIFY( (ResAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage || + ResAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler) || vkStaticSampler == VK_NULL_HANDLE, + "Immutable sampler should only be specified for combined image samplers or separate samplers"); m_LayoutMgr.AllocateResourceSlot(ResAttribs, VariableType,vkStaticSampler, ShaderType, DescriptorSet, Binding, OffsetInCache); SPIRV[ResAttribs.BindingDecorationOffset] = Binding; SPIRV[ResAttribs.DescriptorSetDecorationOffset] = DescriptorSet; diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 548441a7..fe05a3bd 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -663,8 +663,9 @@ void PipelineStateVkImpl::InitializeStaticSRBResources(ShaderResourceCacheVk& Re for (Uint32 s = 0; s < m_NumShaders; ++s) { const auto& StaticResLayout = GetStaticShaderResLayout(s); + const auto& StaticResCache = GetStaticResCache(s); #ifdef DEVELOPMENT - if (!StaticResLayout.dvpVerifyBindings(ResourceCache)) + if (!StaticResLayout.dvpVerifyBindings(StaticResCache)) { const auto* pShaderVk = GetShader<const ShaderVkImpl>(s); LOG_ERROR_MESSAGE("Static resources in SRB of PSO '", GetDesc().Name, "' will not be successfully initialized " @@ -673,7 +674,6 @@ void PipelineStateVkImpl::InitializeStaticSRBResources(ShaderResourceCacheVk& Re "directly or indirectly by passing InitStaticResources=true to CreateShaderResourceBinding() method."); } #endif - const auto& StaticResCache = GetStaticResCache(s); const auto& ShaderResourceLayouts = GetShaderResLayout(s); ShaderResourceLayouts.InitializeStaticResources(StaticResLayout, StaticResCache, ResourceCache); } diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp index 98d4e424..85f835f8 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp @@ -324,6 +324,8 @@ VkDescriptorImageInfo ShaderResourceCacheVk::Resource::GetImageDescriptorWriteIn VkDescriptorImageInfo DescrImgInfo; DescrImgInfo.sampler = VK_NULL_HANDLE; + VERIFY(Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage || !IsImmutableSampler, + "Immutable sampler can't be assigned to separarate image or storage image"); if (Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage && !IsImmutableSampler) { // Immutable samplers are permanently bound into the set layout; later binding a sampler @@ -340,7 +342,7 @@ VkDescriptorImageInfo ShaderResourceCacheVk::Resource::GetImageDescriptorWriteIn #ifdef DEVELOPMENT else { - LOG_ERROR_MESSAGE("No sampler assigned to texture view '", pTexViewVk->GetDesc().Name, "'"); + LOG_ERROR_MESSAGE("No sampler is assigned to texture view '", pTexViewVk->GetDesc().Name, "'"); } #endif } diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index abd606b4..5b3578ba 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -44,7 +44,7 @@ static Int32 FindImmutableSampler(SHADER_TYPE ShaderType, const SPIRVShaderResourceAttribs& Attribs, const char* SamplerSuffix) { - if (Attribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage) + if (Attribs.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage) { SamplerSuffix = nullptr; } @@ -55,6 +55,7 @@ static Int32 FindImmutableSampler(SHADER_TYPE ShaderType, } else { + UNEXPECTED("Immutable sampler can only be assigned to a sampled image or separate sampler"); return -1; } @@ -182,6 +183,14 @@ void ShaderResourceLayoutVk::InitializeStaticResourceLayout(std::shared_ptr<cons if (!IsAllowedType(VarType, AllowedTypeBits)) return; + Int32 SrcImmutableSamplerInd = -1; + if (Attribs.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage || + Attribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler) + { + // Only search for the immutable sampler for combined image samplers and separate samplers + SrcImmutableSamplerInd = FindImmutableSampler(ShaderType, ResourceLayoutDesc, Attribs, CombinedSamplerSuffix); + } + //TODO: how to handle static samplers? Uint32 Binding = Attribs.Type; @@ -196,7 +205,7 @@ void ShaderResourceLayoutVk::InitializeStaticResourceLayout(std::shared_ptr<cons // assigned to this separate image must have been already created. SamplerInd = FindAssignedSampler(Attribs, CurrResInd[VarType], VarType); } - ::new (&GetResource(VarType, CurrResInd[VarType]++)) VkResource(*this, Attribs, VarType, Binding, DescriptorSet, CacheOffset, SamplerInd); + ::new (&GetResource(VarType, CurrResInd[VarType]++)) VkResource(*this, Attribs, VarType, Binding, DescriptorSet, CacheOffset, SamplerInd, SrcImmutableSamplerInd >= 0); } ); @@ -227,7 +236,8 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* const auto& VarDesc = ResourceLayoutDesc.Variables[v]; if (VarDesc.ShaderStages == SHADER_TYPE_UNKNOWN) { - LOG_WARNING_MESSAGE("No allowed shader stages specified for variable '", VarDesc.Name, "' labeled as ", GetShaderVariableTypeLiteralName(VarDesc.Type), "."); + LOG_WARNING_MESSAGE("No allowed shader stages are specified for variable '", VarDesc.Name, "' labeled as ", GetShaderVariableTypeLiteralName(VarDesc.Type), "."); + continue; } for(Uint32 s=0; s < NumShaders && !VariableFound; ++s) @@ -253,7 +263,8 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* const auto& StSamDesc = ResourceLayoutDesc.StaticSamplers[sam]; if (StSamDesc.ShaderStages == SHADER_TYPE_UNKNOWN) { - LOG_WARNING_MESSAGE("No allowed shader stages specified for static sampler '", StSamDesc.SamplerOrTextureName, "."); + LOG_WARNING_MESSAGE("No allowed shader stages are specified for static sampler '", StSamDesc.SamplerOrTextureName, "."); + continue; } bool SamplerFound = false; @@ -333,17 +344,22 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* SamplerInd = ResLayout.FindAssignedSampler(Attribs, CurrResInd[ShaderInd][VarType], VarType); } - Int32 SrcImmutableSamplerInd = FindImmutableSampler(ShaderType, ResourceLayoutDesc, Attribs, Resources.GetCombinedSamplerSuffix()); VkSampler vkImmutableSampler = VK_NULL_HANDLE; - if (SrcImmutableSamplerInd >= 0) + if (Attribs.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage || + Attribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler) { - auto& ImmutableSampler = ResLayout.GetImmutableSampler(CurrImmutableSamplerInd[ShaderInd]++); - VERIFY(!ImmutableSampler, "Immutable sampler has already been initialized!"); - const auto& ImmutableSamplerDesc = ResourceLayoutDesc.StaticSamplers[SrcImmutableSamplerInd].Desc; - pRenderDevice->CreateSampler(ImmutableSamplerDesc, &ImmutableSampler); - vkImmutableSampler = ImmutableSampler.RawPtr<SamplerVkImpl>()->GetVkSampler(); + // Only search for the immutable sampler for combined image samplers and separate samplers + Int32 SrcImmutableSamplerInd = FindImmutableSampler(ShaderType, ResourceLayoutDesc, Attribs, Resources.GetCombinedSamplerSuffix()); + if (SrcImmutableSamplerInd >= 0) + { + auto& ImmutableSampler = ResLayout.GetImmutableSampler(CurrImmutableSamplerInd[ShaderInd]++); + VERIFY(!ImmutableSampler, "Immutable sampler has already been initialized!"); + const auto& ImmutableSamplerDesc = ResourceLayoutDesc.StaticSamplers[SrcImmutableSamplerInd].Desc; + pRenderDevice->CreateSampler(ImmutableSamplerDesc, &ImmutableSampler); + vkImmutableSampler = ImmutableSampler.RawPtr<SamplerVkImpl>()->GetVkSampler(); + } } - + auto& ShaderSPIRV = SPIRVs[ShaderInd]; PipelineLayout.AllocateResourceSlot(Attribs, VarType, vkImmutableSampler, Resources.GetShaderType(), DescriptorSet, Binding, CacheOffset, ShaderSPIRV); VERIFY(DescriptorSet <= std::numeric_limits<decltype(VkResource::DescriptorSet)>::max(), "Descriptor set (", DescriptorSet, ") excceeds max representable value"); @@ -693,7 +709,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 '", pTexViewVk->GetDesc().Name, "'"); + LOG_RESOURCE_BINDING_ERROR("resource", pTexView, SpirvAttribs.GetPrintName(ArrayInd), ParentResLayout.GetShaderName(), "No sampler is assigned to texture view '", pTexViewVk->GetDesc().Name, "'"); } } #endif @@ -712,15 +728,19 @@ void ShaderResourceLayoutVk::VkResource::CacheImage(IDeviceObject* VERIFY_EXPR(!IsImmutableSamplerAssigned()); auto* pSampler = pTexViewVk->GetSampler(); const auto& SamplerAttribs = ParentResLayout.GetResource(GetVariableType(), SamplerInd); - if (pSampler != nullptr) + VERIFY_EXPR(SamplerAttribs.SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler); + if (!SamplerAttribs.IsImmutableSamplerAssigned()) { - 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, '\''); \ + 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, '\''); \ + } } } } |
