#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: // Root arguments in the console compute layout (rt::rootsig::pack_stage: from s4, one dword per table): // s4 a root constant: where the view slot to sample starts inside the view table, in dwords // s5 a root constant: the first element of the output it writes // s6:s7 a root UAV: the console VA of the output buffer // s8 a descriptor table of views (its 32-bit console VA): a T# in the first eight dwords of each slot // s9 a descriptor table of samplers (its 32-bit console VA): 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[s5 + 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[8], 0u)); Words sampler_table = at(uvec2(pc.s[9], 0u)); uint image_key[8], sampler_key[8]; for (int k = 0; k < 8; ++k) { image_key[k] = views.w[pc.s[4] + 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[6], pc.s[7])); result.w[pc.s[5] + i] = packUnorm4x8(texel); }