diff --git a/package/Shaders/VariableRateShading/ComputeNASData.hlsl b/package/Shaders/VariableRateShading/ComputeNASData.hlsl deleted file mode 100644 index f6e75d4f4..000000000 --- a/package/Shaders/VariableRateShading/ComputeNASData.hlsl +++ /dev/null @@ -1,102 +0,0 @@ -#define GROUP_SIZE (8 * 8) - -Texture2D InputTexture : register(t0); -Texture2D InputTextureMotionVectors : register(t1); -RWTexture2D OutputTexture : register(u0); - -groupshared float4 sampleCache[GROUP_SIZE]; -groupshared float2 sampleCacheMotionVectors[GROUP_SIZE]; -groupshared float errXCache[GROUP_SIZE]; -groupshared float errYCache[GROUP_SIZE]; - -float RgbToLuminance(float3 color) -{ - return dot(color, float3(0.299, 0.587, 0.114)); -} - -[numthreads(8, 8, 1)] void main(uint3 GroupID - : SV_GroupID, uint3 GroupThreadID - : SV_GroupThreadID) { - const uint threadIndex = GroupThreadID.y * 8 + GroupThreadID.x; - const uint2 sampleIndex = (GroupID.xy * 8 + GroupThreadID.xy) * 2.0; - - // Fetch color (final post-AA) data - // l0.x l0.y - // l0.z l0.w l2.x - // l1.x l1.y - // l1.z l1.w l2.y - // l2.z - float4 l0; - l0.x = RgbToLuminance(InputTexture[sampleIndex + uint2(0, 0)]); - l0.y = RgbToLuminance(InputTexture[sampleIndex + uint2(1, 0)]); - l0.z = RgbToLuminance(InputTexture[sampleIndex + uint2(0, 1)]); - l0.w = RgbToLuminance(InputTexture[sampleIndex + uint2(1, 1)]); - - float4 l1; - l1.x = RgbToLuminance(InputTexture[sampleIndex + uint2(0, 2)]); - l1.y = RgbToLuminance(InputTexture[sampleIndex + uint2(1, 2)]); - l1.z = RgbToLuminance(InputTexture[sampleIndex + uint2(0, 3)]); - l1.w = RgbToLuminance(InputTexture[sampleIndex + uint2(1, 3)]); - - float3 l2; - l2.x = RgbToLuminance(InputTexture[sampleIndex + uint2(2, 1)]); - l2.y = RgbToLuminance(InputTexture[sampleIndex + uint2(2, 3)]); - l2.z = RgbToLuminance(InputTexture[sampleIndex + uint2(1, 4)]); - - sampleCache[threadIndex] = l0 + l1; - - float2 m = 0.0f; - m += InputTextureMotionVectors[sampleIndex + uint2(0, 0)]; - m += InputTextureMotionVectors[sampleIndex + uint2(1, 0)]; - m += InputTextureMotionVectors[sampleIndex + uint2(0, 1)]; - m += InputTextureMotionVectors[sampleIndex + uint2(1, 1)]; - - m += InputTextureMotionVectors[sampleIndex + uint2(0, 2)]; - m += InputTextureMotionVectors[sampleIndex + uint2(1, 2)]; - m += InputTextureMotionVectors[sampleIndex + uint2(0, 3)]; - m += InputTextureMotionVectors[sampleIndex + uint2(1, 3)]; - - sampleCacheMotionVectors[threadIndex] = m; - - // Derivatives X - float4 a = float4(l0.y, l2.x, l1.y, l2.y); - float4 b = float4(l0.x, l0.w, l1.x, l1.w); - float4 dx = abs(a - b); - - // Derivatives Y - a = float4(l0.z, l1.y, l1.z, l2.z); - b = float4(l0.x, l0.w, l1.x, l1.w); - float4 dy = abs(a - b); - - // Compute maximum partial derivative of all 16x16 pixels (256 total) - // this approach is more "sensitive" to individual outliers in a tile, since it takes the max instead of the average - float maxDx = max(max(dx.x, dx.y), max(dx.z, dx.w)); - float maxDy = max(max(dy.x, dy.y), max(dy.z, dy.w)); - - errXCache[threadIndex] = maxDx; - errYCache[threadIndex] = maxDy; - - GroupMemoryBarrierWithGroupSync(); - - // Parallel reduction - [unroll] for (uint s = (64 >> 1); s > 0; s >>= 1) - { - if (threadIndex < s) { - sampleCache[threadIndex] += sampleCache[threadIndex + s]; - sampleCacheMotionVectors[threadIndex] += sampleCacheMotionVectors[threadIndex + s]; - errXCache[threadIndex] = max(errXCache[threadIndex], errXCache[threadIndex + s]); - errYCache[threadIndex] = max(errYCache[threadIndex], errYCache[threadIndex + s]); - } - - GroupMemoryBarrierWithGroupSync(); - } - - // Average - if (threadIndex == 0) { - float avgLuma = dot(sampleCache[0], 1.0 / 8.0) / GROUP_SIZE + 0.1; - float2 avgMotionVectors = dot(sampleCacheMotionVectors[0], 1.0 / 8.0) / GROUP_SIZE; - float errX = errXCache[0]; - float errY = errYCache[0]; - OutputTexture[GroupID.xy] = float4(float2(errX, errY) / abs(avgLuma), avgMotionVectors); - } -} \ No newline at end of file diff --git a/package/Shaders/VariableRateShading/ComputeShadingRate.hlsl b/package/Shaders/VariableRateShading/ComputeShadingRate.hlsl deleted file mode 100644 index 7a3a24e3f..000000000 --- a/package/Shaders/VariableRateShading/ComputeShadingRate.hlsl +++ /dev/null @@ -1,77 +0,0 @@ -RWTexture2D vrsSurface : register(u0); -Texture2D nasDataSurface : register(t0); - -[numthreads(32, 32, 1)] void main(uint3 DispatchThreadID - : SV_DispatchThreadID, uint3 GroupThreadID - : SV_GroupThreadID, uint3 GroupID - : SV_GroupID) { - float4 nasData = nasDataSurface[DispatchThreadID.xy]; - - float2 mVec = abs(nasData.zw); - - // Error scalers (equations from the I3D 2019 paper) - // bhv for half rate, bqv for quarter rate - float2 bhv = pow(1.0 / (1 + pow(1.05 * mVec, 3.1)), 0.35); - float2 bqv = 2.13 * pow(1.0 / (1 + pow(0.55 * mVec, 2.41)), 0.49); - - // Sample block error data from NAS data pass and apply the error scalars - float2 diff = nasData.xy; - float2 diff2 = diff * bhv; - float2 diff4 = diff * bqv; - - uint screenWidth, screenHeight; - nasDataSurface.GetDimensions(screenWidth, screenHeight); - - float2 uv = DispatchThreadID.xy * rcp(float2(screenWidth, screenHeight)); - float threshold = lerp(0.07, 0.14, distance(float2(0.5, 0.5), uv)); - - /*` - D3D12_SHADING_RATE_1X1 = 0, // 0b0000 - D3D12_SHADING_RATE_1X2 = 0x1, // 0b0001 - D3D12_SHADING_RATE_2X1 = 0x4, // 0b0100 - D3D12_SHADING_RATE_2X2 = 0x5, // 0b0101 - D3D12_SHADING_RATE_2X4 = 0x6, // 0b0110 - D3D12_SHADING_RATE_4X2 = 0x9, // 0b1001 - D3D12_SHADING_RATE_4X4 = 0xa // 0b1010 - */ - - // Compute block shading rate based on if the error computation goes over the threshold - // shading rates in D3D are purposely designed to be able to combined, e.g. 2x1 | 1x2 = 2x2 - uint ShadingRate = 0; - ShadingRate |= ((diff2.x >= threshold) ? 0 : ((diff4.x > threshold) ? 0x4 : 0x8)); - ShadingRate |= ((diff2.y >= threshold) ? 0 : ((diff4.y > threshold) ? 0x1 : 0x2)); - - // Disable 4x4 shading rate (low quality, limited perf gain) - if (ShadingRate == 0xa) { - ShadingRate = (diff2.x > diff2.y) ? 0x6 : 0x9; // use 2x4 or 4x2 based on directional gradient - } - // Disable 4x1 or 1x4 shading rate (unsupported) - else if (ShadingRate == 0x8) { - ShadingRate = 0x4; - } else if (ShadingRate == 0x2) { - ShadingRate = 0x1; - } - - // vsrd[i].shadingRateTable[0] = NV_PIXEL_X1_PER_RASTER_PIXEL; - // vsrd[i].shadingRateTable[1] = NV_PIXEL_X1_PER_2X1_RASTER_PIXELS; - // vsrd[i].shadingRateTable[2] = NV_PIXEL_X1_PER_1X2_RASTER_PIXELS; - // vsrd[i].shadingRateTable[3] = NV_PIXEL_X1_PER_2X2_RASTER_PIXELS; - // vsrd[i].shadingRateTable[4] = NV_PIXEL_X1_PER_4X2_RASTER_PIXELS; - // vsrd[i].shadingRateTable[5] = NV_PIXEL_X1_PER_2X4_RASTER_PIXELS; - // vsrd[i].shadingRateTable[6] = NV_PIXEL_X1_PER_4X4_RASTER_PIXELS; - - if (ShadingRate == 0x1) - ShadingRate = 2; - else if (ShadingRate == 0x4) - ShadingRate = 1; - else if (ShadingRate == 0x5) - ShadingRate = 3; - else if (ShadingRate == 0x6) - ShadingRate = 5; - else if (ShadingRate == 0x9) - ShadingRate = 4; - else if (ShadingRate == 0xa) - ShadingRate = 6; - - vrsSurface[DispatchThreadID.xy] = ShadingRate; -} \ No newline at end of file diff --git a/package/Shaders/VariableRateShading/LICENSE.txt b/package/Shaders/VariableRateShading/LICENSE.txt deleted file mode 100644 index 2014a4832..000000000 --- a/package/Shaders/VariableRateShading/LICENSE.txt +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. \ No newline at end of file