Skip to content

Commit

Permalink
GPU: Clean up D3D12 blit shader compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpydog committed Dec 4, 2024
1 parent 24ed947 commit d8eb68a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
32 changes: 7 additions & 25 deletions src/gpu/d3dcommon/D3D_Blit.hlsl → src/gpu/d3d12/D3D_Blit.hlsl
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
#if D3D12
#define BlitRS \
"DescriptorTable ( Sampler(s0, space=2), visibility = SHADER_VISIBILITY_PIXEL ),"\
"DescriptorTable ( SRV(t0, space=2), visibility = SHADER_VISIBILITY_PIXEL ),"\
"CBV(b0, space=3, visibility = SHADER_VISIBILITY_PIXEL),"\

#define REG(reg, space) register(reg, space)
#else
#define REG(reg, space) register(reg)
#endif

struct VertexToPixel
{
float2 tex : TEXCOORD0;
float4 pos : SV_POSITION;
};

cbuffer SourceRegionBuffer : REG(b0, space3)
cbuffer SourceRegionBuffer : register(b0, space3)
{
float2 UVLeftTop;
float2 UVDimensions;
uint MipLevel;
float LayerOrDepth;
};

Texture2D SourceTexture2D : REG(t0, space2);
Texture2DArray SourceTexture2DArray : REG(t0, space2);
Texture3D SourceTexture3D : REG(t0, space2);
TextureCube SourceTextureCube : REG(t0, space2);
TextureCubeArray SourceTextureCubeArray : REG(t0, space2);
sampler SourceSampler : REG(s0, space2);
Texture2D SourceTexture2D : register(t0, space2);
Texture2DArray SourceTexture2DArray : register(t0, space2);
Texture3D SourceTexture3D : register(t0, space2);
TextureCube SourceTextureCube : register(t0, space2);
TextureCubeArray SourceTextureCubeArray : register(t0, space2);
sampler SourceSampler : register(s0, space2);

#if D3D12
[RootSignature(BlitRS)]
#endif
VertexToPixel FullscreenVert(uint vI : SV_VERTEXID)
{
float2 inTex = float2((vI << 1) & 2, vI & 2);
Expand All @@ -42,36 +34,28 @@ VertexToPixel FullscreenVert(uint vI : SV_VERTEXID)
return Out;
}

#if D3D12
[RootSignature(BlitRS)]
#endif
float4 BlitFrom2D(VertexToPixel input) : SV_Target0
{
float2 newCoord = UVLeftTop + UVDimensions * input.tex;
return SourceTexture2D.SampleLevel(SourceSampler, newCoord, MipLevel);
}

#if D3D12
[RootSignature(BlitRS)]
#endif
float4 BlitFrom2DArray(VertexToPixel input) : SV_Target0
{
float3 newCoord = float3(UVLeftTop + UVDimensions * input.tex, (uint)LayerOrDepth);
return SourceTexture2DArray.SampleLevel(SourceSampler, newCoord, MipLevel);
}

#if D3D12
[RootSignature(BlitRS)]
#endif
float4 BlitFrom3D(VertexToPixel input) : SV_Target0
{
float3 newCoord = float3(UVLeftTop + UVDimensions * input.tex, LayerOrDepth);
return SourceTexture3D.SampleLevel(SourceSampler, newCoord, MipLevel);
}

#if D3D12
[RootSignature(BlitRS)]
#endif
float4 BlitFromCube(VertexToPixel input) : SV_Target0
{
// Thanks, Wikipedia! https://en.wikipedia.org/wiki/Cube_mapping
Expand All @@ -91,9 +75,7 @@ float4 BlitFromCube(VertexToPixel input) : SV_Target0
return SourceTextureCube.SampleLevel(SourceSampler, newCoord, MipLevel);
}

#if D3D12
[RootSignature(BlitRS)]
#endif
float4 BlitFromCubeArray(VertexToPixel input) : SV_Target0
{
// Thanks, Wikipedia! https://en.wikipedia.org/wiki/Cube_mapping
Expand Down
12 changes: 6 additions & 6 deletions src/gpu/d3d12/compile_shaders.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ echo Suffix %SUFFIX%

cd "%~dp0"

%DXC% -E FullscreenVert -T vs_6_0 -Fh D3D12_FullscreenVert.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
%DXC% -E BlitFrom2D -T ps_6_0 -Fh D3D12_BlitFrom2D.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
%DXC% -E BlitFrom2DArray -T ps_6_0 -Fh D3D12_BlitFrom2DArray.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
%DXC% -E BlitFrom3D -T ps_6_0 -Fh D3D12_BlitFrom3D.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
%DXC% -E BlitFromCube -T ps_6_0 -Fh D3D12_BlitFromCube.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
%DXC% -E BlitFromCubeArray -T ps_6_0 -Fh D3D12_BlitFromCubeArray.h ..\d3dcommon\D3D_Blit.hlsl /D D3D12=1
%DXC% -E FullscreenVert -T vs_6_0 -Fh D3D12_FullscreenVert.h D3D_Blit.hlsl
%DXC% -E BlitFrom2D -T ps_6_0 -Fh D3D12_BlitFrom2D.h D3D_Blit.hlsl
%DXC% -E BlitFrom2DArray -T ps_6_0 -Fh D3D12_BlitFrom2DArray.h D3D_Blit.hlsl
%DXC% -E BlitFrom3D -T ps_6_0 -Fh D3D12_BlitFrom3D.h D3D_Blit.hlsl
%DXC% -E BlitFromCube -T ps_6_0 -Fh D3D12_BlitFromCube.h D3D_Blit.hlsl
%DXC% -E BlitFromCubeArray -T ps_6_0 -Fh D3D12_BlitFromCubeArray.h D3D_Blit.hlsl
copy /b D3D12_FullscreenVert.h+D3D12_BlitFrom2D.h+D3D12_BlitFrom2DArray.h+D3D12_BlitFrom3D.h+D3D12_BlitFromCube.h+D3D12_BlitFromCubeArray.h D3D12_Blit%SUFFIX%
del D3D12_FullscreenVert.h D3D12_BlitFrom2D.h D3D12_BlitFrom2DArray.h D3D12_BlitFrom3D.h D3D12_BlitFromCube.h D3D12_BlitFromCubeArray.h

0 comments on commit d8eb68a

Please sign in to comment.