mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 17:18:38 +00:00
RADV puts sparse buffers 64 TiB above ordinary ones, so with the sparse arena of the previous commit every geometry
copy and title-window block lay below heap_base and TitleBufferWindows::allocate refused it (it accepted only a
positive offset below 2^47). Shaders translated since 2026-11-24 sign-extend a V#'s 48-bit base and say so in their
index entry (vsharp_base_sign_extended), and RADV hands out every address from one 2^47 half of the 48-bit space, so
any block is within reach of heap_base as a signed offset.
- shader_library.h: VsharpBaseCensus counts the marker over every loaded module; signed only when all have it.
- The device reads V# bases signed when the census says so (or with LEONIDA_IMPORT_BELOW_ARENA=1, as before). The
import refusal still follows that setting alone. One line logs the census.
- create_arena: the arena is sparse only with signed offsets; otherwise one allocation, and one line says why.
- TitleBufferWindows::shader_reachable replaces the positive-only check. The first failure of each Vulkan call while
making a block, and the first block refused for its address, are logged.
- rebase_title_vsharp sign-extends a base it already rewrote below heap_base.
- device_arena_memory (for tests); cs_user_data.comp reads V# bases sign-extended, as translated shaders do.
Tests: d3d12_title_va_game_device and d3d12_geometry_views_game_device (d3d12_title_va_test --game-device: the
device the game makes, with the arena's bind queue); geometry_views_test (shader_reachable at the measured RADV
addresses and the range edges); shader_library_test (the census). Wine suite on the iGPU: 429 pass / 23 fail against
425 / 23 on main 8bc59a74c, nothing pass to fail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
5.3 KiB
Plaintext
118 lines
5.3 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) {
|
|
// V# bases are signed 48-bit offsets from heap_base, as the translator reads them.
|
|
Words cbv = at(uvec2(table.w[word], uint(int(table.w[word + 1u] << 16u) >> 16)));
|
|
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], uint(int(table.w[1] << 16u) >> 16)); // signed 48-bit offset
|
|
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];
|
|
}
|