Skip to content

Commit cf90599

Browse files
Fixed memory leaks in the test + code cleanup
1 parent 98033c3 commit cf90599

File tree

12 files changed

+60
-59
lines changed

12 files changed

+60
-59
lines changed

Graphics/ShaderTools/include/SPIRVShaderResources.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,9 +32,19 @@
3232

3333
// SPIRVShaderResources class uses continuous chunk of memory to store all resources, as follows:
3434
//
35-
// m_MemoryBuffer m_TotalResources
36-
// | | |
37-
// | Uniform Buffers | Storage Buffers | Storage Images | Sampled Images | Atomic Counters | Separate Samplers | Separate Images | Input Attachments | Accel Structs | Push Constants | Stage Inputs | Resource Names |
35+
// _ _ _ m_MemoryBuffer
36+
// | Uniform Buffers |
37+
// | Storage Buffers | |
38+
// | Storage Images | V
39+
// | Sampled Images |
40+
// | Atomic Counters |
41+
// | Separate Samplers |
42+
// | Separate Images |
43+
// | Input Attachments |
44+
// | Accel Structs |
45+
// | Push Constants | _ _ _ m_TotalResources
46+
// | Stage Inputs |
47+
// | Resource Names |
3848

3949
#include <memory>
4050
#include <vector>
@@ -79,7 +89,7 @@ struct SPIRVShaderResourceAttribs
7989
SeparateSampler,
8090
InputAttachment,
8191
AccelerationStructure,
82-
PushConstant, // Vulkan push constant buffer - special inline constant that uses vkCmdPushConstants
92+
PushConstant,
8393
NumResourceTypes
8494
};
8595

Graphics/ShaderTools/src/SPIRVShaderResources.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const char* _Name,
137137
Uint32 _BufferStaticSize) noexcept :
138138
// clang-format off
139139
Name {_Name},
140-
// For push constants, ArraySize always be 1
140+
// For push constants, ArraySize is always 1
141141
// This is consistent with how inline constants work in the pipeline resource signature
142142
ArraySize {1},
143143
Type {_Type},
@@ -217,8 +217,7 @@ PIPELINE_RESOURCE_FLAGS SPIRVShaderResourceAttribs::GetPipelineResourceFlags(Res
217217
return PIPELINE_RESOURCE_FLAG_COMBINED_SAMPLER;
218218

219219
case SPIRVShaderResourceAttribs::ResourceType::PushConstant:
220-
// Push constants are special inline constants that use vkCmdPushConstants
221-
// Mark them with both INLINE_CONSTANTS and VULKAN_PUSH_CONSTANT flags
220+
// Push constants map to constant buffer with the inline constants flag
222221
return PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS;
223222

224223
default:
@@ -1078,8 +1077,8 @@ std::string SPIRVShaderResources::DumpResources() const
10781077
},
10791078
[&](const SPIRVShaderResourceAttribs& SepImg, Uint32) //
10801079
{
1081-
VERIFY(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage ||
1082-
SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer,
1080+
VERIFY((SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage ||
1081+
SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer),
10831082
"Unexpected resource type");
10841083
if (SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer)
10851084
{

Tests/DiligentCoreTest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if(NOT WEBGPU_SUPPORTED)
2020
)
2121
endif()
2222

23-
if(NOT VULKAN_SUPPORTED OR NOT TARGET glslang)
23+
if(NOT ${DILIGENT_USE_SPIRV_TOOLCHAIN} OR ${DILIGENT_NO_GLSLANG})
2424
list(REMOVE_ITEM SOURCE
2525
${CMAKE_CURRENT_SOURCE_DIR}/src/ShaderTools/SPIRVShaderResourcesTest.cpp
2626
)

Tests/DiligentCoreTest/assets/shaders/SPIRV/InputAttachments.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ float4 main() : SV_Target
1111

1212
// Process the input color
1313
return color * 2.0;
14-
}
14+
}

Tests/DiligentCoreTest/assets/shaders/SPIRV/MixedResources.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ float4 main() : SV_Target
6363
color.rgb *= sin(g_PushConstants.Time) * 0.5 + 0.5;
6464

6565
return color;
66-
}
66+
}

Tests/DiligentCoreTest/assets/shaders/SPIRV/PushConstants.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ float4 main() : SV_Target
2323
result.xy += g_PushConstants.g_Offset;
2424

2525
return result;
26-
}
26+
}

Tests/DiligentCoreTest/assets/shaders/SPIRV/StorageBuffers.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ float4 main() : SV_Target
4040
g_RWAtomicBuffer.Store(0, atomicValue + 1);
4141

4242
return result;
43-
}
43+
}

Tests/DiligentCoreTest/assets/shaders/SPIRV/StorageImages.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ float4 main() : SV_Target
1717
color += g_RWImage3D[uint3(0, 0, 0)];
1818

1919
return color;
20-
}
20+
}

Tests/DiligentCoreTest/assets/shaders/SPIRV/TexelBuffers.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ float4 main() : SV_Target
1212

1313
// Read back from storage texel buffer
1414
return g_StorageTexelBuffer[0];
15-
}
15+
}

Tests/DiligentCoreTest/assets/shaders/SPIRV/Textures.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ float4 main() : SV_Target
2727
float4 color6 = g_Texture.Sample(g_Texture_sampler, float2(0.5, 0.5));
2828

2929
return color1 + color2 + color3 + color4 + color5 + color6;
30-
}
30+
}

0 commit comments

Comments
 (0)