Skip to content

Commit 8a86e2a

Browse files
committed
Fix #717
1 parent 72eed01 commit 8a86e2a

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Graphics/ShaderTools/src/SPIRVShaderResources.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ const std::string& GetUBName(diligent_spirv_cross::Compiler& Compi
262262
return ((IRSource.hlsl || IRSource.lang == spv::SourceLanguageSlang) && !instance_name.empty()) ? instance_name : UB.name;
263263
}
264264

265+
const std::string& GetSSBName(diligent_spirv_cross::Compiler& Compiler,
266+
const diligent_spirv_cross::Resource& SSB,
267+
const diligent_spirv_cross::ParsedIR::Source& IRSource)
268+
{
269+
/*
270+
layout(std430, binding = 3) readonly buffer StructuredBuffer_world_material_t_std430_t_0 // <-- type name
271+
{
272+
world_material_t_std430_0 _data[];
273+
} WorldMaterialSSBO; // <-- instance name
274+
*/
275+
276+
const std::string& instance_name = Compiler.get_name(SSB.id);
277+
return ((IRSource.hlsl || IRSource.lang == spv::SourceLanguageSlang) && !instance_name.empty()) ? instance_name : SSB.name;
278+
}
279+
265280
static SHADER_CODE_BASIC_TYPE SpirvBaseTypeToShaderCodeBasicType(diligent_spirv_cross::SPIRType::BaseType SpvBaseType)
266281
{
267282
switch (SpvBaseType)
@@ -421,10 +436,11 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
421436
size_t ResourceNamesPoolSize = 0;
422437
for (const diligent_spirv_cross::Resource& ub : resources.uniform_buffers)
423438
ResourceNamesPoolSize += GetUBName(Compiler, ub, ParsedIRSource).length() + 1;
439+
for (const diligent_spirv_cross::Resource& sb : resources.storage_buffers)
440+
ResourceNamesPoolSize += GetSSBName(Compiler, sb, ParsedIRSource).length() + 1;
424441
static_assert(Uint32{SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes} == 12, "Please account for the new resource type below");
425442
for (auto* pResType :
426443
{
427-
&resources.storage_buffers,
428444
&resources.storage_images,
429445
&resources.sampled_images,
430446
&resources.atomic_counters,
@@ -538,6 +554,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
538554
Uint32 CurrSB = 0;
539555
for (const diligent_spirv_cross::Resource& SB : resources.storage_buffers)
540556
{
557+
const std::string& name = GetSSBName(Compiler, SB, ParsedIRSource);
541558
diligent_spirv_cross::Bitset BufferFlags = Compiler.get_buffer_block_flags(SB.id);
542559
bool IsReadOnly = BufferFlags.get(spv::DecorationNonWritable);
543560

@@ -553,7 +570,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
553570
{
554571
Compiler,
555572
SB,
556-
ResourceNamesPool.CopyString(SB.name),
573+
ResourceNamesPool.CopyString(name),
557574
ResType,
558575
static_cast<Uint32>(Size),
559576
static_cast<Uint32>(Stride) //

0 commit comments

Comments
 (0)