mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 21:38:37 +00:00
d3d12_rebound_tables, d3d12_rebound_second_device and d3d12_api_descriptor_copy went from pass (main) to fail at line 896 of d3d12_title_va_test: 0/64 GPU words matched on both submissions, although the mirrored CBV in the layer heap was right (checked by printing the slot after the submission). They had been hidden behind line 502 in the same executable. main was right. Its rebound-table check selects the test shader's indexed CBV mode with s5 = 0xFFFFFFFB. #1723 added a mode that returns a descriptor's words instead, also on 0xFFFFFFFB, ahead of main's branch, so the rebound tables read the words at s8 (unset, address 0) instead of the CBV's data. #1723's mode now uses 0xFFFFFFFA, which nothing else uses, and its one caller (the out[3] dispatch in check_title_va) passes that. Both checks run as written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
5.1 KiB
Plaintext
117 lines
5.1 KiB
Plaintext
#version 460
|
|
// A compute shader written to the translator's runtime contract (docs/design.md, "User data" and "Xbox GPU
|
|
// addresses"), standing in for a translated one in d3d12_compute_test: the 144-byte push-constant block holds
|
|
// s0..s31 (the root arguments), the heap base and the code base, and every memory access goes to heap base +
|
|
// console VA. It reads each kind of root argument the D3D12 layer packs, in the console compute layout
|
|
// (rt::rootsig::pack_stage, from s4, one dword per table; s0..s3 are the driver's):
|
|
// s4, s5 root constants: base and step
|
|
// s6:s7 a root UAV: the console VA of the output buffer
|
|
// s8 a descriptor table: the 32-bit console VA of its first entry (the heaps live below 4 GiB); that entry
|
|
// is a 64-bit console VA the application wrote itself
|
|
// code the shader's own program (FSSM blob), dword 1
|
|
// and writes out[i] = s4 + s5 * i + table_target[i % 4] + code[1].
|
|
#extension GL_EXT_buffer_reference : require
|
|
#extension GL_EXT_buffer_reference_uvec2 : require
|
|
|
|
layout(local_size_x = 64) in;
|
|
|
|
layout(buffer_reference, std430, buffer_reference_align = 4) buffer Words {
|
|
uint w[];
|
|
};
|
|
|
|
layout(push_constant) uniform UserData {
|
|
uint s[32];
|
|
uvec2 heap_base;
|
|
uvec2 code_base;
|
|
} pc;
|
|
|
|
uvec2 add64(uvec2 a, uvec2 b) {
|
|
uint carry;
|
|
const uint low = uaddCarry(a.x, b.x, carry);
|
|
return uvec2(low, a.y + b.y + carry);
|
|
}
|
|
|
|
Words at(uvec2 va) {
|
|
return Words(add64(pc.heap_base, va));
|
|
}
|
|
|
|
void main() {
|
|
const uint i = gl_GlobalInvocationID.x;
|
|
Words result = at(uvec2(pc.s[6], pc.s[7]));
|
|
if (pc.s[5] == 0xFFFFFFFAu) {
|
|
// Inspect descriptor words without dereferencing a possibly invalid address. 0xFFFFFFFB is the rebound-table
|
|
// test's indexed CBV mode below.
|
|
Words view = at(uvec2(pc.s[8], 0u));
|
|
result.w[i] = view.w[i % 4u];
|
|
return;
|
|
}
|
|
if (pc.s[5] == 0xFFFFFFFCu) {
|
|
// Direct resource indexing. The explicit table is unrelated; the heap follows it at s9.
|
|
uint value = 0u;
|
|
if (pc.s[9] != 0u) {
|
|
Words view = at(uvec2(pc.s[9] + 32u * pc.s[4], 0u));
|
|
uint byteOffset = (i % 4u) * 4u;
|
|
if (view.w[2] >= byteOffset + 4u) {
|
|
// V# buffer addresses are signed 48-bit offsets from heap_base.
|
|
uint high = uint(int(view.w[1] << 16u) >> 16);
|
|
value = at(uvec2(view.w[0], high)).w[byteOffset / 4u];
|
|
}
|
|
}
|
|
result.w[i] = value;
|
|
return;
|
|
}
|
|
if (pc.s[5] == 0xFFFFFFFEu) {
|
|
// Root view read mode (d3d12_title_va_test): read through the root UAV itself, 256 bytes past its base, and
|
|
// write at the base, so the root view's address is both read and written.
|
|
result.w[i] = result.w[64u + i] + pc.s[4];
|
|
return;
|
|
}
|
|
Words table = at(uvec2(pc.s[8], 0u));
|
|
if (pc.s[5] == 0xFFFFFFFDu) {
|
|
// Root view read to a table pointer (d3d12_title_va_test): read through the root view, 256 bytes past its
|
|
// base, and write where the table entry's raw 64-bit VA points.
|
|
Words target = at(uvec2(table.w[0], table.w[1]));
|
|
target.w[i] = result.w[64u + i] + pc.s[4];
|
|
return;
|
|
}
|
|
if (pc.s[5] == 0u || pc.s[5] == 0xFFFFFFFBu) {
|
|
// CBV V# mode: accept byte-address views and Xbox views counted in 16-byte constant rows.
|
|
// The rebound-table test indexes 32-byte CBV slots with s4.
|
|
const bool indexed = pc.s[5] == 0xFFFFFFFBu;
|
|
const uint word = indexed ? pc.s[4] * 8u : 0u;
|
|
const uint num_records = table.w[word + 2u];
|
|
const uint stride = (table.w[word + 1u] >> 16u) & 0x3fffu;
|
|
const uint mode = (table.w[word + 3u] >> 28u) & 3u;
|
|
const uint bytes_per_record = mode < 2u ? max(stride, 1u) : 1u;
|
|
const uint byte_off = (indexed ? 0u : pc.s[4]) + i * 4u;
|
|
if (byte_off <= 0xfffffffcu && (byte_off + 3u) / bytes_per_record < num_records) {
|
|
Words cbv = at(uvec2(table.w[word], table.w[word + 1u] & 0xFFFFu));
|
|
result.w[i] = cbv.w[byte_off >> 2u];
|
|
} else {
|
|
result.w[i] = 0u;
|
|
}
|
|
return;
|
|
}
|
|
if (pc.s[5] == 0xFFFFFFFFu) {
|
|
// Buffer SRV V# mode: decode 16-byte GFX10 buffer descriptor written by CreateShaderResourceView.
|
|
const uint stride = (table.w[1] >> 16u) & 0x3FFFu;
|
|
const uint num_records = table.w[2];
|
|
const uint oob_select = (table.w[3] >> 28u) & 3u;
|
|
const uvec2 base = uvec2(table.w[0], table.w[1] & 0xFFFFu);
|
|
if (oob_select == 3u) {
|
|
const uint byte_off = pc.s[4] + i * 4u;
|
|
result.w[i] = (byte_off + 4u <= num_records) ? at(base).w[byte_off >> 2u] : 0u;
|
|
} else if (oob_select <= 1u && stride >= 4u) {
|
|
const uint field = pc.s[4];
|
|
const bool in_bounds = i < num_records && (oob_select == 1u || field <= stride - 4u);
|
|
result.w[i] = in_bounds ? at(base).w[(i * stride + field) >> 2u] : 0u;
|
|
} else {
|
|
result.w[i] = 0u;
|
|
}
|
|
return;
|
|
}
|
|
Words constants = at(uvec2(table.w[0], table.w[1]));
|
|
Words code = at(pc.code_base);
|
|
result.w[i] = pc.s[4] + pc.s[5] * i + constants.w[i % 4] + code.w[1];
|
|
}
|