mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 17:28:37 +00:00
Since #1489 the layer binds the device's bindless set at every dispatch as well as at every draw, but only the draw has a test (d3d12_m2_textured_test): d3d12_compute_test takes the binding-free index entry on purpose, and d3d12_descriptor_test samples through set 0 with a Vulkan pipeline of its own. This test covers the compute bind point through D3D12 alone: a compute PSO whose index entry lists set-0 bindings, two SRVs, bytes no view was made for, and a wrapping and a clamping sampler. Four dispatches of test/glsl/cs_set0_sample.comp (GLSL written to the translator's contract) load the T# and the S# from the descriptor tables, find them in the hash table and sample: the two textures texel for texel, the fallback image for the unknown bytes, and the right edge with the clamping sampler. A device without the bindless set refuses the PSO. Registered with ctest like its neighbours (exit 77 is a skip). With the vkCmdBindDescriptorSets call of the compute bind point removed from replay, this test fails (VUID-vkCmdDispatch-None-08600, on llvmpipe). Checked with a mingw-w64 build under Wine on llvmpipe, an RDNA2 integrated GPU and an RX 7900 XTX (RADV), with the validation layer: exact, no validation errors. Not built with MSVC. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
78 lines
3.4 KiB
Plaintext
78 lines
3.4 KiB
Plaintext
#version 460
|
|
// A compute shader that samples through set 0 the way translated shaders do, written to the translator's runtime
|
|
// contract (docs/design.md, "User data", "Xbox GPU addresses" and "Images"; the lookup is tools/rdna2spirv.py
|
|
// desc_probe), standing in for a translated one in d3d12_set0_compute_test. Its root arguments:
|
|
// s0 a root constant: where the view slot to sample starts inside the view table, in dwords
|
|
// s1 a root constant: the first element of the output it writes
|
|
// s2:s3 a root UAV: the console VA of the output buffer
|
|
// s4:s5 a descriptor table of views: a T# in the first eight dwords of each slot
|
|
// s6:s7 a descriptor table of samplers: the S# of its first slot, four dwords
|
|
// It loads the T# and the S# from the tables at heap base + VA, looks both up in the hash table at set 0 binding 2
|
|
// (FNV-1a over the eight key dwords, eight probes, a miss is index 0; an S# key is its four dwords and four of
|
|
// 0xFFFFFFFF), samples the 2D image array at binding 0 with the sampler array at binding 1, and writes
|
|
// out[s1 + i] = the texel at ((i % 8) + 0.5, (i / 8) + 0.5) / 8 + (1, 0), as RGBA8 with red in the low byte.
|
|
// The whole tile to the right in U: a sampler that wraps in U gives the texel at the same place in the image, one
|
|
// that clamps gives the image's right edge. So the result depends on the S# as well as on the T#.
|
|
// Set 0 is the device's bindless set. The D3D12 layer has it in the pipeline layout and binds it at the dispatch,
|
|
// because the index lists bindings for this shader; nothing else in the test binds it.
|
|
#extension GL_EXT_nonuniform_qualifier : require
|
|
#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;
|
|
|
|
layout(set = 0, binding = 0) uniform texture2D images[];
|
|
layout(set = 0, binding = 1) uniform sampler samplers[];
|
|
layout(set = 0, binding = 2, std430) readonly buffer DescriptorMap {
|
|
uint map[]; // mask, then 10 uints per slot: key[8], index, pad
|
|
};
|
|
|
|
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));
|
|
}
|
|
|
|
uint lookup(uint key[8]) {
|
|
uint h = 2166136261u;
|
|
for (int i = 0; i < 8; ++i) h = (h ^ key[i]) * 16777619u;
|
|
const uint mask = map[0];
|
|
for (uint k = 0; k < 8; ++k) {
|
|
const uint slot = 1 + ((h + k) & mask) * 10;
|
|
bool same = true;
|
|
for (int i = 0; i < 8; ++i) same = same && map[slot + i] == key[i];
|
|
if (same) return map[slot + 8];
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void main() {
|
|
const uint i = gl_GlobalInvocationID.x;
|
|
Words views = at(uvec2(pc.s[4], pc.s[5]));
|
|
Words sampler_table = at(uvec2(pc.s[6], pc.s[7]));
|
|
uint image_key[8], sampler_key[8];
|
|
for (int k = 0; k < 8; ++k) {
|
|
image_key[k] = views.w[pc.s[0] + k];
|
|
sampler_key[k] = k < 4 ? sampler_table.w[k] : 0xffffffffu;
|
|
}
|
|
const uint image = lookup(image_key), smp = lookup(sampler_key);
|
|
const vec2 uv = (vec2(i % 8, i / 8) + 0.5) / 8.0 + vec2(1.0, 0.0);
|
|
const vec4 texel = textureLod(sampler2D(images[image], samplers[smp]), uv, 0.0);
|
|
Words result = at(uvec2(pc.s[2], pc.s[3]));
|
|
result.w[pc.s[1] + i] = packUnorm4x8(texel);
|
|
}
|