diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/gpu/d3d12/D3D_Blit.hlsl | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/gpu/d3d12/D3D_Blit.hlsl')
| -rw-r--r-- | contrib/SDL-3.2.8/src/gpu/d3d12/D3D_Blit.hlsl | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/gpu/d3d12/D3D_Blit.hlsl b/contrib/SDL-3.2.8/src/gpu/d3d12/D3D_Blit.hlsl new file mode 100644 index 0000000..69748d4 --- /dev/null +++ b/contrib/SDL-3.2.8/src/gpu/d3d12/D3D_Blit.hlsl | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | #define BlitRS \ | ||
| 2 | "DescriptorTable ( Sampler(s0, space=2), visibility = SHADER_VISIBILITY_PIXEL ),"\ | ||
| 3 | "DescriptorTable ( SRV(t0, space=2), visibility = SHADER_VISIBILITY_PIXEL ),"\ | ||
| 4 | "CBV(b0, space=3, visibility = SHADER_VISIBILITY_PIXEL),"\ | ||
| 5 | |||
| 6 | struct VertexToPixel | ||
| 7 | { | ||
| 8 | float2 tex : TEXCOORD0; | ||
| 9 | float4 pos : SV_POSITION; | ||
| 10 | }; | ||
| 11 | |||
| 12 | cbuffer SourceRegionBuffer : register(b0, space3) | ||
| 13 | { | ||
| 14 | float2 UVLeftTop; | ||
| 15 | float2 UVDimensions; | ||
| 16 | uint MipLevel; | ||
| 17 | float LayerOrDepth; | ||
| 18 | }; | ||
| 19 | |||
| 20 | Texture2D SourceTexture2D : register(t0, space2); | ||
| 21 | Texture2DArray SourceTexture2DArray : register(t0, space2); | ||
| 22 | Texture3D SourceTexture3D : register(t0, space2); | ||
| 23 | TextureCube SourceTextureCube : register(t0, space2); | ||
| 24 | TextureCubeArray SourceTextureCubeArray : register(t0, space2); | ||
| 25 | sampler SourceSampler : register(s0, space2); | ||
| 26 | |||
| 27 | [RootSignature(BlitRS)] | ||
| 28 | VertexToPixel FullscreenVert(uint vI : SV_VERTEXID) | ||
| 29 | { | ||
| 30 | float2 inTex = float2((vI << 1) & 2, vI & 2); | ||
| 31 | VertexToPixel Out = (VertexToPixel)0; | ||
| 32 | Out.tex = inTex; | ||
| 33 | Out.pos = float4(inTex * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f); | ||
| 34 | return Out; | ||
| 35 | } | ||
| 36 | |||
| 37 | [RootSignature(BlitRS)] | ||
| 38 | float4 BlitFrom2D(VertexToPixel input) : SV_Target0 | ||
| 39 | { | ||
| 40 | float2 newCoord = UVLeftTop + UVDimensions * input.tex; | ||
| 41 | return SourceTexture2D.SampleLevel(SourceSampler, newCoord, MipLevel); | ||
| 42 | } | ||
| 43 | |||
| 44 | [RootSignature(BlitRS)] | ||
| 45 | float4 BlitFrom2DArray(VertexToPixel input) : SV_Target0 | ||
| 46 | { | ||
| 47 | float3 newCoord = float3(UVLeftTop + UVDimensions * input.tex, (uint)LayerOrDepth); | ||
| 48 | return SourceTexture2DArray.SampleLevel(SourceSampler, newCoord, MipLevel); | ||
| 49 | } | ||
| 50 | |||
| 51 | [RootSignature(BlitRS)] | ||
| 52 | float4 BlitFrom3D(VertexToPixel input) : SV_Target0 | ||
| 53 | { | ||
| 54 | float3 newCoord = float3(UVLeftTop + UVDimensions * input.tex, LayerOrDepth); | ||
| 55 | return SourceTexture3D.SampleLevel(SourceSampler, newCoord, MipLevel); | ||
| 56 | } | ||
| 57 | |||
| 58 | [RootSignature(BlitRS)] | ||
| 59 | float4 BlitFromCube(VertexToPixel input) : SV_Target0 | ||
| 60 | { | ||
| 61 | // Thanks, Wikipedia! https://en.wikipedia.org/wiki/Cube_mapping | ||
| 62 | float3 newCoord; | ||
| 63 | float2 scaledUV = UVLeftTop + UVDimensions * input.tex; | ||
| 64 | float u = 2.0 * scaledUV.x - 1.0; | ||
| 65 | float v = 2.0 * scaledUV.y - 1.0; | ||
| 66 | switch ((uint)LayerOrDepth) { | ||
| 67 | case 0: newCoord = float3(1.0, -v, -u); break; // POSITIVE X | ||
| 68 | case 1: newCoord = float3(-1.0, -v, u); break; // NEGATIVE X | ||
| 69 | case 2: newCoord = float3(u, 1.0, -v); break; // POSITIVE Y | ||
| 70 | case 3: newCoord = float3(u, -1.0, v); break; // NEGATIVE Y | ||
| 71 | case 4: newCoord = float3(u, -v, 1.0); break; // POSITIVE Z | ||
| 72 | case 5: newCoord = float3(-u, -v, -1.0); break; // NEGATIVE Z | ||
| 73 | default: newCoord = float3(0, 0, 0); break; // silences warning | ||
| 74 | } | ||
| 75 | return SourceTextureCube.SampleLevel(SourceSampler, newCoord, MipLevel); | ||
| 76 | } | ||
| 77 | |||
| 78 | [RootSignature(BlitRS)] | ||
| 79 | float4 BlitFromCubeArray(VertexToPixel input) : SV_Target0 | ||
| 80 | { | ||
| 81 | // Thanks, Wikipedia! https://en.wikipedia.org/wiki/Cube_mapping | ||
| 82 | float3 newCoord; | ||
| 83 | float2 scaledUV = UVLeftTop + UVDimensions * input.tex; | ||
| 84 | float u = 2.0 * scaledUV.x - 1.0; | ||
| 85 | float v = 2.0 * scaledUV.y - 1.0; | ||
| 86 | uint ArrayIndex = (uint)LayerOrDepth / 6; | ||
| 87 | switch ((uint)LayerOrDepth % 6) { | ||
| 88 | case 0: newCoord = float3(1.0, -v, -u); break; // POSITIVE X | ||
| 89 | case 1: newCoord = float3(-1.0, -v, u); break; // NEGATIVE X | ||
| 90 | case 2: newCoord = float3(u, 1.0, -v); break; // POSITIVE Y | ||
| 91 | case 3: newCoord = float3(u, -1.0, v); break; // NEGATIVE Y | ||
| 92 | case 4: newCoord = float3(u, -v, 1.0); break; // POSITIVE Z | ||
| 93 | case 5: newCoord = float3(-u, -v, -1.0); break; // NEGATIVE Z | ||
| 94 | default: newCoord = float3(0, 0, 0); break; // silences warning | ||
| 95 | } | ||
| 96 | return SourceTextureCubeArray.SampleLevel(SourceSampler, float4(newCoord, float(ArrayIndex)), MipLevel); | ||
| 97 | } | ||
