diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 22:03:46 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 22:03:51 -0500 |
| commit | d4f3e0bbc63bbd47c7b0afa762f0f22fed5a5a2e (patch) | |
| tree | 0725672e4c136fc0f2f5bf6650ba473f42ef221a /runtime | |
| parent | 9f82f136f68a84bafa745ff61eb6eebb01128654 (diff) | |
| parent | b07b9ecb09b47fa6496f01ad9d8fe87d205bd5d8 (diff) | |
Merge main (b07b9ecb0) into radv-import-pins
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | runtime/shims/d3d12_com.cpp | 17 | ||||
| -rw-r--r-- | runtime/shims/d3d12_com.h | 14 | ||||
| -rw-r--r-- | runtime/shims/d3d12_vulkan_device.cpp | 25 | ||||
| -rw-r--r-- | runtime/src/root_signature.h | 7 | ||||
| -rw-r--r-- | runtime/src/shader_library.h | 9 | ||||
| -rw-r--r-- | runtime/test/d3d12_mesh_test.cpp | 73 | ||||
| -rw-r--r-- | runtime/test/glsl/ms_draw.mesh | 5 | ||||
| -rw-r--r-- | runtime/test/glsl/ps_draw.frag | 2 | ||||
| -rw-r--r-- | runtime/test/glsl/ps_image_atomic.frag | 2 | ||||
| -rw-r--r-- | runtime/test/root_signature_test.cpp | 42 | ||||
| -rw-r--r-- | runtime/test/subgroup_size_test.cpp | 27 |
12 files changed, 207 insertions, 30 deletions
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 652003b19..05e125a70 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt | |||
| @@ -3712,21 +3712,11 @@ if(TARGET Vulkan::Headers) | |||
| 3712 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ms_draw.mesh | 3712 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ms_draw.mesh |
| 3713 | COMMENT "Compiling the mesh test shader ms_draw.mesh" | 3713 | COMMENT "Compiling the mesh test shader ms_draw.mesh" |
| 3714 | VERBATIM) | 3714 | VERBATIM) |
| 3715 | # The mesh test's signature is on the s0 fallback layout (see d3d12_mesh_test.cpp), so its pixel shader is | ||
| 3716 | # ps_draw.frag reading the tint VA at s2:s3 instead of s10:s11. | ||
| 3717 | set(LEONIDA_TEST_PS_S0 ${CMAKE_CURRENT_BINARY_DIR}/generated/ps_draw_s0.spv) | ||
| 3718 | add_custom_command( | ||
| 3719 | OUTPUT ${LEONIDA_TEST_PS_S0} | ||
| 3720 | COMMAND ${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE} -V --target-env vulkan1.3 -DROOT_BASE=0 -o ${LEONIDA_TEST_PS_S0} | ||
| 3721 | ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ps_draw.frag | ||
| 3722 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/ps_draw.frag | ||
| 3723 | COMMENT "Compiling the mesh test's pixel shader ps_draw.frag (s0 layout)" | ||
| 3724 | VERBATIM) | ||
| 3725 | add_executable(d3d12_mesh_test test/d3d12_mesh_test.cpp shims/d3d12_xs_device.cpp shims/d3d12_xs_pso_stream.cpp ${LEONIDA_TEST_MS} | 3715 | add_executable(d3d12_mesh_test test/d3d12_mesh_test.cpp shims/d3d12_xs_device.cpp shims/d3d12_xs_pso_stream.cpp ${LEONIDA_TEST_MS} |
| 3726 | ${LEONIDA_TEST_PS_S0} ${LEONIDA_TEST_VS_FULLSCREEN}) | 3716 | ${LEONIDA_TEST_PS} ${LEONIDA_TEST_VS_FULLSCREEN}) |
| 3727 | target_link_libraries(d3d12_mesh_test PRIVATE gta6rt_d3d12_com) | 3717 | target_link_libraries(d3d12_mesh_test PRIVATE gta6rt_d3d12_com) |
| 3728 | target_compile_definitions(d3d12_mesh_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX | 3718 | target_compile_definitions(d3d12_mesh_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX |
| 3729 | LEONIDA_TEST_MS_SPV="${LEONIDA_TEST_MS}" LEONIDA_TEST_PS_SPV="${LEONIDA_TEST_PS_S0}" | 3719 | LEONIDA_TEST_MS_SPV="${LEONIDA_TEST_MS}" LEONIDA_TEST_PS_SPV="${LEONIDA_TEST_PS}" |
| 3730 | LEONIDA_TEST_VS_FULLSCREEN_SPV="${LEONIDA_TEST_VS_FULLSCREEN}") | 3720 | LEONIDA_TEST_VS_FULLSCREEN_SPV="${LEONIDA_TEST_VS_FULLSCREEN}") |
| 3731 | target_compile_options(d3d12_mesh_test PRIVATE /W4 /permissive- /utf-8) | 3721 | target_compile_options(d3d12_mesh_test PRIVATE /W4 /permissive- /utf-8) |
| 3732 | add_test(NAME d3d12_mesh COMMAND d3d12_mesh_test) | 3722 | add_test(NAME d3d12_mesh COMMAND d3d12_mesh_test) |
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index b6ec111c7..f919cc1eb 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp | |||
| @@ -529,6 +529,11 @@ public: | |||
| 529 | d3d12_trace::record("ID3D12GraphicsCommandList6::DispatchMesh"); | 529 | d3d12_trace::record("ID3D12GraphicsCommandList6::DispatchMesh"); |
| 530 | if (x > 65535 || y > 65535 || z > 65535 || std::uint64_t(x) * y * z > (1u << 22)) return check(false); | 530 | if (x > 65535 || y > 65535 || z > 65535 || std::uint64_t(x) * y * z > (1u << 22)) return check(false); |
| 531 | if (!graphics_pipeline_ || !graphics_.layout) return check(false); | 531 | if (!graphics_pipeline_ || !graphics_.layout) return check(false); |
| 532 | // A mesh shader reads the root arguments from s16 through a 16-dword window (RootArgumentLayout::mesh_ok). | ||
| 533 | if (!graphics_.layout->mesh_ok) { | ||
| 534 | stub("DispatchMesh(root signature larger than a mesh shader's root window)"); | ||
| 535 | return check(false); | ||
| 536 | } | ||
| 532 | if (!any_nonempty_viewport()) return; // as record_draw: nothing is rasterized | 537 | if (!any_nonempty_viewport()) return; // as record_draw: nothing is rasterized |
| 533 | leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, {}, 0, viewport_, | 538 | leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, {}, 0, viewport_, |
| 534 | scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0}; | 539 | scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0}; |
| @@ -1440,9 +1445,20 @@ private: | |||
| 1440 | if ((count && !data) || std::uint64_t(offset) + count > p->constant_count) return check(false); | 1445 | if ((count && !data) || std::uint64_t(offset) + count > p->constant_count) return check(false); |
| 1441 | const auto* values = static_cast<const std::uint32_t*>(data); | 1446 | const auto* values = static_cast<const std::uint32_t*>(data); |
| 1442 | const std::uint32_t first = first_dword(state, *p); | 1447 | const std::uint32_t first = first_dword(state, *p); |
| 1448 | if (first == rt::rootsig::kNoSgpr) return spilled(); | ||
| 1443 | for (UINT i = 0; i < count; ++i) write(state, first + offset + i, values[i]); | 1449 | for (UINT i = 0; i < count; ++i) write(state, first + offset + i, values[i]); |
| 1444 | } | 1450 | } |
| 1445 | 1451 | ||
| 1452 | // A parameter in the spill array behind s[0:1] (a compute signature past s31: pack_stage gives it no SGPR, only a | ||
| 1453 | // spill_dword): that array is not written yet, so its value is not stored; kNoSgpr plus an offset must never | ||
| 1454 | // reach write(), where it would wrap round to s0. | ||
| 1455 | static void spilled() { | ||
| 1456 | static std::atomic<bool> said{false}; | ||
| 1457 | if (!said.exchange(true)) | ||
| 1458 | std::fprintf(stderr, "[rt] d3d12: root arguments in the spill array behind s[0:1] are not stored (the " | ||
| 1459 | "array is not written yet)\n"); | ||
| 1460 | } | ||
| 1461 | |||
| 1446 | void address(RootState& state, UINT index, std::uint64_t va, rt::rootsig::ParamType type) { | 1462 | void address(RootState& state, UINT index, std::uint64_t va, rt::rootsig::ParamType type) { |
| 1447 | if (list_.closed()) return; | 1463 | if (list_.closed()) return; |
| 1448 | if (defer([=, compute = &state == &compute_](GraphicsCommandList& l) { | 1464 | if (defer([=, compute = &state == &compute_](GraphicsCommandList& l) { |
| @@ -1466,6 +1482,7 @@ private: | |||
| 1466 | tables_.emplace_back(va, p->table_descriptors); | 1482 | tables_.emplace_back(va, p->table_descriptors); |
| 1467 | } | 1483 | } |
| 1468 | const std::uint32_t first = first_dword(state, *p); | 1484 | const std::uint32_t first = first_dword(state, *p); |
| 1485 | if (first == rt::rootsig::kNoSgpr) return spilled(); | ||
| 1469 | write(state, first, std::uint32_t(va)); | 1486 | write(state, first, std::uint32_t(va)); |
| 1470 | // In the console layouts a descriptor table is one dword, the 32-bit VA of its first descriptor (the heaps | 1487 | // In the console layouts a descriptor table is one dword, the 32-bit VA of its first descriptor (the heaps |
| 1471 | // live below 4 GiB); a root view keeps both halves. pack()'s graphics layout gives every address two dwords. | 1488 | // live below 4 GiB); a root view keeps both halves. pack()'s graphics layout gives every address two dwords. |
diff --git a/runtime/shims/d3d12_com.h b/runtime/shims/d3d12_com.h index 66226383b..c55229a82 100644 --- a/runtime/shims/d3d12_com.h +++ b/runtime/shims/d3d12_com.h | |||
| @@ -451,10 +451,13 @@ std::unique_ptr<WindowPresenter> create_window_presenter(ID3D12Device* device, H | |||
| 451 | // carries both layouts: | 451 | // carries both layouts: |
| 452 | // - graphics: rt::rootsig::pack_stage(Stage::Pixel), the console layout of vertex, pixel and geometry shaders | 452 | // - graphics: rt::rootsig::pack_stage(Stage::Pixel), the console layout of vertex, pixel and geometry shaders |
| 453 | // (from s8, one dword per table), which the game's own shaders read: VS_Blit/PS_BlitColour and the Scaleform | 453 | // (from s8, one dword per table), which the game's own shaders read: VS_Blit/PS_BlitColour and the Scaleform |
| 454 | // VS load their table's first descriptor from s[8:9] with s9 forced to 0. A signature that would spill there | 454 | // VS load their table's first descriptor from s[8:9] with s9 forced to 0. A vertex, pixel or geometry shader |
| 455 | // reads SGPR i from push dword i, so root dword k is push dword 8 + k. A signature that would spill there | ||
| 455 | // (more than 24 dwords) keeps rt::rootsig::pack() (from s0, two dwords per table), logged: the graphics spill | 456 | // (more than 24 dwords) keeps rt::rootsig::pack() (from s0, two dwords per table), logged: the graphics spill |
| 456 | // array is not modelled. A mesh shader reads from s16 and shares the block with its pixel shader (s8), so mesh | 457 | // array is not modelled. A mesh shader's root arguments start at s16; the translator loads its s16.. from push |
| 457 | // pipelines still see their arguments 8 dwords early (D3D-448); | 458 | // dwords 8.. ("root_window" in index.json), so the same block serves both stages of a mesh pipeline. Its window |
| 459 | // is 16 dwords: mesh_ok says whether Stage::Mesh places the signature too, and a mesh draw with one it refuses | ||
| 460 | // invalidates the list (D3D-448-GRAPHICS); | ||
| 458 | // - compute: rt::rootsig::pack_stage(Stage::Compute), the measured console layout (from s4, one dword per table). | 461 | // - compute: rt::rootsig::pack_stage(Stage::Compute), the measured console layout (from s4, one dword per table). |
| 459 | // A layout that refuses the signature is marked unusable; binding the signature there invalidates the list. | 462 | // A layout that refuses the signature is marked unusable; binding the signature there invalidates the list. |
| 460 | // LEONIDA_GRAPHICS_STAGE_LAYOUT=0 keeps rt::rootsig::pack() (from s0, two dwords per address) for every graphics | 463 | // LEONIDA_GRAPHICS_STAGE_LAYOUT=0 keeps rt::rootsig::pack() (from s0, two dwords per address) for every graphics |
| @@ -469,7 +472,7 @@ inline bool local_graphics_stage_layout() { | |||
| 469 | struct RootArgumentLayout { | 472 | struct RootArgumentLayout { |
| 470 | struct Parameter { | 473 | struct Parameter { |
| 471 | rt::rootsig::ParamType type; | 474 | rt::rootsig::ParamType type; |
| 472 | std::uint32_t user_offset; // graphics: first dword; unused for a parameter with no dwords | 475 | std::uint32_t user_offset; // graphics: first push dword; unused for a parameter with no dwords |
| 473 | std::uint32_t constant_count; // constants only | 476 | std::uint32_t constant_count; // constants only |
| 474 | std::uint32_t compute_offset = rt::rootsig::kNoSgpr; // compute: first user SGPR | 477 | std::uint32_t compute_offset = rt::rootsig::kNoSgpr; // compute: first user SGPR |
| 475 | // A table: the slots its ranges declare, for the scan of title-written V#s before a submission | 478 | // A table: the slots its ranges declare, for the scan of title-written V#s before a submission |
| @@ -482,6 +485,9 @@ struct RootArgumentLayout { | |||
| 482 | // The graphics layout is the console's (pack_stage(Stage::Pixel)): a table takes one dword. False: pack()'s, two. | 485 | // The graphics layout is the console's (pack_stage(Stage::Pixel)): a table takes one dword. False: pack()'s, two. |
| 483 | bool graphics_console = false; | 486 | bool graphics_console = false; |
| 484 | bool graphics_ok = true; | 487 | bool graphics_ok = true; |
| 488 | // The console graphics layout also fits a mesh shader's 16-dword window (s16..s31 = push dwords 8..23). False | ||
| 489 | // for a signature on pack()'s s0 layout, which a mesh shader translated with the root window cannot read. | ||
| 490 | bool mesh_ok = false; | ||
| 485 | bool compute_ok = true; | 491 | bool compute_ok = true; |
| 486 | // One past the last user-data dword the explicit root arguments take at each bind point, where the console puts | 492 | // One past the last user-data dword the explicit root arguments take at each bind point, where the console puts |
| 487 | // the directly indexed heaps (resource heap, then sampler heap). kNoSgpr: no such dword (the compute arguments | 493 | // the directly indexed heaps (resource heap, then sampler heap). kNoSgpr: no such dword (the compute arguments |
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 25bb7d33b..4a892c21a 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp | |||
| @@ -7354,6 +7354,15 @@ public: | |||
| 7354 | std::fprintf(stderr, "[rt] d3d12: %s\n", refusal.c_str()); | 7354 | std::fprintf(stderr, "[rt] d3d12: %s\n", refusal.c_str()); |
| 7355 | return stream_unsupported("mesh shader exceeds a device mesh limit"); | 7355 | return stream_unsupported("mesh shader exceeds a device mesh limit"); |
| 7356 | } | 7356 | } |
| 7357 | // The graphics bind point lays root arguments out from push dword 8, which a mesh shader reads from | ||
| 7358 | // its s16 only when translated with the graphics root window (index "root_window", D3D-448). | ||
| 7359 | if (!stage.entry->graphics_root_window) { | ||
| 7360 | std::fprintf(stderr, | ||
| 7361 | "[rt] d3d12: mesh shader %s was translated before the graphics root window; translate " | ||
| 7362 | "the shaders again (make_game.py --stages shaders)\n", | ||
| 7363 | stage.entry->name.c_str()); | ||
| 7364 | return E_INVALIDARG; | ||
| 7365 | } | ||
| 7357 | } | 7366 | } |
| 7358 | if (stage.entry->uses_code_base) { | 7367 | if (stage.entry->uses_code_base) { |
| 7359 | if (code_stage) { | 7368 | if (code_stage) { |
| @@ -11889,8 +11898,8 @@ public: | |||
| 11889 | if (container_size != size) return E_INVALIDARG; | 11898 | if (container_size != size) return E_INVALIDARG; |
| 11890 | } | 11899 | } |
| 11891 | // The repository's root-signature model (runtime/src/root_signature.h): parse the RTS0 blob, then pack | 11900 | // The repository's root-signature model (runtime/src/root_signature.h): parse the RTS0 blob, then pack |
| 11892 | // the parameters into the 32 user-data dwords. pack() refuses what it cannot place (more than 32 dwords: | 11901 | // the parameters into the 32 user-data dwords in the console layout. pack_stage() refuses what it cannot |
| 11893 | // the console spills those to memory, in a layout that is still open), and so does this. | 11902 | // place (past s31: the console spills those to memory, in a layout that is still open), and so does this. |
| 11894 | const rt::rootsig::DecodeResult parsed = rt::rootsig::parse_rts0(bytes, size); | 11903 | const rt::rootsig::DecodeResult parsed = rt::rootsig::parse_rts0(bytes, size); |
| 11895 | if (!parsed.ok) { | 11904 | if (!parsed.ok) { |
| 11896 | std::fprintf(stderr, "[rt] d3d12: root signature not understood: %s\n", parsed.error.c_str()); | 11905 | std::fprintf(stderr, "[rt] d3d12: root signature not understood: %s\n", parsed.error.c_str()); |
| @@ -11899,11 +11908,14 @@ public: | |||
| 11899 | // Two layouts, one per bind point (RootArgumentLayout): graphics takes the console layout of vertex and | 11908 | // Two layouts, one per bind point (RootArgumentLayout): graphics takes the console layout of vertex and |
| 11900 | // pixel shaders (s8, one dword per table) where it fits without a spill and keeps pack() otherwise, compute | 11909 | // pixel shaders (s8, one dword per table) where it fits without a spill and keeps pack() otherwise, compute |
| 11901 | // the console layout pack_stage() measured (D3D-448). The signature is refused only when neither can place it. | 11910 | // the console layout pack_stage() measured (D3D-448). The signature is refused only when neither can place it. |
| 11911 | // A mesh shader reads the same graphics block from its s16 (the translator's root window, push dword 8 = s16), | ||
| 11912 | // so its 16-dword window only needs checking (D3D-448-GRAPHICS). | ||
| 11902 | const rt::rootsig::PackResult packed = rt::rootsig::pack(parsed.sig); | 11913 | const rt::rootsig::PackResult packed = rt::rootsig::pack(parsed.sig); |
| 11903 | // LEONIDA_GRAPHICS_STAGE_LAYOUT=0 keeps pack() for every graphics signature. | 11914 | // LEONIDA_GRAPHICS_STAGE_LAYOUT=0 keeps pack() for every graphics signature. |
| 11904 | const rt::rootsig::StagePackResult pixel = | 11915 | const rt::rootsig::StagePackResult pixel = |
| 11905 | local_graphics_stage_layout() ? rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Pixel) | 11916 | local_graphics_stage_layout() ? rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Pixel) |
| 11906 | : rt::rootsig::StagePackResult{}; | 11917 | : rt::rootsig::StagePackResult{}; |
| 11918 | const rt::rootsig::StagePackResult mesh = rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Mesh); | ||
| 11907 | const rt::rootsig::StagePackResult compute = rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Compute); | 11919 | const rt::rootsig::StagePackResult compute = rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Compute); |
| 11908 | if (!pixel.ok && packed.ok && local_graphics_stage_layout()) { | 11920 | if (!pixel.ok && packed.ok && local_graphics_stage_layout()) { |
| 11909 | static std::atomic<unsigned> kept{0}; | 11921 | static std::atomic<unsigned> kept{0}; |
| @@ -11920,12 +11932,21 @@ public: | |||
| 11920 | } | 11932 | } |
| 11921 | if (!graphics_ok) | 11933 | if (!graphics_ok) |
| 11922 | std::fprintf(stderr, "[rt] d3d12: root signature usable for compute only: %s\n", packed.error.c_str()); | 11934 | std::fprintf(stderr, "[rt] d3d12: root signature usable for compute only: %s\n", packed.error.c_str()); |
| 11935 | else if (pixel.ok && !mesh.ok) { | ||
| 11936 | static std::atomic<unsigned> too_large{0}; | ||
| 11937 | const unsigned n = ++too_large; | ||
| 11938 | if (n == 1 || (n & (n - 1)) == 0) | ||
| 11939 | std::fprintf(stderr, | ||
| 11940 | "[rt] d3d12: root signature too large for a mesh shader's root window: %s (%u so far)\n", | ||
| 11941 | mesh.error.c_str(), n); | ||
| 11942 | } | ||
| 11923 | if (!compute.ok) | 11943 | if (!compute.ok) |
| 11924 | std::fprintf(stderr, "[rt] d3d12: root signature usable for graphics only: %s\n", compute.error.c_str()); | 11944 | std::fprintf(stderr, "[rt] d3d12: root signature usable for graphics only: %s\n", compute.error.c_str()); |
| 11925 | RootArgumentLayout layout; | 11945 | RootArgumentLayout layout; |
| 11926 | layout.flags = parsed.sig.flags; | 11946 | layout.flags = parsed.sig.flags; |
| 11927 | layout.graphics_console = pixel.ok; | 11947 | layout.graphics_console = pixel.ok; |
| 11928 | layout.graphics_ok = graphics_ok; | 11948 | layout.graphics_ok = graphics_ok; |
| 11949 | layout.mesh_ok = pixel.ok && mesh.ok; | ||
| 11929 | layout.compute_ok = compute.ok; | 11950 | layout.compute_ok = compute.ok; |
| 11930 | if (compute.ok && !compute.spill_dwords) layout.compute_arguments_end = compute.end_sgpr; | 11951 | if (compute.ok && !compute.spill_dwords) layout.compute_arguments_end = compute.end_sgpr; |
| 11931 | // Vertex, pixel and geometry shaders share the s8 layout and one user-data block (a non-compute stage | 11952 | // Vertex, pixel and geometry shaders share the s8 layout and one user-data block (a non-compute stage |
diff --git a/runtime/src/root_signature.h b/runtime/src/root_signature.h index 60b0d5632..e7976fc73 100644 --- a/runtime/src/root_signature.h +++ b/runtime/src/root_signature.h | |||
| @@ -129,8 +129,11 @@ constexpr uint32_t kMaxD3d12Cost = 64; | |||
| 129 | // in this layout equals the program's RSRC2 USER_SGPR count in 29 of 29, and the programs read the tables and | 129 | // in this layout equals the program's RSRC2 USER_SGPR count in 29 of 29, and the programs read the tables and |
| 130 | // root CBVs at exactly these SGPRs (tools/rootsig_census.py --disasm). The game's compute census agrees (lowest | 130 | // root CBVs at exactly these SGPRs (tools/rootsig_census.py --disasm). The game's compute census agrees (lowest |
| 131 | // pointer s4, one-dword tables). | 131 | // pointer s4, one-dword tables). |
| 132 | // - vertex/pixel/geometry s8 and mesh s16: a hypothesis from the corpus census only (lowest pointer SGPR per stage); | 132 | // - vertex/pixel/geometry s8 and mesh s16: from the corpus census (lowest pointer SGPR per stage) and one live |
| 133 | // no signature confirms them, and visibility is not modelled (every parameter takes its place in every stage). | 133 | // retail frame (a VS and PS reading their tables at s8, s9, s10; issue #14, comment 7131556366); no serialized |
| 134 | // signature confirms them yet, and visibility is not modelled (every parameter takes its place in every stage). | ||
| 135 | // The graphics bind point uses Stage::Pixel (s8, as vertex and geometry); a mesh shader reads the same dwords | ||
| 136 | // through its translator-side window (docs/d3d12_vulkan.md section 3.5). | ||
| 134 | // A parameter that does not fit goes to the console's spill array behind s[0:1] (compute, section 7) together with | 137 | // A parameter that does not fit goes to the console's spill array behind s[0:1] (compute, section 7) together with |
| 135 | // every parameter after it. For compute that packed spill array (1 dword per 32-bit constant, 2 per root descriptor, | 138 | // every parameter after it. For compute that packed spill array (1 dword per 32-bit constant, 2 per root descriptor, |
| 136 | // 1 per descriptor table, no alignment padding) is modelled in StagePackResult; non-compute stages still refuse spills | 139 | // 1 per descriptor table, no alignment padding) is modelled in StagePackResult; non-compute stages still refuse spills |
diff --git a/runtime/src/shader_library.h b/runtime/src/shader_library.h index ae045e80b..a359287cb 100644 --- a/runtime/src/shader_library.h +++ b/runtime/src/shader_library.h | |||
| @@ -865,6 +865,9 @@ struct ShaderEntry { | |||
| 865 | // stages or an index written without the analysis. | 865 | // stages or an index written without the analysis. |
| 866 | std::string wave64_graphics; | 866 | std::string wave64_graphics; |
| 867 | bool emulated() const { return wave64_exchange == "workgroup"; } | 867 | bool emulated() const { return wave64_exchange == "workgroup"; } |
| 868 | // Mesh shaders: the index's "root_window" is {"sgpr": 16, "dword": 8}, so the module reads its root arguments | ||
| 869 | // from the graphics window (push dword 8 = root dword 0, D3D-448 follow-up). False for one translated before it. | ||
| 870 | bool graphics_root_window = false; | ||
| 868 | std::vector<SignatureElement> input_signature; // vertex shaders: what the input layout must feed | 871 | std::vector<SignatureElement> input_signature; // vertex shaders: what the input layout must feed |
| 869 | std::vector<std::uint32_t> inputs; // pixel shaders: input locations declared | 872 | std::vector<std::uint32_t> inputs; // pixel shaders: input locations declared |
| 870 | std::vector<std::uint32_t> outputs; // pixel/vertex shaders: output locations written | 873 | std::vector<std::uint32_t> outputs; // pixel/vertex shaders: output locations written |
| @@ -1177,6 +1180,12 @@ private: | |||
| 1177 | e.subgroup_size = u32(g); | 1180 | e.subgroup_size = u32(g); |
| 1178 | if (const Json* x = meta.find("wave64_exchange"); x && x->kind == Json::Kind::string) | 1181 | if (const Json* x = meta.find("wave64_exchange"); x && x->kind == Json::Kind::string) |
| 1179 | e.wave64_exchange = x->string; | 1182 | e.wave64_exchange = x->string; |
| 1183 | if (const Json* r = meta.find("root_window"); r && r->kind == Json::Kind::object) { | ||
| 1184 | const Json* sgpr = r->find("sgpr"); | ||
| 1185 | const Json* dword = r->find("dword"); | ||
| 1186 | e.graphics_root_window = sgpr && dword && sgpr->kind == Json::Kind::number && | ||
| 1187 | dword->kind == Json::Kind::number && u32(sgpr) == 16 && u32(dword) == 8; | ||
| 1188 | } | ||
| 1180 | if (const Json* wg = meta.find("wave64_graphics"); wg && wg->kind == Json::Kind::string) | 1189 | if (const Json* wg = meta.find("wave64_graphics"); wg && wg->kind == Json::Kind::string) |
| 1181 | e.wave64_graphics = wg->string; | 1190 | e.wave64_graphics = wg->string; |
| 1182 | if (const Json* s = meta.find("input_signature"); s && s->kind == Json::Kind::array) { | 1191 | if (const Json* s = meta.find("input_signature"); s && s->kind == Json::Kind::array) { |
diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp index 2108cb1b7..e59414a01 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp | |||
| @@ -113,16 +113,21 @@ int main(int argc, char** argv) { | |||
| 113 | EXPECT(device_status == vktest::DeviceStatus::ready); | 113 | EXPECT(device_status == vktest::DeviceStatus::ready); |
| 114 | 114 | ||
| 115 | const auto ms_program = fssm_program({0x4d530001, 0xbf810000}); | 115 | const auto ms_program = fssm_program({0x4d530001, 0xbf810000}); |
| 116 | // The same mesh shader listed without "root_window": one translated before the graphics root window (D3D-448). | ||
| 117 | const auto ms_old_program = fssm_program({0x4d530002, 0xbf810000}); | ||
| 116 | const auto ps_program = fssm_program({0x50530001, 0xbf810000}); | 118 | const auto ps_program = fssm_program({0x50530001, 0xbf810000}); |
| 117 | const auto vs_program = fssm_program({0x56530002, 0xbf810000}); | 119 | const auto vs_program = fssm_program({0x56530002, 0xbf810000}); |
| 118 | auto ms_container = shader_container(ms_program); | 120 | auto ms_container = shader_container(ms_program); |
| 121 | auto ms_old_container = shader_container(ms_old_program); | ||
| 119 | const auto ps_container = shader_container(ps_program); | 122 | const auto ps_container = shader_container(ps_program); |
| 120 | // The synthetic container has one part at 36, followed by its eight-byte header. | 123 | // The synthetic container has one part at 36, followed by its eight-byte header. |
| 121 | ms_container[36 + 8 + 2] = 13; // DXIL mesh shader kind | 124 | ms_container[36 + 8 + 2] = 13; // DXIL mesh shader kind |
| 125 | ms_old_container[36 + 8 + 2] = 13; | ||
| 122 | const auto vs_container = shader_container(vs_program); | 126 | const auto vs_container = shader_container(vs_program); |
| 123 | const auto library = std::filesystem::temp_directory_path() / "leonida_mesh_test"; | 127 | const auto library = std::filesystem::temp_directory_path() / "leonida_mesh_test"; |
| 124 | std::filesystem::create_directories(library); | 128 | std::filesystem::create_directories(library); |
| 125 | std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_draw.spv", std::filesystem::copy_options::overwrite_existing); | 129 | std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_draw.spv", std::filesystem::copy_options::overwrite_existing); |
| 130 | std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_old.spv", std::filesystem::copy_options::overwrite_existing); | ||
| 126 | std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); | 131 | std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); |
| 127 | std::filesystem::copy_file(LEONIDA_TEST_VS_FULLSCREEN_SPV, library / "vs_fullscreen.spv", | 132 | std::filesystem::copy_file(LEONIDA_TEST_VS_FULLSCREEN_SPV, library / "vs_fullscreen.spv", |
| 128 | std::filesystem::copy_options::overwrite_existing); | 133 | std::filesystem::copy_options::overwrite_existing); |
| @@ -130,6 +135,9 @@ int main(int argc, char** argv) { | |||
| 130 | std::ofstream index(library / "index.json", std::ios::binary); | 135 | std::ofstream index(library / "index.json", std::ios::binary); |
| 131 | index << "{\"ms_draw\": {\"stage\": \"ms\", \"fssm_sha256\": \"" << leonida::sha256_hex(ms_program) | 136 | index << "{\"ms_draw\": {\"stage\": \"ms\", \"fssm_sha256\": \"" << leonida::sha256_hex(ms_program) |
| 132 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"local_size\": [32, 1, 1], " | 137 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"local_size\": [32, 1, 1], " |
| 138 | "\"max_vertices\": 4, \"max_primitives\": 2, \"root_window\": {\"sgpr\": 16, \"dword\": 8}},\n" | ||
| 139 | " \"ms_old\": {\"stage\": \"ms\", \"fssm_sha256\": \"" << leonida::sha256_hex(ms_old_program) | ||
| 140 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"local_size\": [32, 1, 1], " | ||
| 133 | "\"max_vertices\": 4, \"max_primitives\": 2},\n" | 141 | "\"max_vertices\": 4, \"max_primitives\": 2},\n" |
| 134 | " \"vs_fullscreen\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program) | 142 | " \"vs_fullscreen\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program) |
| 135 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": []},\n" | 143 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": []},\n" |
| @@ -164,23 +172,35 @@ int main(int argc, char** argv) { | |||
| 164 | return true; | 172 | return true; |
| 165 | }; | 173 | }; |
| 166 | const auto root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root) { | 174 | const auto root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root) { |
| 167 | // The mesh fixture reads s0:s1 (offset) and the colour fixture, built as ps_draw_s0.spv, s2:s3 (tint VA). | 175 | // [0] two constants (push dwords 8, 9: offset), [1] a root CBV (10, 11: tint), as in d3d12_draw_test. The |
| 168 | // Select the runtime's packed s0 layout by declaring 25 words: one more than fits above s8. | 176 | // mesh shader reads them as s16..s19 and the pixel shader as s8..s11 (the graphics root window, D3D-448). |
| 169 | D3D12_ROOT_PARAMETER params[3] = {}; | 177 | D3D12_ROOT_PARAMETER params[2] = {}; |
| 170 | params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; | 178 | params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; |
| 171 | params[0].Constants = {0, 0, 2}; | 179 | params[0].Constants = {0, 0, 2}; |
| 172 | params[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; | 180 | params[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; |
| 173 | params[1].Descriptor = {1, 0}; | 181 | params[1].Descriptor = {1, 0}; |
| 174 | params[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; | ||
| 175 | params[2].Constants = {2, 0, 21}; | ||
| 176 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; | 182 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; |
| 177 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; | 183 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; |
| 178 | root_desc.Desc_1_0 = {3, params, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE}; | 184 | root_desc.Desc_1_0 = {2, params, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE}; |
| 185 | const auto blob = serialize_root_signature(root_desc); | ||
| 186 | return !blob.empty() && | ||
| 187 | SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p))); | ||
| 188 | }; | ||
| 189 | // Twenty constants: s8..s27 for a pixel shader, but past a mesh shader's 16-dword window (s16..s31). Thirty: | ||
| 190 | // past the graphics window (24 from s8) and the compute one (28 from s4) too, as a retail start-up signature is. | ||
| 191 | const auto wide_root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root, UINT values = 20) { | ||
| 192 | D3D12_ROOT_PARAMETER param{}; | ||
| 193 | param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; | ||
| 194 | param.Constants = {0, 0, values}; | ||
| 195 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; | ||
| 196 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; | ||
| 197 | root_desc.Desc_1_0 = {1, ¶m, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE}; | ||
| 179 | const auto blob = serialize_root_signature(root_desc); | 198 | const auto blob = serialize_root_signature(root_desc); |
| 180 | return !blob.empty() && | 199 | return !blob.empty() && |
| 181 | SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p))); | 200 | SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p))); |
| 182 | }; | 201 | }; |
| 183 | const D3D12_SHADER_BYTECODE ms{ms_container.data(), ms_container.size()}; | 202 | const D3D12_SHADER_BYTECODE ms{ms_container.data(), ms_container.size()}; |
| 203 | const D3D12_SHADER_BYTECODE ms_old{ms_old_container.data(), ms_old_container.size()}; | ||
| 184 | const D3D12_SHADER_BYTECODE ps{ps_container.data(), ps_container.size()}; | 204 | const D3D12_SHADER_BYTECODE ps{ps_container.data(), ps_container.size()}; |
| 185 | const D3D12_SHADER_BYTECODE vs{vs_container.data(), vs_container.size()}; | 205 | const D3D12_SHADER_BYTECODE vs{vs_container.data(), vs_container.size()}; |
| 186 | 206 | ||
| @@ -231,6 +251,14 @@ int main(int argc, char** argv) { | |||
| 231 | vs_stream.add(TopologySubobject{.inner = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE}); | 251 | vs_stream.add(TopologySubobject{.inner = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE}); |
| 232 | vs_stream.add(TargetsSubobject{.inner = one_target()}); | 252 | vs_stream.add(TargetsSubobject{.inner = one_target()}); |
| 233 | EXPECT(SUCCEEDED(create(device.p, vs_stream, vs_pso))); | 253 | EXPECT(SUCCEEDED(create(device.p, vs_stream, vs_pso))); |
| 254 | // A mesh shader translated before the graphics root window would read its root arguments from the wrong | ||
| 255 | // dwords: refused, with a log line that asks for the shaders stage again. | ||
| 256 | { | ||
| 257 | Stream old_stream; | ||
| 258 | old_stream.add(RootSubobject{.inner = root.p}).add(MsSubobject{.inner = ms_old}).add(PsSubobject{.inner = ps}); | ||
| 259 | old_stream.add(TargetsSubobject{.inner = one_target()}); | ||
| 260 | EXPECT(create(device.p, old_stream, refused) == E_INVALIDARG && !refused.p); | ||
| 261 | } | ||
| 234 | 262 | ||
| 235 | // Streams the PC runtime refuses. | 263 | // Streams the PC runtime refuses. |
| 236 | Stream bad = mesh_stream; | 264 | Stream bad = mesh_stream; |
| @@ -466,6 +494,39 @@ int main(int argc, char** argv) { | |||
| 466 | list->RSSetViewports(1, &viewport); | 494 | list->RSSetViewports(1, &viewport); |
| 467 | list6->DispatchMesh(4096, 1025, 1); | 495 | list6->DispatchMesh(4096, 1025, 1); |
| 468 | EXPECT(list->Close() == E_INVALIDARG); | 496 | EXPECT(list->Close() == E_INVALIDARG); |
| 497 | // A root signature the graphics bind point places (s8..s27) but a mesh shader's window cannot (s16..s31): a | ||
| 498 | // vertex draw may use it, DispatchMesh may not. | ||
| 499 | { | ||
| 500 | Ref<ID3D12RootSignature> wide; | ||
| 501 | EXPECT(wide_root_signature(device.p, wide)); | ||
| 502 | EXPECT(SUCCEEDED(list->Reset(allocator.p, mesh_pso.p))); | ||
| 503 | list->SetGraphicsRootSignature(wide.p); | ||
| 504 | list->RSSetViewports(1, &viewport); | ||
| 505 | list6->DispatchMesh(1, 1, 1); | ||
| 506 | EXPECT(list->Close() == E_INVALIDARG); | ||
| 507 | // Past the console graphics window (24 dwords from s8): still created, on pack()'s s0 layout (logged). | ||
| 508 | // Setting its 30 constants is valid; a mesh shader, which reads the console layout, may not use it. | ||
| 509 | Ref<ID3D12RootSignature> huge; | ||
| 510 | EXPECT(wide_root_signature(device.p, huge, 30)); | ||
| 511 | EXPECT(SUCCEEDED(list->Reset(allocator.p, mesh_pso.p))); | ||
| 512 | list->SetGraphicsRootSignature(huge.p); | ||
| 513 | const std::array<std::uint32_t, 30> values{}; | ||
| 514 | list->SetGraphicsRoot32BitConstants(0, 30, values.data(), 0); | ||
| 515 | EXPECT(SUCCEEDED(list->Close())); | ||
| 516 | EXPECT(SUCCEEDED(list->Reset(allocator.p, mesh_pso.p))); | ||
| 517 | list->SetGraphicsRootSignature(huge.p); | ||
| 518 | list->RSSetViewports(1, &viewport); | ||
| 519 | list6->DispatchMesh(1, 1, 1); | ||
| 520 | EXPECT(list->Close() == E_INVALIDARG); // a mesh shader cannot read it | ||
| 521 | // Four constants: the console layout, and the mesh window holds them. | ||
| 522 | Ref<ID3D12RootSignature> console_layout; | ||
| 523 | EXPECT(wide_root_signature(device.p, console_layout, 4)); | ||
| 524 | EXPECT(SUCCEEDED(list->Reset(allocator.p, mesh_pso.p))); | ||
| 525 | list->SetGraphicsRootSignature(console_layout.p); | ||
| 526 | list->RSSetViewports(1, &viewport); | ||
| 527 | list6->DispatchMesh(1, 1, 1); | ||
| 528 | EXPECT(SUCCEEDED(list->Close())); | ||
| 529 | } | ||
| 469 | // A DISPATCH_MESH command signature (D3D12_DISPATCH_MESH_ARGUMENTS, 12 bytes) is created; a stride below its | 530 | // A DISPATCH_MESH command signature (D3D12_DISPATCH_MESH_ARGUMENTS, 12 bytes) is created; a stride below its |
| 470 | // 12 bytes is refused as the PC runtime refuses it. ExecuteIndirect with it records nothing yet (#3777 replays | 531 | // 12 bytes is refused as the PC runtime refuses it. ExecuteIndirect with it records nothing yet (#3777 replays |
| 471 | // it), so the list still closes. | 532 | // it), so the list still closes. |
diff --git a/runtime/test/glsl/ms_draw.mesh b/runtime/test/glsl/ms_draw.mesh index 8bfd21785..e66b04bb6 100644 --- a/runtime/test/glsl/ms_draw.mesh +++ b/runtime/test/glsl/ms_draw.mesh | |||
| @@ -2,7 +2,8 @@ | |||
| 2 | // A mesh shader written to the translator's runtime contract (docs/design.md, "User data" and "Mesh shaders"), | 2 | // A mesh shader written to the translator's runtime contract (docs/design.md, "User data" and "Mesh shaders"), |
| 3 | // standing in for a translated one in d3d12_mesh_test. Each workgroup emits one quad (4 vertices, 2 triangles) on a | 3 | // standing in for a translated one in d3d12_mesh_test. Each workgroup emits one quad (4 vertices, 2 triangles) on a |
| 4 | // 4x4 grid of clip-space cells: column = WorkgroupId.x + WorkgroupId.z, row = WorkgroupId.y, so all three | 4 | // 4x4 grid of clip-space cells: column = WorkgroupId.x + WorkgroupId.z, row = WorkgroupId.y, so all three |
| 5 | // DispatchMesh counts reach the shader. s0, s1 (root constants) move the quad in clip space; the colour is red. The | 5 | // DispatchMesh counts reach the shader. Push dwords 8, 9 (the root constants, which a translated mesh shader reads as |
| 6 | // s16, s17 through the graphics root window) move the quad in clip space; the colour is red. The | ||
| 6 | // corners are top-left, top-right, bottom-left, bottom-right and the triangles (0,1,2) and (2,1,3), clockwise in D3D | 7 | // corners are top-left, top-right, bottom-left, bottom-right and the triangles (0,1,2) and (2,1,3), clockwise in D3D |
| 7 | // screen space as in d3d12_draw_test, so they are front-facing with the default winding. | 8 | // screen space as in d3d12_draw_test, so they are front-facing with the default winding. |
| 8 | #extension GL_EXT_mesh_shader : require | 9 | #extension GL_EXT_mesh_shader : require |
| @@ -22,7 +23,7 @@ void main() { | |||
| 22 | SetMeshOutputsEXT(4, 2); | 23 | SetMeshOutputsEXT(4, 2); |
| 23 | const uint i = gl_LocalInvocationIndex; | 24 | const uint i = gl_LocalInvocationIndex; |
| 24 | const float column = float(gl_WorkGroupID.x + gl_WorkGroupID.z), row = float(gl_WorkGroupID.y); | 25 | const float column = float(gl_WorkGroupID.x + gl_WorkGroupID.z), row = float(gl_WorkGroupID.y); |
| 25 | const vec2 offset = vec2(uintBitsToFloat(pc.s[0]), uintBitsToFloat(pc.s[1])); | 26 | const vec2 offset = vec2(uintBitsToFloat(pc.s[8]), uintBitsToFloat(pc.s[9])); |
| 26 | if (i < 4) { | 27 | if (i < 4) { |
| 27 | const vec2 corner = vec2(float(i & 1u), float(i >> 1)); | 28 | const vec2 corner = vec2(float(i & 1u), float(i >> 1)); |
| 28 | const vec2 top_left = vec2(-1.0 + 0.5 * column, 1.0 - 0.5 * row); | 29 | const vec2 top_left = vec2(-1.0 + 0.5 * column, 1.0 - 0.5 * row); |
diff --git a/runtime/test/glsl/ps_draw.frag b/runtime/test/glsl/ps_draw.frag index d8e29425d..5f2ab1e86 100644 --- a/runtime/test/glsl/ps_draw.frag +++ b/runtime/test/glsl/ps_draw.frag | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | // d3d12_draw_test. The tests' signatures are two root constants then a root CBV, so in the console's graphics layout | 3 | // d3d12_draw_test. The tests' signatures are two root constants then a root CBV, so in the console's graphics layout |
| 4 | // (from s8, two dwords per root view: docs/d3d12_vulkan.md, D3D-448) s10:s11 is the CBV: the console VA of three | 4 | // (from s8, two dwords per root view: docs/d3d12_vulkan.md, D3D-448) s10:s11 is the CBV: the console VA of three |
| 5 | // floats (a tint), read at heap base + VA. The output is (red * tint.x, tint.y, blue * tint.z, 1). | 5 | // floats (a tint), read at heap base + VA. The output is (red * tint.x, tint.y, blue * tint.z, 1). |
| 6 | // d3d12_mesh_test pads its signature onto the runtime's s0 fallback layout and builds this with -DROOT_BASE=0 (s2:s3). | 6 | // d3d12_mesh_test uses it as is: its mesh shader reads the same block through the root window (push dword 8 = s16). |
| 7 | #extension GL_EXT_buffer_reference : require | 7 | #extension GL_EXT_buffer_reference : require |
| 8 | #extension GL_EXT_buffer_reference_uvec2 : require | 8 | #extension GL_EXT_buffer_reference_uvec2 : require |
| 9 | 9 | ||
diff --git a/runtime/test/glsl/ps_image_atomic.frag b/runtime/test/glsl/ps_image_atomic.frag index 97c9b53b5..b23d09ed7 100644 --- a/runtime/test/glsl/ps_image_atomic.frag +++ b/runtime/test/glsl/ps_image_atomic.frag | |||
| @@ -19,6 +19,6 @@ layout(push_constant) uniform UserData { | |||
| 19 | layout(set = 0, binding = 4, r32ui) uniform uimage2D counters[]; | 19 | layout(set = 0, binding = 4, r32ui) uniform uimage2D counters[]; |
| 20 | 20 | ||
| 21 | void main() { | 21 | void main() { |
| 22 | const uint before = imageAtomicMax(counters[0], ivec2(gl_FragCoord.xy), pc.s[0]); | 22 | const uint before = imageAtomicMax(counters[0], ivec2(gl_FragCoord.xy), pc.s[8]); |
| 23 | target = vec4(color.rgb, float(before & 1u)); | 23 | target = vec4(color.rgb, float(before & 1u)); |
| 24 | } | 24 | } |
diff --git a/runtime/test/root_signature_test.cpp b/runtime/test/root_signature_test.cpp index 169c656f9..c7f726599 100644 --- a/runtime/test/root_signature_test.cpp +++ b/runtime/test/root_signature_test.cpp | |||
| @@ -492,6 +492,48 @@ int main() { | |||
| 492 | "pack_stage: non-compute graphics stages still refuse spills"); | 492 | "pack_stage: non-compute graphics stages still refuse spills"); |
| 493 | } | 493 | } |
| 494 | 494 | ||
| 495 | // The graphics root window (D3D-448-GRAPHICS): the graphics bind point lays a signature out once with | ||
| 496 | // Stage::Pixel, root dword k at push dword 8 + k. A vertex, pixel or geometry shader reads SGPR i from push | ||
| 497 | // dword i, and a mesh shader its s16 + k from push dword 8 + k (tools/rdna2spirv.py, user_data_dword), so every | ||
| 498 | // stage of a pipeline finds each parameter in the same dword. The mesh window holds 16 dwords, the others 24. | ||
| 499 | { | ||
| 500 | const std::vector<RootSignature> shapes = [] { | ||
| 501 | std::vector<RootSignature> out(4); | ||
| 502 | out[0].params = {consts(2), view()}; | ||
| 503 | out[1].params = {table(), table(), consts(1)}; | ||
| 504 | out[2].params = {table(), consts(4), view(), table()}; | ||
| 505 | out[3].params.assign(16, table()); | ||
| 506 | return out; | ||
| 507 | }(); | ||
| 508 | for (std::size_t s = 0; s < shapes.size(); ++s) { | ||
| 509 | const StagePackResult vs = pack_stage(shapes[s], Stage::Vertex); | ||
| 510 | const StagePackResult ps = pack_stage(shapes[s], Stage::Pixel); | ||
| 511 | const StagePackResult gs = pack_stage(shapes[s], Stage::Geometry); | ||
| 512 | const StagePackResult ms = pack_stage(shapes[s], Stage::Mesh); | ||
| 513 | check(vs.ok && ps.ok && gs.ok && ms.ok, "graphics window: the shape fits every graphics stage"); | ||
| 514 | check(vs.first_sgpr == ps.first_sgpr && vs.first_sgpr == gs.first_sgpr, | ||
| 515 | "graphics window: VS, PS and GS place every parameter in the same SGPR"); | ||
| 516 | bool same_dword = vs.first_sgpr.size() == ms.first_sgpr.size(); | ||
| 517 | for (std::size_t i = 0; same_dword && i < vs.first_sgpr.size(); ++i) | ||
| 518 | same_dword = vs.first_sgpr[i] - 8 == ms.first_sgpr[i] - 16; | ||
| 519 | check(same_dword, "graphics window: a mesh shader's s16 + k is the pixel shader's s8 + k"); | ||
| 520 | } | ||
| 521 | RootSignature twenty; | ||
| 522 | twenty.params = {consts(20)}; | ||
| 523 | check(pack_stage(twenty, Stage::Vertex).ok && !pack_stage(twenty, Stage::Mesh).ok, | ||
| 524 | "graphics window: 20 dwords fit a pixel shader (24 from s8) but not a mesh shader (16 from s16)"); | ||
| 525 | RootSignature full; | ||
| 526 | full.params = {consts(24)}; | ||
| 527 | check(pack_stage(full, Stage::Pixel).ok, "graphics window: 24 constants fill s8..s31 exactly"); | ||
| 528 | full.params = {consts(23), view()}; | ||
| 529 | check(!pack_stage(full, Stage::Pixel).ok, "graphics window: a root view past s31 spills"); | ||
| 530 | RootSignature tables; | ||
| 531 | tables.params = {table(), table()}; | ||
| 532 | const StagePackResult t = pack_stage(tables, Stage::Pixel); | ||
| 533 | check(t.ok && t.first_sgpr == std::vector<uint32_t>({8, 9}) && t.end_sgpr == 10, | ||
| 534 | "graphics window: two tables are s8 and s9, one dword each (pack() gave s[0:1] and s[2:3])"); | ||
| 535 | } | ||
| 536 | |||
| 495 | // pack_stage keeps pack()'s validation. | 537 | // pack_stage keeps pack()'s validation. |
| 496 | { | 538 | { |
| 497 | RootSignature invalid_sig; | 539 | RootSignature invalid_sig; |
diff --git a/runtime/test/subgroup_size_test.cpp b/runtime/test/subgroup_size_test.cpp index 2628509fc..2a6fbdf97 100644 --- a/runtime/test/subgroup_size_test.cpp +++ b/runtime/test/subgroup_size_test.cpp | |||
| @@ -7,8 +7,10 @@ | |||
| 7 | // - an old RADV: sizes 32..64, COMPUTE only. | 7 | // - an old RADV: sizes 32..64, COMPUTE only. |
| 8 | // No game data. | 8 | // No game data. |
| 9 | #include "../src/subgroup_size.h" | 9 | #include "../src/subgroup_size.h" |
| 10 | #include "test_temp_dir.h" | ||
| 10 | 11 | ||
| 11 | #include <cstdio> | 12 | #include <cstdio> |
| 13 | #include <fstream> | ||
| 12 | #include <string> | 14 | #include <string> |
| 13 | 15 | ||
| 14 | #define CHECK(condition) do { \ | 16 | #define CHECK(condition) do { \ |
| @@ -138,6 +140,31 @@ int main() { | |||
| 138 | CHECK(emulated.outcome == SubgroupOutcome::emulated && emulated.size == 0); | 140 | CHECK(emulated.outcome == SubgroupOutcome::emulated && emulated.size == 0); |
| 139 | } | 141 | } |
| 140 | 142 | ||
| 143 | // Read the translator's graphics tier through the same index lookup used at pipeline creation: tiers A and B are | ||
| 144 | // partition invariant (the device's 32-wide size is exact for them), C, an unknown tier and a non-string are not. | ||
| 145 | { | ||
| 146 | const testfiles::ScratchDir scratch("leonida_subgroup_graphics"); | ||
| 147 | std::ofstream(scratch.path() / "index.json") << R"({ | ||
| 148 | "a": {"stage":"vs","wave64":true,"subgroup_size":64,"fssm_sha256":"a","wave64_graphics":"A"}, | ||
| 149 | "b": {"stage":"ps","wave64":true,"subgroup_size":64,"fssm_sha256":"b","wave64_graphics":"B"}, | ||
| 150 | "c": {"stage":"gs","wave64":true,"subgroup_size":64,"fssm_sha256":"c","wave64_graphics":"C"}, | ||
| 151 | "unknown": {"stage":"ps","wave64":true,"fssm_sha256":"unknown","wave64_graphics":"D"}, | ||
| 152 | "bad": {"stage":"ps","wave64":true,"fssm_sha256":"bad","wave64_graphics":1} | ||
| 153 | })"; | ||
| 154 | ShaderLibrary library; | ||
| 155 | CHECK(library.load(scratch.path())); | ||
| 156 | const auto* a = library.find("vs", "a"); | ||
| 157 | const auto* b = library.find("ps", "b"); | ||
| 158 | CHECK(a && b && graphics_partition_invariant(*a) && graphics_partition_invariant(*b)); | ||
| 159 | for (const auto* shader : {library.find("gs", "c"), library.find("ps", "unknown"), library.find("ps", "bad")}) | ||
| 160 | CHECK(shader && !graphics_partition_invariant(*shader)); | ||
| 161 | // The size decision itself does not change: 64 cannot be had on NVIDIA, and AMD still gets it natively. | ||
| 162 | const auto fixed = decide_subgroup_size(*b, nvidia()); | ||
| 163 | CHECK(fixed.outcome == SubgroupOutcome::unavailable && fixed.wanted == 64 && fixed.size == 0 && fixed.flags == 0); | ||
| 164 | const auto native = decide_subgroup_size(*b, amd()); | ||
| 165 | CHECK(native.outcome == SubgroupOutcome::required && native.size == 64); | ||
| 166 | } | ||
| 167 | |||
| 141 | // --- An old RADV: COMPUTE only ---------------------------------------------------------------------------------- | 168 | // --- An old RADV: COMPUTE only ---------------------------------------------------------------------------------- |
| 142 | { | 169 | { |
| 143 | const SubgroupSizeCaps caps = old_radv(); | 170 | const SubgroupSizeCaps caps = old_radv(); |