Merge pull request #895 from Kikoarl/feat/s-call-b64

feat(shader): implement S_CALL_B64
This commit is contained in:
Adrià
2026-10-08 19:24:59 +02:00
committed by GitHub
5 changed files with 88 additions and 1 deletions
@@ -902,6 +902,14 @@ if(BUILD_TESTING)
set_tests_properties(scalar_scratch_load PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test_executable(scalar_call_tests ${LIBS_INCLUDE_DIR}/tests/ScalarCall.cpp)
target_link_libraries(scalar_call_tests PRIVATE shader_recompiler_agc_driver libc)
configure_windows_unwind(scalar_call_tests)
add_test(NAME scalar_call COMMAND scalar_call_tests)
if(WIN32)
set_tests_properties(scalar_call PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test_executable(image_sample_gather_tests ${LIBS_INCLUDE_DIR}/tests/ImageSampleGather.cpp)
target_link_libraries(image_sample_gather_tests PRIVATE shader_recompiler_agc_driver libc)
configure_windows_unwind(image_sample_gather_tests)
+73
View File
@@ -0,0 +1,73 @@
#include "Translation/TranslationContext.hpp"
#include "Translation/InstructionTranslator.hpp"
#include "RdnaDecoder/RdnaScalarOpDecoder.hpp"
#include "RdnaDecoder/RdnaInstructionDecoder.hpp"
#include "ControlFlow/GraphBuilder.hpp"
#include <array>
#include <stdexcept>
#include <string>
#include <vector>
using namespace ShaderRecompiler;
static void Require(bool value) { if (!value) throw std::runtime_error("scalar call regression"); }
static void CheckDecodeAndBranch() {
const std::array<std::uint32_t, 1> code{0xbb040008u};
const RdnaInstruction instruction = DecodeRdnaSopk(0u, code, 0u);
Require(instruction.op == RdnaOpcode::SCallB64);
Require(instruction.family == RdnaInstructionFamily::SOPK);
Require(instruction.destination.kind == RdnaOperandKind::ScalarRegister);
Require(instruction.destination.reg == 4u);
Require(instruction.dataDwordCount == 2u);
Require(instruction.branchTarget == 36u);
}
static void CheckNegativeOffset() {
const std::uint32_t word = 0xb8000000u | (0x16u << 23u) | (2u << 16u) | static_cast<std::uint16_t>(-4);
const std::array<std::uint32_t, 1> code{word};
const RdnaInstruction instruction = DecodeRdnaSopk(16u, code, 0u);
Require(instruction.op == RdnaOpcode::SCallB64);
Require(instruction.destination.reg == 2u);
Require(instruction.branchTarget == 4u);
}
static void CheckTranslationThrows() {
const std::array<std::uint32_t, 1> code{0xbb040008u};
const RdnaInstruction instruction = DecodeRdnaSopk(0u, code, 0u);
IrProgram program;
auto& block = program.CreateBlock();
program.SetEntryBlock(block);
TranslationContext context(program, block, 256);
bool threw = false;
try {
context.TranslateInstruction(instruction);
} catch (const std::runtime_error&) {
threw = true;
}
Require(threw);
}
static void CheckProgramGraphBuilderAndTranslationThrows() {
const std::vector<std::uint32_t> code{0xbb040001u, 0xbf810000u, 0xbf810000u};
const auto decoded = RdnaInstructionDecoder{}.Decode(code);
const auto cfg = GraphBuilder{}.Build(decoded);
ShaderComputeInputInfo computeInfo{};
TranslateOptions options{};
options.stage = ShaderStageKind::Compute;
options.inputInfo.compute = &computeInfo;
bool threw = false;
try {
static_cast<void>(InstructionTranslator{}.Translate(decoded, cfg, options));
} catch (const std::runtime_error& err) {
threw = std::string(err.what()).find("s_call_b64 at pc 0 is not implemented") != std::string::npos;
}
Require(threw);
}
int main() {
CheckDecodeAndBranch();
CheckNegativeOffset();
CheckTranslationThrows();
CheckProgramGraphBuilderAndTranslationThrows();
return 0;
}
@@ -203,6 +203,7 @@ enum class RdnaOpcode : std::uint16_t {
SMovrelsd2B32,
SQuadmaskB64,
SGetpcB64,
SCallB64,
SSubvectorLoopBegin,
SSubvectorLoopEnd,
SAndSaveexecB32,
@@ -180,6 +180,7 @@ RdnaOpcode decodeSopkOpcode(std::uint32_t opcode) {
case 0x12u: return RdnaOpcode::SGetregB32;
case 0x13u: return RdnaOpcode::SSetregB32;
case 0x15u: return RdnaOpcode::SSetregImm32B32;
case 0x16u: return RdnaOpcode::SCallB64;
case 0x17u: return RdnaOpcode::SWaitcnt;
case 0x18u: return RdnaOpcode::SWaitcnt;
case 0x19u: return RdnaOpcode::SWaitcnt;
@@ -290,6 +291,7 @@ std::uint32_t scalarDestinationDwordCount(RdnaOpcode opcode) {
case RdnaOpcode::SLshlB64:
case RdnaOpcode::SLshrB64:
case RdnaOpcode::SBfmB64:
case RdnaOpcode::SCallB64:
case RdnaOpcode::SBfeU64: return 2u;
default: return 1u;
}
@@ -416,8 +418,9 @@ RdnaInstruction DecodeRdnaSopk(std::uint32_t programCounter, std::span<const std
instruction.destination = DecodeRdnaScalarDestination(scalarRegister, programCounter);
return instruction;
}
if (instruction.op == RdnaOpcode::SSubvectorLoopBegin || instruction.op == RdnaOpcode::SSubvectorLoopEnd) {
if (instruction.op == RdnaOpcode::SSubvectorLoopBegin || instruction.op == RdnaOpcode::SSubvectorLoopEnd || instruction.op == RdnaOpcode::SCallB64) {
instruction.destination = DecodeRdnaScalarDestination(scalarRegister, programCounter);
instruction.dataDwordCount = scalarDestinationDwordCount(instruction.op);
instruction.branchTarget = programCounter + 4u + static_cast<std::uint32_t>(immediate * 4);
return instruction;
}
@@ -29,6 +29,8 @@ bool TranslationContext::emitScalar(const RdnaInstruction& inst) {
return true;
case RdnaOpcode::SSetpcB64:
return true;
case RdnaOpcode::SCallB64:
throw std::runtime_error("s_call_b64 at pc " + std::to_string(inst.programCounter) + " is not implemented");
case RdnaOpcode::SSubvectorLoopBegin:
sSubvectorLoop(inst, true);
return true;