Files
mandy/runtime/test/glsl/cs_user_data.comp
NotRexed 9ad7277af2 d3d12: constant-buffer views are V#s of 16-byte records (batched UI shapes and text, the diagonal line)
The start screen drew a 1-pixel white line from the bottom left to the top right and no batched text. The title's
console-compiled Scaleform batch shaders read their constant buffer's float4 rows with buffer_load_dwordx4 ... idxen
and the row number (rows 4b..4b+3: colour transform, then the position matrix), and MUBUF addressing is
base + index * STRIDE. CreateConstantBufferView wrote a raw V# (STRIDE 0), so every row read the first one: x and y
came from the same row, so every batched shape and glyph landed on clip-space y = x, coloured white.

A constant-buffer view is now STRIDE 16, NUM_RECORDS the size in rows, format 32_32_32_32_FLOAT, OOB_SELECT 1
(gfx10::constant_buffer_descriptor). s_buffer_load keeps its bound (NUM_RECORDS * STRIDE bytes) and offen loads reach
the whole buffer. With it the line is gone and the batched text (titles, button prompts) draws.

Tests: gfx10_descriptors_test checks the fields; d3d12_compute_test's CBV pass reads through them (its GLSL stand-in
now bounds a CBV read as s_buffer_load does).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 05:26:02 -05:00

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];
}