diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-04 06:07:30 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-02-04 06:07:30 +0000 |
| commit | dc4be8ba0ea8722b8f93d92833ee40dea411a53c (patch) | |
| tree | ca0512330faf188e80c2eb008cc7ebefd9d0620f | |
| parent | PRS tests: fixed mesh shader compilation, added test for descriptor indexing (diff) | |
| download | DiligentCore-dc4be8ba0ea8722b8f93d92833ee40dea411a53c.tar.gz DiligentCore-dc4be8ba0ea8722b8f93d92833ee40dea411a53c.zip | |
Reworked PipelineResourceSignatureTest.VulkanDescriptorIndexing to validate resource bindings
5 files changed, 93 insertions, 60 deletions
diff --git a/Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VulkanDescriptorIndexing.glsl b/Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VulkanDescriptorIndexing.glsl new file mode 100644 index 00000000..65d4af4e --- /dev/null +++ b/Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/VulkanDescriptorIndexing.glsl @@ -0,0 +1,45 @@ +#version 460 core +#extension GL_ARB_shading_language_420pack : enable +#extension GL_EXT_nonuniform_qualifier : require + +uniform sampler2D g_Textures[]; + +vec4 CheckValue(vec4 Val, vec4 Expected) +{ + return vec4(Val.x == Expected.x ? 1.0 : 0.0, + Val.y == Expected.y ? 1.0 : 0.0, + Val.z == Expected.z ? 1.0 : 0.0, + Val.w == Expected.w ? 1.0 : 0.0); +} + + +vec4 VerifyResources(uint index, vec2 coord) +{ + vec4 RefValues[NUM_TEXTURES]; + RefValues[0] = Tex2D_Ref0; + RefValues[1] = Tex2D_Ref1; + RefValues[2] = Tex2D_Ref2; + RefValues[3] = Tex2D_Ref3; + RefValues[4] = Tex2D_Ref4; + RefValues[5] = Tex2D_Ref5; + RefValues[6] = Tex2D_Ref6; + RefValues[7] = Tex2D_Ref7; + + return CheckValue(textureLod(g_Textures[nonuniformEXT(index)], coord, 0.0), RefValues[index]); +} + +layout(rgba8) writeonly uniform image2D g_OutImage; + +layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in; +void main () +{ + ivec2 Dim = imageSize(g_OutImage); + if (gl_GlobalInvocationID.x >= uint(Dim.x) || gl_GlobalInvocationID.y >= uint(Dim.y)) + return; + + vec4 Color = vec4(vec2(gl_GlobalInvocationID.xy % 256u) / 256.0, 0.0, 1.0); + vec2 uv = vec2(gl_GlobalInvocationID.xy + vec2(0.5,0.5)) / vec2(gl_WorkGroupSize.xy * gl_NumWorkGroups.xy); + Color *= VerifyResources(gl_LocalInvocationIndex % NUM_TEXTURES, uv); + + imageStore(g_OutImage, ivec2(gl_GlobalInvocationID.xy), Color); +} diff --git a/Tests/DiligentCoreAPITest/include/ResourceLayoutTestCommon.hpp b/Tests/DiligentCoreAPITest/include/ResourceLayoutTestCommon.hpp index 31b4bbe3..a4b57454 100644 --- a/Tests/DiligentCoreAPITest/include/ResourceLayoutTestCommon.hpp +++ b/Tests/DiligentCoreAPITest/include/ResourceLayoutTestCommon.hpp @@ -181,7 +181,7 @@ public: std::vector<Uint32> TexData(Width * Height, F4Color_To_RGBA8Unorm(Value)); String Name = String{"Reference texture "} + std::to_string(i); - pTexture = pEnv->CreateTexture("Test texture", TEX_FORMAT_RGBA8_UNORM, BindFlags, Width, Height, TexData.data()); + pTexture = pEnv->CreateTexture(Name.c_str(), TEX_FORMAT_RGBA8_UNORM, BindFlags, Width, Height, TexData.data()); ppViewObjects[i] = pTexture->GetDefaultView(ViewType); } } diff --git a/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp b/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp index 48c11d76..07307609 100644 --- a/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp +++ b/Tests/DiligentCoreAPITest/src/PipelineResourceSignatureTest.cpp @@ -32,6 +32,7 @@ #include "ShaderMacroHelper.hpp" #include "GraphicsAccessories.hpp" #include "ResourceLayoutTestCommon.hpp" +#include "TestingSwapChainBase.hpp" #include "gtest/gtest.h" @@ -136,13 +137,13 @@ protected: const char* EntryPoint, const char* Name, bool UseCombinedSamplers, - const ShaderMacro* Macros = nullptr, - bool UseDXC = false) + const ShaderMacro* Macros = nullptr, + SHADER_COMPILER ShaderCompiler = SHADER_COMPILER_DEFAULT) { ShaderCreateInfo ShaderCI; ShaderCI.pShaderSourceStreamFactory = pShaderSourceFactory; ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; - ShaderCI.ShaderCompiler = UseDXC ? SHADER_COMPILER_DXC : SHADER_COMPILER_DEFAULT; + ShaderCI.ShaderCompiler = ShaderCompiler; ShaderCI.Source = Source; ShaderCI.Macros = Macros; ShaderCI.Desc.Name = Name; @@ -162,7 +163,7 @@ protected: bool UseCombinedSamplers, const ShaderMacro* Macros = nullptr) { - return CreateShaderFromSource(ShaderType, Source, EntryPoint, Name, UseCombinedSamplers, Macros, true); + return CreateShaderFromSource(ShaderType, Source, EntryPoint, Name, UseCombinedSamplers, Macros, SHADER_COMPILER_DXC); } static RefCntAutoPtr<IShaderSourceInputStreamFactory> pShaderSourceFactory; @@ -1394,41 +1395,31 @@ TEST_F(PipelineResourceSignatureTest, FormattedBuffers) TEST_F(PipelineResourceSignatureTest, VulkanDescriptorIndexing) { - const std::string DescrIndexingTest_CS{R"( -#version 460 core -#extension GL_ARB_shading_language_420pack : enable -#extension GL_EXT_nonuniform_qualifier : require - -layout (local_size_x = 8, local_size_y = 1, local_size_z = 1) in; - -uniform sampler2D g_Textures[]; - -layout(rgba8) writeonly uniform image2D g_OutImage; - -void main () -{ - const int i = int(gl_LocalInvocationIndex); - const vec2 coord = vec2(gl_GlobalInvocationID.xy) / vec2(gl_WorkGroupSize.xy * gl_NumWorkGroups.xy - 1); - vec4 color = texture(g_Textures[nonuniformEXT(i)], coord); - - imageStore(g_OutImage, ivec2(gl_GlobalInvocationID.xy), color); -} -)"}; - - auto* pEnv = TestingEnvironment::GetInstance(); - auto* pDevice = pEnv->GetDevice(); - auto* pContext = pEnv->GetDeviceContext(); - - // There is not feature for descriptor indexing, but ray tracing extensions requires descripter indexing extension so test the RayTracing feature. - if (!pDevice->GetDeviceCaps().IsVulkanDevice() && !pDevice->GetDeviceCaps().Features.RayTracing) + auto* pEnv = TestingEnvironment::GetInstance(); + auto* pDevice = pEnv->GetDevice(); + if (!pDevice->GetDeviceCaps().IsVulkanDevice()) { GTEST_SKIP() << "Descriptor indexing is not supported by this device"; } TestingEnvironment::ScopedReset EnvironmentAutoReset; + auto* pContext = pEnv->GetDeviceContext(); + auto* pSwapChain = pEnv->GetSwapChain(); + + ComputeShaderReference(pSwapChain); + + constexpr Uint32 TexArraySize = 8; + ReferenceTextures RefTextures{ + TexArraySize, + 128, 128, + USAGE_DEFAULT, + BIND_SHADER_RESOURCE, + TEXTURE_VIEW_SHADER_RESOURCE // + }; + RefCntAutoPtr<IPipelineResourceSignature> pSignature; - const Uint32 TexArraySize = 8; + { const PipelineResourceDesc Resources[] = { @@ -1459,15 +1450,24 @@ void main () PSODesc.Name = "PRS descriptor indexing test"; PSODesc.PipelineType = PIPELINE_TYPE_COMPUTE; + ShaderMacroHelper Macros; + + Macros.AddShaderMacro("NUM_TEXTURES", TexArraySize); + Macros.AddShaderMacro("float4", "vec4"); + for (Uint32 i = 0; i < TexArraySize; ++i) + Macros.AddShaderMacro((String{"Tex2D_Ref"} + std::to_string(i)).c_str(), RefTextures.GetColor(i)); + RefCntAutoPtr<IShader> pCS; { ShaderCreateInfo ShaderCI; + ShaderCI.pShaderSourceStreamFactory = pShaderSourceFactory; ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_GLSL_VERBATIM; ShaderCI.UseCombinedTextureSamplers = true; ShaderCI.Desc.ShaderType = SHADER_TYPE_COMPUTE; ShaderCI.EntryPoint = "main"; ShaderCI.Desc.Name = "DescrIndexingTest - CS"; - ShaderCI.Source = DescrIndexingTest_CS.c_str(); + ShaderCI.FilePath = "VulkanDescriptorIndexing.glsl"; + ShaderCI.Macros = Macros; pDevice->CreateShader(ShaderCI, &pCS); ASSERT_NE(pCS, nullptr); } @@ -1490,34 +1490,24 @@ void main () pSignature->CreateShaderResourceBinding(&pSRB, true); ASSERT_NE(pSRB, nullptr); - RefCntAutoPtr<ITexture> pOutImage; - { - TextureDesc TexDesc; - TexDesc.Type = RESOURCE_DIM_TEX_2D; - TexDesc.Width = 256; - TexDesc.Height = 256; - TexDesc.Usage = USAGE_DEFAULT; - TexDesc.Format = TEX_FORMAT_RGBA8_UNORM; - TexDesc.BindFlags = BIND_UNORDERED_ACCESS; - - pDevice->CreateTexture(TexDesc, nullptr, &pOutImage); - ASSERT_NE(pOutImage, nullptr); - } - - pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_OutImage")->Set(pOutImage->GetDefaultView(TEXTURE_VIEW_UNORDERED_ACCESS)); - + RefCntAutoPtr<ISampler> pSampler; + pDevice->CreateSampler(SamplerDesc{}, &pSampler); for (Uint32 i = 0; i < TexArraySize; ++i) - { - IDeviceObject* pSRV = pTexSRVs[i % pTexSRVs.size()]; - pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_Textures")->SetArray(&pSRV, i, 1); - } + RefTextures.GetView(i)->SetSampler(pSampler); + RefCntAutoPtr<ITestingSwapChain> pTestingSwapChain{pSwapChain, IID_TestingSwapChain}; + ASSERT_TRUE(pTestingSwapChain); + pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_OutImage")->Set(pTestingSwapChain->GetCurrentBackBufferUAV()); + pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_Textures")->SetArray(RefTextures.GetViewObjects(0), 0, TexArraySize); pContext->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pContext->SetPipelineState(pPSO); - DispatchComputeAttribs dispathAttribs{1, 1, 1}; - pContext->DispatchCompute(dispathAttribs); + const auto& SCDesc = pSwapChain->GetDesc(); + DispatchComputeAttribs DispatchAttribs((SCDesc.Width + 15) / 16, (SCDesc.Height + 15) / 16, 1); + pContext->DispatchCompute(DispatchAttribs); + + pSwapChain->Present(); } } // namespace Diligent diff --git a/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.cpp b/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.cpp index cc573ac7..f686eabd 100644 --- a/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.cpp +++ b/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.cpp @@ -386,4 +386,4 @@ BOOL CalculateDXBCChecksum(BYTE* pData, DWORD dwSize, DWORD dwHash[4]) memcpy(dwHash, md5Ctx.buf, 4 * sizeof(DWORD)); return TRUE; -}
\ No newline at end of file +} diff --git a/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.h b/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.h index 1e0c53da..404a1672 100644 --- a/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.h +++ b/ThirdParty/GPUOpenShaderUtils/DXBCChecksum.h @@ -1,5 +1,3 @@ -// from https://github.com/GPUOpen-Archive/common-src-ShaderUtils - //===================================================================== // Copyright 2008-2016 (c), Advanced Micro Devices, Inc. All rights reserved. // @@ -77,4 +75,4 @@ /// \return TRUE if successful, otherwise FALSE. BOOL CalculateDXBCChecksum(BYTE* pData, DWORD dwSize, DWORD dwHash[4]); -#endif // DXBCCHECKSUM_H
\ No newline at end of file +#endif // DXBCCHECKSUM_H |
