From b1722c06e38675ed4877bb36a76327bc409f3ae3 Mon Sep 17 00:00:00 2001 From: boykopovar Date: Wed, 23 Sep 2026 13:57:22 +0300 Subject: [PATCH] fix(shader): avoid mixing ir block ids with metadata indices --- README.md | 12 +++---- .../SpirvBackend/src/SpirvFlowEmitter.cpp | 32 ++++++++++++++----- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7d5be45f3..ac9e59a0c 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ Releases will be published after the first full successful launch of at least on ## Status -Execution reaches `_start`, stack unwinding and exception handling tables are built. All unimplemented functions throw std::runtime_error. `what()` is printed to stderr and the process terminates. -Audio output and video output initialization pass. -Reaches the `main` function with render loop (deep call chain, ~64KB stack frame function) - init and shader loading from disk fully complete. +Execution reaches `_start`, [stack unwinding](core/libs/prx/libc/src/exception/Unwind.cpp) and exception handling tables are built, reaches main. Unsupported or unexpected states strictly throw `std::runtime_error`. `what()` is printed to stderr and the process terminates. -A standalone [SPIR-V triangle test](core/libs/prx/libSceAgcDriver/tests/Visual.cpp) passes GPU readback checks and presents a frame through the [libSceAgcDriver](core/libs/prx/libSceAgcDriver). -The [shader recompiler](core/shader/recompiler/Recompiler.cpp) successfully produces validated via [Spirv-Tools](3rdparty/SPIRV-Tools) SPIR-V. The first application draw currently stops in [libSceAgcDriver](core/libs/prx/libSceAgcDriver), where support for shaders using textures is not implemented. +The [shader recompiler](core/shader/recompiler/Recompiler.cpp) successfully produces validated via [Spirv-Tools](3rdparty/SPIRV-Tools) SPIR-V. + +The application reaches the render loop and **successfully presents its first frame**: the application logo is visible on screen. + +Current exception: `AGC graphics: unsupported primitive type 17`. -Now: `libSceAgcDriver: TextureDetiler not implemented`. ## Build diff --git a/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp b/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp index 3aa9a1058..52773a7d5 100644 --- a/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp +++ b/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp @@ -33,21 +33,37 @@ void EmitKillIfPixelValidMaskInactive(SpirvEmitterState& state) { } const IrBlock* TargetBlock(const IrProgram& program, std::uint32_t id) { - for (const IrBlock* block : program.BlockOrder()) { - if (block != nullptr && block->Id() == id) { - return block; + const auto& blocks = program.BlockOrder(); + const auto& blockInfo = program.Metadata().blockInfo; + if (blocks.size() != blockInfo.size()) { + throw std::runtime_error("SPIR-V control flow block metadata is inconsistent"); + } + for (std::size_t index = 0; index < blockInfo.size(); index++) { + if (blockInfo[index].id == id) { + if (blocks[index] == nullptr) { + throw std::runtime_error("SPIR-V control flow target block is null"); + } + return blocks[index]; } } - return nullptr; + throw std::runtime_error("SPIR-V control flow target block is missing"); } const BlockInfo* BlockInfoFor(const IrProgram& program, const IrBlock* block) { - for (const BlockInfo& info : program.Metadata().blockInfo) { - if (info.id == block->Id()) { - return &info; + const auto& blocks = program.BlockOrder(); + const auto& blockInfo = program.Metadata().blockInfo; + if (blocks.size() != blockInfo.size()) { + throw std::runtime_error("SPIR-V control flow block metadata is inconsistent"); + } + if (block == nullptr) { + throw std::runtime_error("SPIR-V control flow block is null"); + } + for (std::size_t index = 0; index < blocks.size(); index++) { + if (blocks[index] == block) { + return &blockInfo[index]; } } - return nullptr; + throw std::runtime_error("SPIR-V control flow block has no metadata"); } void EmitReturnTerminator(SpirvValueEmitContext& ctx) {