From e1e0f42b37dd7f2343b9df99222f32ae56963456 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 7 Jul 2022 17:00:21 -0700 Subject: [PATCH] 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);