Skip to content

Commit 75b63b7

Browse files
Fixed image format mismatch Vulkan validation warnings (close #665)
1 parent ac0e92f commit 75b63b7

File tree

12 files changed

+65
-40
lines changed

12 files changed

+65
-40
lines changed

Tests/DiligentCoreAPITest/assets/shaders/PipelineResourceSignature/RunTimeResourceArray.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct StructBuffData
7272
};
7373
StructuredBuffer<StructBuffData> g_StructuredBuffers[STRUCT_BUFFERS_COUNT];
7474

75-
RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTextures[RWTEXTURES_COUNT] : register(u10, space5);
75+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTextures[RWTEXTURES_COUNT] : register(u10, space5);
7676

7777

7878
#ifndef VULKAN // RW structured buffers are not supported by DXC
@@ -169,7 +169,7 @@ float4 VerifyResources(uint index, float2 coord)
169169
return AllCorrect;
170170
}
171171

172-
RWTexture2D<float4> g_OutImage;
172+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_OutImage;
173173

174174
[numthreads(16, 16, 1)]
175175
void main(uint3 GlobalInvocationID : SV_DispatchThreadID,

Tests/DiligentCoreAPITest/assets/shaders/RenderStateCache/ComputeShader.csh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Defines.h"
22

3-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV;
3+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV;
44

55
#if INTERNAL_MACROS == 1 && EXTERNAL_MACROS == 2
66
[numthreads(16, 16, 1)]

Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/RWFormattedBuffers.hlsl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ float4 VerifyResources()
7171
return AllCorrect;
7272
}
7373

74-
75-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV;
74+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV;
7675

7776
[numthreads(16, 16, 1)]
7877
void main(uint3 DTid : SV_DispatchThreadID)

Tests/DiligentCoreAPITest/assets/shaders/ShaderResourceLayout/RWTextures.hlsl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2D_Static;
2-
RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2D_Mut;
3-
RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2D_Dyn;
41

5-
RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2DArr_Static[STATIC_TEX_ARRAY_SIZE]; // 2
6-
RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2DArr_Mut [MUTABLE_TEX_ARRAY_SIZE]; // 4 or 2 in D3D11
7-
RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2DArr_Dyn [DYNAMIC_TEX_ARRAY_SIZE]; // 3 or 1 in D3D11
2+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2D_Static;
3+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2D_Mut;
4+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2D_Dyn;
5+
6+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2DArr_Static[STATIC_TEX_ARRAY_SIZE]; // 2
7+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2DArr_Mut [MUTABLE_TEX_ARRAY_SIZE]; // 4 or 2 in D3D11
8+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<unorm float4 /*format=rgba8*/> g_RWTex2DArr_Dyn [DYNAMIC_TEX_ARRAY_SIZE]; // 3 or 1 in D3D11
89

910
float4 CheckValue(float4 Val, float4 Expected)
1011
{
@@ -69,7 +70,7 @@ float4 VerifyResources()
6970
return AllCorrect;
7071
}
7172

72-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV;
73+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV;
7374

7475
[numthreads(16, 16, 1)]
7576
void main(uint3 DTid : SV_DispatchThreadID)

