11/*
2- * Copyright 2019-2025 Diligent Graphics LLC
2+ * Copyright 2019-2026 Diligent Graphics LLC
33 * Copyright 2015-2019 Egor Yusov
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -471,12 +471,9 @@ ShaderCodeBufferDescX LoadUBReflection(const diligent_spirv_cross::Compiler& Com
471471
472472SPIRVShaderResources::SPIRVShaderResources (IMemoryAllocator& Allocator,
473473 std::vector<uint32_t > spirv_binary,
474- const ShaderDesc& shaderDesc,
475- const char * CombinedSamplerSuffix,
476- bool LoadShaderStageInputs,
477- bool LoadUniformBufferReflection,
474+ const CreateInfo& CI,
478475 std::string& EntryPoint) noexcept (false ) :
479- m_ShaderType{shaderDesc .ShaderType }
476+ m_ShaderType{CI .ShaderType }
480477{
481478 // https://github.com/KhronosGroup/SPIRV-Cross/wiki/Reflection-API-user-guide
482479 diligent_spirv_cross::Parser parser{std::move (spirv_binary)};
@@ -486,15 +483,15 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
486483 m_IsHLSLSource = ParsedIRSource.hlsl ;
487484 diligent_spirv_cross::Compiler Compiler{std::move (parser.get_parsed_ir ())};
488485
489- spv::ExecutionModel ExecutionModel = ShaderTypeToSpvExecutionModel (shaderDesc. ShaderType );
486+ spv::ExecutionModel ExecutionModel = ShaderTypeToSpvExecutionModel (m_ShaderType );
490487 auto EntryPoints = Compiler.get_entry_points_and_stages ();
491488 for (const diligent_spirv_cross::EntryPoint& CurrEntryPoint : EntryPoints)
492489 {
493490 if (CurrEntryPoint.execution_model == ExecutionModel)
494491 {
495492 if (!EntryPoint.empty ())
496493 {
497- LOG_WARNING_MESSAGE (" More than one entry point of type " , GetShaderTypeLiteralName (shaderDesc. ShaderType ), " found in SPIRV binary for shader '" , shaderDesc .Name , " '. The first one ('" , EntryPoint, " ') will be used." );
494+ LOG_WARNING_MESSAGE (" More than one entry point of type " , GetShaderTypeLiteralName (m_ShaderType ), " found in SPIRV binary for shader '" , CI .Name , " '. The first one ('" , EntryPoint, " ') will be used." );
498495 }
499496 else
500497 {
@@ -504,7 +501,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
504501 }
505502 if (EntryPoint.empty ())
506503 {
507- LOG_ERROR_AND_THROW (" Unable to find entry point of type " , GetShaderTypeLiteralName (shaderDesc. ShaderType ), " in SPIRV binary for shader '" , shaderDesc .Name , " '" );
504+ LOG_ERROR_AND_THROW (" Unable to find entry point of type " , GetShaderTypeLiteralName (m_ShaderType ), " in SPIRV binary for shader '" , CI .Name , " '" );
508505 }
509506 Compiler.set_entry_point (EntryPoint, ExecutionModel);
510507
@@ -521,7 +518,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
521518 // Process push constant buffers - Vulkan spec allows only one push_constant buffer per pipeline
522519 if (resources.push_constant_buffers .size () > 1 )
523520 {
524- LOG_ERROR_AND_THROW (" Shader '" , shaderDesc .Name , " ' contains " , resources.push_constant_buffers .size (),
521+ LOG_ERROR_AND_THROW (" Shader '" , CI .Name , " ' contains " , resources.push_constant_buffers .size (),
525522 " push constant buffers, but Vulkan spec allows only one push_constant buffer per pipeline." );
526523 }
527524 // For push constants, use GetPushConstantName which also tries to get the name from the base type
@@ -543,16 +540,17 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
543540 ResourceNamesPoolSize += res.name .length () + 1 ;
544541 }
545542
546- if (CombinedSamplerSuffix != nullptr )
543+ if (CI. CombinedSamplerSuffix != nullptr )
547544 {
548- ResourceNamesPoolSize += strlen (CombinedSamplerSuffix) + 1 ;
545+ ResourceNamesPoolSize += strlen (CI. CombinedSamplerSuffix ) + 1 ;
549546 }
550547
551- VERIFY_EXPR (shaderDesc .Name != nullptr );
552- ResourceNamesPoolSize += strlen (shaderDesc .Name ) + 1 ;
548+ VERIFY_EXPR (CI .Name != nullptr );
549+ ResourceNamesPoolSize += strlen (CI .Name ) + 1 ;
553550
554551 Uint32 NumShaderStageInputs = 0 ;
555552
553+ bool LoadShaderStageInputs = CI.LoadShaderStageInputs ;
556554 if (!m_IsHLSLSource || resources.stage_inputs .empty ())
557555 LoadShaderStageInputs = false ;
558556 if (LoadShaderStageInputs)
@@ -587,7 +585,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
587585 LoadShaderStageInputs = false ;
588586 if (m_IsHLSLSource)
589587 {
590- LOG_WARNING_MESSAGE (" SPIRV byte code of shader '" , shaderDesc .Name ,
588+ LOG_WARNING_MESSAGE (" SPIRV byte code of shader '" , CI .Name ,
591589 " ' does not use SPV_GOOGLE_hlsl_functionality1 extension. "
592590 " As a result, it is not possible to get semantics of shader inputs and map them to proper locations. "
593591 " The shader will still work correctly if all attributes are declared in ascending order without any gaps. "
@@ -632,7 +630,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
632630 static_cast <Uint32>(Size) //
633631 };
634632
635- if (LoadUniformBufferReflection)
633+ if (CI. LoadUniformBufferReflection )
636634 {
637635 UBReflections.emplace_back (LoadUBReflection (Compiler, UB, m_IsHLSLSource));
638636 }
@@ -813,12 +811,12 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
813811
814812 static_assert (Uint32{SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes} == 13 , " Please initialize SPIRVShaderResourceAttribs for the new resource type here" );
815813
816- if (CombinedSamplerSuffix != nullptr )
814+ if (CI. CombinedSamplerSuffix != nullptr )
817815 {
818- m_CombinedSamplerSuffix = ResourceNamesPool.CopyString (CombinedSamplerSuffix);
816+ m_CombinedSamplerSuffix = ResourceNamesPool.CopyString (CI. CombinedSamplerSuffix );
819817 }
820818
821- m_ShaderName = ResourceNamesPool.CopyString (shaderDesc .Name );
819+ m_ShaderName = ResourceNamesPool.CopyString (CI .Name );
822820
823821 if (LoadShaderStageInputs)
824822 {
@@ -840,15 +838,15 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
840838
841839 VERIFY (ResourceNamesPool.GetRemainingSize () == 0 , " Names pool must be empty" );
842840
843- if (shaderDesc. ShaderType == SHADER_TYPE_COMPUTE)
841+ if (m_ShaderType == SHADER_TYPE_COMPUTE)
844842 {
845843 for (uint32_t i = 0 ; i < m_ComputeGroupSize.size (); ++i)
846844 m_ComputeGroupSize[i] = Compiler.get_execution_mode_argument (spv::ExecutionModeLocalSize, i);
847845 }
848846
849847 if (!UBReflections.empty ())
850848 {
851- VERIFY_EXPR (LoadUniformBufferReflection);
849+ VERIFY_EXPR (CI. LoadUniformBufferReflection );
852850 VERIFY_EXPR (UBReflections.size () == GetNumUBs ());
853851 m_UBReflectionBuffer = ShaderCodeBufferDescX::PackArray (UBReflections.cbegin (), UBReflections.cend (), GetRawAllocator ());
854852 }
0 commit comments