From 9ceedb540940a47ab6c4b290d4c355643cdf043d Mon Sep 17 00:00:00 2001 From: mjnhbg3 <2287071+mjnhbg3@users.noreply.github.com> Date: Wed, 25 Nov 2026 23:46:02 -0500 Subject: [PATCH] fix(kyty): reject invalid image LOD and compute exports --- .../recompiler/frontend/translate/Attribute.cpp | 8 +++++++- .../recompiler/frontend/translate/Memory.cpp | 3 +++ .../KytyShim/tests/RecompilerRobustness.cpp | 14 +++++++++++++- .../debt/changes/fix-kyty-spirv-execution-model.md | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 docs/dev/debt/changes/fix-kyty-spirv-execution-model.md diff --git a/core/kyty/graphics/shader/recompiler/frontend/translate/Attribute.cpp b/core/kyty/graphics/shader/recompiler/frontend/translate/Attribute.cpp index 3a7301a14f9..6ca10f48d92 100644 --- a/core/kyty/graphics/shader/recompiler/frontend/translate/Attribute.cpp +++ b/core/kyty/graphics/shader/recompiler/frontend/translate/Attribute.cpp @@ -96,9 +96,15 @@ void Translator::V_INTERP_MOV_F32(const Decoder::Instruction& inst) { void Translator::EXP(const Decoder::Instruction& inst) { uint32_t index = 0; - if (ExportTargetKindFromTarget(inst.exp.target, index) == IR::ExportTargetKind::Unknown) { + const auto kind = ExportTargetKindFromTarget(inst.exp.target, index); + if (kind == IR::ExportTargetKind::Unknown) { EXIT("unsupported EXP target 0x%02x at pc 0x%08x", inst.exp.target, inst.pc); } + if (program.stage == ShaderType::Compute && inst.exp.en != 0u && + kind != IR::ExportTargetKind::Null) { + EXIT("EXP target 0x%02x is not valid in a compute shader at pc 0x%08x", + inst.exp.target, inst.pc); + } std::array components {IR::Value(0u), IR::Value(0u), IR::Value(0u), IR::Value(0u)}; for (uint32_t source = 0; source < std::min(inst.src_count, 4u); source++) { diff --git a/core/kyty/graphics/shader/recompiler/frontend/translate/Memory.cpp b/core/kyty/graphics/shader/recompiler/frontend/translate/Memory.cpp index d152d2b2e18..4490f841a0d 100644 --- a/core/kyty/graphics/shader/recompiler/frontend/translate/Memory.cpp +++ b/core/kyty/graphics/shader/recompiler/frontend/translate/Memory.cpp @@ -647,6 +647,9 @@ void Translator::IMAGE_GET_RESINFO(const Decoder::Instruction& inst) { } void Translator::IMAGE_GET_LOD(const Decoder::Instruction& inst) { + if (program.stage != ShaderType::Pixel && program.stage != ShaderType::Compute) { + EXIT("image_get_lod requires a pixel or compute shader at pc 0x%08x", inst.pc); + } const auto memory = MemoryInfoFromDecoded(inst); const auto resource = GetImageResource(memory); const auto sampler = GetSamplerResource(memory); diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp index 501bcf19940..ad06d263f04 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp @@ -24,6 +24,12 @@ const std::vector Cases = { {"empty-program-end", 0x00, 0x00, {0xbf810000u}}, {"lds-atomic-in-a-pixel-shader", 0x04, 0x00, {0xd8000000u, 0x00000100u, 0xbf810000u}}, {"lds-umin-in-a-vertex-shader", 0x03, 0x00, {0xd8070000u, 0x00000100u, 0xbf810000u}}, + {"image-get-lod-in-a-pixel-shader", 0x04, 0x00, + {0xf1800108u, 0x00400400u, 0xf8000801u, 0x00000004u, 0xbf810000u}}, + {"null-export-in-a-compute-shader", 0x00, 0x00, + {0xf8000891u, 0x03020100u, 0xbf810000u}}, + {"disabled-parameter-export-in-a-compute-shader", 0x00, 0x00, + {0xf8000a00u, 0x03020100u, 0xbf810000u}}, }; struct Refusal { @@ -43,13 +49,19 @@ const std::vector Refusals = { {"position-export-from-a-pixel-shader", 0x04, 0x00, {0xf80008cfu, 0x03020100u, 0xbf810000u}, "position export outside a vertex processing stage"}, {"position-export-from-a-compute-shader", 0x00, 0x00, {0xf80008cfu, 0x03020100u, 0xbf810000u}, - "position export outside a vertex processing stage"}, + "not valid in a compute shader"}, + {"parameter-export-from-a-compute-shader", 0x00, 0x00, + {0xf8000a01u, 0x03020100u, 0xbf810000u}, + "not valid in a compute shader"}, {"depth-compare-sample-on-a-3d-image", 0x04, 0x00, {0xf0a00110u, 0x00400400u, 0xf8000801u, 0x00000004u, 0xbf810000u}, "depth comparison with a 3D image"}, {"depth-compare-sample-on-a-multisampled-image", 0x04, 0x00, {0xf0a00130u, 0x00400400u, 0xf8000801u, 0x00000004u, 0xbf810000u}, "samples a multisampled image"}, {"sample-on-a-multisampled-image", 0x04, 0x00, {0xf0800130u, 0x00400400u, 0xf8000801u, 0x00000004u, 0xbf810000u}, "samples a multisampled image"}, + {"image-get-lod-in-a-vertex-shader", 0x03, 0x00, + {0xf1800308u, 0x00820000u, 0xf80008cfu, 0x03020100u, 0xbf810000u}, + "image_get_lod requires a pixel or compute shader"}, }; struct ModeWrite { diff --git a/docs/dev/debt/changes/fix-kyty-spirv-execution-model.md b/docs/dev/debt/changes/fix-kyty-spirv-execution-model.md new file mode 100644 index 00000000000..1f7905bbe34 --- /dev/null +++ b/docs/dev/debt/changes/fix-kyty-spirv-execution-model.md @@ -0,0 +1,6 @@ +# kyty + +## add Functional + +- [IMAGE_GET_LOD](../../../core/kyty/graphics/shader/recompiler/frontend/translate/Memory.cpp) is refused outside pixel and compute shaders because its current lowering emits `OpImageQueryLod`, which is invalid in vertex, local and tessellation execution models. Mesh also lacks the derivative-group execution mode that `OpImageQueryLod` requires. Closes when these stages have a validated alternative lowering or, for mesh, a valid derivative mode and coverage. +- [EXP](../../../core/kyty/graphics/shader/recompiler/frontend/translate/Attribute.cpp) with enabled components and a non-null target is refused in compute shaders. A parameter export otherwise creates an `Output` storage variable, which Vulkan forbids in `GLCompute`; other live export targets lack a compute output contract. Null and disabled exports retain their no-output behavior. Closes when a valid compute-stage meaning is established and its lowering passes SPIR-V validation.