git.s-ol.nu ~forks/DiligentCore / 17062f3
Fixed few issues with run-time sized arrays in D3D12; enabled test. assiduous 6 months ago
9 changed file(s) with 160 addition(s) and 108 deletion(s). Raw diff Collapse all Expand all
239239 };
240240 typedef struct ShaderVersion ShaderVersion;
241241
242
243 // clang-format off
244
245 /// Shader compilation flags
246 DILIGENT_TYPED_ENUM(SHADER_COMPILE_FLAGS, Uint32)
247 {
248 /// No flags.
249 SHADER_COMPILE_FLAG_NONE = 0x0,
250
251 /// Enable unbounded resource arrays (e.g. Texture2D g_Texture[]).
252 SHADER_COMPILE_FLAG_ENABLE_UNBOUNDED_ARRAYS = 0x01,
253
254 SHADER_COMPILE_FLAG_LAST = SHADER_COMPILE_FLAG_ENABLE_UNBOUNDED_ARRAYS
255 };
256 DEFINE_FLAG_ENUM_OPERATORS(SHADER_COMPILE_FLAGS);
257
258 // clang-format on
259
260
242261 /// Shader creation attributes
243262 struct ShaderCreateInfo
244263 {
341360 /// supported by the device.
342361 ShaderVersion GLESSLVersion DEFAULT_INITIALIZER({});
343362
363 /// Shader compile flags (see Diligent::SHADER_COMPILE_FLAGS).
364 SHADER_COMPILE_FLAGS CompileFlags DEFAULT_INITIALIZER(SHADER_COMPILE_FLAG_NONE);
344365
345366 /// Memory address where pointer to the compiler messages data blob will be written
346367
745745
746746 if (Attribs.BindCount == 0)
747747 {
748 if ((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY) != 0)
748 if ((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY) == 0)
749749 {
750750 LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' contains resource with name '", Attribs.Name,
751751 "' that is runtime-sized array, but in resource signature '", pSignature->GetDesc().Name,
2828 #include <vector>
2929 #include <memory>
3030
31 #ifndef NOMINMAX
32 # define NOMINMAX
33 #endif
3134 #include <D3Dcompiler.h>
3235
3336 #include <atlcomcli.h>
3942 #include "ShaderD3DBase.hpp"
4043 #include "DXCompiler.hpp"
4144 #include "HLSLUtils.hpp"
45 #include "BasicMath.hpp"
4246
4347 namespace Diligent
4448 {
104108 // dwShaderFlags |= D3D10_SHADER_OPTIMIZATION_LEVEL3;
105109 #endif
106110
111 for (auto CompileFlags = ShaderCI.CompileFlags; CompileFlags != SHADER_COMPILE_FLAG_NONE;)
112 {
113 auto Flag = ExtractLSB(CompileFlags);
114 static_assert(SHADER_COMPILE_FLAG_LAST == 1, "Please updated the switch below to handle the new shader flag");
115 switch (Flag)
116 {
117 case SHADER_COMPILE_FLAG_ENABLE_UNBOUNDED_ARRAYS:
118 dwShaderFlags |= D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES;
119 break;
120
121 default:
122 UNEXPECTED("Unexpected shader compile flag");
123 }
124 }
125
107126 D3DIncludeImpl IncludeImpl{ShaderCI.pShaderSourceStreamFactory};
108127 return D3DCompile(Source, SourceLength, NULL, nullptr, &IncludeImpl, ShaderCI.EntryPoint, profile, dwShaderFlags, 0, ppBlobOut, ppCompilerOutput);
109128 }
0 #version 460 core
1 #extension GL_ARB_shading_language_420pack : enable
2 #extension GL_EXT_nonuniform_qualifier : require
3
4 uniform texture2D g_Textures[];
5 uniform sampler g_Sampler;
6
7 vec4 CheckValue(vec4 Val, vec4 Expected)
8 {
9 return vec4(Val.x == Expected.x ? 1.0 : 0.0,
10 Val.y == Expected.y ? 1.0 : 0.0,
11 Val.z == Expected.z ? 1.0 : 0.0,
12 Val.w == Expected.w ? 1.0 : 0.0);
13 }
14
15
16 vec4 VerifyResources(uint index, vec2 coord)
17 {
18 vec4 RefValues[NUM_TEXTURES];
19 RefValues[0] = Tex2D_Ref0;
20 RefValues[1] = Tex2D_Ref1;
21 RefValues[2] = Tex2D_Ref2;
22 RefValues[3] = Tex2D_Ref3;
23 RefValues[4] = Tex2D_Ref4;
24 RefValues[5] = Tex2D_Ref5;
25 RefValues[6] = Tex2D_Ref6;
26 RefValues[7] = Tex2D_Ref7;
27
28 return CheckValue(textureLod(sampler2D(g_Textures[nonuniformEXT(index)], g_Sampler), coord, 0.0), RefValues[index]);
29 }
30
31 layout(rgba8) writeonly uniform image2D g_OutImage;
32
33 layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
34 void main()
35 {
36 ivec2 Dim = imageSize(g_OutImage);
37 if (gl_GlobalInvocationID.x >= uint(Dim.x) || gl_GlobalInvocationID.y >= uint(Dim.y))
38 return;
39
40 vec4 Color = vec4(vec2(gl_GlobalInvocationID.xy % 256u) / 256.0, 0.0, 1.0);
41 vec2 uv = vec2(gl_GlobalInvocationID.xy + vec2(0.5,0.5)) / vec2(Dim);
42 Color *= VerifyResources(gl_LocalInvocationIndex % NUM_TEXTURES, uv);
43
44 imageStore(g_OutImage, ivec2(gl_GlobalInvocationID.xy), Color);
45 }
0 Texture2D g_Textures[] : register(t0, space1);
1 SamplerState g_Sampler;
2
3 float4 CheckValue(float4 Val, float4 Expected)
4 {
5 return float4(Val.x == Expected.x ? 1.0 : 0.0,
6 Val.y == Expected.y ? 1.0 : 0.0,
7 Val.z == Expected.z ? 1.0 : 0.0,
8 Val.w == Expected.w ? 1.0 : 0.0);
9 }
10
11
12 float4 VerifyResources(uint index, float2 coord)
13 {
14 float4 RefValues[NUM_TEXTURES];
15 RefValues[0] = Tex2D_Ref0;
16 RefValues[1] = Tex2D_Ref1;
17 RefValues[2] = Tex2D_Ref2;
18 RefValues[3] = Tex2D_Ref3;
19 RefValues[4] = Tex2D_Ref4;
20 RefValues[5] = Tex2D_Ref5;
21 RefValues[6] = Tex2D_Ref6;
22 RefValues[7] = Tex2D_Ref7;
23
24 return CheckValue(g_Textures[NonUniformResourceIndex(index)].SampleLevel(g_Sampler, coord, 0.0), RefValues[index]);
25 }
26
27 RWTexture2D<float4> g_OutImage;
28
29 [numthreads(16, 16, 1)]
30 void main(uint3 GlobalInvocationID : SV_DispatchThreadID,
31 uint LocalInvocationIndex : SV_GroupIndex)
32 {
33 uint2 Dim;
34 g_OutImage.GetDimensions(Dim.x, Dim.y);
35 if (GlobalInvocationID.x >= Dim.x || GlobalInvocationID.y >= Dim.y)
36 return;
37
38 float4 Color = float4(float2(GlobalInvocationID.xy % 256u) / 256.0, 0.0, 1.0);
39 float2 uv = float2(GlobalInvocationID.xy + float2(0.5,0.5)) / float2(Dim);
40 Color *= VerifyResources(LocalInvocationIndex % NUM_TEXTURES, uv);
41
42 g_OutImage[GlobalInvocationID.xy] = Color;
43 }
+0
-46
Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VulkanDescriptorIndexing.glsl less more
0 #version 460 core
1 #extension GL_ARB_shading_language_420pack : enable
2 #extension GL_EXT_nonuniform_qualifier : require
3
4 uniform texture2D g_Textures[];
5 uniform sampler g_Sampler;
6
7 vec4 CheckValue(vec4 Val, vec4 Expected)
8 {
9 return vec4(Val.x == Expected.x ? 1.0 : 0.0,
10 Val.y == Expected.y ? 1.0 : 0.0,
11 Val.z == Expected.z ? 1.0 : 0.0,
12 Val.w == Expected.w ? 1.0 : 0.0);
13 }
14
15
16 vec4 VerifyResources(uint index, vec2 coord)
17 {
18 vec4 RefValues[NUM_TEXTURES];
19 RefValues[0] = Tex2D_Ref0;
20 RefValues[1] = Tex2D_Ref1;
21 RefValues[2] = Tex2D_Ref2;
22 RefValues[3] = Tex2D_Ref3;
23 RefValues[4] = Tex2D_Ref4;
24 RefValues[5] = Tex2D_Ref5;
25 RefValues[6] = Tex2D_Ref6;
26 RefValues[7] = Tex2D_Ref7;
27
28 return CheckValue(textureLod(sampler2D(g_Textures[nonuniformEXT(index)], g_Sampler), coord, 0.0), RefValues[index]);
29 }
30
31 layout(rgba8) writeonly uniform image2D g_OutImage;
32
33 layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
34 void main()
35 {
36 ivec2 Dim = imageSize(g_OutImage);
37 if (gl_GlobalInvocationID.x >= uint(Dim.x) || gl_GlobalInvocationID.y >= uint(Dim.y))
38 return;
39
40 vec4 Color = vec4(vec2(gl_GlobalInvocationID.xy % 256u) / 256.0, 0.0, 1.0);
41 vec2 uv = vec2(gl_GlobalInvocationID.xy + vec2(0.5,0.5)) / vec2(gl_WorkGroupSize.xy * gl_NumWorkGroups.xy);
42 Color *= VerifyResources(gl_LocalInvocationIndex % NUM_TEXTURES, uv);
43
44 imageStore(g_OutImage, ivec2(gl_GlobalInvocationID.xy), Color);
45 }
+0
-44
Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VulkanDescriptorIndexing.hlsl less more
0 Texture2D g_Textures[] : register(t0, space1);
1 SamplerState g_Sampler;
2
3 float4 CheckValue(float4 Val, float4 Expected)
4 {
5 return float4(Val.x == Expected.x ? 1.0 : 0.0,
6 Val.y == Expected.y ? 1.0 : 0.0,
7 Val.z == Expected.z ? 1.0 : 0.0,
8 Val.w == Expected.w ? 1.0 : 0.0);
9 }
10
11
12 float4 VerifyResources(uint index, float2 coord)
13 {
14 float4 RefValues[NUM_TEXTURES];
15 RefValues[0] = Tex2D_Ref0;
16 RefValues[1] = Tex2D_Ref1;
17 RefValues[2] = Tex2D_Ref2;
18 RefValues[3] = Tex2D_Ref3;
19 RefValues[4] = Tex2D_Ref4;
20 RefValues[5] = Tex2D_Ref5;
21 RefValues[6] = Tex2D_Ref6;
22 RefValues[7] = Tex2D_Ref7;
23
24 return CheckValue(g_Textures[index].Sample(g_Sampler, coord, 0.0), RefValues[index]);
25 }
26
27 RWTexture2D<float4> g_OutImage;
28
29 [numthreads(16, 16, 1)]
30 void main(uint3 GlobalInvocationID : SV_DispatchThreadID,
31 uint LocalInvocationIndex : SV_GroupIndex)
32 {
33 uint2 Dim;
34 g_OutImage.GetDimensions(Dim.x, Dim.y);
35 if (GlobalInvocationID.x >= Dim.x || GlobalInvocationID.y >= Dim.y)
36 return;
37
38 float4 Color = float4(float2(GlobalInvocationID.xy % 256u) / 256.0, 0.0, 1.0);
39 float2 uv = float2(GlobalInvocationID.xy + float2(0.5,0.5)) / float(Dim);
40 Color *= VerifyResources(LocalInvocationIndex % NUM_TEXTURES, uv);
41
42 g_OutImage[GlobalInvocationID.xy] = Color;
43 }
21522152
21532153 ShaderCreateInfo ShaderCI;
21542154 ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
2155 ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
21562155 ShaderCI.UseCombinedTextureSamplers = true;
21572156 if (UseArray && pEnv->NeedWARPResourceArrayIndexingBugWorkaround())
21582157 {
21922191 {
21932192 ShaderCI.Source = UseArray ? HLSL::DrawTest_VSFormattedBufferArray.c_str() : HLSL::DrawTest_VSFormattedBuffers.c_str();
21942193 }
2194 ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
21952195 pDevice->CreateShader(ShaderCI, &pVS);
21962196 ASSERT_NE(pVS, nullptr);
21972197 }
21992199 RefCntAutoPtr<IShader> pPS;
22002200 {
22012201 ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
2202 ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
22022203 ShaderCI.Desc.ShaderType = SHADER_TYPE_PIXEL;
22032204 ShaderCI.EntryPoint = "main";
22042205 ShaderCI.Desc.Name = "Draw command test structured buffers - PS";
102102 const ShaderMacro* Macros,
103103 ModifyCIHandlerType ModifyCIHandler)
104104 {
105 auto* pEnv = TestingEnvironment::GetInstance();
106 auto* pDevice = pEnv->GetDevice();
107
105108 ShaderCreateInfo ShaderCI;
106109 ShaderCI.pShaderSourceStreamFactory = pShaderSourceFactory;
107110 ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
111114 ShaderCI.EntryPoint = EntryPoint;
112115 ShaderCI.Desc.ShaderType = ShaderType;
113116 ShaderCI.UseCombinedTextureSamplers = false;
114
115 auto* pDevice = TestingEnvironment::GetInstance()->GetDevice();
117 ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
118
116119 if (pDevice->GetDeviceCaps().IsGLDevice())
117120 ShaderCI.UseCombinedTextureSamplers = true;
118121
13071310 ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_GLSL;
13081311 ShaderCI.UseCombinedTextureSamplers = true;
13091312 ShaderCI.Macros = Macros;
1313 ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
13101314
13111315 RefCntAutoPtr<IShader> pVS;
13121316 {
14641468
14651469 auto ModifyShaderCI = [&](ShaderCreateInfo& ShaderCI) {
14661470 ShaderCI.SourceLanguage = SrcLanguage;
1471 ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
14671472
14681473 if (pEnv->NeedWARPResourceArrayIndexingBugWorkaround())
14691474 {
15421547 TestFormattedOrStructuredBuffer(BUFFER_MODE_STRUCTURED);
15431548 }
15441549
1545 static void TestVulkanDescriptorIndexing(bool IsGLSL, IShaderSourceInputStreamFactory* pShaderSourceFactory)
1550 static void TestRunTimeResourceArray(bool IsGLSL, IShaderSourceInputStreamFactory* pShaderSourceFactory)
15461551 {
15471552 auto* pEnv = TestingEnvironment::GetInstance();
15481553 auto* pDevice = pEnv->GetDevice();
15491554
15501555 const auto& deviceCaps = pDevice->GetDeviceCaps();
1551 if (!deviceCaps.Features.ShaderResourceRuntimeArray || !deviceCaps.IsVulkanDevice())
1552 {
1553 GTEST_SKIP() << "Descriptor indexing is not supported by this device";
1556 if (!deviceCaps.Features.ShaderResourceRuntimeArray)
1557 {
1558 GTEST_SKIP() << "Shader Resource Runtime Arrays are not supported by this device";
1559 }
1560
1561 if (IsGLSL && deviceCaps.IsD3DDevice())
1562 {
1563 GTEST_SKIP() << "Direct3D does not support GLSL";
15541564 }
15551565
15561566 TestingEnvironment::ScopedReset EnvironmentAutoReset;
15741584 {
15751585 const PipelineResourceDesc Resources[] =
15761586 {
1577 {SHADER_TYPE_COMPUTE, "g_Textures", TexArraySize, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE},
1587 {SHADER_TYPE_COMPUTE, "g_Textures", TexArraySize, SHADER_RESOURCE_TYPE_TEXTURE_SRV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY},
15781588 {SHADER_TYPE_COMPUTE, "g_Sampler", 1, SHADER_RESOURCE_TYPE_SAMPLER, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE},
15791589 {SHADER_TYPE_COMPUTE, "g_OutImage", 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} //
15801590 };
16141624 {
16151625 ShaderCreateInfo ShaderCI;
16161626 ShaderCI.pShaderSourceStreamFactory = pShaderSourceFactory;
1617 ShaderCI.UseCombinedTextureSamplers = true;
16181627 ShaderCI.Desc.ShaderType = SHADER_TYPE_COMPUTE;
16191628 ShaderCI.EntryPoint = "main";
1620 ShaderCI.Desc.Name = "DescrIndexingTest - CS";
1629 ShaderCI.Desc.Name = "RunTimeResourceArray - CS";
16211630 ShaderCI.Macros = Macros;
16221631 ShaderCI.SourceLanguage = IsGLSL ? SHADER_SOURCE_LANGUAGE_GLSL_VERBATIM : SHADER_SOURCE_LANGUAGE_HLSL;
1623 ShaderCI.FilePath = IsGLSL ? "VulkanDescriptorIndexing.glsl" : "VulkanDescriptorIndexing.hlsl";
1632 ShaderCI.FilePath = IsGLSL ? "RunTimeResourceArray.glsl" : "RunTimeResourceArray.hlsl";
1633 ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_ENABLE_UNBOUNDED_ARRAYS;
1634 ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
16241635
16251636 pDevice->CreateShader(ShaderCI, &pCS);
16261637 ASSERT_NE(pCS, nullptr);
16591670 pSwapChain->Present();
16601671 }
16611672
1662 TEST_F(PipelineResourceSignatureTest, VulkanDescriptorIndexing_GLSL)
1663 {
1664 TestVulkanDescriptorIndexing(true, pShaderSourceFactory);
1673 TEST_F(PipelineResourceSignatureTest, RunTimeResourceArray_GLSL)
1674 {
1675 TestRunTimeResourceArray(true, pShaderSourceFactory);
16651676 }
16661677
1667 TEST_F(PipelineResourceSignatureTest, VulkanDescriptorIndexing_HLSL)
1668 {
1669 TestVulkanDescriptorIndexing(false, pShaderSourceFactory);
1678 TEST_F(PipelineResourceSignatureTest, RunTimeResourceArray_HLSL)
1679 {
1680 TestRunTimeResourceArray(false, pShaderSourceFactory);
16701681 }
16711682
16721683 } // namespace Diligent