Skip to content

Commit ac0e92f

Browse files
Added VK_IMAGE_FORMAT shader macro
1 parent 17d10ab commit ac0e92f

File tree

8 files changed

+28
-38
lines changed

8 files changed

+28
-38
lines changed

Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,4 +1361,6 @@ void _GetGLTessLevelInner(out float InnerLevel)
13611361

13621362
#endif
13631363

1364+
#define VK_IMAGE_FORMAT(format)
1365+
13641366
#endif // _GLSL_DEFINITIONS_

Graphics/ShaderTools/include/HLSLDefinitions.fxh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,11 @@ float2x2 MatrixFromRows(float2 row0, float2 row1)
7878
return float2x2(row0, row1);
7979
}
8080

81+
#if defined(VULKAN) && defined(DXCOMPILER)
82+
# define VK_IMAGE_FORMAT(format) [[vk::image_format(format)]]
83+
#else
84+
# define VK_IMAGE_FORMAT(format)
85+
#endif
86+
8187
#endif // _HLSL_DEFINITIONS_
8288

Tests/DiligentCoreAPITest/assets/shaders/HLSL2GLSLConverter/CS_RWTex1D.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ cbuffer cbTest6
2525
int cbuffer_fake;
2626
int fakecbuffer;
2727

28-
RWTexture1D<float /* format=r32f */ >Tex1D_F1 /*comment*/:/*comment*/ register(u0)/*comment*/;
29-
RWTexture1D<int2 /*format=rg32i*/ >Tex1D_I;
30-
RWTexture1D<uint4 /* format= rgba32ui */ >Tex1D_U;
28+
VK_IMAGE_FORMAT("r32f") RWTexture1D<float /* format=r32f */ >Tex1D_F1 /*comment*/:/*comment*/ register(u0)/*comment*/;
29+
VK_IMAGE_FORMAT("r32i") RWTexture1D<int2 /*format=rg32i*/ >Tex1D_I;
30+
VK_IMAGE_FORMAT("rgba32ui") RWTexture1D<uint4 /* format= rgba32ui */ >Tex1D_U;
3131

3232
RWTexture1DArray </* format = r32f */ float > Tex1D_F_A : register(u1);
3333
RWTexture1DArray </* format = rg16i */ int2 > Tex1D_I_A;

Tests/DiligentCoreAPITest/assets/shaders/HLSL2GLSLConverter/CS_RWTex2D_1.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ RWTexture2D<float4/* format = rgba32f */>Tex2D_F1/*comment*/: /*comment*/registe
2929
RWTexture2D<float/* format = r32f */>Tex2D_F3: register(u3),/*cmt*/Tex2D_F4, Tex2D_F5
3030
/*comment*/:/*comment*/
3131
register(u4);
32-
RWTexture2D<int4/* format = rgba16i */>Tex2D_I;
33-
RWTexture2D<uint/* format = r32ui */>Tex2D_U;
32+
VK_IMAGE_FORMAT("rgba16i") RWTexture2D<int4/* format = rgba16i */>Tex2D_I;
33+
VK_IMAGE_FORMAT("r32ui") RWTexture2D<uint/* format = r32ui */>Tex2D_U;
3434

3535

3636
int GlobalIntVar;Texture2D Tex2D_Test1:register(t0);Texture2D Tex2D_Test2;/*Comment* / *//* /** Comment2*/Texture2D Tex2D_Test3 /*Cmnt*/: /*comment*/register(t1)/*comment*/,/*comment*/

Tests/DiligentCoreAPITest/assets/shaders/HLSL2GLSLConverter/CS_RWTex2D_2.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RWTexture2DArray <int2// format = rg8i
88
RWTexture2DArray <uint4// format = rgba8ui
99
> Tex2D_U_A;
1010

