mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:48:38 +00:00
A UINT opaque-white border read back as 0 (Vonsek, on an RTX 5080). The S# has no integer border types, since the hardware reads them by the image's format. So bind_sampler gave Vulkan VK_BORDER_COLOR_FLOAT_*, which an integer image reads as 0. The float and UINT samplers also shared one S# key and so one VkSampler. An integer border is now marked in the S#: BORDER_COLOR_PTR = 0x800 (gfx10::kIntegerBorderPtr), a field the hardware reads only for table colours. That gives it its own key, and vulkan_sampler picks VK_BORDER_COLOR_INT_*. d3d12_descriptor_test runs Vonsek's case: an R8G8B8A8_UINT texture sampled past its edge through UINT black and white border samplers reads 0 and 1, and a float white border reads 255. The case fails with the float enums on an RTX 4090. gfx10_descriptors_test and d3d12_sampler2_test check the mark. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
3.0 KiB
Plaintext
66 lines
3.0 KiB
Plaintext
#version 460
|
|
// A compute shader that finds and samples an image the way translated shaders do (docs/design.md, "Images"; the
|
|
// lookup is tools/rdna2spirv.py desc_probe), for d3d12_descriptor_test. A translated shader loads a T# and an S#
|
|
// from its descriptor tables; this one is handed them as push constants: the eight dwords of a heap slot and the
|
|
// four of a sampler slot. It 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
|
|
// result[first + i] = the texel at ((i % 8) + 0.5, (i / 8) + 0.5) / 8 + (1, 0), as RGBA8 with red in the low byte.
|
|
// With `integer` set the image is an integer one (an R8G8B8A8_UINT view, read through the same binding as a
|
|
// utexture2D), and each channel is stored as its value clamped to 255: a UINT border colour shows as 0 or 1.
|
|
// 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 (as the fallback sampler at index 0 does) the image's right edge. So the result shows that
|
|
// the S# was found, not only the T#.
|
|
// Set 0 is the device's bindless set; set 1 is the test's output buffer.
|
|
#extension GL_EXT_nonuniform_qualifier : require
|
|
|
|
layout(local_size_x = 64) in;
|
|
|
|
layout(push_constant) uniform Descriptors {
|
|
uint tsharp[8];
|
|
uint ssharp[4];
|
|
uint first;
|
|
uint integer;
|
|
} pc;
|
|
|
|
layout(set = 0, binding = 0) uniform texture2D images[];
|
|
layout(set = 0, binding = 0) uniform utexture2D uimages[];
|
|
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
|
|
};
|
|
layout(set = 1, binding = 0, std430) writeonly buffer Result {
|
|
uint result[];
|
|
};
|
|
|
|
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;
|
|
uint image_key[8], sampler_key[8];
|
|
for (int k = 0; k < 8; ++k) {
|
|
image_key[k] = pc.tsharp[k];
|
|
sampler_key[k] = k < 4 ? pc.ssharp[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);
|
|
if (pc.integer != 0) {
|
|
const uvec4 t = min(textureLod(usampler2D(uimages[image], samplers[smp]), uv, 0.0), uvec4(255));
|
|
result[pc.first + i] = t.r | (t.g << 8) | (t.b << 16) | (t.a << 24);
|
|
} else {
|
|
const vec4 texel = textureLod(sampler2D(images[image], samplers[smp]), uv, 0.0);
|
|
result[pc.first + i] = packUnorm4x8(texel);
|
|
}
|
|
}
|