From 0fac1d6e87990a732916b107ec836ca3b0f0e393 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Mon, 13 Jun 2022 13:07:20 -0700 Subject: [PATCH 1/3] VideoCommon: Fix D3D shader warning X3571 (negative base for pow()) Add abs() to fix "pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them". --- Source/Core/VideoCommon/TextureConversionShader.cpp | 4 ++-- Source/Core/VideoCommon/TextureConverterShaderGen.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index 19f2a384f0..2c53250cea 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -749,8 +749,8 @@ static void WriteXFBEncoder(ShaderCode& code, APIType api_type, const EFBCopyPar WriteSampleColor(code, "rgb", "color1", 1, api_type, params); // Gamma is only applied to XFB copies. - code.Write(" color0 = pow(color0, float3(gamma_rcp, gamma_rcp, gamma_rcp));\n" - " color1 = pow(color1, float3(gamma_rcp, gamma_rcp, gamma_rcp));\n"); + code.Write(" color0 = pow(abs(color0), float3(gamma_rcp, gamma_rcp, gamma_rcp));\n" + " color1 = pow(abs(color1), float3(gamma_rcp, gamma_rcp, gamma_rcp));\n"); // Convert to YUV. code.Write(" const float3 y_const = float3(0.257, 0.504, 0.098);\n" diff --git a/Source/Core/VideoCommon/TextureConverterShaderGen.cpp b/Source/Core/VideoCommon/TextureConverterShaderGen.cpp index c5a440b801..579dbf69c5 100644 --- a/Source/Core/VideoCommon/TextureConverterShaderGen.cpp +++ b/Source/Core/VideoCommon/TextureConverterShaderGen.cpp @@ -313,8 +313,8 @@ ShaderCode GeneratePixelShader(APIType api_type, const UidData* uid_data) break; case EFBCopyFormat::XFB: - out.Write( - " ocol0 = float4(pow(texcol.rgb, float3(gamma_rcp, gamma_rcp, gamma_rcp)), 1.0f);\n"); + out.Write(" ocol0 = float4(pow(abs(texcol.rgb), float3(gamma_rcp, gamma_rcp, gamma_rcp)), " + "1.0f);\n"); break; default: From 71541c13242ef36e49ee7974d792a9e887c405df Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 7 Jul 2022 13:54:31 -0700 Subject: [PATCH 2/3] VideoCommon: Fix D3D shader warning X4000 (uninitialized variables) Initialize alpha_A and alpha_B. They were previously only initialized in cases where they were used, but D3D isn't able to figure that out. --- Source/Core/VideoCommon/UberShaderPixel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/UberShaderPixel.cpp b/Source/Core/VideoCommon/UberShaderPixel.cpp index a96b15c83d..67f7ce5524 100644 --- a/Source/Core/VideoCommon/UberShaderPixel.cpp +++ b/Source/Core/VideoCommon/UberShaderPixel.cpp @@ -889,8 +889,8 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config, out.Write( " uint alpha_compare_op = alpha_scale << 1 | uint(alpha_op);\n" "\n" - " int alpha_A;\n" - " int alpha_B;\n" + " int alpha_A = 0;\n" + " int alpha_B = 0;\n" " if (alpha_bias != 3u || alpha_compare_op > 5u) {{\n" " // Small optimisation here: alpha_A and alpha_B are unused by compare ops 0-5\n" " alpha_A = selectAlphaInput(s, ss, {0}colors_0, {0}colors_1, alpha_a) & 255;\n" From e1e0f42b37dd7f2343b9df99222f32ae56963456 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 7 Jul 2022 17:00:21 -0700 Subject: [PATCH 3/3] VideoCommon: Fix D3D shader warning X3557 (single iteration loop) Fix warning "loop only executes for 1 iteration(s), forcing loop to unroll" when vertex_in == 1 --- Source/Core/VideoCommon/GeometryShaderGen.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/GeometryShaderGen.cpp b/Source/Core/VideoCommon/GeometryShaderGen.cpp index 150354e4f3..b9ec0786b2 100644 --- a/Source/Core/VideoCommon/GeometryShaderGen.cpp +++ b/Source/Core/VideoCommon/GeometryShaderGen.cpp @@ -216,7 +216,11 @@ ShaderCode GenerateGeometryShaderCode(APIType api_type, const ShaderHostConfig& if (wireframe) out.Write("\tVS_OUTPUT first;\n"); - out.Write("\tfor (int i = 0; i < {}; ++i) {{\n", vertex_in); + // Avoid D3D warning about forced unrolling of single-iteration loop + if (vertex_in > 1) + out.Write("\tfor (int i = 0; i < {}; ++i) {{\n", vertex_in); + else + out.Write("\tint i = 0;\n"); if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) { @@ -307,7 +311,9 @@ ShaderCode GenerateGeometryShaderCode(APIType api_type, const ShaderHostConfig& EmitVertex(out, host_config, uid_data, "f", api_type, wireframe, stereo, true); } - out.Write("\t}}\n"); + // Only close loop if previous code was in one (See D3D warning above) + if (vertex_in > 1) + out.Write("\t}}\n"); EndPrimitive(out, host_config, uid_data, api_type, wireframe, stereo);