11+
VK_IMAGE_FORMAT("rgba32f")
1112
RWTexture3D< float4/*
1213
format
1314
=

Tests/DiligentCoreAPITest/include/InlineShaders/RayTracingTestHLSL.h

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ const std::string RayTracingTest1_RG = RayTracingTest_Payload +
4646
R"hlsl(
4747
RaytracingAccelerationStructure g_TLAS : register(t0);
4848
49-
#ifdef VULKAN
50-
[[vk::image_format("rgba8")]]
51-
#endif
52-
RWTexture2D<float4> g_ColorBuffer : register(u0);
49+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_ColorBuffer : register(u0);
5350
5451
[shader("raygeneration")]
5552
void main()
@@ -100,10 +97,7 @@ const std::string RayTracingTest2_RG = RayTracingTest_Payload +
10097
R"hlsl(
10198
RaytracingAccelerationStructure g_TLAS : register(t0);
10299
103-
#ifdef VULKAN
104-
[[vk::image_format("rgba8")]]
105-
#endif
106-
RWTexture2D<float4> g_ColorBuffer : register(u0);
100+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_ColorBuffer : register(u0);
107101
108102
[shader("raygeneration")]
109103
void main()
@@ -166,10 +160,7 @@ const std::string RayTracingTest3_RG = RayTracingTest_Payload +
166160
R"hlsl(
167161
RaytracingAccelerationStructure g_TLAS : register(t0);
168162
169-
#ifdef VULKAN
170-
[[vk::image_format("rgba8")]]
171-
#endif
172-
RWTexture2D<float4> g_ColorBuffer : register(u0);
163+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_ColorBuffer : register(u0);
173164
174165
[shader("raygeneration")]
175166
void main()
@@ -253,10 +244,7 @@ const std::string RayTracingTest4_RG = RayTracingTest_Payload +
253244
R"hlsl(
254245
RaytracingAccelerationStructure g_TLAS : register(t0);
255246
256-
#ifdef VULKAN
257-
[[vk::image_format("rgba8")]]
258-
#endif
259-
RWTexture2D<float4> g_ColorBuffer : register(u0);
247+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_ColorBuffer : register(u0);
260248
261249
[shader("raygeneration")]
262250
void main()
@@ -353,10 +341,7 @@ const std::string RayTracingTest5_RG = RayTracingTest_Payload +
353341
R"hlsl(
354342
RaytracingAccelerationStructure g_TLAS;
355343
356-
#ifdef VULKAN
357-
[[vk::image_format("rgba8")]]
358-
#endif
359-
RWTexture2D<float4> g_ColorBuffer;
344+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_ColorBuffer;
360345
361346
[shader("raygeneration")]
362347
void main()
@@ -442,10 +427,7 @@ void main(inout RTPayload payload, in BuiltInTriangleIntersectionAttributes attr
442427
const std::string RayTracingTest6_RG{R"hlsl(
443428
RaytracingAccelerationStructure g_TLAS;
444429
445-
#ifdef VULKAN
446-
[[vk::image_format("rgba8")]]
447-
#endif
448-
RWTexture2D<float4> g_ColorBuffer;
430+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_ColorBuffer;
449431
450432
float4 HitShader(float2 attrBarycentrics)
451433
{
@@ -563,10 +545,7 @@ float4 main(in PSInput PSIn) : SV_Target
563545
const std::string RayTracingTest8_CS{R"hlsl(
564546
RaytracingAccelerationStructure g_TLAS;
565547
566-
#ifdef VULKAN
567-
[[vk::image_format("rgba8")]]
568-
#endif
569-
RWTexture2D<float4> g_ColorBuffer;
548+
VK_IMAGE_FORMAT("rgba8") RWTexture2D<float4> g_ColorBuffer;
570549
571550
float4 HitShader(float2 attrBarycentrics)
572551
{

Tests/DiligentCoreAPITest/src/ArchiveTest.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,10 +1298,7 @@ namespace HLSL
12981298
// Test shader source as string
12991299
const std::string ComputePSOTest_CS{R"(
13001300
1301-
#if defined(VULKAN) && defined(DXCOMPILER)
1302-
[[vk::image_format("rgba8")]]
1303-
#endif
1304-
RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
1301+
VK_IMAGE_FORMAT("rgba8") RWTexture2D</*format=rgba8*/ float4> g_tex2DUAV : register(u0);
13051302
13061303
[numthreads(16, 16, 1)]
13071304
void main(uint3 DTid : SV_DispatchThreadID)

Tests/DiligentCoreAPITest/src/D3D12/RayTracingReferenceD3D12.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "InlineShaders/RayTracingTestHLSL.h"
3737
#include "RayTracingTestConstants.hpp"
3838

39+
#include "dxc/dxcapi.h"
40+
3941
namespace Diligent
4042
{
4143

@@ -120,8 +122,11 @@ struct RTSubobjectsHelper
120122

121123
void SetDxilLibrary(Uint32 Index, const String& Source, const wchar_t* ExportName)
122124
{
125+
static constexpr DxcDefine Defines[]{
126+
{L"VK_IMAGE_FORMAT(x)", L""},
127+
};
123128
TestingEnvironmentD3D12* pEnv = TestingEnvironmentD3D12::GetInstance();
124-
HRESULT hr = pEnv->CompileDXILShader(Source, L"main", nullptr, 0, L"lib_6_3", &ShadersByteCode[Index]);
129+
HRESULT hr = pEnv->CompileDXILShader(Source, L"main", Defines, _countof(Defines), L"lib_6_3", &ShadersByteCode[Index]);
125130
ASSERT_HRESULT_SUCCEEDED(hr) << "Failed to compile ray tracing shader";
126131

127132
D3D12_EXPORT_DESC& RGExportDesc = ExportDescs[Index];

0 commit comments

Comments
 (0)