Atlas - D3D_Blit.hlsl
Home / ext / SDL / src / gpu / d3d12 Lines: 1 | Size: 3716 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]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 6struct VertexToPixel 7{ 8 float2 tex : TEXCOORD0; 9 float4 pos : SV_POSITION; 10}; 11 12cbuffer SourceRegionBuffer : register(b0, space3) 13{ 14 float2 UVLeftTop; 15 float2 UVDimensions; 16 uint MipLevel; 17 float LayerOrDepth; 18}; 19 20Texture2D SourceTexture2D : register(t0, space2); 21Texture2DArray SourceTexture2DArray : register(t0, space2); 22Texture3D SourceTexture3D : register(t0, space2); 23TextureCube SourceTextureCube : register(t0, space2); 24TextureCubeArray SourceTextureCubeArray : register(t0, space2); 25sampler SourceSampler : register(s0, space2); 26 27[RootSignature(BlitRS)] 28VertexToPixel 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)] 38float4 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)] 45float4 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)] 52float4 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)] 59float4 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)] 79float4 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} 98[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.