Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,8 @@ if(BUILD_TESTING)
add_test(NAME spirv_f16_halves COMMAND spirv_f16_halves_test)
add_executable(dual_source_fragment_test test/dual_source_fragment_test.cpp)
add_test(NAME dual_source_fragment COMMAND dual_source_fragment_test)
add_executable(spirv_bary_fallback_test test/spirv_bary_fallback_test.cpp)
add_test(NAME spirv_bary_fallback COMMAND spirv_bary_fallback_test)
# Optional: skips unless LEONIDA_SHADERS names a translated work folder (<work>/shaders/spirv).
add_executable(shader_library_corpus_test test/shader_library_corpus_test.cpp)
add_test(NAME shader_library_corpus COMMAND shader_library_corpus_test)
Expand Down Expand Up @@ -3411,6 +3413,14 @@ if(TARGET Vulkan::Headers)
add_test(NAME d3d12_f16_halves COMMAND d3d12_f16_halves_test)
set_tests_properties(d3d12_f16_halves PROPERTIES SKIP_RETURN_CODE 77)

# Per-pipeline --bary-fallback GS synthesis (RT-BARY-FALLBACK-PSO): perspective barycentrics + ClipDistance + f16 halves.
add_executable(d3d12_bary_fallback_test test/d3d12_bary_fallback_test.cpp shims/d3d12_xs_device.cpp)
target_link_libraries(d3d12_bary_fallback_test PRIVATE gta6rt_d3d12_com d3d12 dxgi)
target_compile_definitions(d3d12_bary_fallback_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
target_compile_options(d3d12_bary_fallback_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_bary_fallback COMMAND d3d12_bary_fallback_test)
set_tests_properties(d3d12_bary_fallback PROPERTIES SKIP_RETURN_CODE 77)

# PresentX and the frame events on the Vulkan device (shims/xbox_present.h), checked on swapchain pixels.
add_executable(xbox_present_test test/xbox_present_test.cpp)
target_link_libraries(xbox_present_test PRIVATE gta6rt_d3d12_com user32)
Expand Down
3 changes: 3 additions & 0 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ struct VulkanDeviceInfo {
bool push_constants_need_fallback = false;
// Top location for relocated f16 halves (0: read from device limits; non-zero: override for testing low-limit devices).
std::uint32_t f16_half_top_location = 0;
// Geometry shader per-vertex interface component limits (0: read from physical device; non-zero: test override).
std::uint32_t max_geometry_input_components = 0;
std::uint32_t max_geometry_output_components = 0;
// maxBufferSize and maxMemoryAllocationSize, which cap the GPU address arena (src/arena_size.h). 0: read from
// the physical device when the D3D12 device is created; a test sets smaller ones to simulate a device.
VkDeviceSize max_buffer_size = 0;
Expand Down
164 changes: 154 additions & 10 deletions runtime/shims/d3d12_vulkan_device.cpp

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions runtime/src/shader_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fstream>
#include <iterator>
#include <map>
#include <optional>
#include <span>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -873,6 +874,8 @@ struct ShaderEntry {
std::vector<std::uint32_t> outputs; // pixel/vertex shaders: output locations written
// --f16-interp-fallback: param/attr index -> {low_half_location, high_half_location} (SHADER-378).
std::map<std::uint32_t, std::array<std::uint32_t, 2>> f16_halves;
// --bary-fallback: input location where a pass-through GS supplies one-hot barycentrics (RT-BARY-FALLBACK-PSO).
std::optional<std::uint32_t> bary_fallback_location;
// The S#s the shader builds from immediates (the index's literal_samplers): no heap slot names them, so a
// pipeline that uses the shader registers them in the bindless set itself (docs/design.md, Literal samplers).
std::vector<std::array<std::uint32_t, 4>> literal_samplers;
Expand Down Expand Up @@ -1301,6 +1304,13 @@ class ShaderLibrary {
e.f16_halves[std::uint32_t(param)] = {u32(&val.array[0]), u32(&val.array[1])};
}
}
if (const Json* bf = meta.find("bary_fallback_input"); bf && bf->kind == Json::Kind::object) {
if (const Json* loc = bf->find("location"); loc && loc->kind == Json::Kind::number &&
loc->number >= 0.0 && loc->number <= 4294967295.0 &&
double(std::uint32_t(loc->number)) == loc->number) {
e.bary_fallback_location = std::uint32_t(loc->number);
}
}
if (const Json* l = meta.find("literal_samplers"); l && l->kind == Json::Kind::array) {
for (const Json& item : l->array) {
if (item.kind != Json::Kind::array || item.array.size() != 4) continue;
Expand Down
534 changes: 534 additions & 0 deletions runtime/src/spirv_bary_fallback.h

Large diffs are not rendered by default.

900 changes: 900 additions & 0 deletions runtime/test/d3d12_bary_fallback_test.cpp

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions runtime/test/shader_library_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,40 @@ int main() {

CHECK(huffman_lut_checks() == 0);

// bary_fallback_input.location: exact non-negative u32 parsed; absent or malformed values stay nullopt.
{
const auto dir = std::filesystem::temp_directory_path() / "leonida_shader_library_bary_test";
std::filesystem::remove_all(dir);
std::filesystem::create_directories(dir);
const std::string h0(64, 'a'), h1(64, 'b'), h2(64, 'c'), h3(64, 'd'), h4(64, 'e');
{
std::ofstream out(dir / "index.json", std::ios::binary | std::ios::trunc);
out << "{\"ps_ok\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << h0
<< "\", \"bary_fallback_input\": {\"location\": 3}},\n"
" \"ps_zero\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << h1
<< "\", \"bary_fallback_input\": {\"location\": 0}},\n"
" \"ps_neg\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << h2
<< "\", \"bary_fallback_input\": {\"location\": -1}},\n"
" \"ps_frac\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << h3
<< "\", \"bary_fallback_input\": {\"location\": 1.5}},\n"
" \"ps_none\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << h4 << "\"}}";
}
ShaderLibrary lib;
std::string err;
CHECK(lib.load(dir, &err));
const ShaderEntry* ok = lib.find("ps", h0);
const ShaderEntry* zero = lib.find("ps", h1);
const ShaderEntry* neg = lib.find("ps", h2);
const ShaderEntry* frac = lib.find("ps", h3);
const ShaderEntry* none = lib.find("ps", h4);
CHECK(ok && ok->bary_fallback_location.has_value() && *ok->bary_fallback_location == 3u);
CHECK(zero && zero->bary_fallback_location.has_value() && *zero->bary_fallback_location == 0u);
CHECK(neg && !neg->bary_fallback_location.has_value());
CHECK(frac && !frac->bary_fallback_location.has_value());
CHECK(none && !none->bary_fallback_location.has_value());
std::filesystem::remove_all(dir);
}

std::printf("SHA-256, inflate (stored/fixed/dynamic), JSON, FSSM extraction, FSPX programs and index lookup OK\n");
return 0;
}
Loading
Loading