Tests/DiligentCoreAPITest/include/InlineShaders/ComputeShaderTestHLSL.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 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");
@@ -36,7 +36,12 @@ namespace HLSL
3636
// clang-format off
3737
const std::string FillTextureCS{
3838
R"(
39-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
39+
40+
#ifndef VK_IMAGE_FORMAT
41+
# define VK_IMAGE_FORMAT(x)
42+
#endif
43+
44+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
4045
4146
[numthreads(16, 16, 1)]
4247
void main(uint3 DTid : SV_DispatchThreadID)
@@ -54,7 +59,8 @@ void main(uint3 DTid : SV_DispatchThreadID)
5459
const std::string FillTextureCS2{
5560
R"(
5661
Texture2D<float4> g_tex2DWhiteTexture;
57-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
62+
63+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
5864
5965
[numthreads(16, 16, 1)]
6066
void main(uint3 DTid : SV_DispatchThreadID)
@@ -97,7 +103,7 @@ struct VSOutput
97103
float4 Pos : SV_Position;
98104
};
99105
100-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
106+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
101107
102108
void main(in VSOutput VSOut)
103109
{
@@ -119,7 +125,7 @@ cbuffer Constants
119125
float4 g_Color;
120126
};
121127
122-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
128+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
123129
124130
void main(in VSOutput VSOut)
125131
{

Tests/DiligentCoreAPITest/include/InlineShaders/SparseResourcesTest.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -73,7 +73,8 @@ float4 main(in PSInput PSIn) : SV_Target
7373

7474

7575
const std::string FillTexture3D_CS{R"hlsl(
76-
RWTexture3D<float4> g_DstTexture;
76+
77+
VK_IMAGE_FORMAT("rgba8") RWTexture3D<float4 /*format=rgba8*/> g_DstTexture;
7778
7879
cbuffer CB
7980
{
@@ -85,7 +86,7 @@ cbuffer CB
8586
[numthreads(4, 4, 4)]
8687
void main(uint3 DTid : SV_DispatchThreadID)
8788
{
88-
if (all(DTid < Size))
89+
if (all(Less(DTid, Size)))
8990
{
9091
g_DstTexture[Offset + DTid] = Color;
9192
}

Tests/DiligentCoreAPITest/src/ComputeShaderTest.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ TEST(ComputeShaderTest, FillTexture)
160160
ShaderCI.Desc = {"Compute shader test - FillTextureCS", SHADER_TYPE_COMPUTE, true};
161161
ShaderCI.EntryPoint = "main";
162162
ShaderCI.Source = HLSL::FillTextureCS.c_str();
163+
ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL;
163164
RefCntAutoPtr<IShader> pCS;
164165
pDevice->CreateShader(ShaderCI, &pCS);
165166
ASSERT_NE(pCS, nullptr);
@@ -225,6 +226,7 @@ TEST(ComputeShaderTest, GenerateMips_CSInterference)
225226
ShaderCI.Desc = {"Compute shader test - FillTextureCS2", SHADER_TYPE_COMPUTE, true};
226227
ShaderCI.EntryPoint = "main";
227228
ShaderCI.Source = HLSL::FillTextureCS2.c_str();
229+
ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL;
228230
RefCntAutoPtr<IShader> pCS;
229231
pDevice->CreateShader(ShaderCI, &pCS);
230232
ASSERT_NE(pCS, nullptr);
@@ -243,11 +245,19 @@ TEST(ComputeShaderTest, GenerateMips_CSInterference)
243245

244246
const SwapChainDesc& SCDesc = pSwapChain->GetDesc();
245247

246-
RefCntAutoPtr<ITexture> pWhiteTex;
248+
RefCntAutoPtr<ITextureView> pWhiteTexSRV;
247249
{
248-
std::vector<Uint8> WhiteRGBA(SCDesc.Width * SCDesc.Width * 4, 255);
249-
pWhiteTex = pEnv->CreateTexture("White Texture", TEX_FORMAT_RGBA8_UNORM, BIND_SHADER_RESOURCE, SCDesc.Width, SCDesc.Width, WhiteRGBA.data());
250+
std::vector<Uint8> WhiteRGBA(SCDesc.Width * SCDesc.Width * 4, 255);
251+
RefCntAutoPtr<ITexture> pWhiteTex = pEnv->CreateTexture("White Texture", TEX_FORMAT_RGBA8_UNORM, BIND_SHADER_RESOURCE, SCDesc.Width, SCDesc.Width, WhiteRGBA.data());
250252
ASSERT_NE(pWhiteTex, nullptr);
253+
pWhiteTexSRV = pWhiteTex->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
254+
ASSERT_NE(pWhiteTexSRV, nullptr);
255+
256+
SamplerDesc SamDesc;
257+
SamDesc.Name = "Dummy sampler";
258+
RefCntAutoPtr<ISampler> pSampler;
259+
pDevice->CreateSampler(SamDesc, &pSampler);
260+
pWhiteTexSRV->SetSampler(pSampler);
251261
}
252262

253263
RefCntAutoPtr<ITexture> pBlackTex;
@@ -271,7 +281,7 @@ TEST(ComputeShaderTest, GenerateMips_CSInterference)
271281
pPSO->CreateShaderResourceBinding(&pSRB, true);
272282
ASSERT_NE(pSRB, nullptr);
273283

274-
pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_tex2DWhiteTexture")->Set(pWhiteTex->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE));
284+
pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_tex2DWhiteTexture")->Set(pWhiteTexSRV);
275285
pSRB->GetVariableByName(SHADER_TYPE_COMPUTE, "g_tex2DUAV")->Set(pTestingSwapChain->GetCurrentBackBufferUAV());
276286

277287
pContext->SetPipelineState(pPSO);
@@ -341,9 +351,10 @@ static void TestFillTexturePS(bool UseRenderPass)
341351
pDevice->CreateShader(ShaderCI, &pVS);
342352
ASSERT_NE(pVS, nullptr);
343353

344-
ShaderCI.Desc = {"Compute shader test - FillTexturePS", SHADER_TYPE_PIXEL, true};
345-
ShaderCI.EntryPoint = "main";
346-
ShaderCI.Source = HLSL::FillTexturePS.c_str();
354+
ShaderCI.Desc = {"Compute shader test - FillTexturePS", SHADER_TYPE_PIXEL, true};
355+
ShaderCI.EntryPoint = "main";
356+
ShaderCI.Source = HLSL::FillTexturePS.c_str();
357+
ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL;
347358
RefCntAutoPtr<IShader> pPS;
348359
pDevice->CreateShader(ShaderCI, &pPS);
349360
ASSERT_NE(pPS, nullptr);
@@ -511,9 +522,10 @@ TEST(ComputeShaderTest, FillTexturePS_Signatures)
511522
pDevice->CreateShader(ShaderCI, &pVS);
512523
ASSERT_NE(pVS, nullptr);
513524

514-
ShaderCI.Desc = {"Compute shader test - FillTexturePS", SHADER_TYPE_PIXEL, true};
515-
ShaderCI.EntryPoint = "main";
516-
ShaderCI.Source = HLSL::FillTexturePS2.c_str();
525+
ShaderCI.Desc = {"Compute shader test - FillTexturePS", SHADER_TYPE_PIXEL, true};
526+
ShaderCI.EntryPoint = "main";
527+
ShaderCI.Source = HLSL::FillTexturePS2.c_str();
528+
ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL;
517529
RefCntAutoPtr<IShader> pPS;
518530
pDevice->CreateShader(ShaderCI, &pPS);
519531
ASSERT_NE(pPS, nullptr);

Tests/DiligentCoreAPITest/src/D3D11/ComputeShaderRefenceD3D11.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 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");
@@ -38,20 +38,20 @@ namespace Testing
3838

3939
void ComputeShaderReferenceD3D11(ISwapChain* pSwapChain)
4040
{
41-
auto* pEnvD3D11 = TestingEnvironmentD3D11::GetInstance();
42-
auto* pd3d11Context = pEnvD3D11->GetD3D11Context();
43-
auto* pTestingSwapChainD3D11 = ClassPtrCast<TestingSwapChainD3D11>(pSwapChain);
41+
TestingEnvironmentD3D11* pEnvD3D11 = TestingEnvironmentD3D11::GetInstance();
42+
ID3D11DeviceContext* pd3d11Context = pEnvD3D11->GetD3D11Context();
43+
TestingSwapChainD3D11* pTestingSwapChainD3D11 = ClassPtrCast<TestingSwapChainD3D11>(pSwapChain);
4444

4545
pd3d11Context->ClearState();
4646

47-
auto pCS = pEnvD3D11->CreateComputeShader(HLSL::FillTextureCS);
47+
CComPtr<ID3D11ComputeShader> pCS = pEnvD3D11->CreateComputeShader(HLSL::FillTextureCS);
4848
ASSERT_NE(pCS, nullptr);
4949

5050
pd3d11Context->CSSetShader(pCS, nullptr, 0);
5151
ID3D11UnorderedAccessView* pUAVs[] = {pTestingSwapChainD3D11->GetD3D11UAV()};
5252
pd3d11Context->CSSetUnorderedAccessViews(0, 1, pUAVs, nullptr);
5353

54-
const auto& SCDesc = pSwapChain->GetDesc();
54+
const SwapChainDesc& SCDesc = pSwapChain->GetDesc();
5555
pd3d11Context->Dispatch((SCDesc.Width + 15) / 16, (SCDesc.Height + 15) / 16, 1);
5656

5757
pd3d11Context->ClearState();

Tests/DiligentCoreAPITest/src/FenceTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ namespace
3737
{
3838

3939
const std::string FenceTest_CS{R"(
40-
RWTexture2D<float4/* format = rgba8 */> g_DstTexture;
40+
41+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4/* format = rgba8 */> g_DstTexture;
4142
4243
cbuffer Constants
4344
{
@@ -75,6 +76,7 @@ class FenceTest : public ::testing::Test
7576
ShaderCreateInfo ShaderCI;
7677
ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
7778
ShaderCI.ShaderCompiler = pEnv->GetDefaultCompiler(ShaderCI.SourceLanguage);
79+
ShaderCI.CompileFlags = SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL;
7880

7981
RefCntAutoPtr<IShader> pCS;
8082
{

Tests/DiligentCoreAPITest/src/RenderStateCacheTest.cpp

Lines changed: 2 additions & 1 deletion
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
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -342,6 +342,7 @@ void CreateComputeShader(IRenderStateCache* pCache,
342342
RefCntAutoPtr<IShader>& pCS,
343343
bool PresentInCache)
344344
{
345+
CompileFlags |= SHADER_COMPILE_FLAG_HLSL_TO_SPIRV_VIA_GLSL;
345346
CreateShader(pCache, pShaderSourceFactory, SHADER_TYPE_COMPUTE, CompileFlags,
346347
"RenderStateCache - CS", "ComputeShader.csh",
347348
PresentInCache, pCS);

0 commit comments

Comments
 (0)