From fc26cff30ff132d862e635722da16617b3c89183 Mon Sep 17 00:00:00 2001 From: SamG-Coder <13449963+SamG-Coder@users.noreply.github.com> Date: Sun, 27 Sep 2026 09:00:03 +1000 Subject: [PATCH] test(shader): cover decoded buffer address operands --- core/libs/CMakeLists.txt | 8 +++++ core/libs/tests/ShaderBufferAddress.cpp | 42 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 core/libs/tests/ShaderBufferAddress.cpp diff --git a/core/libs/CMakeLists.txt b/core/libs/CMakeLists.txt index d97236260..3374519ba 100644 --- a/core/libs/CMakeLists.txt +++ b/core/libs/CMakeLists.txt @@ -137,6 +137,14 @@ if(BUILD_TESTING) "PATH=path_list_prepend:$") endif() add_executable(guest_indexed_draw_tests tests/GuestIndexedDraw.cpp) + add_executable(shader_buffer_address_tests tests/ShaderBufferAddress.cpp) + target_link_libraries(shader_buffer_address_tests PRIVATE shader_recompiler_agc_driver libc) + configure_windows_unwind(shader_buffer_address_tests) + add_test(NAME shader_buffer_address COMMAND shader_buffer_address_tests) + if(WIN32) + set_tests_properties(shader_buffer_address PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() target_include_directories(guest_indexed_draw_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(guest_indexed_draw_tests PRIVATE libSceAgc libSceAgcDriver libc) configure_windows_unwind(guest_indexed_draw_tests) diff --git a/core/libs/tests/ShaderBufferAddress.cpp b/core/libs/tests/ShaderBufferAddress.cpp new file mode 100644 index 000000000..8062fb67d --- /dev/null +++ b/core/libs/tests/ShaderBufferAddress.cpp @@ -0,0 +1,42 @@ +#include "Translation/TranslationContext.hpp" +#include "RdnaDecoder/RdnaMemoryOpDecoder.hpp" +#include +#include + +using namespace ShaderRecompiler; +static void Require(bool value) { if (!value) throw std::runtime_error("buffer address operand regression"); } +static void CheckRegister(IrValue* value, IrOpcode opcode, unsigned index) { + Require(value->Opcode() == opcode); + Require(value->Argument(0)->Register().index == index); +} +static void Check(bool typed, unsigned opcode, IrOpcode expected, bool idxen, bool offen, bool immediate) { + const std::array code{ + (typed ? (0x3au<<26)|(opcode<<16)|(4u<<19) : (0x38u<<26)|(opcode<<18)) + | (unsigned(idxen)<<13)|(unsigned(offen)<<12)|12u, + ((immediate?128u:20u)<<24)|(2u<<16)|(4u<<8)|10u + }; + const auto instruction = typed ? DecodeRdnaMtbuf(0,code,0) : DecodeRdnaMubuf(0,code,0); + IrProgram program; + auto& block=program.CreateBlock(); + program.SetEntryBlock(block); + TranslationContext context(program,block,256); + context.TranslateInstruction(instruction); + IrValue* memory=nullptr; + for(auto* value:block.Instructions()) if(value->Opcode()==expected) memory=value; + Require(memory!=nullptr); + if(idxen) CheckRegister(memory->Argument(1),IrOpcode::GetVectorRegister,10); + else Require(memory->Argument(1)->HasImmediate() && memory->Argument(1)->ImmediateU32()==0); + if(offen) CheckRegister(memory->Argument(2),IrOpcode::GetVectorRegister,idxen?11:10); + else Require(memory->Argument(2)->HasImmediate() && memory->Argument(2)->ImmediateU32()==0); + if(immediate) Require(memory->Argument(3)->HasImmediate() && memory->Argument(3)->ImmediateU32()==0); + else CheckRegister(memory->Argument(3),IrOpcode::GetScalarRegister,20); +} +int main() { + for(bool idxen:{false,true}) for(bool offen:{false,true}) for(bool immediate:{false,true}) { + Check(false,0x0c,IrOpcode::LoadBufferU32,idxen,offen,immediate); + Check(false,0x1c,IrOpcode::StoreBufferU32,idxen,offen,immediate); + Check(false,0x32,IrOpcode::BufferAtomicIAdd32,idxen,offen,immediate); + Check(true,0,IrOpcode::LoadBufferU32,idxen,offen,immediate); + Check(true,4,IrOpcode::StoreBufferU32,idxen,offen,immediate); + } +}