diff --git a/core/libs/CMakeLists.txt b/core/libs/CMakeLists.txt index b82185b3a..d13244ed9 100644 --- a/core/libs/CMakeLists.txt +++ b/core/libs/CMakeLists.txt @@ -186,6 +186,14 @@ if(BUILD_TESTING) set_tests_properties(shader_buffer_address PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") endif() + add_executable(ray_tracing_miss_tests tests/RayTracingMiss.cpp) + target_link_libraries(ray_tracing_miss_tests PRIVATE shader_recompiler_agc_driver libc) + configure_windows_unwind(ray_tracing_miss_tests) + add_test(NAME ray_tracing_miss COMMAND ray_tracing_miss_tests) + if(WIN32) + set_tests_properties(ray_tracing_miss 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/RayTracingMiss.cpp b/core/libs/tests/RayTracingMiss.cpp new file mode 100644 index 000000000..a755da1eb --- /dev/null +++ b/core/libs/tests/RayTracingMiss.cpp @@ -0,0 +1,30 @@ +#include "Translation/TranslationContext.hpp" +#include "RdnaDecoder/RdnaImageOpDecoder.hpp" +#include "Recompiler.hpp" +#include +#include + +using namespace ShaderRecompiler; +static void Require(bool value) { if (!value) throw std::runtime_error("ray tracing miss regression"); } +int main() { + const std::array code{0xF1981F01u, 0x00000000u}; + const RdnaInstruction instruction = DecodeRdnaMimg(0u, code, 0u); + Require(instruction.op == RdnaOpcode::ImageBvhIntersectRay); + Require(instruction.family == RdnaInstructionFamily::MIMG); + Require(IsImageOpcode(instruction.op)); + IrProgram program; + auto& block = program.CreateBlock(); + program.SetEntryBlock(block); + TranslationContext context(program, block, 256); + if (RayTracingStrict()) { + bool thrown = false; + try { + context.TranslateInstruction(instruction); + } catch (const std::runtime_error&) { + thrown = true; + } + Require(thrown); + } else { + context.TranslateInstruction(instruction); + } +} diff --git a/core/shader/recompiler/CacheKey.hpp b/core/shader/recompiler/CacheKey.hpp index fc574d67c..c7515d453 100644 --- a/core/shader/recompiler/CacheKey.hpp +++ b/core/shader/recompiler/CacheKey.hpp @@ -33,6 +33,7 @@ public: appendMesh(key, request); append(key, request.target); append(key, DebugProbeActive()); + append(key, RayTracingStrict()); } // A hash over every field Build appends except the code, the target and the probe flag: the diff --git a/core/shader/recompiler/Recompiler.hpp b/core/shader/recompiler/Recompiler.hpp index 588bae6fd..59c3e0ca9 100644 --- a/core/shader/recompiler/Recompiler.hpp +++ b/core/shader/recompiler/Recompiler.hpp @@ -364,6 +364,7 @@ struct ResourceCapture; // cache keys on it. void SetDebugProbeActive(bool active); [[nodiscard]] bool DebugProbeActive(); +[[nodiscard]] bool RayTracingStrict(); struct RectListShaders { RecompileResult control; diff --git a/core/shader/recompiler/Translation/src/DispatchInstructions.cpp b/core/shader/recompiler/Translation/src/DispatchInstructions.cpp index 6bfc43eca..a291afc15 100644 --- a/core/shader/recompiler/Translation/src/DispatchInstructions.cpp +++ b/core/shader/recompiler/Translation/src/DispatchInstructions.cpp @@ -3,6 +3,7 @@ #include "Recompiler.hpp" #include #include +#include #include #include @@ -83,6 +84,14 @@ bool DebugProbeActive() { return g_debugProbeActive.load(); } +bool RayTracingStrict() { + static const bool strict = [] { + const char* text = std::getenv("APS5_RAYTRACING"); + return text != nullptr && std::strcmp(text, "strict") == 0; + }(); + return strict; +} + DebugProbe DebugProbeConfig() { static const DebugProbe parsed = [] { DebugProbe result; diff --git a/core/shader/recompiler/Translation/src/MemoryInstructions/ImageInstructions.cpp b/core/shader/recompiler/Translation/src/MemoryInstructions/ImageInstructions.cpp index da921ca2e..ca562cb66 100644 --- a/core/shader/recompiler/Translation/src/MemoryInstructions/ImageInstructions.cpp +++ b/core/shader/recompiler/Translation/src/MemoryInstructions/ImageInstructions.cpp @@ -1,5 +1,6 @@ #include "Translation/MemoryInstructions.hpp" #include "Translation/TranslationContext.hpp" +#include "Recompiler.hpp" #include namespace ShaderRecompiler { @@ -41,6 +42,9 @@ MemoryInfo imageMemoryInfoFromInstruction(const RdnaInstruction& inst) { } bool TranslationContext::imageBvhIntersectRay(const RdnaInstruction& inst) { + if (RayTracingStrict()) { + throw std::runtime_error("ray tracing is not implemented"); + } if (inst.dataDwordCount != 4u || inst.imageD16) { throw std::runtime_error("image_bvh_intersect_ray returns four dwords"); }