From e15ae750a2d87061506fc7d516f7419a4d7c66df Mon Sep 17 00:00:00 2001 From: AMZN-tpeng <82184807+AMZN-tpeng@users.noreply.github.com> Date: Wed, 18 Aug 2021 13:43:16 -0700 Subject: [PATCH] =?UTF-8?q?[ATOm][RHI][Vulkan][Android]=20-=20Reorganize?= =?UTF-8?q?=20float2=20data=20members=20to=20floa=E2=80=A6=20(#2718)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ATOm][RHI][Vulkan][Android] - Reorganize float2 data members to float to avoid Android Mali GPUdriver crashes Signed-off-by: Peng * [ATOM][RHI][Vulkan][Android] - Added reason comment for modifying float2 in the shader Signed-off-by: Peng --- .../Assets/Shaders/PostProcessing/SMAA.azsli | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SMAA.azsli b/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SMAA.azsli index 58c2bc1ce9..8c03816b26 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SMAA.azsli +++ b/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/SMAA.azsli @@ -1135,13 +1135,13 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord, if (!o_enableDiagonalDetectionFeature || weights.r == -weights.g) // weights.r + weights.g == 0.0 { - float2 d; + // NOTE: using separate floats for (dx, dy) and (sqrt_d_x, sqrt_d_y) instead of float2 due to android Mali driver problem crashing the device // Find the distance to the left: float3 coords; coords.x = SMAASearchXLeft(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].xy, offset[2].x); coords.y = offset[1].y; // offset[1].y = texcoord.y - 0.25 * SMAA_RT_METRICS.y (@CROSSING_OFFSET) - d.x = coords.x; + float dx = coords.x; // Now fetch the left crossing edges, two at a time using bilinear // filtering. Sampling at -0.25 (see @CROSSING_OFFSET) enables to @@ -1150,26 +1150,29 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord, // Find the distance to the right: coords.z = SMAASearchXRight(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].zw, offset[2].y); - d.y = coords.z; + float dy = coords.z; // We want the distances to be in pixel units (doing this here allow to // better interleave arithmetic and memory accesses): - d = abs(round(mad(SMAA_RT_METRICS.zz, d, -pixcoord.xx))); + dx = abs(round(mad(SMAA_RT_METRICS.z, dx, -pixcoord.x))); + dy = abs(round(mad(SMAA_RT_METRICS.z, dy, -pixcoord.x))); // SMAAArea below needs a sqrt, as the areas texture is compressed // quadratically: - float2 sqrt_d = sqrt(d); + float sqrt_d_x = sqrt(dx); + float sqrt_d_y = sqrt(dy); + // Fetch the right crossing edges: float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.zy, int2(1, 0)).r; // Ok, we know how this pattern looks like, now it is time for getting // the actual area: - weights.rg = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.y); + weights.rg = SMAAArea(SMAATexturePass2D(areaTex), float2(sqrt_d_x, sqrt_d_y), e1, e2, subsampleIndices.y); // Fix corners: coords.y = texcoord.y; - SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, d); + SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, float2(dx, dy)); } else { @@ -1180,37 +1183,37 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord, SMAA_BRANCH if (e.r > 0.0) // Edge at west { - float2 d; - // Find the distance to the top: float3 coords; coords.y = SMAASearchYUp(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].xy, offset[2].z); coords.x = offset[0].x; // offset[1].x = texcoord.x - 0.25 * SMAA_RT_METRICS.x; - d.x = coords.y; + float dx = coords.y; // Fetch the top crossing edges: float e1 = SMAASampleLevelZero(edgesTex, coords.xy).g; // Find the distance to the bottom: coords.z = SMAASearchYDown(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].zw, offset[2].w); - d.y = coords.z; + float dy = coords.z; // We want the distances to be in pixel units: - d = abs(round(mad(SMAA_RT_METRICS.ww, d, -pixcoord.yy))); + dx = abs(round(mad(SMAA_RT_METRICS.w, dx, -pixcoord.y))); + dy = abs(round(mad(SMAA_RT_METRICS.w, dy, -pixcoord.y))); // SMAAArea below needs a sqrt, as the areas texture is compressed // quadratically: - float2 sqrt_d = sqrt(d); + float sqrt_d_x = sqrt(dx); + float sqrt_d_y = sqrt(dy); // Fetch the bottom crossing edges: float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.xz, int2(0, 1)).g; // Get the area for this direction: - weights.ba = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.x); + weights.ba = SMAAArea(SMAATexturePass2D(areaTex), float2(sqrt_d_x, sqrt_d_y), e1, e2, subsampleIndices.x); // Fix corners: coords.x = texcoord.x; - SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, d); + SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, float2(dx, dy)); } return weights;