mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 20:38:37 +00:00
R32G32B32_FLOAT/UINT/SINT/TYPELESS textures were refused ("texture format not
supported yet"). They are now R32G32B32A32 images on every GPU: most have no
optimal-tiling RGB32 image, and one that has would not avoid the repack, since
D3D12 places subresources at multiples of 512 bytes and Vulkan wants a copy's
buffer offset to be a multiple of the texel size
(VUID-vkCmdCopyBufferToImage-dstImage-07975).
- Footprints keep D3D12's 12-byte texels (compared with WARP).
- CopyTextureRegion between a texture and a buffer is repacked by the D24
compute pass (depth24_convert.comp modes 2 and 3, Depth24Job::rgb96): the
same scratch, parts and lifetime, texels of three words in the footprint and
four in the scratch, copied uninterpreted. depth24_convert.inc is
regenerated with the documented glslc command; the same glslc reproduces the
previous blob byte for byte from the previous source.
- WriteToSubresource/ReadFromSubresource take the staged copy, as D24-as-D32.
- A view's T# names GFX10_FORMAT_32_32_32_*, so alpha reads as one.
- Refused: unordered access and depth (as WARP), render targets (WARP has
them; not done, and FORMAT_SUPPORT and GetResourceAllocationInfo agree),
copies between a 96-bit and a four-channel texture, views of another
format family.
Tested on an RX 9070 XT (AMD 26.11.2), Windows 11: d3d12_rgb96_test matches
WARP and the expected texels bit for bit for 4 formats as 2D arrays with mips
and as volumes; d3d12_descriptor_test samples FLOAT, UINT and TYPELESS views.
Clean under the validation layer with sync validation; depth24_convert_test
and ctest (62) pass.
AI-assisted (Claude Code).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
74 lines
3.9 KiB
Plaintext
74 lines
3.9 KiB
Plaintext
// D24_UNORM_S8_UINT on a GPU without D24: the layer stores D32_SFLOAT_S8_UINT, and the depth words of a copy
|
|
// footprint (24-bit UNORM in bits 0-23, bits 24-31 unspecified) are converted here. depth24_convert_spv.h is this file
|
|
// compiled with `glslc --target-env=vulkan1.1 -O -mfmt=c` (see the header for the command); keep them together.
|
|
//
|
|
// to_float != 0 (upload): scratch[s] = float bits of the float nearest to d / 16777215, d = app[a] & 0xffffff
|
|
// to_float == 0 (readback): app[a] = D3D's quantisation of scratch[s] (depth24.h; round to nearest even of f * 16777215,
|
|
// NaN and negatives 0, 1 and above 16777215), the unspecified top byte written as 0
|
|
// The upload direction is integer arithmetic (no float division, whose rounding is the GPU's choice); the readback
|
|
// uses one float multiply, which Vulkan requires to be correctly rounded, and roundEven.
|
|
//
|
|
// The same pass repacks 96-bit R32G32B32 texels, which the layer holds in R32G32B32A32 images (D3D-62; `to_float`
|
|
// 2 and 3). A footprint texel is then three words and a scratch texel four, and the words are copied as they are:
|
|
// to_float == 3 (upload): scratch[s .. s+2] = app[a .. a+2], scratch[s+3] = 0 (never read: views read alpha as one)
|
|
// to_float == 2 (readback): app[a .. a+2] = scratch[s .. s+2]
|
|
#version 450
|
|
|
|
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
|
|
|
layout(set = 0, binding = 0) buffer App { uint app[]; };
|
|
layout(set = 0, binding = 1) buffer Scratch { uint scratch[]; };
|
|
|
|
layout(push_constant) uniform Push {
|
|
uint width, height, slices;
|
|
uint to_float; // 0 and 1: D24 words and floats; 2 and 3: 96-bit texels of 3 and 4 words (see above)
|
|
uint app_base; // first word of the region in `app`, within the bound window
|
|
uint app_row; // words between rows and between slices of the app buffer
|
|
uint app_slice;
|
|
uint scratch_base; // first word of the region in `scratch`, within the bound window
|
|
} pc;
|
|
|
|
// d / (2^24 - 1) as a float. With m the 24-bit mantissa of d (d = m * 2^(e-23)) the quotient is
|
|
// (m + m / (2^24 - 1)) * 2^(e-47), and m / (2^24 - 1) lies in (0.5, 1] for every m in [2^23, 2^24], so the nearest
|
|
// 24-bit mantissa is m + 1 and the result is exactly float(m + 1) * 2^(e-47).
|
|
float depth24_to_float(uint d) {
|
|
if (d == 0u) return 0.0;
|
|
int e = findMSB(d);
|
|
uint m = d << uint(23 - e);
|
|
return float(m + 1u) * uintBitsToFloat(uint(e - 47 + 127) << 23);
|
|
}
|
|
|
|
// The 24-bit UNORM of f as WARP and AMD's D3D12 drivers write it: the product with 2^24 - 1 is rounded to a float
|
|
// first, then to the nearest integer with ties to even (NVIDIA's hardware breaks some ties the other way; see
|
|
// depth24.h). NaN and negatives give 0, 1 and above the maximum.
|
|
uint depth24_from_bits(uint bits) {
|
|
// In unsigned order, all negative encodings and positive NaNs lie above positive infinity.
|
|
if (bits > 0x7f800000u) return 0u;
|
|
if (bits >= 0x3f800000u) return 0xffffffu;
|
|
return uint(roundEven(uintBitsToFloat(bits) * 16777215.0));
|
|
}
|
|
|
|
void main() {
|
|
uvec3 g = gl_GlobalInvocationID;
|
|
if (g.x >= pc.width || g.y >= pc.height || g.z >= pc.slices) return;
|
|
if (pc.to_float >= 2u) {
|
|
uint a = pc.app_base + g.z * pc.app_slice + g.y * pc.app_row + g.x * 3u;
|
|
uint s = pc.scratch_base + ((g.z * pc.height + g.y) * pc.width + g.x) * 4u;
|
|
if (pc.to_float == 3u) {
|
|
scratch[s] = app[a];
|
|
scratch[s + 1u] = app[a + 1u];
|
|
scratch[s + 2u] = app[a + 2u];
|
|
scratch[s + 3u] = 0u;
|
|
} else {
|
|
app[a] = scratch[s];
|
|
app[a + 1u] = scratch[s + 1u];
|
|
app[a + 2u] = scratch[s + 2u];
|
|
}
|
|
return;
|
|
}
|
|
uint a = pc.app_base + g.z * pc.app_slice + g.y * pc.app_row + g.x;
|
|
uint s = pc.scratch_base + (g.z * pc.height + g.y) * pc.width + g.x;
|
|
if (pc.to_float != 0u) scratch[s] = floatBitsToUint(depth24_to_float(app[a] & 0xffffffu));
|
|
else app[a] = depth24_from_bits(scratch[s]);
|
|
}
|