test(shader): cover decoded buffer address operands

This commit is contained in:
SamG-Coder
2026-09-27 09:00:03 +10:00
parent b25025c682
commit fc26cff30f
2 changed files with 50 additions and 0 deletions
+8
View File
@@ -137,6 +137,14 @@ if(BUILD_TESTING)
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
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:$<TARGET_FILE_DIR:libc>")
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)
+42
View File
@@ -0,0 +1,42 @@
#include "Translation/TranslationContext.hpp"
#include "RdnaDecoder/RdnaMemoryOpDecoder.hpp"
#include <array>
#include <stdexcept>
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<std::uint32_t,2> 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);
}
}