upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authoriFeyz <62035583+iFeyz@users.noreply.github.com>2026-11-24 16:45:13 +0100
committeriFeyz <62035583+iFeyz@users.noreply.github.com>2026-11-24 16:50:49 +0100
commit5fdd6abbc07a0b2e4120944b4e624e3a70ddb76e (patch)
tree22a6ccd466c4e735b5d78e1912d55d3c0a2e8a2a /runtime
parent1504c1af63aeab49fb451ee42d3d051b29d4c976 (diff)
D3D-448-GRAPHICS: graphics root arguments in the console layout, mesh shaders through a window
The graphics bind point laid root arguments out with pack() (from s0, two dwords per table), while the console starts them at s8 for VS/PS/GS with one dword per table (the corpus census, and the retail frame loop reading its tables at s8..s10). Compute already took the console layout (D3D-448); graphics waited because a mesh shader (s16) and a pixel shader (s8) share one push-constant block. - translator: user_data_dword() - a mesh shader loads s16..s31 from push dwords 8..23, s8..s15 as 0, s0..s7 unchanged, so root dword k is push dword 8 + k for every graphics stage; index.json records the window as "root_window" on mesh shaders. VS/PS/GS/CS are unchanged. - runtime: CreateRootSignature lays graphics out with pack_stage(Stage::Vertex) and checks Stage::Mesh (mesh_ok); a table is one dword at both bind points; DispatchMesh with a signature past the 16-dword mesh window invalidates the list; a mesh PSO whose mesh shader has no root_window (translated before) is refused with a log line. - fixtures: the GLSL stand-ins read the root arguments at push dword 8 + k; the M1.5/M2/M3 asm read their tables as one dword from s8. - tests: tests/semantic/test_ms_root_window.py (MeshEXT and --mesh-compute on the CPU interpreter), graphics-window cases in root_signature_test, the two refusals in d3d12_mesh_test. - docs: d3d12_vulkan.md 3.5, design.md user-data row.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/d3d12_com.cpp11
-rw-r--r--runtime/shims/d3d12_com.h14
-rw-r--r--runtime/shims/d3d12_vulkan_device.cpp49
-rw-r--r--runtime/src/root_signature.h7
-rw-r--r--runtime/src/shader_library.h9
-rw-r--r--runtime/test/d3d12_mesh_test.cpp42
-rw-r--r--runtime/test/glsl/ms_draw.mesh5
-rw-r--r--runtime/test/glsl/ps_depth_write.frag4
-rw-r--r--runtime/test/glsl/ps_draw.frag4
-rw-r--r--runtime/test/glsl/ps_image_atomic.frag2
-rw-r--r--runtime/test/glsl/vs_depth.vert6
-rw-r--r--runtime/test/glsl/vs_draw.vert4
-rw-r--r--runtime/test/glsl/vs_draw_int.vert2
-rw-r--r--runtime/test/root_signature_test.cpp42
-rw-r--r--runtime/test/shaders/ps_m15.asm13
-rw-r--r--runtime/test/shaders/ps_m2.asm6
-rw-r--r--runtime/test/shaders/ps_m2_array.asm6
-rw-r--r--runtime/test/shaders/ps_m2_literal.asm4
-rw-r--r--runtime/test/shaders/ps_m2_uoff.asm8
-rw-r--r--runtime/test/shaders/ps_m3.asm5
-rw-r--r--runtime/test/shaders/ps_m3_post.asm7
-rw-r--r--runtime/test/shaders/ps_m3_query.asm5
-rw-r--r--runtime/test/shaders/vs_m15.asm19
-rw-r--r--runtime/test/shaders/vs_m3.asm10
24 files changed, 227 insertions, 57 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp
index 4f4904e96..f67254bc5 100644
--- a/runtime/shims/d3d12_com.cpp
+++ b/runtime/shims/d3d12_com.cpp
@@ -486,6 +486,11 @@ public:
486 d3d12_trace::record("ID3D12GraphicsCommandList6::DispatchMesh"); 486 d3d12_trace::record("ID3D12GraphicsCommandList6::DispatchMesh");
487 if (x > 65535 || y > 65535 || z > 65535 || std::uint64_t(x) * y * z > (1u << 22)) return check(false); 487 if (x > 65535 || y > 65535 || z > 65535 || std::uint64_t(x) * y * z > (1u << 22)) return check(false);
488 if (!graphics_pipeline_ || !graphics_.layout) return check(false); 488 if (!graphics_pipeline_ || !graphics_.layout) return check(false);
489 // A mesh shader reads the root arguments from s16 through a 16-dword window (RootArgumentLayout::mesh_ok).
490 if (!graphics_.layout->mesh_ok) {
491 stub("DispatchMesh(root signature larger than a mesh shader's root window)");
492 return check(false);
493 }
489 if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; // as record_draw: nothing is rasterized 494 if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; // as record_draw: nothing is rasterized
490 leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, {}, 0, viewport_, 495 leonida::Draw draw{graphics_pipeline_, graphics_.data, draw_views(), depth_, {}, 0, viewport_,
491 scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0}; 496 scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0};
@@ -1242,9 +1247,9 @@ private:
1242 if (!p) return; 1247 if (!p) return;
1243 const std::uint32_t first = first_dword(state, *p); 1248 const std::uint32_t first = first_dword(state, *p);
1244 write(state, first, std::uint32_t(va)); 1249 write(state, first, std::uint32_t(va));
1245 // In the compute layout a descriptor table is one dword, the 32-bit VA of its first descriptor (the heaps 1250 // In the console layout of both bind points a descriptor table is one dword, the 32-bit VA of its first
1246 // live below 4 GiB); a root view keeps both halves. The graphics layout gives every address two dwords. 1251 // descriptor (the heaps live below 4 GiB); a root view keeps both halves (D3D-448).
1247 if (!(is_compute(state) && type == rt::rootsig::ParamType::Table)) write(state, first + 1, std::uint32_t(va >> 32)); 1252 if (type != rt::rootsig::ParamType::Table) write(state, first + 1, std::uint32_t(va >> 32));
1248 } 1253 }
1249 1254
1250 D3D12_COMMAND_LIST_TYPE type_; 1255 D3D12_COMMAND_LIST_TYPE type_;
diff --git a/runtime/shims/d3d12_com.h b/runtime/shims/d3d12_com.h
index c0ff3cf8d..f389e39cf 100644
--- a/runtime/shims/d3d12_com.h
+++ b/runtime/shims/d3d12_com.h
@@ -381,21 +381,25 @@ std::unique_ptr<WindowPresenter> create_window_presenter(ID3D12Device* device, H
381 381
382// Where each root parameter's arguments go in the 32 user-data dwords the translated shaders read (docs section 382// Where each root parameter's arguments go in the 32 user-data dwords the translated shaders read (docs section
383// 3.5). Built when a Vulkan device creates the root signature. A signature can be bound at either bind point, so it 383// 3.5). Built when a Vulkan device creates the root signature. A signature can be bound at either bind point, so it
384// carries both layouts: 384// carries both layouts, each the console layout rt::rootsig::pack_stage() gives (one dword per table):
385// - graphics: rt::rootsig::pack() (from s0, two dwords per table; D3D-448 keeps it until per-stage user-data windows 385// - graphics: Stage::Vertex, from s8. A vertex, pixel or geometry shader reads SGPR i from push dword i, so root
386// exist, because a mesh shader (s16) and a pixel shader (s8) share one push-constant block); 386// dword k is push dword 8 + k for all three. A mesh shader's root arguments start at s16; the translator loads its
387// - compute: rt::rootsig::pack_stage(Stage::Compute), the measured console layout (from s4, one dword per table). 387// s16.. from push dwords 8.. ("root_window" in index.json), so the same block serves both stages of a mesh
388// pipeline. Its window is 16 dwords: mesh_ok says whether Stage::Mesh places the signature too, and a mesh draw
389// with one it refuses invalidates the list (D3D-448 follow-up);
390// - compute: Stage::Compute, from s4 (measured, D3D-448).
388// A layout that refuses the signature is marked unusable; binding the signature there invalidates the list. 391// A layout that refuses the signature is marked unusable; binding the signature there invalidates the list.
389struct RootArgumentLayout { 392struct RootArgumentLayout {
390 struct Parameter { 393 struct Parameter {
391 rt::rootsig::ParamType type; 394 rt::rootsig::ParamType type;
392 std::uint32_t user_offset; // graphics: first dword; unused for a parameter with no dwords 395 std::uint32_t user_offset; // graphics: first push dword; unused for a parameter with no dwords
393 std::uint32_t constant_count; // constants only 396 std::uint32_t constant_count; // constants only
394 std::uint32_t compute_offset = rt::rootsig::kNoSgpr; // compute: first user SGPR 397 std::uint32_t compute_offset = rt::rootsig::kNoSgpr; // compute: first user SGPR
395 }; 398 };
396 std::vector<Parameter> parameters; 399 std::vector<Parameter> parameters;
397 std::uint32_t flags = 0; // D3D12_ROOT_SIGNATURE_FLAGS from the serialized blob 400 std::uint32_t flags = 0; // D3D12_ROOT_SIGNATURE_FLAGS from the serialized blob
398 bool graphics_ok = true; 401 bool graphics_ok = true;
402 bool mesh_ok = true; // the graphics layout also fits a mesh shader's 16-dword window
399 bool compute_ok = true; 403 bool compute_ok = true;
400}; 404};
401 405
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp
index 97ed334a1..d8b18a11d 100644
--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -3558,6 +3558,15 @@ public:
3558 std::fprintf(stderr, "[rt] d3d12: %s\n", refusal.c_str()); 3558 std::fprintf(stderr, "[rt] d3d12: %s\n", refusal.c_str());
3559 return E_NOTIMPL; 3559 return E_NOTIMPL;
3560 } 3560 }
3561 // The graphics bind point lays root arguments out from push dword 8, which a mesh shader reads from
3562 // its s16 only when translated with the graphics root window (index "root_window", D3D-448).
3563 if (!stage.entry->graphics_root_window) {
3564 std::fprintf(stderr,
3565 "[rt] d3d12: mesh shader %s was translated before the graphics root window; translate "
3566 "the shaders again (make_game.py --stages shaders)\n",
3567 stage.entry->name.c_str());
3568 return E_INVALIDARG;
3569 }
3561 } 3570 }
3562 if (stage.entry->uses_code_base) { 3571 if (stage.entry->uses_code_base) {
3563 if (code_stage) { 3572 if (code_stage) {
@@ -6020,40 +6029,42 @@ public:
6020 if (container_size != size) return E_INVALIDARG; 6029 if (container_size != size) return E_INVALIDARG;
6021 } 6030 }
6022 // The repository's root-signature model (runtime/src/root_signature.h): parse the RTS0 blob, then pack 6031 // The repository's root-signature model (runtime/src/root_signature.h): parse the RTS0 blob, then pack
6023 // the parameters into the 32 user-data dwords. pack() refuses what it cannot place (more than 32 dwords: 6032 // the parameters into the 32 user-data dwords in the console layout. pack_stage() refuses what it cannot
6024 // the console spills those to memory, in a layout that is still open), and so does this. 6033 // place (past s31: the console spills those to memory, in a layout that is still open), and so does this.
6025 const rt::rootsig::DecodeResult parsed = rt::rootsig::parse_rts0(bytes, size); 6034 const rt::rootsig::DecodeResult parsed = rt::rootsig::parse_rts0(bytes, size);
6026 if (!parsed.ok) { 6035 if (!parsed.ok) {
6027 std::fprintf(stderr, "[rt] d3d12: root signature not understood: %s\n", parsed.error.c_str()); 6036 std::fprintf(stderr, "[rt] d3d12: root signature not understood: %s\n", parsed.error.c_str());
6028 return E_INVALIDARG; 6037 return E_INVALIDARG;
6029 } 6038 }
6030 // Two layouts, one per bind point (RootArgumentLayout): graphics keeps pack(), compute takes the console 6039 // One layout per bind point (RootArgumentLayout), both the console's (D3D-448): graphics from s8, where a
6031 // layout pack_stage() measured (D3D-448). The signature is refused only when neither can place it. 6040 // vertex, pixel or geometry shader reads SGPR i from push dword i, and compute from s4. A mesh shader reads
6032 const rt::rootsig::PackResult packed = rt::rootsig::pack(parsed.sig); 6041 // the same graphics window from its s16, so its 16-dword window only needs checking. The signature is
6042 // refused only when neither bind point can place it.
6043 const rt::rootsig::StagePackResult graphics = rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Vertex);
6044 const rt::rootsig::StagePackResult mesh = rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Mesh);
6033 const rt::rootsig::StagePackResult compute = rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Compute); 6045 const rt::rootsig::StagePackResult compute = rt::rootsig::pack_stage(parsed.sig, rt::rootsig::Stage::Compute);
6034 if (!packed.ok && !compute.ok) { 6046 if (!graphics.ok && !compute.ok) {
6035 std::fprintf(stderr, "[rt] d3d12: root signature refused: %s (compute: %s)\n", packed.error.c_str(), 6047 std::fprintf(stderr, "[rt] d3d12: root signature refused: %s (compute: %s)\n", graphics.error.c_str(),
6036 compute.error.c_str()); 6048 compute.error.c_str());
6037 return E_INVALIDARG; 6049 return E_INVALIDARG;
6038 } 6050 }
6039 if (!packed.ok) 6051 if (!graphics.ok)
6040 std::fprintf(stderr, "[rt] d3d12: root signature usable for compute only: %s\n", packed.error.c_str()); 6052 std::fprintf(stderr, "[rt] d3d12: root signature usable for compute only: %s\n", graphics.error.c_str());
6053 else if (!mesh.ok)
6054 std::fprintf(stderr, "[rt] d3d12: root signature too large for a mesh shader's root window: %s\n",
6055 mesh.error.c_str());
6041 if (!compute.ok) 6056 if (!compute.ok)
6042 std::fprintf(stderr, "[rt] d3d12: root signature usable for graphics only: %s\n", compute.error.c_str()); 6057 std::fprintf(stderr, "[rt] d3d12: root signature usable for graphics only: %s\n", compute.error.c_str());
6043 RootArgumentLayout layout; 6058 RootArgumentLayout layout;
6044 layout.flags = parsed.sig.flags; 6059 layout.flags = parsed.sig.flags;
6045 layout.graphics_ok = packed.ok; 6060 layout.graphics_ok = graphics.ok;
6061 layout.mesh_ok = graphics.ok && mesh.ok;
6046 layout.compute_ok = compute.ok; 6062 layout.compute_ok = compute.ok;
6047 for (std::size_t i = 0; i < parsed.sig.params.size(); ++i) { 6063 for (std::size_t i = 0; i < parsed.sig.params.size(); ++i)
6048 std::uint32_t first = UINT32_MAX; 6064 layout.parameters.push_back({parsed.sig.params[i].type,
6049 for (std::uint32_t d = 0; packed.ok && d < packed.dword_count; ++d) 6065 graphics.ok ? graphics.first_sgpr[i] : rt::rootsig::kNoSgpr,
6050 if (packed.provenance[d].param_index == i) { 6066 parsed.sig.params[i].num_values,
6051 first = d;
6052 break;
6053 }
6054 layout.parameters.push_back({parsed.sig.params[i].type, first, parsed.sig.params[i].num_values,
6055 compute.ok ? compute.first_sgpr[i] : rt::rootsig::kNoSgpr}); 6067 compute.ok ? compute.first_sgpr[i] : rt::rootsig::kNoSgpr});
6056 }
6057 register_static_samplers(parsed.sig); 6068 register_static_samplers(parsed.sig);
6058 auto* signature = new RootSignature( 6069 auto* signature = new RootSignature(
6059 std::move(layout), leonida::sha256_hex({static_cast<const std::uint8_t*>(blob), size})); 6070 std::move(layout), leonida::sha256_hex({static_cast<const std::uint8_t*>(blob), size}));
diff --git a/runtime/src/root_signature.h b/runtime/src/root_signature.h
index 376962940..d1b8e38b4 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::Vertex; a mesh shader reads the same dwords through its translator-side
136// 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; that array is not modelled, so such a signature is refused, never truncated. 138// every parameter after it; that array is not modelled, so such a signature is refused, never truncated.
136enum class Stage : uint32_t { Vertex = 0, Pixel = 1, Geometry = 2, Compute = 3, Mesh = 4 }; 139enum class Stage : uint32_t { Vertex = 0, Pixel = 1, Geometry = 2, Compute = 3, Mesh = 4 };
diff --git a/runtime/src/shader_library.h b/runtime/src/shader_library.h
index 9f752317e..9cfb902ef 100644
--- a/runtime/src/shader_library.h
+++ b/runtime/src/shader_library.h
@@ -827,6 +827,9 @@ struct ShaderEntry {
827 // subgroup size. Empty for a native translation. 827 // subgroup size. Empty for a native translation.
828 std::string wave64_exchange; 828 std::string wave64_exchange;
829 bool emulated() const { return wave64_exchange == "workgroup"; } 829 bool emulated() const { return wave64_exchange == "workgroup"; }
830 // Mesh shaders: the index's "root_window" is {"sgpr": 16, "dword": 8}, so the module reads its root arguments
831 // from the graphics window (push dword 8 = root dword 0, D3D-448 follow-up). False for one translated before it.
832 bool graphics_root_window = false;
830 std::vector<SignatureElement> input_signature; // vertex shaders: what the input layout must feed 833 std::vector<SignatureElement> input_signature; // vertex shaders: what the input layout must feed
831 std::vector<std::uint32_t> inputs; // pixel shaders: input locations declared 834 std::vector<std::uint32_t> inputs; // pixel shaders: input locations declared
832 std::vector<std::uint32_t> outputs; // pixel/vertex shaders: output locations written 835 std::vector<std::uint32_t> outputs; // pixel/vertex shaders: output locations written
@@ -1026,6 +1029,12 @@ private:
1026 e.subgroup_size = u32(g); 1029 e.subgroup_size = u32(g);
1027 if (const Json* x = meta.find("wave64_exchange"); x && x->kind == Json::Kind::string) 1030 if (const Json* x = meta.find("wave64_exchange"); x && x->kind == Json::Kind::string)
1028 e.wave64_exchange = x->string; 1031 e.wave64_exchange = x->string;
1032 if (const Json* r = meta.find("root_window"); r && r->kind == Json::Kind::object) {
1033 const Json* sgpr = r->find("sgpr");
1034 const Json* dword = r->find("dword");
1035 e.graphics_root_window = sgpr && dword && sgpr->kind == Json::Kind::number &&
1036 dword->kind == Json::Kind::number && u32(sgpr) == 16 && u32(dword) == 8;
1037 }
1029 if (const Json* s = meta.find("input_signature"); s && s->kind == Json::Kind::array) { 1038 if (const Json* s = meta.find("input_signature"); s && s->kind == Json::Kind::array) {
1030 for (const Json& item : s->array) { 1039 for (const Json& item : s->array) {
1031 SignatureElement element; 1040 SignatureElement element;
diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp
index 1b99b8d0b..b4bf9adce 100644
--- a/runtime/test/d3d12_mesh_test.cpp
+++ b/runtime/test/d3d12_mesh_test.cpp
@@ -106,13 +106,17 @@ int main() {
106 EXPECT(device_status == vktest::DeviceStatus::ready); 106 EXPECT(device_status == vktest::DeviceStatus::ready);
107 107
108 const auto ms_program = fssm_program({0x4d530001, 0xbf810000}); 108 const auto ms_program = fssm_program({0x4d530001, 0xbf810000});
109 // The same mesh shader listed without "root_window": one translated before the graphics root window (D3D-448).
110 const auto ms_old_program = fssm_program({0x4d530002, 0xbf810000});
109 const auto ps_program = fssm_program({0x50530001, 0xbf810000}); 111 const auto ps_program = fssm_program({0x50530001, 0xbf810000});
110 const auto vs_program = fssm_program({0x56530002, 0xbf810000}); 112 const auto vs_program = fssm_program({0x56530002, 0xbf810000});
111 const auto ms_container = shader_container(ms_program), ps_container = shader_container(ps_program); 113 const auto ms_container = shader_container(ms_program), ps_container = shader_container(ps_program);
114 const auto ms_old_container = shader_container(ms_old_program);
112 const auto vs_container = shader_container(vs_program); 115 const auto vs_container = shader_container(vs_program);
113 const auto library = std::filesystem::temp_directory_path() / "leonida_mesh_test"; 116 const auto library = std::filesystem::temp_directory_path() / "leonida_mesh_test";
114 std::filesystem::create_directories(library); 117 std::filesystem::create_directories(library);
115 std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_draw.spv", std::filesystem::copy_options::overwrite_existing); 118 std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_draw.spv", std::filesystem::copy_options::overwrite_existing);
119 std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_old.spv", std::filesystem::copy_options::overwrite_existing);
116 std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); 120 std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing);
117 std::filesystem::copy_file(LEONIDA_TEST_VS_FULLSCREEN_SPV, library / "vs_fullscreen.spv", 121 std::filesystem::copy_file(LEONIDA_TEST_VS_FULLSCREEN_SPV, library / "vs_fullscreen.spv",
118 std::filesystem::copy_options::overwrite_existing); 122 std::filesystem::copy_options::overwrite_existing);
@@ -120,6 +124,9 @@ int main() {
120 std::ofstream index(library / "index.json", std::ios::binary); 124 std::ofstream index(library / "index.json", std::ios::binary);
121 index << "{\"ms_draw\": {\"stage\": \"ms\", \"fssm_sha256\": \"" << leonida::sha256_hex(ms_program) 125 index << "{\"ms_draw\": {\"stage\": \"ms\", \"fssm_sha256\": \"" << leonida::sha256_hex(ms_program)
122 << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"local_size\": [32, 1, 1], " 126 << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"local_size\": [32, 1, 1], "
127 "\"max_vertices\": 4, \"max_primitives\": 2, \"root_window\": {\"sgpr\": 16, \"dword\": 8}},\n"
128 " \"ms_old\": {\"stage\": \"ms\", \"fssm_sha256\": \"" << leonida::sha256_hex(ms_old_program)
129 << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"local_size\": [32, 1, 1], "
123 "\"max_vertices\": 4, \"max_primitives\": 2},\n" 130 "\"max_vertices\": 4, \"max_primitives\": 2},\n"
124 " \"vs_fullscreen\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program) 131 " \"vs_fullscreen\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program)
125 << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": []},\n" 132 << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": []},\n"
@@ -152,7 +159,8 @@ int main() {
152 return true; 159 return true;
153 }; 160 };
154 const auto root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root) { 161 const auto root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root) {
155 // [0] two constants (s0, s1: offset), [1] a root CBV (s2:s3: tint), as in d3d12_draw_test. 162 // [0] two constants (push dwords 8, 9: offset), [1] a root CBV (10, 11: tint), as in d3d12_draw_test. The
163 // mesh shader reads them as s16..s19 and the pixel shader as s8..s11 (the graphics root window, D3D-448).
156 D3D12_ROOT_PARAMETER params[2] = {}; 164 D3D12_ROOT_PARAMETER params[2] = {};
157 params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; 165 params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
158 params[0].Constants = {0, 0, 2}; 166 params[0].Constants = {0, 0, 2};
@@ -165,7 +173,20 @@ int main() {
165 return !blob.empty() && 173 return !blob.empty() &&
166 SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p))); 174 SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p)));
167 }; 175 };
176 // Twenty constants: s8..s27 for a pixel shader, but past a mesh shader's 16-dword window (s16..s31).
177 const auto wide_root_signature = [&](ID3D12Device* device, Ref<ID3D12RootSignature>& root) {
178 D3D12_ROOT_PARAMETER param{};
179 param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
180 param.Constants = {0, 0, 20};
181 D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{};
182 root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
183 root_desc.Desc_1_0 = {1, &param, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE};
184 const auto blob = serialize_root_signature(root_desc);
185 return !blob.empty() &&
186 SUCCEEDED(device->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p)));
187 };
168 const D3D12_SHADER_BYTECODE ms{ms_container.data(), ms_container.size()}; 188 const D3D12_SHADER_BYTECODE ms{ms_container.data(), ms_container.size()};
189 const D3D12_SHADER_BYTECODE ms_old{ms_old_container.data(), ms_old_container.size()};
169 const D3D12_SHADER_BYTECODE ps{ps_container.data(), ps_container.size()}; 190 const D3D12_SHADER_BYTECODE ps{ps_container.data(), ps_container.size()};
170 const D3D12_SHADER_BYTECODE vs{vs_container.data(), vs_container.size()}; 191 const D3D12_SHADER_BYTECODE vs{vs_container.data(), vs_container.size()};
171 192
@@ -211,6 +232,14 @@ int main() {
211 vs_stream.add(TopologySubobject{.inner = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE}); 232 vs_stream.add(TopologySubobject{.inner = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE});
212 vs_stream.add(TargetsSubobject{.inner = one_target()}); 233 vs_stream.add(TargetsSubobject{.inner = one_target()});
213 EXPECT(SUCCEEDED(create(device.p, vs_stream, vs_pso))); 234 EXPECT(SUCCEEDED(create(device.p, vs_stream, vs_pso)));
235 // A mesh shader translated before the graphics root window would read its root arguments from the wrong
236 // dwords: refused, with a log line that asks for the shaders stage again.
237 {
238 Stream old_stream;
239 old_stream.add(RootSubobject{.inner = root.p}).add(MsSubobject{.inner = ms_old}).add(PsSubobject{.inner = ps});
240 old_stream.add(TargetsSubobject{.inner = one_target()});
241 EXPECT(create(device.p, old_stream, refused) == E_INVALIDARG && !refused.p);
242 }
214 243
215 // Streams the PC runtime refuses. 244 // Streams the PC runtime refuses.
216 Stream bad = mesh_stream; 245 Stream bad = mesh_stream;
@@ -399,6 +428,17 @@ int main() {
399 list->RSSetViewports(1, &viewport); 428 list->RSSetViewports(1, &viewport);
400 list6->DispatchMesh(4096, 1025, 1); 429 list6->DispatchMesh(4096, 1025, 1);
401 EXPECT(list->Close() == E_INVALIDARG); 430 EXPECT(list->Close() == E_INVALIDARG);
431 // A root signature the graphics bind point places (s8..s27) but a mesh shader's window cannot (s16..s31): a
432 // vertex draw may use it, DispatchMesh may not.
433 {
434 Ref<ID3D12RootSignature> wide;
435 EXPECT(wide_root_signature(device.p, wide));
436 EXPECT(SUCCEEDED(list->Reset(allocator.p, mesh_pso.p)));
437 list->SetGraphicsRootSignature(wide.p);
438 list->RSSetViewports(1, &viewport);
439 list6->DispatchMesh(1, 1, 1);
440 EXPECT(list->Close() == E_INVALIDARG);
441 }
402 EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr))); 442 EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr)));
403 443
404 // D3D-291: pipeline statistics around mesh draws. Query 0 holds a vertex draw, two mesh draws and another 444 // D3D-291: pipeline statistics around mesh draws. Query 0 holds a vertex draw, two mesh draws and another
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_depth_write.frag b/runtime/test/glsl/ps_depth_write.frag
index 959d1dd9d..b176e08cc 100644
--- a/runtime/test/glsl/ps_depth_write.frag
+++ b/runtime/test/glsl/ps_depth_write.frag
@@ -1,5 +1,5 @@
1#version 460 1#version 460
2// A pixel shader that writes its own depth (SV_Depth), for d3d12_depth24_draw_test: s2 is the depth it writes. On a 2// A pixel shader that writes its own depth (SV_Depth), for d3d12_depth24_draw_test: s10 is the depth it writes. On a
3// D24 target the value is stored quantised to 24 bits, and D3D applies no depth bias to it. 3// D24 target the value is stored quantised to 24 bits, and D3D applies no depth bias to it.
4 4
5layout(push_constant) uniform UserData { 5layout(push_constant) uniform UserData {
@@ -9,5 +9,5 @@ layout(push_constant) uniform UserData {
9} pc; 9} pc;
10 10
11void main() { 11void main() {
12 gl_FragDepth = uintBitsToFloat(pc.s[2]); 12 gl_FragDepth = uintBitsToFloat(pc.s[10]);
13} 13}
diff --git a/runtime/test/glsl/ps_draw.frag b/runtime/test/glsl/ps_draw.frag
index 2361330f4..b356cf743 100644
--- a/runtime/test/glsl/ps_draw.frag
+++ b/runtime/test/glsl/ps_draw.frag
@@ -1,6 +1,6 @@
1#version 460 1#version 460
2// A pixel shader written to the translator's runtime contract, standing in for a translated one in 2// A pixel shader written to the translator's runtime contract, standing in for a translated one in
3// d3d12_draw_test. s2:s3 is a root CBV: the console VA of three floats (a tint), read at heap base + VA. The output 3// d3d12_draw_test. s10:s11 is a root CBV: the console VA of three floats (a tint), read at heap base + VA. The output
4// is (red * tint.x, tint.y, blue * tint.z, 1). 4// is (red * tint.x, tint.y, blue * tint.z, 1).
5#extension GL_EXT_buffer_reference : require 5#extension GL_EXT_buffer_reference : require
6#extension GL_EXT_buffer_reference_uvec2 : require 6#extension GL_EXT_buffer_reference_uvec2 : require
@@ -25,6 +25,6 @@ uvec2 add64(uvec2 a, uvec2 b) {
25} 25}
26 26
27void main() { 27void main() {
28 Floats tint = Floats(add64(pc.heap_base, uvec2(pc.s[2], pc.s[3]))); 28 Floats tint = Floats(add64(pc.heap_base, uvec2(pc.s[10], pc.s[11])));
29 target = vec4(color.r * tint.f[0], tint.f[1], color.b * tint.f[2], 1.0); 29 target = vec4(color.r * tint.f[0], tint.f[1], color.b * tint.f[2], 1.0);
30} 30}
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 {
19layout(set = 0, binding = 4, r32ui) uniform uimage2D counters[]; 19layout(set = 0, binding = 4, r32ui) uniform uimage2D counters[];
20 20
21void main() { 21void 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/glsl/vs_depth.vert b/runtime/test/glsl/vs_depth.vert
index de1d6ee40..1ade14c15 100644
--- a/runtime/test/glsl/vs_depth.vert
+++ b/runtime/test/glsl/vs_depth.vert
@@ -1,7 +1,7 @@
1#version 460 1#version 460
2// A full-screen triangle at a chosen depth, written to the translator's runtime contract (docs/design.md, "User 2// A full-screen triangle at a chosen depth, written to the translator's runtime contract (docs/design.md, "User
3// data"), for d3d12_depth24_draw_test: s0 is the depth at the centre and s1 how much it changes per unit of clip-space 3// data"), for d3d12_depth24_draw_test: s8 is the depth at the centre and s9 how much it changes per unit of clip-space
4// x, so s1 = 0 gives a flat triangle and anything else a constant slope across the target. 4// x, so s9 = 0 gives a flat triangle and anything else a constant slope across the target.
5 5
6layout(push_constant) uniform UserData { 6layout(push_constant) uniform UserData {
7 uint s[32]; 7 uint s[32];
@@ -12,5 +12,5 @@ layout(push_constant) uniform UserData {
12void main() { 12void main() {
13 const vec2 corner = vec2(float(gl_VertexIndex & 2), float((gl_VertexIndex << 1) & 2)); 13 const vec2 corner = vec2(float(gl_VertexIndex & 2), float((gl_VertexIndex << 1) & 2));
14 const vec2 xy = corner * 2.0 - 1.0; 14 const vec2 xy = corner * 2.0 - 1.0;
15 gl_Position = vec4(xy, uintBitsToFloat(pc.s[0]) + uintBitsToFloat(pc.s[1]) * xy.x, 1.0); 15 gl_Position = vec4(xy, uintBitsToFloat(pc.s[8]) + uintBitsToFloat(pc.s[9]) * xy.x, 1.0);
16} 16}
diff --git a/runtime/test/glsl/vs_draw.vert b/runtime/test/glsl/vs_draw.vert
index 3cde02a50..a76402e76 100644
--- a/runtime/test/glsl/vs_draw.vert
+++ b/runtime/test/glsl/vs_draw.vert
@@ -2,7 +2,7 @@
2// A vertex shader written to the translator's runtime contract (docs/design.md, "Vertex fetch" and "User data"), 2// A vertex shader written to the translator's runtime contract (docs/design.md, "Vertex fetch" and "User data"),
3// standing in for a translated one in d3d12_draw_test. Inputs sit at location = D3D input register: COLOR is 3// standing in for a translated one in d3d12_draw_test. Inputs sit at location = D3D input register: COLOR is
4// register 0 and POSITION register 1 here, the reverse of the input layout's order, so the test shows that the 4// register 0 and POSITION register 1 here, the reverse of the input layout's order, so the test shows that the
5// layout is matched by semantic. s0, s1 (root constants) move the vertex in clip space. 5// layout is matched by semantic. s8, s9 (root constants) move the vertex in clip space.
6 6
7layout(location = 0) in vec4 color; // COLOR0, input register 0 7layout(location = 0) in vec4 color; // COLOR0, input register 0
8layout(location = 1) in vec4 position; // POSITION0, input register 1 8layout(location = 1) in vec4 position; // POSITION0, input register 1
@@ -16,7 +16,7 @@ layout(push_constant) uniform UserData {
16} pc; 16} pc;
17 17
18void main() { 18void main() {
19 const vec2 offset = vec2(uintBitsToFloat(pc.s[0]), uintBitsToFloat(pc.s[1])); 19 const vec2 offset = vec2(uintBitsToFloat(pc.s[8]), uintBitsToFloat(pc.s[9]));
20 gl_Position = vec4(position.xy + offset, 0.0, 1.0); 20 gl_Position = vec4(position.xy + offset, 0.0, 1.0);
21 out_color = color; 21 out_color = color;
22} 22}
diff --git a/runtime/test/glsl/vs_draw_int.vert b/runtime/test/glsl/vs_draw_int.vert
index ea5782469..cb4f5ca73 100644
--- a/runtime/test/glsl/vs_draw_int.vert
+++ b/runtime/test/glsl/vs_draw_int.vert
@@ -14,7 +14,7 @@ layout(push_constant) uniform UserData {
14} pc; 14} pc;
15 15
16void main() { 16void main() {
17 const vec2 offset = vec2(uintBitsToFloat(pc.s[0]), uintBitsToFloat(pc.s[1])); 17 const vec2 offset = vec2(uintBitsToFloat(pc.s[8]), uintBitsToFloat(pc.s[9]));
18 gl_Position = vec4(position.xy + offset, 0.0, 1.0); 18 gl_Position = vec4(position.xy + offset, 0.0, 1.0);
19 out_color = vec4(color); 19 out_color = vec4(color);
20} 20}
diff --git a/runtime/test/root_signature_test.cpp b/runtime/test/root_signature_test.cpp
index 831739a8c..9c3d6c69f 100644
--- a/runtime/test/root_signature_test.cpp
+++ b/runtime/test/root_signature_test.cpp
@@ -449,6 +449,48 @@ int main() {
449 check(!pack_stage(tables, Stage::Mesh).ok, "pack_stage: a 17th table spills on mesh"); 449 check(!pack_stage(tables, Stage::Mesh).ok, "pack_stage: a 17th table spills on mesh");
450 } 450 }
451 451
452 // The graphics root window (D3D-448 follow-up): the graphics bind point lays a signature out once with
453 // Stage::Vertex, root dword k at push dword 8 + k. A vertex, pixel or geometry shader reads SGPR i from push
454 // dword i, and a mesh shader its s16 + k from push dword 8 + k (tools/rdna2spirv.py, user_data_dword), so every
455 // stage of a pipeline finds each parameter in the same dword. The mesh window holds 16 dwords, the others 24.
456 {
457 const std::vector<RootSignature> shapes = [] {
458 std::vector<RootSignature> out(4);
459 out[0].params = {consts(2), view()};
460 out[1].params = {table(), table(), consts(1)};
461 out[2].params = {table(), consts(4), view(), table()};
462 out[3].params.assign(16, table());
463 return out;
464 }();
465 for (std::size_t s = 0; s < shapes.size(); ++s) {
466 const StagePackResult vs = pack_stage(shapes[s], Stage::Vertex);
467 const StagePackResult ps = pack_stage(shapes[s], Stage::Pixel);
468 const StagePackResult gs = pack_stage(shapes[s], Stage::Geometry);
469 const StagePackResult ms = pack_stage(shapes[s], Stage::Mesh);
470 check(vs.ok && ps.ok && gs.ok && ms.ok, "graphics window: the shape fits every graphics stage");
471 check(vs.first_sgpr == ps.first_sgpr && vs.first_sgpr == gs.first_sgpr,
472 "graphics window: VS, PS and GS place every parameter in the same SGPR");
473 bool same_dword = vs.first_sgpr.size() == ms.first_sgpr.size();
474 for (std::size_t i = 0; same_dword && i < vs.first_sgpr.size(); ++i)
475 same_dword = vs.first_sgpr[i] - 8 == ms.first_sgpr[i] - 16;
476 check(same_dword, "graphics window: a mesh shader's s16 + k is the pixel shader's s8 + k");
477 }
478 RootSignature twenty;
479 twenty.params = {consts(20)};
480 check(pack_stage(twenty, Stage::Vertex).ok && !pack_stage(twenty, Stage::Mesh).ok,
481 "graphics window: 20 dwords fit a pixel shader (24 from s8) but not a mesh shader (16 from s16)");
482 RootSignature full;
483 full.params = {consts(24)};
484 check(pack_stage(full, Stage::Pixel).ok, "graphics window: 24 constants fill s8..s31 exactly");
485 full.params = {consts(23), view()};
486 check(!pack_stage(full, Stage::Pixel).ok, "graphics window: a root view past s31 spills");
487 RootSignature tables;
488 tables.params = {table(), table()};
489 const StagePackResult t = pack_stage(tables, Stage::Pixel);
490 check(t.ok && t.first_sgpr == std::vector<uint32_t>({8, 9}) && t.end_sgpr == 10,
491 "graphics window: two tables are s8 and s9, one dword each (pack() gave s[0:1] and s[2:3])");
492 }
493
452 // pack_stage keeps pack()'s validation. 494 // pack_stage keeps pack()'s validation.
453 { 495 {
454 RootSignature zero; 496 RootSignature zero;
diff --git a/runtime/test/shaders/ps_m15.asm b/runtime/test/shaders/ps_m15.asm
index 4c924a72f..9baeecc53 100644
--- a/runtime/test/shaders/ps_m15.asm
+++ b/runtime/test/shaders/ps_m15.asm
@@ -5,7 +5,8 @@
5; code base, dwords 34-35, is the console VA of the FSSM program the layer uploaded). The table of four floats is at 5; code base, dwords 34-35, is the console VA of the FSSM program the layer uploaded). The table of four floats is at
6; blob offset 0x100: 0x100 - 4 = 0xfc. build.py writes that blob (fssm-at / fssm-data below) next to the SPIR-V, and 6; blob offset 0x100: 0x100 - 4 = 0xfc. build.py writes that blob (fssm-at / fssm-data below) next to the SPIR-V, and
7; adds its SHA-256 to the index, as the translator's --fssm-dir does for the game's programs. 7; adds its SHA-256 to the index, as the translator's --fssm-dir does for the game's programs.
8; scale = (0.5, 2.0, 1.0, 1.0) s4 = bias, a float from the root constants (s2, s3 are the VS offset) 8; scale = (0.5, 2.0, 1.0, 1.0) s11 = bias, a float from the root constants (s9, s10 are the VS offset;
9; console root layout from s8, D3D-448)
9; mrt0 = (r * 0.5 + bias, g * 2.0 + bias, b * 1.0 + bias, a * 1.0) 10; mrt0 = (r * 0.5 + bias, g * 2.0 + bias, b * 1.0 + bias, a * 1.0)
10; The test draws colour (0.25, 0.5, 0.75, 1) with bias 0 and 0.125, and colour (1, 0, 0.5, 1) with bias 0.25. Every 11; The test draws colour (0.25, 0.5, 0.75, 1) with bias 0 and 0.125, and colour (1, 0, 0.5, 1) with bias 0.25. Every
11; value is a short binary fraction, so the float render target holds the exact result, bit for bit: 12; value is a short binary fraction, so the float render target holds the exact result, bit for bit:
@@ -18,7 +19,7 @@
18s_getpc_b64 s[6:7] 19s_getpc_b64 s[6:7]
19s_add_u32 s6, s6, 0xfc 20s_add_u32 s6, s6, 0xfc
20s_addc_u32 s7, s7, 0 21s_addc_u32 s7, s7, 0
21s_load_dwordx4 s[8:11], s[6:7], 0x0 22s_load_dwordx4 s[12:15], s[6:7], 0x0
22v_interp_p1_f32_e32 v2, v0, attr0.x 23v_interp_p1_f32_e32 v2, v0, attr0.x
23v_interp_p2_f32_e32 v2, v1, attr0.x 24v_interp_p2_f32_e32 v2, v1, attr0.x
24v_interp_p1_f32_e32 v3, v0, attr0.y 25v_interp_p1_f32_e32 v3, v0, attr0.y
@@ -28,9 +29,9 @@ v_interp_p2_f32_e32 v4, v1, attr0.z
28v_interp_p1_f32_e32 v5, v0, attr0.w 29v_interp_p1_f32_e32 v5, v0, attr0.w
29v_interp_p2_f32_e32 v5, v1, attr0.w 30v_interp_p2_f32_e32 v5, v1, attr0.w
30s_waitcnt lgkmcnt(0) 31s_waitcnt lgkmcnt(0)
31v_fma_f32 v2, v2, s8, s4 32v_fma_f32 v2, v2, s12, s11
32v_fma_f32 v3, v3, s9, s4 33v_fma_f32 v3, v3, s13, s11
33v_fma_f32 v4, v4, s10, s4 34v_fma_f32 v4, v4, s14, s11
34v_mul_f32_e32 v5, s11, v5 35v_mul_f32_e32 v5, s15, v5
35exp mrt0 v2, v3, v4, v5 done vm 36exp mrt0 v2, v3, v4, v5 done vm
36s_endpgm 37s_endpgm
diff --git a/runtime/test/shaders/ps_m2.asm b/runtime/test/shaders/ps_m2.asm
index 0f23cefa3..c19b07550 100644
--- a/runtime/test/shaders/ps_m2.asm
+++ b/runtime/test/shaders/ps_m2.asm
@@ -7,6 +7,12 @@
7; attr0.xy = (u, v), 0..1 over the quad. mrt0 = the texel under the pixel. 7; attr0.xy = (u, v), 0..1 over the quad. mrt0 = the texel under the pixel.
8; fssm-at: 0x10 8; fssm-at: 0x10
9; fssm-data: 0x324d5350 0x20535020 9; fssm-data: 0x324d5350 0x20535020
10; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
11; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
12s_mov_b32 s0, s8
13s_mov_b32 s2, s9
14s_mov_b32 s1, 0
15s_mov_b32 s3, 0
10s_load_dwordx8 s[8:15], s[0:1], 0x0 16s_load_dwordx8 s[8:15], s[0:1], 0x0
11s_load_dwordx4 s[16:19], s[2:3], 0x0 17s_load_dwordx4 s[16:19], s[2:3], 0x0
12s_waitcnt lgkmcnt(0) 18s_waitcnt lgkmcnt(0)
diff --git a/runtime/test/shaders/ps_m2_array.asm b/runtime/test/shaders/ps_m2_array.asm
index 96260bd0a..2d9723bd7 100644
--- a/runtime/test/shaders/ps_m2_array.asm
+++ b/runtime/test/shaders/ps_m2_array.asm
@@ -4,6 +4,12 @@
4; attr0.xy = (u, v), 0..1 over the quad. mrt0 = the texel under the pixel. 4; attr0.xy = (u, v), 0..1 over the quad. mrt0 = the texel under the pixel.
5; fssm-at: 0x10 5; fssm-at: 0x10
6; fssm-data: 0x324d5350 0x59525241 6; fssm-data: 0x324d5350 0x59525241
7; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
8; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
9s_mov_b32 s0, s8
10s_mov_b32 s2, s9
11s_mov_b32 s1, 0
12s_mov_b32 s3, 0
7s_load_dwordx8 s[8:15], s[0:1], 0x0 13s_load_dwordx8 s[8:15], s[0:1], 0x0
8s_load_dwordx4 s[16:19], s[2:3], 0x0 14s_load_dwordx4 s[16:19], s[2:3], 0x0
9s_waitcnt lgkmcnt(0) 15s_waitcnt lgkmcnt(0)
diff --git a/runtime/test/shaders/ps_m2_literal.asm b/runtime/test/shaders/ps_m2_literal.asm
index f77ef197f..6268c292f 100644
--- a/runtime/test/shaders/ps_m2_literal.asm
+++ b/runtime/test/shaders/ps_m2_literal.asm
@@ -5,6 +5,10 @@
5; s[0:1] = console VA of the SRV table's first slot (the T#). attr0.xy = (u, v). mrt0 = the sampled texel. 5; s[0:1] = console VA of the SRV table's first slot (the T#). attr0.xy = (u, v). mrt0 = the sampled texel.
6; fssm-at: 0x10 6; fssm-at: 0x10
7; fssm-data: 0x324d5350 0x4c544c20 7; fssm-data: 0x324d5350 0x4c544c20
8; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
9; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
10s_mov_b32 s0, s8
11s_mov_b32 s1, 0
8s_load_dwordx8 s[8:15], s[0:1], 0x0 12s_load_dwordx8 s[8:15], s[0:1], 0x0
9s_movk_i32 s16, 0x92 13s_movk_i32 s16, 0x92
10s_mov_b32 s17, 0xc00000 14s_mov_b32 s17, 0xc00000
diff --git a/runtime/test/shaders/ps_m2_uoff.asm b/runtime/test/shaders/ps_m2_uoff.asm
index 1c96f50d5..59f7be679 100644
--- a/runtime/test/shaders/ps_m2_uoff.asm
+++ b/runtime/test/shaders/ps_m2_uoff.asm
@@ -6,6 +6,14 @@
6; the descriptor index and byte stride, respectively. 6; the descriptor index and byte stride, respectively.
7; fssm-at: 0x10 7; fssm-at: 0x10
8; fssm-data: 0x324d5350 0x4f465520 8; fssm-data: 0x324d5350 0x4f465520
9; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
10; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
11s_mov_b32 s0, s8
12s_mov_b32 s2, s9
13s_mov_b32 s4, s10
14s_mov_b32 s5, s11
15s_mov_b32 s1, 0
16s_mov_b32 s3, 0
9s_mul_i32 s20, s4, s5 17s_mul_i32 s20, s4, s5
10s_load_dwordx8 s[8:15], s[0:1], s20 18s_load_dwordx8 s[8:15], s[0:1], s20
11s_load_dwordx4 s[16:19], s[2:3], 0x0 19s_load_dwordx4 s[16:19], s[2:3], 0x0
diff --git a/runtime/test/shaders/ps_m3.asm b/runtime/test/shaders/ps_m3.asm
index be2a59e2d..4153ce798 100644
--- a/runtime/test/shaders/ps_m3.asm
+++ b/runtime/test/shaders/ps_m3.asm
@@ -4,6 +4,11 @@
4; mrt1 = (c1 + c2) an R32_FLOAT target: one float add, so the CPU gets the same bits 4; mrt1 = (c1 + c2) an R32_FLOAT target: one float add, so the CPU gets the same bits
5; fssm-at: 0x10 5; fssm-at: 0x10
6; fssm-data: 0x33535350 0x20535020 6; fssm-data: 0x33535350 0x20535020
7; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
8; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
9s_mov_b32 s5, s13
10s_mov_b32 s6, s14
11s_mov_b32 s7, s15
7v_mov_b32_e32 v2, s5 12v_mov_b32_e32 v2, s5
8v_mov_b32_e32 v3, s6 13v_mov_b32_e32 v3, s6
9v_mov_b32_e32 v4, s7 14v_mov_b32_e32 v4, s7
diff --git a/runtime/test/shaders/ps_m3_post.asm b/runtime/test/shaders/ps_m3_post.asm
index 848803058..d4e093b4a 100644
--- a/runtime/test/shaders/ps_m3_post.asm
+++ b/runtime/test/shaders/ps_m3_post.asm
@@ -6,6 +6,13 @@
6; attr0.xy = (u, v), 0..1 over the target. mrt0 = (texel.b, texel.g, texel.r, s4) 6; attr0.xy = (u, v), 0..1 over the target. mrt0 = (texel.b, texel.g, texel.r, s4)
7; fssm-at: 0x10 7; fssm-at: 0x10
8; fssm-data: 0x33505350 0x20535020 8; fssm-data: 0x33505350 0x20535020
9; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
10; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
11s_mov_b32 s0, s8
12s_mov_b32 s2, s9
13s_mov_b32 s4, s10
14s_mov_b32 s1, 0
15s_mov_b32 s3, 0
9s_load_dwordx8 s[8:15], s[0:1], 0x0 16s_load_dwordx8 s[8:15], s[0:1], 0x0
10s_load_dwordx4 s[16:19], s[2:3], 0x0 17s_load_dwordx4 s[16:19], s[2:3], 0x0
11s_waitcnt lgkmcnt(0) 18s_waitcnt lgkmcnt(0)
diff --git a/runtime/test/shaders/ps_m3_query.asm b/runtime/test/shaders/ps_m3_query.asm
index 0693cf5e2..636d89fc8 100644
--- a/runtime/test/shaders/ps_m3_query.asm
+++ b/runtime/test/shaders/ps_m3_query.asm
@@ -4,6 +4,11 @@
4; Keep the probe single-output so its count can be compared exactly with the CPU's visible rectangle area. 4; Keep the probe single-output so its count can be compared exactly with the CPU's visible rectangle area.
5; fssm-at: 0x10 5; fssm-at: 0x10
6; fssm-data: 0x33515350 0x20535020 6; fssm-data: 0x33515350 0x20535020
7; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
8; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
9s_mov_b32 s5, s13
10s_mov_b32 s6, s14
11s_mov_b32 s7, s15
7v_mov_b32_e32 v2, s5 12v_mov_b32_e32 v2, s5
8v_mov_b32_e32 v3, s6 13v_mov_b32_e32 v3, s6
9v_mov_b32_e32 v4, s7 14v_mov_b32_e32 v4, s7
diff --git a/runtime/test/shaders/vs_m15.asm b/runtime/test/shaders/vs_m15.asm
index 3ac449b0b..2f4946f63 100644
--- a/runtime/test/shaders/vs_m15.asm
+++ b/runtime/test/shaders/vs_m15.asm
@@ -3,23 +3,26 @@
3; a D3D12 graphics PSO found by the SHA-256 of its FSSM program). 3; a D3D12 graphics PSO found by the SHA-256 of its FSSM program).
4; 4;
5; User data, from the root signature [0] descriptor table, [1] four 32-bit constants (docs/d3d12_vulkan.md 3.5): 5; User data, from the root signature [0] descriptor table, [1] four 32-bit constants (docs/d3d12_vulkan.md 3.5):
6; s[0:1] = console VA of the table's first slot: the 16 bytes of a V# (base VA, stride 32, 9 records) 6; s8 = console VA of the table's first slot: the 16 bytes of a V# (base VA, stride 32, 9 records). In the console
7; s2, s3 = the draw's clip-space offset (x, y) as floats; s4, s5 = used by the pixel shader (s4: bias) 7; root layout (D3D-448) a table is one dword, its 32-bit VA (the heaps live below 4 GiB): s[0:1] = (s8, 0)
8; s9, s10 = the draw's clip-space offset (x, y) as floats; s11, s12 = used by the pixel shader (s11: bias)
8; v0 = VertexIndex. The draw has BaseVertex 0 and BaseInstance 0, so v0 is the same with and without the translator's 9; v0 = VertexIndex. The draw has BaseVertex 0 and BaseInstance 0, so v0 is the same with and without the translator's
9; zero-based ids (PR 436): both give 0, 1, 2, ... for DrawInstanced(n, 1, 0, 0). A non-zero StartVertexLocation would 10; zero-based ids (PR 436): both give 0, 1, 2, ... for DrawInstanced(n, 1, 0, 0). A non-zero StartVertexLocation would
10; make the two differ (hardware: zero-based, base in an SGPR), so the test never uses one. 11; make the two differ (hardware: zero-based, base in an SGPR), so the test never uses one.
11; Vertex record, 32 bytes: position xyzw at 0, colour rgba at 16 (both float). 12; Vertex record, 32 bytes: position xyzw at 0, colour rgba at 16 (both float).
12; pos0 = (position.x + s2, position.y + s3, position.z, position.w) 13; pos0 = (position.x + s9, position.y + s10, position.z, position.w)
13; param0 = colour 14; param0 = colour
14; fssm-at: 0x10 15; fssm-at: 0x10
15; fssm-data: 0x35314d56 0x20535620 16; fssm-data: 0x35314d56 0x20535620
16s_load_dwordx4 s[8:11], s[0:1], 0x0 17s_mov_b32 s0, s8
18s_mov_b32 s1, 0
19s_load_dwordx4 s[16:19], s[0:1], 0x0
17s_waitcnt lgkmcnt(0) 20s_waitcnt lgkmcnt(0)
18buffer_load_dwordx4 v[4:7], v0, s[8:11], 0 idxen 21buffer_load_dwordx4 v[4:7], v0, s[16:19], 0 idxen
19buffer_load_dwordx4 v[8:11], v0, s[8:11], 0 idxen offset:16 22buffer_load_dwordx4 v[8:11], v0, s[16:19], 0 idxen offset:16
20s_waitcnt vmcnt(0) 23s_waitcnt vmcnt(0)
21v_add_f32_e32 v4, s2, v4 24v_add_f32_e32 v4, s9, v4
22v_add_f32_e32 v5, s3, v5 25v_add_f32_e32 v5, s10, v5
23exp pos0 v4, v5, v6, v7 done 26exp pos0 v4, v5, v6, v7 done
24exp param0 v8, v9, v10, v11 27exp param0 v8, v9, v10, v11
25s_endpgm 28s_endpgm
diff --git a/runtime/test/shaders/vs_m3.asm b/runtime/test/shaders/vs_m3.asm
index 3bcc2278e..6768e06eb 100644
--- a/runtime/test/shaders/vs_m3.asm
+++ b/runtime/test/shaders/vs_m3.asm
@@ -8,6 +8,16 @@
8; The corners are multiples of 1/32 and the depths are dyadic, so every operation here is exact however it is fused. 8; The corners are multiples of 1/32 and the depths are dyadic, so every operation here is exact however it is fused.
9; fssm-at: 0x10 9; fssm-at: 0x10
10; fssm-data: 0x33534d56 0x20535620 10; fssm-data: 0x33534d56 0x20535620
11; Console root layout (D3D-448): root arguments from s8, a descriptor table is one dword (its 32-bit VA; the heaps
12; live below 4 GiB, so the high half is 0). The first lines rebuild the registers the program below was written for.
13s_mov_b32 s0, s8
14s_mov_b32 s1, s9
15s_mov_b32 s2, s10
16s_mov_b32 s3, s11
17s_mov_b32 s4, s12
18s_mov_b32 s5, s13
19s_mov_b32 s6, s14
20s_mov_b32 s7, s15
11v_and_b32_e32 v1, 1, v0 21v_and_b32_e32 v1, 1, v0
12v_and_b32_e32 v2, 2, v0 22v_and_b32_e32 v2, 2, v0
13v_cvt_f32_u32_e32 v1, v1 23v_cvt_f32_u32_e32 v1, v1