From 8b72b4b6141dd509e113d6f6c821eefd0a21fc62 Mon Sep 17 00:00:00 2001 From: Jarrod Norwell Date: Sat, 23 Mar 2024 17:09:20 +0800 Subject: [PATCH] Added SR_WScaleFactorXY stubs for all rendering backends in preparation for a Prince of Persia issue fix --- src/android/build.gradle.kts | 4 +-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../glasm/emit_glasm_context_get_set.cpp | 30 +++++-------------- .../backend/glasm/emit_glasm_instructions.h | 1 + .../glsl/emit_glsl_context_get_set.cpp | 30 +++++-------------- .../backend/glsl/emit_glsl_instructions.h | 1 + .../spirv/emit_spirv_context_get_set.cpp | 30 +++++-------------- .../backend/spirv/emit_spirv_instructions.h | 1 + .../frontend/ir/ir_emitter.cpp | 4 +++ .../frontend/ir/ir_emitter.h | 1 + src/shader_recompiler/frontend/ir/opcodes.inc | 1 + .../translate/impl/move_special_register.cpp | 2 +- src/shader_recompiler/runtime_info.h | 18 +++++++++++ 13 files changed, 52 insertions(+), 73 deletions(-) diff --git a/src/android/build.gradle.kts b/src/android/build.gradle.kts index 7d7c2c3..0a45976 100644 --- a/src/android/build.gradle.kts +++ b/src/android/build.gradle.kts @@ -3,8 +3,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id("com.android.application") version "8.1.2" apply false - id("com.android.library") version "8.1.2" apply false + id("com.android.application") version "8.3.0" apply false + id("com.android.library") version "8.3.0" apply false id("org.jetbrains.kotlin.android") version "1.9.20" apply false } diff --git a/src/android/gradle/wrapper/gradle-wrapper.properties b/src/android/gradle/wrapper/gradle-wrapper.properties index 578c71b..42b415f 100644 --- a/src/android/gradle/wrapper/gradle-wrapper.properties +++ b/src/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp index 6645699..c27f2e3 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp @@ -406,30 +406,10 @@ void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) { case Stage::TessellationEval: ctx.Add("SHL.U {}.x,primitive.vertexcount,16;", inst); break; - case Stage::Geometry: { - u32 vertices_count = 0; - switch (ctx.runtime_info.input_topology) { - case InputTopology::Lines: - vertices_count = 2; - break; - case InputTopology::LinesAdjacency: - vertices_count = 4; - break; - case InputTopology::Triangles: - vertices_count = 3; - break; - case InputTopology::TrianglesAdjacency: - vertices_count = 6; - break; - case InputTopology::Points: - default: - vertices_count = 1; - break; - }; - - ctx.Add("SHL.U {}.x,{},16;", inst, vertices_count); + case Stage::Geometry: + ctx.Add("SHL.U {}.x,{},16;", inst, + InputTopologyVertices::vertices(ctx.runtime_info.input_topology)); break; - } default: LOG_WARNING(Shader, "(STUBBED) called"); ctx.Add("MOV.S {}.x,0x00ff0000;", inst); @@ -444,6 +424,10 @@ void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst) { ctx.Add("MOV.S {}.x,fragment.helperthread.x;", inst); } +void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst) { + LOG_WARNING(Shader, "(STUBBED) called"); +} + void EmitYDirection(EmitContext& ctx, IR::Inst& inst) { ctx.uses_y_direction = true; ctx.Add("MOV.F {}.x,y_direction[0].w;", inst); diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h index 2550282..42ae9b4 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h +++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h @@ -72,6 +72,7 @@ void EmitInvocationId(EmitContext& ctx, IR::Inst& inst); void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst); void EmitSampleId(EmitContext& ctx, IR::Inst& inst); void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst); +void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst); void EmitYDirection(EmitContext& ctx, IR::Inst& inst); void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst); void EmitRenderArea(EmitContext& ctx, IR::Inst& inst); diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp index bacb068..31a7ea1 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp @@ -426,30 +426,10 @@ void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) { case Stage::TessellationEval: ctx.AddU32("{}=uint(gl_PatchVerticesIn)<<16;", inst); break; - case Stage::Geometry: { - u32 vertices_count = 0; - switch (ctx.runtime_info.input_topology) { - case InputTopology::Lines: - vertices_count = 2; - break; - case InputTopology::LinesAdjacency: - vertices_count = 4; - break; - case InputTopology::Triangles: - vertices_count = 3; - break; - case InputTopology::TrianglesAdjacency: - vertices_count = 6; - break; - case InputTopology::Points: - default: - vertices_count = 1; - break; - }; - - ctx.AddU32("{}=uint({});", inst, vertices_count << 16); + case Stage::Geometry: + ctx.AddU32("{}=uint({}<<16);", inst, + InputTopologyVertices::vertices(ctx.runtime_info.input_topology)); break; - } default: LOG_WARNING(Shader, "(STUBBED) called"); ctx.AddU32("{}=uint(0x00ff0000);", inst); @@ -464,6 +444,10 @@ void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst) { ctx.AddU1("{}=gl_HelperInvocation;", inst); } +void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst) { + LOG_WARNING(Shader, "(STUBBED) called"); +} + void EmitYDirection(EmitContext& ctx, IR::Inst& inst) { ctx.uses_y_direction = true; ctx.AddF32("{}=gl_FrontMaterial.ambient.a;", inst); diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index 5d2b1f3..8e135c2 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h @@ -86,6 +86,7 @@ void EmitInvocationId(EmitContext& ctx, IR::Inst& inst); void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst); void EmitSampleId(EmitContext& ctx, IR::Inst& inst); void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst); +void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst); void EmitYDirection(EmitContext& ctx, IR::Inst& inst); void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst); void EmitRenderArea(EmitContext& ctx, IR::Inst& inst); diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 5af3a3d..39cc401 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp @@ -549,29 +549,8 @@ Id EmitInvocationInfo(EmitContext& ctx) { case Stage::TessellationEval: return ctx.OpShiftLeftLogical(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.patch_vertices_in), ctx.Const(16u)); - case Stage::Geometry: { - u32 vertices_count = 0; - switch (ctx.runtime_info.input_topology) { - case InputTopology::Lines: - vertices_count = 2; - break; - case InputTopology::LinesAdjacency: - vertices_count = 4; - break; - case InputTopology::Triangles: - vertices_count = 3; - break; - case InputTopology::TrianglesAdjacency: - vertices_count = 6; - break; - case InputTopology::Points: - default: - vertices_count = 1; - break; - }; - - return ctx.Const(vertices_count << 16); - } + case Stage::Geometry: + return ctx.Const(InputTopologyVertices::vertices(ctx.runtime_info.input_topology) << 16); default: LOG_WARNING(Shader, "(STUBBED) called"); return ctx.Const(0x00ff0000u); @@ -586,6 +565,11 @@ Id EmitIsHelperInvocation(EmitContext& ctx) { return ctx.OpLoad(ctx.U1, ctx.is_helper_invocation); } +Id EmitSR_WScaleFactorXY(EmitContext& ctx) { + LOG_WARNING(Shader, "(STUBBED) called"); + return ctx.Const(0x00ff0000u); +} + Id EmitYDirection(EmitContext& ctx) { return ctx.Const(ctx.runtime_info.y_negate ? -1.0f : 1.0f); } diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index f8b049a..05cda37 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h @@ -75,6 +75,7 @@ Id EmitInvocationId(EmitContext& ctx); Id EmitInvocationInfo(EmitContext& ctx); Id EmitSampleId(EmitContext& ctx); Id EmitIsHelperInvocation(EmitContext& ctx); +Id EmitSR_WScaleFactorXY(EmitContext& ctx); Id EmitYDirection(EmitContext& ctx); Id EmitResolutionDownFactor(EmitContext& ctx); Id EmitRenderArea(EmitContext& ctx); diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index 8361a48..ba81c6b 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp @@ -382,6 +382,10 @@ U1 IREmitter::IsHelperInvocation() { return Inst(Opcode::IsHelperInvocation); } +U32 IREmitter::SR_WScaleFactorXY() { + return Inst(Opcode::SR_WScaleFactorXY); +} + F32 IREmitter::YDirection() { return Inst(Opcode::YDirection); } diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index cc93408..736bea8 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h @@ -102,6 +102,7 @@ public: [[nodiscard]] U32 InvocationInfo(); [[nodiscard]] U32 SampleId(); [[nodiscard]] U1 IsHelperInvocation(); + [[nodiscard]] U32 SR_WScaleFactorXY(); [[nodiscard]] F32 YDirection(); [[nodiscard]] F32 ResolutionDownFactor(); diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index 24843ad..1b368dc 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc @@ -62,6 +62,7 @@ OPCODE(InvocationId, U32, OPCODE(InvocationInfo, U32, ) OPCODE(SampleId, U32, ) OPCODE(IsHelperInvocation, U1, ) +OPCODE(SR_WScaleFactorXY, U32, ) OPCODE(YDirection, F32, ) OPCODE(ResolutionDownFactor, F32, ) OPCODE(RenderArea, F32x4, ) diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/move_special_register.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/move_special_register.cpp index 3ff88f3..c48ac77 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/move_special_register.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/move_special_register.cpp @@ -139,7 +139,7 @@ enum class SpecialRegister : u64 { return ir.WorkgroupIdZ(); case SpecialRegister::SR_WSCALEFACTOR_XY: LOG_WARNING(Shader, "(STUBBED) SR_WSCALEFACTOR_XY"); - return ir.Imm32(Common::BitCast(1.0f)); + return ir.SR_WScaleFactorXY(); case SpecialRegister::SR_WSCALEFACTOR_Z: LOG_WARNING(Shader, "(STUBBED) SR_WSCALEFACTOR_Z"); return ir.Imm32(Common::BitCast(1.0f)); diff --git a/src/shader_recompiler/runtime_info.h b/src/shader_recompiler/runtime_info.h index e851ca7..500da5a 100644 --- a/src/shader_recompiler/runtime_info.h +++ b/src/shader_recompiler/runtime_info.h @@ -30,6 +30,24 @@ enum class InputTopology { TrianglesAdjacency, }; +struct InputTopologyVertices { + static u32 vertices(InputTopology input_topology) { + switch (input_topology) { + case InputTopology::Lines: + return 2; + case InputTopology::LinesAdjacency: + return 4; + case InputTopology::Triangles: + return 3; + case InputTopology::TrianglesAdjacency: + return 6; + case InputTopology::Points: + default: + return 1; + } + } +}; + enum class CompareFunction { Never, Less,