From aa3215db655c421ee41c830d13b429a436b2b32c Mon Sep 17 00:00:00 2001 From: Maufeat Date: Tue, 22 Jul 2025 15:22:53 +0200 Subject: [PATCH 1/5] reverts 9f4ef30b55 & 44dc152a2b --- .../glasm/emit_glasm_context_get_set.cpp | 62 +++++++++++++++---- .../backend/glasm/emit_glasm_instructions.h | 2 - .../backend/glsl/emit_glsl_instructions.h | 2 - .../backend/spirv/emit_spirv_instructions.h | 2 - .../frontend/ir/ir_emitter.h | 2 - src/shader_recompiler/frontend/ir/opcodes.inc | 2 - .../translate/impl/move_special_register.cpp | 4 +- src/video_core/dma_pusher.cpp | 6 -- 8 files changed, 51 insertions(+), 31 deletions(-) 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 47babcdc07..a2dd823b6a 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 @@ -6,8 +6,8 @@ #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" #include "shader_recompiler/backend/glasm/glasm_emit_context.h" #include "shader_recompiler/frontend/ir/value.h" -#include "shader_recompiler/runtime_info.h" #include "shader_recompiler/profile.h" +#include "shader_recompiler/runtime_info.h" #include "shader_recompiler/shader_info.h" namespace Shader::Backend::GLASM { @@ -404,16 +404,60 @@ void EmitInvocationId(EmitContext& ctx, IR::Inst& inst) { void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) { switch (ctx.stage) { case Stage::TessellationControl: + ctx.Add("SHL.U {}.x,primitive.vertexcount,16;", inst); + break; case Stage::TessellationEval: ctx.Add("SHL.U {}.x,primitive.vertexcount,16;", inst); break; - case Stage::Geometry: - ctx.Add("SHL.U {}.x,{},16;", inst, - InputTopologyVertices::vertices(ctx.runtime_info.input_topology)); + case Stage::Fragment: + // Return sample mask in upper 16 bits + ctx.Add("SHL.U {}.x,fragment.samplemask,16;", inst); + break; + case Stage::Geometry: { + // Return vertex count in upper 16 bits based on input topology + // Using a lookup table approach for vertex counts + const std::array vertex_counts = { + 1, // Points + 2, // Lines + 4, // LinesAdjacency + 3, // Triangles + 6 // TrianglesAdjacency + }; + + // Map the input topology to an index in our lookup table + u32 topology_index = 0; + switch (ctx.runtime_info.input_topology) { + case Shader::InputTopology::Lines: + topology_index = 1; + break; + case Shader::InputTopology::LinesAdjacency: + topology_index = 2; + break; + case Shader::InputTopology::Triangles: + topology_index = 3; + break; + case Shader::InputTopology::TrianglesAdjacency: + topology_index = 4; + break; + case Shader::InputTopology::Points: + default: + topology_index = 0; + break; + } + + // Get the vertex count from the lookup table and shift it + const u32 result = vertex_counts[topology_index] << 16; + ctx.Add("MOV.S {}.x,0x{:x};", inst, result); + break; + } + case Stage::Compute: + // Return standard format (0x00ff0000) + ctx.Add("MOV.S {}.x,0x00ff0000;", inst); break; default: - LOG_WARNING(Shader, "(STUBBED) called"); + // Return standard format (0x00ff0000) ctx.Add("MOV.S {}.x,0x00ff0000;", inst); + break; } } @@ -425,14 +469,6 @@ 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 EmitSR_WScaleFactorZ(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 c5d4835fa9..1a1ea61d5e 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h +++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h @@ -72,8 +72,6 @@ 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 EmitSR_WScaleFactorZ(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_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index 9e405b37fb..acebaa7851 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h @@ -86,8 +86,6 @@ 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 EmitSR_WScaleFactorZ(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_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index b8e98e6c58..5c01b10127 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h @@ -75,8 +75,6 @@ Id EmitInvocationId(EmitContext& ctx); Id EmitInvocationInfo(EmitContext& ctx); Id EmitSampleId(EmitContext& ctx); Id EmitIsHelperInvocation(EmitContext& ctx); -Id EmitSR_WScaleFactorXY(EmitContext& ctx); -Id EmitSR_WScaleFactorZ(EmitContext& ctx); Id EmitYDirection(EmitContext& ctx); Id EmitResolutionDownFactor(EmitContext& ctx); Id EmitRenderArea(EmitContext& ctx); diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index 073091ea58..6c30897f4e 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h @@ -102,8 +102,6 @@ public: [[nodiscard]] U32 InvocationInfo(); [[nodiscard]] U32 SampleId(); [[nodiscard]] U1 IsHelperInvocation(); - [[nodiscard]] U32 SR_WScaleFactorXY(); - [[nodiscard]] U32 SR_WScaleFactorZ(); [[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 2f880a8596..4447d67b04 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc @@ -62,8 +62,6 @@ OPCODE(InvocationId, U32, OPCODE(InvocationInfo, U32, ) OPCODE(SampleId, U32, ) OPCODE(IsHelperInvocation, U1, ) -OPCODE(SR_WScaleFactorXY, U32, ) -OPCODE(SR_WScaleFactorZ, 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 b9b8671b07..e593132e61 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,10 +139,10 @@ enum class SpecialRegister : u64 { return ir.WorkgroupIdZ(); case SpecialRegister::SR_WSCALEFACTOR_XY: LOG_WARNING(Shader, "(STUBBED) SR_WSCALEFACTOR_XY"); - return ir.SR_WScaleFactorXY(); + return ir.Imm32(Common::BitCast(1.0f)); case SpecialRegister::SR_WSCALEFACTOR_Z: LOG_WARNING(Shader, "(STUBBED) SR_WSCALEFACTOR_Z"); - return ir.SR_WScaleFactorZ(); + return ir.Imm32(Common::BitCast(1.0f)); case SpecialRegister::SR_LANEID: return ir.LaneId(); case SpecialRegister::SR_EQMASK: diff --git a/src/video_core/dma_pusher.cpp b/src/video_core/dma_pusher.cpp index 401329eea0..aaacccfa90 100644 --- a/src/video_core/dma_pusher.cpp +++ b/src/video_core/dma_pusher.cpp @@ -15,12 +15,6 @@ namespace Tegra { constexpr u32 MacroRegistersStart = 0xE00; constexpr u32 ComputeInline = 0x6D; -//start on PR#76 of Eden this is a unused variable in android (need to investigate) - -// Dummy function that uses ComputeInline -constexpr void UseComputeInline() { - static_cast(ComputeInline); // Suppress unused variable error -} DmaPusher::DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_, Control::ChannelState& channel_state_) From c175e56a3970847635b13fc3bc952637e277efa9 Mon Sep 17 00:00:00 2001 From: Maufeat Date: Tue, 22 Jul 2025 15:37:24 +0200 Subject: [PATCH 2/5] ups, fix the ir scalefactor thing --- src/shader_recompiler/frontend/ir/ir_emitter.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index e1e46cb81c..49171c470c 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp @@ -382,14 +382,6 @@ U1 IREmitter::IsHelperInvocation() { return Inst(Opcode::IsHelperInvocation); } -U32 IREmitter::SR_WScaleFactorXY() { - return Inst(Opcode::SR_WScaleFactorXY); -} - -U32 IREmitter::SR_WScaleFactorZ() { - return Inst(Opcode::SR_WScaleFactorZ); -} - F32 IREmitter::YDirection() { return Inst(Opcode::YDirection); } From dda2364eddb244e23e6f98e6aab671a3deb90372 Mon Sep 17 00:00:00 2001 From: Maufeat Date: Tue, 22 Jul 2025 20:33:53 +0200 Subject: [PATCH 3/5] i forgot to hit save... --- .../backend/glsl/emit_glsl_context_get_set.cpp | 8 -------- 1 file changed, 8 deletions(-) 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 ffe5cd116c..f964c25507 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 @@ -444,14 +444,6 @@ 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 EmitSR_WScaleFactorZ(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); From b85708da0142b5f2b35e56faea744a1f83ecfec4 Mon Sep 17 00:00:00 2001 From: Maufeat Date: Tue, 22 Jul 2025 21:23:29 +0200 Subject: [PATCH 4/5] man... --- .../backend/spirv/emit_spirv_context_get_set.cpp | 10 ---------- 1 file changed, 10 deletions(-) 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 5dab8b62ea..d8e0c78421 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 @@ -573,16 +573,6 @@ 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 EmitSR_WScaleFactorZ(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); } From 0ce6371f279fbab173a1a89208b5acea264d6808 Mon Sep 17 00:00:00 2001 From: Maufeat Date: Tue, 22 Jul 2025 21:45:40 +0200 Subject: [PATCH 5/5] sadge unused wariable errors --- src/video_core/dma_pusher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/dma_pusher.cpp b/src/video_core/dma_pusher.cpp index aaacccfa90..24f9002aa5 100644 --- a/src/video_core/dma_pusher.cpp +++ b/src/video_core/dma_pusher.cpp @@ -14,7 +14,7 @@ namespace Tegra { constexpr u32 MacroRegistersStart = 0xE00; -constexpr u32 ComputeInline = 0x6D; +//constexpr u32 ComputeInline = 0x6D; DmaPusher::DmaPusher(Core::System& system_, GPU& gpu_, MemoryManager& memory_manager_, Control::ChannelState& channel_state_)