upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorzneel <14263028+zneel@users.noreply.github.com>2026-11-22 10:50:10 +0100
committerzneel <14263028+zneel@users.noreply.github.com>2026-11-22 11:26:48 +0100
commit983862e2a885a3d7082cf9678e863fdce1bd6f4e (patch)
tree57ecd89e512f1d7e3fe5e34b37bfce2d0eff7125 /runtime/src
parentf85582e23d4ab9e19acbf694358f137d6b8531b1 (diff)
Runtime: 96-bit R32G32B32 textures on the Vulkan layer (D3D-62)
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>
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/depth24.h9
-rw-r--r--runtime/src/depth24_convert.comp22
-rw-r--r--runtime/src/depth24_convert.inc318
-rw-r--r--runtime/src/vulkan_depth24.h32
-rw-r--r--runtime/src/vulkan_replay.h51
5 files changed, 297 insertions, 135 deletions
diff --git a/runtime/src/depth24.h b/runtime/src/depth24.h
index ced51bcb1..b9100297b 100644
--- a/runtime/src/depth24.h
+++ b/runtime/src/depth24.h
@@ -50,8 +50,15 @@ inline float depth24_clear_value(float value) { return depth24_to_float(depth24_
50// One copy between a footprint (words of 24-bit depth) and the D32 aspect of a texture, as the compute pass sees it. 50// One copy between a footprint (words of 24-bit depth) and the D32 aspect of a texture, as the compute pass sees it.
51// The pass converts between the application's buffer and a tight scratch buffer of floats; a copy command moves the 51// The pass converts between the application's buffer and a tight scratch buffer of floats; a copy command moves the
52// scratch to or from the image. vulkan_depth24.h fills the scratch and descriptor fields in `prepare`. 52// scratch to or from the image. vulkan_depth24.h fills the scratch and descriptor fields in `prepare`.
53//
54// The same pass, scratch and job repack 96-bit R32G32B32 texels (`rgb96`, D3D-62): the footprint then has three
55// words a texel and the scratch four (the layer's R32G32B32A32 image), copied as they are. The row and slice
56// distances stay in words; only the texel's width differs (app_texel_words, scratch_texel_words).
53struct Depth24Job { 57struct Depth24Job {
54 bool to_float = false; // an upload (D24 words to floats); false: a readback (floats to words) 58 bool to_float = false; // an upload (D24 words to floats); false: a readback (floats to words)
59 bool rgb96 = false; // 96-bit texels: `to_float` is only the direction (true: the upload)
60 std::uint32_t app_texel_words() const { return rgb96 ? 3 : 1; }
61 std::uint32_t scratch_texel_words() const { return rgb96 ? 4 : 1; }
55 VkBuffer app = VK_NULL_HANDLE; // the application's buffer 62 VkBuffer app = VK_NULL_HANDLE; // the application's buffer
56 std::uint64_t app_offset = 0; // bytes, a multiple of 4 63 std::uint64_t app_offset = 0; // bytes, a multiple of 4
57 std::uint64_t app_size = 0; // bytes in the buffer 64 std::uint64_t app_size = 0; // bytes in the buffer
@@ -59,7 +66,7 @@ struct Depth24Job {
59 std::uint32_t app_row_words = 0; // words between rows and between slices of the footprint 66 std::uint32_t app_row_words = 0; // words between rows and between slices of the footprint
60 std::uint32_t app_slice_words = 0; 67 std::uint32_t app_slice_words = 0;
61 // Set by prepare: 68 // Set by prepare:
62 VkBuffer scratch = VK_NULL_HANDLE; // width * height * slices floats, tightly packed 69 VkBuffer scratch = VK_NULL_HANDLE; // width * height * slices texels (floats, or four words), tightly packed
63 VkDeviceSize scratch_offset = 0; 70 VkDeviceSize scratch_offset = 0;
64 VkDescriptorSet set = VK_NULL_HANDLE; 71 VkDescriptorSet set = VK_NULL_HANDLE;
65 std::uint32_t app_base_words = 0; // the region's first word in the descriptor's window 72 std::uint32_t app_base_words = 0; // the region's first word in the descriptor's window
diff --git a/runtime/src/depth24_convert.comp b/runtime/src/depth24_convert.comp
index 688f68d78..822a67459 100644
--- a/runtime/src/depth24_convert.comp
+++ b/runtime/src/depth24_convert.comp
@@ -7,6 +7,11 @@
7// NaN and negatives 0, 1 and above 16777215), the unspecified top byte written as 0 7// NaN and negatives 0, 1 and above 16777215), the unspecified top byte written as 0
8// The upload direction is integer arithmetic (no float division, whose rounding is the GPU's choice); the readback 8// The upload direction is integer arithmetic (no float division, whose rounding is the GPU's choice); the readback
9// uses one float multiply, which Vulkan requires to be correctly rounded, and roundEven. 9// uses one float multiply, which Vulkan requires to be correctly rounded, and roundEven.
10//
11// The same pass repacks 96-bit R32G32B32 texels, which the layer holds in R32G32B32A32 images (D3D-62; `to_float`
12// 2 and 3). A footprint texel is then three words and a scratch texel four, and the words are copied as they are:
13// to_float == 3 (upload): scratch[s .. s+2] = app[a .. a+2], scratch[s+3] = 0 (never read: views read alpha as one)
14// to_float == 2 (readback): app[a .. a+2] = scratch[s .. s+2]
10#version 450 15#version 450
11 16
12layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; 17layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
@@ -16,7 +21,7 @@ layout(set = 0, binding = 1) buffer Scratch { uint scratch[]; };
16 21
17layout(push_constant) uniform Push { 22layout(push_constant) uniform Push {
18 uint width, height, slices; 23 uint width, height, slices;
19 uint to_float; 24 uint to_float; // 0 and 1: D24 words and floats; 2 and 3: 96-bit texels of 3 and 4 words (see above)
20 uint app_base; // first word of the region in `app`, within the bound window 25 uint app_base; // first word of the region in `app`, within the bound window
21 uint app_row; // words between rows and between slices of the app buffer 26 uint app_row; // words between rows and between slices of the app buffer
22 uint app_slice; 27 uint app_slice;
@@ -46,6 +51,21 @@ uint depth24_from_bits(uint bits) {
46void main() { 51void main() {
47 uvec3 g = gl_GlobalInvocationID; 52 uvec3 g = gl_GlobalInvocationID;
48 if (g.x >= pc.width || g.y >= pc.height || g.z >= pc.slices) return; 53 if (g.x >= pc.width || g.y >= pc.height || g.z >= pc.slices) return;
54 if (pc.to_float >= 2u) {
55 uint a = pc.app_base + g.z * pc.app_slice + g.y * pc.app_row + g.x * 3u;
56 uint s = pc.scratch_base + ((g.z * pc.height + g.y) * pc.width + g.x) * 4u;
57 if (pc.to_float == 3u) {
58 scratch[s] = app[a];
59 scratch[s + 1u] = app[a + 1u];
60 scratch[s + 2u] = app[a + 2u];
61 scratch[s + 3u] = 0u;
62 } else {
63 app[a] = scratch[s];
64 app[a + 1u] = scratch[s + 1u];
65 app[a + 2u] = scratch[s + 2u];
66 }
67 return;
68 }
49 uint a = pc.app_base + g.z * pc.app_slice + g.y * pc.app_row + g.x; 69 uint a = pc.app_base + g.z * pc.app_slice + g.y * pc.app_row + g.x;
50 uint s = pc.scratch_base + (g.z * pc.height + g.y) * pc.width + g.x; 70 uint s = pc.scratch_base + (g.z * pc.height + g.y) * pc.width + g.x;
51 if (pc.to_float != 0u) scratch[s] = floatBitsToUint(depth24_to_float(app[a] & 0xffffffu)); 71 if (pc.to_float != 0u) scratch[s] = floatBitsToUint(depth24_to_float(app[a] & 0xffffffu));
diff --git a/runtime/src/depth24_convert.inc b/runtime/src/depth24_convert.inc
index 9438af65b..155b6b22f 100644
--- a/runtime/src/depth24_convert.inc
+++ b/runtime/src/depth24_convert.inc
@@ -1,4 +1,4 @@
1{0x07230203,0x00010300,0x000d000b,0x0000010a, 1{0x07230203,0x00010300,0x000d000b,0x0000016d,
20x00000000,0x00020011,0x00000001,0x0006000b, 20x00000000,0x00020011,0x00000001,0x0006000b,
30x00000001,0x4c534c47,0x6474732e,0x3035342e, 30x00000001,0x4c534c47,0x6474732e,0x3035342e,
40x00000000,0x0003000e,0x00000000,0x00000001, 40x00000000,0x0003000e,0x00000000,0x00000001,
@@ -17,17 +17,17 @@
170x00000014,0x00050048,0x00000051,0x00000006, 170x00000014,0x00050048,0x00000051,0x00000006,
180x00000023,0x00000018,0x00050048,0x00000051, 180x00000023,0x00000018,0x00050048,0x00000051,
190x00000007,0x00000023,0x0000001c,0x00040047, 190x00000007,0x00000023,0x0000001c,0x00040047,
200x0000009f,0x00000006,0x00000004,0x00030047, 200x000000a8,0x00000006,0x00000004,0x00030047,
210x000000a0,0x00000002,0x00050048,0x000000a0, 210x000000a9,0x00000002,0x00050048,0x000000a9,
220x00000000,0x00000023,0x00000000,0x00040047, 220x00000000,0x00000023,0x00000000,0x00040047,
230x000000a2,0x00000021,0x00000001,0x00040047, 230x000000ab,0x00000021,0x00000001,0x00040047,
240x000000a2,0x00000022,0x00000000,0x00040047, 240x000000ab,0x00000022,0x00000000,0x00040047,
250x000000a4,0x00000006,0x00000004,0x00030047, 250x000000ad,0x00000006,0x00000004,0x00030047,
260x000000a5,0x00000002,0x00050048,0x000000a5, 260x000000ae,0x00000002,0x00050048,0x000000ae,
270x00000000,0x00000023,0x00000000,0x00040047, 270x00000000,0x00000023,0x00000000,0x00040047,
280x000000a7,0x00000021,0x00000000,0x00040047, 280x000000b0,0x00000021,0x00000000,0x00040047,
290x000000a7,0x00000022,0x00000000,0x00040047, 290x000000b0,0x00000022,0x00000000,0x00040047,
300x000000ba,0x0000000b,0x00000019,0x00020013, 300x00000117,0x0000000b,0x00000019,0x00020013,
310x00000002,0x00030021,0x00000003,0x00000002, 310x00000002,0x00030021,0x00000003,0x00000002,
320x00040015,0x00000006,0x00000020,0x00000000, 320x00040015,0x00000006,0x00000020,0x00000000,
330x00030016,0x00000008,0x00000020,0x0004002b, 330x00030016,0x00000008,0x00000020,0x0004002b,
@@ -51,27 +51,30 @@
510x00000019,0x00000054,0x00000000,0x00040020, 510x00000019,0x00000054,0x00000000,0x00040020,
520x00000055,0x00000009,0x00000006,0x0004002b, 520x00000055,0x00000009,0x00000006,0x0004002b,
530x00000019,0x0000005e,0x00000001,0x0004002b, 530x00000019,0x0000005e,0x00000001,0x0004002b,
540x00000006,0x00000066,0x00000002,0x0004002b,
540x00000019,0x00000069,0x00000002,0x0004002b, 550x00000019,0x00000069,0x00000002,0x0004002b,
550x00000019,0x00000072,0x00000004,0x0004002b, 560x00000019,0x00000071,0x00000003,0x0004002b,
560x00000019,0x00000077,0x00000006,0x0004002b, 570x00000019,0x00000078,0x00000004,0x0004002b,
570x00000019,0x0000007e,0x00000005,0x0004002b, 580x00000019,0x0000007d,0x00000006,0x0004002b,
580x00000019,0x00000087,0x00000007,0x0004002b, 590x00000019,0x00000084,0x00000005,0x0004002b,
590x00000019,0x00000099,0x00000003,0x0003001d, 600x00000006,0x0000008b,0x00000003,0x0004002b,
600x0000009f,0x00000006,0x0003001e,0x000000a0, 610x00000019,0x0000008f,0x00000007,0x0004002b,
610x0000009f,0x00040020,0x000000a1,0x0000000c, 620x00000006,0x000000a0,0x00000004,0x0003001d,
620x000000a0,0x0004003b,0x000000a1,0x000000a2, 630x000000a8,0x00000006,0x0003001e,0x000000a9,
630x0000000c,0x0003001d,0x000000a4,0x00000006, 640x000000a8,0x00040020,0x000000aa,0x0000000c,
640x0003001e,0x000000a5,0x000000a4,0x00040020, 650x000000a9,0x0004003b,0x000000aa,0x000000ab,
650x000000a6,0x0000000c,0x000000a5,0x0004003b, 660x0000000c,0x0003001d,0x000000ad,0x00000006,
660x000000a6,0x000000a7,0x0000000c,0x00040020, 670x0003001e,0x000000ae,0x000000ad,0x00040020,
670x000000a9,0x0000000c,0x00000006,0x0004002b, 680x000000af,0x0000000c,0x000000ae,0x0004003b,
680x00000006,0x000000b9,0x00000008,0x0006002c, 690x000000af,0x000000b0,0x0000000c,0x00040020,
690x00000049,0x000000ba,0x000000b9,0x000000b9, 700x000000b2,0x0000000c,0x00000006,0x0004002b,
700x00000026,0x0004002b,0x00000019,0x00000109, 710x00000006,0x00000116,0x00000008,0x0006002c,
720x00000049,0x00000117,0x00000116,0x00000116,
730x00000026,0x0004002b,0x00000019,0x0000016c,
710x00000050,0x00050036,0x00000002,0x00000004, 740x00000050,0x00050036,0x00000002,0x00000004,
720x00000000,0x00000003,0x000200f8,0x00000005, 750x00000000,0x00000003,0x000200f8,0x00000005,
730x000300f7,0x000000bb,0x00000000,0x000300fb, 760x000300f7,0x00000118,0x00000000,0x000300fb,
740x00000012,0x000000bc,0x000200f8,0x000000bc, 770x00000012,0x00000119,0x000200f8,0x00000119,
750x0004003d,0x00000049,0x0000004e,0x0000004d, 780x0004003d,0x00000049,0x0000004e,0x0000004d,
760x00050051,0x00000006,0x00000050,0x0000004e, 790x00050051,0x00000006,0x00000050,0x0000004e,
770x00000000,0x00050041,0x00000055,0x00000056, 800x00000000,0x00050041,0x00000055,0x00000056,
@@ -87,7 +90,7 @@
870x00000060,0x0000005f,0x000500ae,0x00000013, 900x00000060,0x0000005f,0x000500ae,0x00000013,
880x00000061,0x0000005d,0x00000060,0x000200f9, 910x00000061,0x0000005d,0x00000060,0x000200f9,
890x0000005b,0x000200f8,0x0000005b,0x000700f5, 920x0000005b,0x000200f8,0x0000005b,0x000700f5,
900x00000013,0x00000062,0x00000058,0x000000bc, 930x00000013,0x00000062,0x00000058,0x00000119,
910x00000061,0x0000005a,0x000400a8,0x00000013, 940x00000061,0x0000005a,0x000400a8,0x00000013,
920x00000063,0x00000062,0x000300f7,0x00000065, 950x00000063,0x00000062,0x000300f7,0x00000065,
930x00000000,0x000400fa,0x00000063,0x00000064, 960x00000000,0x000400fa,0x00000063,0x00000064,
@@ -101,93 +104,174 @@
1010x0000006d,0x00000062,0x0000005b,0x0000006c, 1040x0000006d,0x00000062,0x0000005b,0x0000006c,
1020x00000064,0x000300f7,0x0000006f,0x00000000, 1050x00000064,0x000300f7,0x0000006f,0x00000000,
1030x000400fa,0x0000006d,0x0000006e,0x0000006f, 1060x000400fa,0x0000006d,0x0000006e,0x0000006f,
1040x000200f8,0x0000006e,0x000200f9,0x000000bb, 1070x000200f8,0x0000006e,0x000200f9,0x00000118,
1050x000200f8,0x0000006f,0x00050041,0x00000055, 1080x000200f8,0x0000006f,0x00050041,0x00000055,
1060x00000073,0x00000053,0x00000072,0x0004003d, 1090x00000072,0x00000053,0x00000071,0x0004003d,
1070x00000006,0x00000074,0x00000073,0x00050051, 1100x00000006,0x00000073,0x00000072,0x000500ae,
1080x00000006,0x00000076,0x0000004e,0x00000002, 1110x00000013,0x00000074,0x00000073,0x00000066,
1090x00050041,0x00000055,0x00000078,0x00000053, 1120x000300f7,0x00000076,0x00000000,0x000400fa,
1100x00000077,0x0004003d,0x00000006,0x00000079, 1130x00000074,0x00000075,0x00000076,0x000200f8,
1110x00000078,0x00050084,0x00000006,0x0000007a, 1140x00000075,0x00050041,0x00000055,0x00000079,
1120x00000076,0x00000079,0x00050080,0x00000006, 1150x00000053,0x00000078,0x0004003d,0x00000006,
1130x0000007b,0x00000074,0x0000007a,0x00050051, 1160x0000007a,0x00000079,0x00050051,0x00000006,
1140x00000006,0x0000007d,0x0000004e,0x00000001, 1170x0000007c,0x0000004e,0x00000002,0x00050041,
1150x00050041,0x00000055,0x0000007f,0x00000053, 1180x00000055,0x0000007e,0x00000053,0x0000007d,
1160x0000007e,0x0004003d,0x00000006,0x00000080, 1190x0004003d,0x00000006,0x0000007f,0x0000007e,
1170x0000007f,0x00050084,0x00000006,0x00000081, 1200x00050084,0x00000006,0x00000080,0x0000007c,
1180x0000007d,0x00000080,0x00050080,0x00000006, 1210x0000007f,0x00050080,0x00000006,0x00000081,
1190x00000082,0x0000007b,0x00000081,0x00050080, 1220x0000007a,0x00000080,0x00050051,0x00000006,
1200x00000006,0x00000085,0x00000082,0x00000050, 1230x00000083,0x0000004e,0x00000001,0x00050041,
1210x00050041,0x00000055,0x00000088,0x00000053, 1240x00000055,0x00000085,0x00000053,0x00000084,
1220x00000087,0x0004003d,0x00000006,0x00000089, 1250x0004003d,0x00000006,0x00000086,0x00000085,
1230x00000088,0x00050041,0x00000055,0x0000008c, 1260x00050084,0x00000006,0x00000087,0x00000083,
1270x00000086,0x00050080,0x00000006,0x00000088,
1280x00000081,0x00000087,0x00050084,0x00000006,
1290x0000008c,0x00000050,0x0000008b,0x00050080,
1300x00000006,0x0000008d,0x00000088,0x0000008c,
1310x00050041,0x00000055,0x00000090,0x00000053,
1320x0000008f,0x0004003d,0x00000006,0x00000091,
1330x00000090,0x00050041,0x00000055,0x00000094,
1240x00000053,0x0000005e,0x0004003d,0x00000006, 1340x00000053,0x0000005e,0x0004003d,0x00000006,
1250x0000008d,0x0000008c,0x00050084,0x00000006, 1350x00000095,0x00000094,0x00050084,0x00000006,
1260x0000008e,0x00000076,0x0000008d,0x00050080, 1360x00000096,0x0000007c,0x00000095,0x00050080,
1270x00000006,0x00000091,0x0000008e,0x0000007d, 1370x00000006,0x00000099,0x00000096,0x00000083,
1280x00050084,0x00000006,0x00000094,0x00000091, 1380x00050084,0x00000006,0x0000009c,0x00000099,
1290x00000057,0x00050080,0x00000006,0x00000095, 1390x00000057,0x00050080,0x00000006,0x0000009f,
1300x00000089,0x00000094,0x00050080,0x00000006, 1400x0000009c,0x00000050,0x00050084,0x00000006,
1310x00000098,0x00000095,0x00000050,0x00050041, 1410x000000a1,0x0000009f,0x000000a0,0x00050080,
1320x00000055,0x0000009a,0x00000053,0x00000099, 1420x00000006,0x000000a2,0x00000091,0x000000a1,
1330x0004003d,0x00000006,0x0000009b,0x0000009a, 1430x000500aa,0x00000013,0x000000a5,0x00000073,
1340x000500ab,0x00000013,0x0000009c,0x0000009b, 1440x0000008b,0x000300f7,0x000000a7,0x00000000,
1350x00000012,0x000300f7,0x0000009e,0x00000000, 1450x000400fa,0x000000a5,0x000000a6,0x000000c7,
1360x000400fa,0x0000009c,0x0000009d,0x000000b1, 1460x000200f8,0x000000a6,0x00060041,0x000000b2,
1370x000200f8,0x0000009d,0x00060041,0x000000a9, 1470x000000b3,0x000000b0,0x00000054,0x0000008d,
1380x000000aa,0x000000a7,0x00000054,0x00000085, 1480x0004003d,0x00000006,0x000000b4,0x000000b3,
1390x0004003d,0x00000006,0x000000ab,0x000000aa, 1490x00060041,0x000000b2,0x000000b5,0x000000ab,
1400x000500c7,0x00000006,0x000000ac,0x000000ab, 1500x00000054,0x000000a2,0x0003003e,0x000000b5,
1410x0000003f,0x000300f7,0x000000e8,0x00000000, 1510x000000b4,0x00050080,0x00000006,0x000000b7,
1420x000300fb,0x00000012,0x000000d2,0x000200f8, 1520x000000a2,0x00000026,0x00050080,0x00000006,
1430x000000d2,0x000500aa,0x00000013,0x000000d4, 1530x000000b9,0x0000008d,0x00000026,0x00060041,
1440x000000ac,0x00000012,0x000300f7,0x000000d6, 1540x000000b2,0x000000ba,0x000000b0,0x00000054,
1450x00000000,0x000400fa,0x000000d4,0x000000d5, 1550x000000b9,0x0004003d,0x00000006,0x000000bb,
1460x000000d6,0x000200f8,0x000000d5,0x000200f9, 1560x000000ba,0x00060041,0x000000b2,0x000000bc,
1470x000000e8,0x000200f8,0x000000d6,0x0006000c, 1570x000000ab,0x00000054,0x000000b7,0x0003003e,
1480x00000019,0x000000d8,0x00000001,0x0000004b, 1580x000000bc,0x000000bb,0x00050080,0x00000006,
1490x000000ac,0x00050082,0x00000019,0x000000db, 1590x000000be,0x000000a2,0x00000066,0x00050080,
1500x00000020,0x000000d8,0x0004007c,0x00000006, 1600x00000006,0x000000c0,0x0000008d,0x00000066,
1510x000000dc,0x000000db,0x000500c4,0x00000006, 1610x00060041,0x000000b2,0x000000c1,0x000000b0,
1520x000000dd,0x000000ac,0x000000dc,0x00050080, 1620x00000054,0x000000c0,0x0004003d,0x00000006,
1530x00000006,0x000000df,0x000000dd,0x00000026, 1630x000000c2,0x000000c1,0x00060041,0x000000b2,
1540x00040070,0x00000008,0x000000e0,0x000000df, 1640x000000c3,0x000000ab,0x00000054,0x000000be,
1550x00050080,0x00000019,0x000000e3,0x000000d8, 1650x0003003e,0x000000c3,0x000000c2,0x00050080,
1560x00000109,0x0004007c,0x00000006,0x000000e4, 1660x00000006,0x000000c5,0x000000a2,0x0000008b,
1570x000000e3,0x000500c4,0x00000006,0x000000e5, 1670x00060041,0x000000b2,0x000000c6,0x000000ab,
1580x000000e4,0x00000020,0x0004007c,0x00000008, 1680x00000054,0x000000c5,0x0003003e,0x000000c6,
1590x000000e6,0x000000e5,0x00050085,0x00000008, 1690x00000012,0x000200f9,0x000000a7,0x000200f8,
1600x000000e7,0x000000e0,0x000000e6,0x000200f9, 1700x000000c7,0x00060041,0x000000b2,0x000000ca,
1610x000000e8,0x000200f8,0x000000e8,0x000700f5, 1710x000000ab,0x00000054,0x000000a2,0x0004003d,
1620x00000008,0x00000108,0x00000017,0x000000d5, 1720x00000006,0x000000cb,0x000000ca,0x00060041,
1630x000000e7,0x000000d6,0x0004007c,0x00000006, 1730x000000b2,0x000000cc,0x000000b0,0x00000054,
1640x000000af,0x00000108,0x00060041,0x000000a9, 1740x0000008d,0x0003003e,0x000000cc,0x000000cb,
1650x000000b0,0x000000a2,0x00000054,0x00000098, 1750x00050080,0x00000006,0x000000ce,0x0000008d,
1660x0003003e,0x000000b0,0x000000af,0x000200f9, 1760x00000026,0x00050080,0x00000006,0x000000d0,
1670x0000009e,0x000200f8,0x000000b1,0x00060041, 1770x000000a2,0x00000026,0x00060041,0x000000b2,
1680x000000a9,0x000000b5,0x000000a2,0x00000054, 1780x000000d1,0x000000ab,0x00000054,0x000000d0,
1690x00000098,0x0004003d,0x00000006,0x000000b6, 1790x0004003d,0x00000006,0x000000d2,0x000000d1,
1700x000000b5,0x000300f7,0x000000fc,0x00000000, 1800x00060041,0x000000b2,0x000000d3,0x000000b0,
1710x000300fb,0x00000012,0x000000ee,0x000200f8, 1810x00000054,0x000000ce,0x0003003e,0x000000d3,
1720x000000ee,0x000500ac,0x00000013,0x000000f0, 1820x000000d2,0x00050080,0x00000006,0x000000d5,
1730x000000b6,0x00000035,0x000300f7,0x000000f2, 1830x0000008d,0x00000066,0x00050080,0x00000006,
1740x00000000,0x000400fa,0x000000f0,0x000000f1, 1840x000000d7,0x000000a2,0x00000066,0x00060041,
1750x000000f2,0x000200f8,0x000000f1,0x000200f9, 1850x000000b2,0x000000d8,0x000000ab,0x00000054,
1760x000000fc,0x000200f8,0x000000f2,0x000500ae, 1860x000000d7,0x0004003d,0x00000006,0x000000d9,
1770x00000013,0x000000f4,0x000000b6,0x0000003b, 1870x000000d8,0x00060041,0x000000b2,0x000000da,
1780x000300f7,0x000000f6,0x00000000,0x000400fa, 1880x000000b0,0x00000054,0x000000d5,0x0003003e,
1790x000000f4,0x000000f5,0x000000f6,0x000200f8, 1890x000000da,0x000000d9,0x000200f9,0x000000a7,
1800x000000f5,0x000200f9,0x000000fc,0x000200f8, 1900x000200f8,0x000000a7,0x000200f9,0x00000118,
1810x000000f6,0x0004007c,0x00000008,0x000000f8, 1910x000200f8,0x00000076,0x00050041,0x00000055,
1820x000000b6,0x00050085,0x00000008,0x000000f9, 1920x000000dd,0x00000053,0x00000078,0x0004003d,
1830x000000f8,0x00000043,0x0006000c,0x00000008, 1930x00000006,0x000000de,0x000000dd,0x00050051,
1840x000000fa,0x00000001,0x00000002,0x000000f9, 1940x00000006,0x000000e0,0x0000004e,0x00000002,
1850x0004006d,0x00000006,0x000000fb,0x000000fa, 1950x00050041,0x00000055,0x000000e1,0x00000053,
1860x000200f9,0x000000fc,0x000200f8,0x000000fc, 1960x0000007d,0x0004003d,0x00000006,0x000000e2,
1870x000900f5,0x00000006,0x00000107,0x00000012, 1970x000000e1,0x00050084,0x00000006,0x000000e3,
1880x000000f1,0x0000003f,0x000000f5,0x000000fb, 1980x000000e0,0x000000e2,0x00050080,0x00000006,
1890x000000f6,0x00060041,0x000000a9,0x000000b8, 1990x000000e4,0x000000de,0x000000e3,0x00050051,
1900x000000a7,0x00000054,0x00000085,0x0003003e, 2000x00000006,0x000000e6,0x0000004e,0x00000001,
1910x000000b8,0x00000107,0x000200f9,0x0000009e, 2010x00050041,0x00000055,0x000000e7,0x00000053,
1920x000200f8,0x0000009e,0x000200f9,0x000000bb, 2020x00000084,0x0004003d,0x00000006,0x000000e8,
1930x000200f8,0x000000bb,0x000100fd,0x00010038} 2030x000000e7,0x00050084,0x00000006,0x000000e9,
2040x000000e6,0x000000e8,0x00050080,0x00000006,
2050x000000ea,0x000000e4,0x000000e9,0x00050080,
2060x00000006,0x000000ed,0x000000ea,0x00000050,
2070x00050041,0x00000055,0x000000ef,0x00000053,
2080x0000008f,0x0004003d,0x00000006,0x000000f0,
2090x000000ef,0x00050041,0x00000055,0x000000f3,
2100x00000053,0x0000005e,0x0004003d,0x00000006,
2110x000000f4,0x000000f3,0x00050084,0x00000006,
2120x000000f5,0x000000e0,0x000000f4,0x00050080,
2130x00000006,0x000000f8,0x000000f5,0x000000e6,
2140x00050084,0x00000006,0x000000fb,0x000000f8,
2150x00000057,0x00050080,0x00000006,0x000000fc,
2160x000000f0,0x000000fb,0x00050080,0x00000006,
2170x000000ff,0x000000fc,0x00000050,0x000500ab,
2180x00000013,0x00000102,0x00000073,0x00000012,
2190x000300f7,0x00000104,0x00000000,0x000400fa,
2200x00000102,0x00000103,0x0000010e,0x000200f8,
2210x00000103,0x00060041,0x000000b2,0x00000107,
2220x000000b0,0x00000054,0x000000ed,0x0004003d,
2230x00000006,0x00000108,0x00000107,0x000500c7,
2240x00000006,0x00000109,0x00000108,0x0000003f,
2250x000300f7,0x00000145,0x00000000,0x000300fb,
2260x00000012,0x0000012f,0x000200f8,0x0000012f,
2270x000500aa,0x00000013,0x00000131,0x00000109,
2280x00000012,0x000300f7,0x00000133,0x00000000,
2290x000400fa,0x00000131,0x00000132,0x00000133,
2300x000200f8,0x00000132,0x000200f9,0x00000145,
2310x000200f8,0x00000133,0x0006000c,0x00000019,
2320x00000135,0x00000001,0x0000004b,0x00000109,
2330x00050082,0x00000019,0x00000138,0x00000020,
2340x00000135,0x0004007c,0x00000006,0x00000139,
2350x00000138,0x000500c4,0x00000006,0x0000013a,
2360x00000109,0x00000139,0x00050080,0x00000006,
2370x0000013c,0x0000013a,0x00000026,0x00040070,
2380x00000008,0x0000013d,0x0000013c,0x00050080,
2390x00000019,0x00000140,0x00000135,0x0000016c,
2400x0004007c,0x00000006,0x00000141,0x00000140,
2410x000500c4,0x00000006,0x00000142,0x00000141,
2420x00000020,0x0004007c,0x00000008,0x00000143,
2430x00000142,0x00050085,0x00000008,0x00000144,
2440x0000013d,0x00000143,0x000200f9,0x00000145,
2450x000200f8,0x00000145,0x000700f5,0x00000008,
2460x0000016b,0x00000017,0x00000132,0x00000144,
2470x00000133,0x0004007c,0x00000006,0x0000010c,
2480x0000016b,0x00060041,0x000000b2,0x0000010d,
2490x000000ab,0x00000054,0x000000ff,0x0003003e,
2500x0000010d,0x0000010c,0x000200f9,0x00000104,
2510x000200f8,0x0000010e,0x00060041,0x000000b2,
2520x00000112,0x000000ab,0x00000054,0x000000ff,
2530x0004003d,0x00000006,0x00000113,0x00000112,
2540x000300f7,0x00000159,0x00000000,0x000300fb,
2550x00000012,0x0000014b,0x000200f8,0x0000014b,
2560x000500ac,0x00000013,0x0000014d,0x00000113,
2570x00000035,0x000300f7,0x0000014f,0x00000000,
2580x000400fa,0x0000014d,0x0000014e,0x0000014f,
2590x000200f8,0x0000014e,0x000200f9,0x00000159,
2600x000200f8,0x0000014f,0x000500ae,0x00000013,
2610x00000151,0x00000113,0x0000003b,0x000300f7,
2620x00000153,0x00000000,0x000400fa,0x00000151,
2630x00000152,0x00000153,0x000200f8,0x00000152,
2640x000200f9,0x00000159,0x000200f8,0x00000153,
2650x0004007c,0x00000008,0x00000155,0x00000113,
2660x00050085,0x00000008,0x00000156,0x00000155,
2670x00000043,0x0006000c,0x00000008,0x00000157,
2680x00000001,0x00000002,0x00000156,0x0004006d,
2690x00000006,0x00000158,0x00000157,0x000200f9,
2700x00000159,0x000200f8,0x00000159,0x000900f5,
2710x00000006,0x0000016a,0x00000012,0x0000014e,
2720x0000003f,0x00000152,0x00000158,0x00000153,
2730x00060041,0x000000b2,0x00000115,0x000000b0,
2740x00000054,0x000000ed,0x0003003e,0x00000115,
2750x0000016a,0x000200f9,0x00000104,0x000200f8,
2760x00000104,0x000200f9,0x00000118,0x000200f8,
2770x00000118,0x000100fd,0x00010038}
diff --git a/runtime/src/vulkan_depth24.h b/runtime/src/vulkan_depth24.h
index da57d45b4..1bc9c8ba5 100644
--- a/runtime/src/vulkan_depth24.h
+++ b/runtime/src/vulkan_depth24.h
@@ -1,3 +1,6 @@
1// Also the repack of 96-bit R32G32B32 texels, held in R32G32B32A32 images (Depth24Job::rgb96, D3D-62): the same
2// scratch, parts and lifetime, with texels of three words in the footprint and four in the scratch.
3//
1// The compute pass behind D24_UNORM_S8_UINT on a GPU without D24 (depth24.h, depth24_convert.comp). A copy between a 4// The compute pass behind D24_UNORM_S8_UINT on a GPU without D24 (depth24.h, depth24_convert.comp). A copy between a
2// footprint and the depth aspect of such a texture goes through a scratch buffer of floats: an upload converts the 5// footprint and the depth aspect of such a texture goes through a scratch buffer of floats: an upload converts the
3// footprint's words into the scratch and a copy command moves the scratch into the image; a readback copies the image 6// footprint's words into the scratch and a copy command moves the scratch into the image; a readback copies the image
@@ -54,22 +57,26 @@ public:
54 // larger, so no copy is too big for the device. `whole.scratch` and `whole.scratch_offset` tell the copy where 57 // larger, so no copy is too big for the device. `whole.scratch` and `whole.scratch_offset` tell the copy where
55 // the floats are. 58 // the floats are.
56 bool prepare(Depth24Job& whole, std::vector<Depth24Job>& parts) { 59 bool prepare(Depth24Job& whole, std::vector<Depth24Job>& parts) {
60 // A row of the footprint is `aw` words wide and a row of the scratch `sw` (a texel is one word of each for
61 // D24, three and four for 96-bit texels).
62 const std::uint64_t aw = std::uint64_t(whole.width) * whole.app_texel_words();
63 const std::uint64_t sw = std::uint64_t(whole.width) * whole.scratch_texel_words();
57 if (!loaded_ || !make_pipeline() || !whole.app || !whole.width || !whole.height || !whole.slices || 64 if (!loaded_ || !make_pipeline() || !whole.app || !whole.width || !whole.height || !whole.slices ||
58 whole.app_offset % 4 || whole.app_row_words < whole.width || 65 whole.app_offset % 4 || whole.app_row_words < aw ||
59 whole.app_slice_words < std::uint64_t(whole.app_row_words) * (whole.height - 1) + whole.width) 66 whole.app_slice_words < std::uint64_t(whole.app_row_words) * (whole.height - 1) + aw)
60 return false; 67 return false;
61 const std::uint64_t w = whole.width, h = whole.height, s = whole.slices; 68 const std::uint64_t h = whole.height, s = whole.slices;
62 const std::uint64_t span_words = (s - 1) * whole.app_slice_words + (h - 1) * whole.app_row_words + w; 69 const std::uint64_t span_words = (s - 1) * whole.app_slice_words + (h - 1) * whole.app_row_words + aw;
63 if (whole.app_offset + span_words * 4 > whole.app_size) return false; 70 if (whole.app_offset + span_words * 4 > whole.app_size) return false;
64 if (!whole.scratch && !scratch(w * h * s * 4, whole.scratch, whole.scratch_offset)) return false; 71 if (!whole.scratch && !scratch(sw * h * s * 4, whole.scratch, whole.scratch_offset)) return false;
65 72
66 // A window starts at a multiple of 256 (the largest minStorageBufferOffsetAlignment), which costs up to 252 bytes. 73 // A window starts at a multiple of 256 (the largest minStorageBufferOffsetAlignment), which costs up to 252 bytes.
67 constexpr std::uint64_t slack = 256; 74 constexpr std::uint64_t slack = 256;
68 const std::uint64_t limit = max_range_; 75 const std::uint64_t limit = max_range_;
69 const auto app_bytes = [&](std::uint64_t slices, std::uint64_t rows) { 76 const auto app_bytes = [&](std::uint64_t slices, std::uint64_t rows) {
70 return ((slices - 1) * whole.app_slice_words + (rows - 1) * whole.app_row_words + w) * 4 + slack; 77 return ((slices - 1) * whole.app_slice_words + (rows - 1) * whole.app_row_words + aw) * 4 + slack;
71 }; 78 };
72 const auto scratch_bytes = [&](std::uint64_t slices, std::uint64_t rows) { return slices * rows * w * 4 + slack; }; 79 const auto scratch_bytes = [&](std::uint64_t slices, std::uint64_t rows) { return slices * rows * sw * 4 + slack; };
73 std::uint64_t slices_per_part = 0; // 0: a slice alone is too big 80 std::uint64_t slices_per_part = 0; // 0: a slice alone is too big
74 while (slices_per_part < s && app_bytes(slices_per_part + 1, h) <= limit && scratch_bytes(slices_per_part + 1, h) <= limit) 81 while (slices_per_part < s && app_bytes(slices_per_part + 1, h) <= limit && scratch_bytes(slices_per_part + 1, h) <= limit)
75 ++slices_per_part; 82 ++slices_per_part;
@@ -89,7 +96,7 @@ public:
89 part.slices = std::uint32_t(n); 96 part.slices = std::uint32_t(n);
90 part.height = std::uint32_t(rows); 97 part.height = std::uint32_t(rows);
91 part.app_offset = whole.app_offset + (z * whole.app_slice_words + y * whole.app_row_words) * 4; 98 part.app_offset = whole.app_offset + (z * whole.app_slice_words + y * whole.app_row_words) * 4;
92 part.scratch_offset = whole.scratch_offset + ((z * h + y) * w) * 4; 99 part.scratch_offset = whole.scratch_offset + ((z * h + y) * sw) * 4;
93 if (!make_part(part, whole.app_size)) return false; 100 if (!make_part(part, whole.app_size)) return false;
94 parts.push_back(part); 101 parts.push_back(part);
95 } 102 }
@@ -103,8 +110,8 @@ public:
103 void run(VkCommandBuffer command_buffer, const Depth24Job& job) const { 110 void run(VkCommandBuffer command_buffer, const Depth24Job& job) const {
104 struct Push { 111 struct Push {
105 std::uint32_t width, height, slices, to_float, app_base, app_row, app_slice, scratch_base; 112 std::uint32_t width, height, slices, to_float, app_base, app_row, app_slice, scratch_base;
106 } push{job.width, job.height, job.slices, job.to_float ? 1u : 0u, job.app_base_words, job.app_row_words, 113 } push{job.width, job.height, job.slices, (job.to_float ? 1u : 0u) | (job.rgb96 ? 2u : 0u), job.app_base_words,
107 job.app_slice_words, job.scratch_base_words}; 114 job.app_row_words, job.app_slice_words, job.scratch_base_words};
108 vk_.vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_); 115 vk_.vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_);
109 vk_.vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout_, 0, 1, &job.set, 0, 116 vk_.vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout_, 0, 1, &job.set, 0,
110 nullptr); 117 nullptr);
@@ -238,10 +245,11 @@ private:
238 bool make_part(Depth24Job& part, std::uint64_t app_size) { 245 bool make_part(Depth24Job& part, std::uint64_t app_size) {
239 constexpr std::uint64_t alignment = 256; 246 constexpr std::uint64_t alignment = 256;
240 const std::uint64_t span = ((std::uint64_t(part.slices) - 1) * part.app_slice_words + 247 const std::uint64_t span = ((std::uint64_t(part.slices) - 1) * part.app_slice_words +
241 (std::uint64_t(part.height) - 1) * part.app_row_words + part.width) * 4; 248 (std::uint64_t(part.height) - 1) * part.app_row_words +
249 std::uint64_t(part.width) * part.app_texel_words()) * 4;
242 const std::uint64_t window = part.app_offset / alignment * alignment; 250 const std::uint64_t window = part.app_offset / alignment * alignment;
243 const std::uint64_t range = part.app_offset - window + span; 251 const std::uint64_t range = part.app_offset - window + span;
244 const std::uint64_t tight = std::uint64_t(part.width) * part.height * part.slices * 4; 252 const std::uint64_t tight = std::uint64_t(part.width) * part.scratch_texel_words() * part.height * part.slices * 4;
245 const std::uint64_t scratch_window = part.scratch_offset / alignment * alignment; 253 const std::uint64_t scratch_window = part.scratch_offset / alignment * alignment;
246 const std::uint64_t scratch_range = part.scratch_offset - scratch_window + tight; 254 const std::uint64_t scratch_range = part.scratch_offset - scratch_window + tight;
247 if (window + range > app_size) return false; 255 if (window + range > app_size) return false;
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h
index 6df4beba5..1b1d0dbe5 100644
--- a/runtime/src/vulkan_replay.h
+++ b/runtime/src/vulkan_replay.h
@@ -79,6 +79,9 @@ struct ResourceBinding {
79 // (depth24.h) and clears quantise to 24 bits. 79 // (depth24.h) and clears quantise to 24 bits.
80 bool depth24_as_float = false; 80 bool depth24_as_float = false;
81 bool depth24 = false; // a D24 family format, native or not: depth clears are quantised to 24 bits first 81 bool depth24 = false; // a D24 family format, native or not: depth clears are quantised to 24 bits first
82 // A D3D12 R32G32B32 texture (12 bytes a texel) held in an R32G32B32A32 image (16): footprints keep D3D12's 12
83 // bytes, and copies between it and a buffer are repacked by the depth24 pass (Depth24Job::rgb96).
84 bool rgb96 = false;
82 bool color_attachment = false; // has COLOR_ATTACHMENT usage: unordered-access rectangle clears need it 85 bool color_attachment = false; // has COLOR_ATTACHMENT usage: unordered-access rectangle clears need it
83 bool host_readable = false; // D3D12_HEAP_TYPE_READBACK (or CUSTOM write-back): needs host-read flush 86 bool host_readable = false; // D3D12_HEAP_TYPE_READBACK (or CUSTOM write-back): needs host-read flush
84}; 87};
@@ -458,6 +461,14 @@ inline BlockFormat block_format(VkFormat format, VkImageAspectFlags aspect) {
458 } 461 }
459} 462}
460 463
464// The same for a resource as D3D12 lays it out, which for an rgb96 texture is not its image's layout.
465inline constexpr std::uint32_t rgb96_bytes = 12;
466inline BlockFormat copy_block_format(const ResourceBinding& resource, VkImageAspectFlags aspect) {
467 BlockFormat format = block_format(resource.format, aspect);
468 if (resource.rgb96 && format.bytes) format.bytes = rgb96_bytes;
469 return format;
470}
471
461inline bool two_planes(const ResourceBinding& resource) { 472inline bool two_planes(const ResourceBinding& resource) {
462 return (resource.aspects & depth_stencil_aspects) == depth_stencil_aspects; 473 return (resource.aspects & depth_stencil_aspects) == depth_stencil_aspects;
463} 474}
@@ -748,6 +759,9 @@ struct Prepared {
748 VkResolveModeFlagBits resolve_mode = VK_RESOLVE_MODE_NONE; 759 VkResolveModeFlagBits resolve_mode = VK_RESOLVE_MODE_NONE;
749 VkImageView resolve_view = VK_NULL_HANDLE; 760 VkImageView resolve_view = VK_NULL_HANDLE;
750 bool has_depth24 = false; // a depth plane copy of a depth24_as_float texture: convert through depth24 761 bool has_depth24 = false; // a depth plane copy of a depth24_as_float texture: convert through depth24
762 // (or a copy of an rgb96 texture: repacked by the same pass)
763 std::uint32_t rgb96_row_words = 0; // an rgb96 footprint: words between its rows and between its slices
764 std::uint32_t rgb96_slice_words = 0;
751 Depth24Job depth24; // the whole copy: where its scratch floats are 765 Depth24Job depth24; // the whole copy: where its scratch floats are
752 std::vector<Depth24Job> depth24_parts; // the dispatches that convert it 766 std::vector<Depth24Job> depth24_parts; // the dispatches that convert it
753 std::vector<VkImageSubresourceRange> discards; // DiscardResource: the subresources to discard 767 std::vector<VkImageSubresourceRange> discards; // DiscardResource: the subresources to discard
@@ -1041,7 +1055,7 @@ inline ReplayResult prepare_texture_copy(const CopyTexture& copy, Prepared& p) {
1041 !copy_subresource(p.source, copy.src.subresource, src)) 1055 !copy_subresource(p.source, copy.src.subresource, src))
1042 return ReplayResult::invalid_subresource; 1056 return ReplayResult::invalid_subresource;
1043 if (dst.aspectMask != src.aspectMask || p.binding.volume != p.source.volume || 1057 if (dst.aspectMask != src.aspectMask || p.binding.volume != p.source.volume ||
1044 p.binding.samples != p.source.samples) 1058 p.binding.samples != p.source.samples || p.binding.rgb96 != p.source.rgb96)
1045 return ReplayResult::invalid_copy; 1059 return ReplayResult::invalid_copy;
1046 const VkExtent2D from = mip_extent(p.source, src.baseMipLevel), to = mip_extent(p.binding, dst.baseMipLevel); 1060 const VkExtent2D from = mip_extent(p.source, src.baseMipLevel), to = mip_extent(p.binding, dst.baseMipLevel);
1047 const auto from_depth = std::max(1u, p.source.depth >> src.baseMipLevel); 1061 const auto from_depth = std::max(1u, p.source.depth >> src.baseMipLevel);
@@ -1122,8 +1136,10 @@ inline ReplayResult prepare_texture_copy(const CopyTexture& copy, Prepared& p) {
1122 VkImageSubresourceRange range{}; 1136 VkImageSubresourceRange range{};
1123 if (!copy_subresource(image, texture.subresource, range)) return ReplayResult::invalid_subresource; 1137 if (!copy_subresource(image, texture.subresource, range)) return ReplayResult::invalid_subresource;
1124 if (image.samples != 1) return ReplayResult::invalid_copy; // multisampled textures have no footprint 1138 if (image.samples != 1) return ReplayResult::invalid_copy; // multisampled textures have no footprint
1125 const BlockFormat format = block_format(image.format, range.aspectMask); 1139 const BlockFormat format = copy_block_format(image, range.aspectMask);
1126 if (!format.bytes || placed.row_pitch % format.bytes) return ReplayResult::unsupported; 1140 // A 12-byte texel does not divide D3D12's 256-byte pitches; an rgb96 copy hands Vulkan the scratch buffer of
1141 // the repack, never this pitch, and the pass reads the footprint in words.
1142 if (!format.bytes || placed.row_pitch % (image.rgb96 ? 4 : format.bytes)) return ReplayResult::unsupported;
1127 const VkExtent2D mip = mip_extent(image, range.baseMipLevel); 1143 const VkExtent2D mip = mip_extent(image, range.baseMipLevel);
1128 const auto mip_depth = std::max(1u, image.depth >> range.baseMipLevel); 1144 const auto mip_depth = std::max(1u, image.depth >> range.baseMipLevel);
1129 // The box is in the source's coordinates: the footprint for an upload, the texture for a readback. 1145 // The box is in the source's coordinates: the footprint for an upload, the texture for a readback.
@@ -1153,7 +1169,9 @@ inline ReplayResult prepare_texture_copy(const CopyTexture& copy, Prepared& p) {
1153 std::uint64_t(placed_x / format.block) * format.bytes; 1169 std::uint64_t(placed_x / format.block) * format.bytes;
1154 if (!within(slice_start, in_slice, buffer.size)) return ReplayResult::invalid_copy; 1170 if (!within(slice_start, in_slice, buffer.size)) return ReplayResult::invalid_copy;
1155 const auto offset = slice_start + in_slice; 1171 const auto offset = slice_start + in_slice;
1156 const std::uint32_t alignment = (range.aspectMask & depth_stencil_aspects) ? 4 : format.bytes; 1172 // Vulkan wants a buffer offset that is a multiple of the texel size (VUID-vkCmdCopyBufferToImage-dstImage-07975),
1173 // which D3D12's 512-byte placement does not give a 12-byte texel: one more reason an rgb96 copy is repacked.
1174 const std::uint32_t alignment = (range.aspectMask & depth_stencil_aspects) || image.rgb96 ? 4 : format.bytes;
1157 if (offset % alignment) return ReplayResult::unsupported; 1175 if (offset % alignment) return ReplayResult::unsupported;
1158 const std::uint64_t rows = (std::uint64_t(h) + format.block - 1) / format.block; 1176 const std::uint64_t rows = (std::uint64_t(h) + format.block - 1) / format.block;
1159 const std::uint64_t row_bytes = (std::uint64_t(w) + format.block - 1) / format.block * format.bytes; 1177 const std::uint64_t row_bytes = (std::uint64_t(w) + format.block - 1) / format.block * format.bytes;
@@ -1168,6 +1186,13 @@ inline ReplayResult prepare_texture_copy(const CopyTexture& copy, Prepared& p) {
1168 region.imageSubresource = {range.aspectMask, range.baseMipLevel, range.baseArrayLayer, 1}; 1186 region.imageSubresource = {range.aspectMask, range.baseMipLevel, range.baseArrayLayer, 1};
1169 region.imageOffset = {std::int32_t(texture_x), std::int32_t(texture_y), std::int32_t(texture_z)}; 1187 region.imageOffset = {std::int32_t(texture_x), std::int32_t(texture_y), std::int32_t(texture_z)};
1170 region.imageExtent = {w, h, depth}; 1188 region.imageExtent = {w, h, depth};
1189 if (image.rgb96) { // the repack's scratch replaces this buffer in the copy; these are for the pass
1190 if (placed.row_pitch / 4 > UINT32_MAX || slice_pitch / 4 > UINT32_MAX) return ReplayResult::unsupported;
1191 p.rgb96_row_words = std::uint32_t(placed.row_pitch / 4);
1192 p.rgb96_slice_words = std::uint32_t(slice_pitch / 4);
1193 region.bufferRowLength = 0;
1194 region.bufferImageHeight = 0;
1195 }
1171 p.buffer_image_copies.push_back(region); 1196 p.buffer_image_copies.push_back(region);
1172 (upload ? p.range : p.source_range) = range; 1197 (upload ? p.range : p.source_range) = range;
1173 return ReplayResult::success; 1198 return ReplayResult::success;
@@ -1192,6 +1217,7 @@ inline ReplayResult prepare_resource_copy(Prepared& p) {
1192 if (!dst.image || !src.image || !same_shape || 1217 if (!dst.image || !src.image || !same_shape ||
1193 dst.depth != src.depth || dst.volume != src.volume || dst.mip_levels != src.mip_levels || 1218 dst.depth != src.depth || dst.volume != src.volume || dst.mip_levels != src.mip_levels ||
1194 dst.array_layers != src.array_layers || dst.aspects != src.aspects || dst.samples != src.samples || 1219 dst.array_layers != src.array_layers || dst.aspects != src.aspects || dst.samples != src.samples ||
1220 dst.rgb96 != src.rgb96 ||
1195 block_format(dst.format, VK_IMAGE_ASPECT_COLOR_BIT).bytes != block_format(src.format, VK_IMAGE_ASPECT_COLOR_BIT).bytes) 1221 block_format(dst.format, VK_IMAGE_ASPECT_COLOR_BIT).bytes != block_format(src.format, VK_IMAGE_ASPECT_COLOR_BIT).bytes)
1196 return ReplayResult::invalid_copy; 1222 return ReplayResult::invalid_copy;
1197 for (const VkImageAspectFlags aspect : {VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_ASPECT_STENCIL_BIT}) { 1223 for (const VkImageAspectFlags aspect : {VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_ASPECT_STENCIL_BIT}) {
@@ -1634,6 +1660,23 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun
1634 job.app_slice_words = job.app_row_words * (region.bufferImageHeight ? region.bufferImageHeight : job.height); 1660 job.app_slice_words = job.app_row_words * (region.bufferImageHeight ? region.bufferImageHeight : job.height);
1635 if (!vk.depth24_prepare || !vk.depth24_run || !vk.depth24_prepare(job, p.depth24_parts)) return ReplayResult::unsupported; 1661 if (!vk.depth24_prepare || !vk.depth24_run || !vk.depth24_prepare(job, p.depth24_parts)) return ReplayResult::unsupported;
1636 p.has_depth24 = true; 1662 p.has_depth24 = true;
1663 } else if (result == ReplayResult::success && image.rgb96 && !p.buffer_image_copies.empty()) {
1664 // A footprint of a 96-bit texture: 12-byte texels, 16 in the image. The same pass and scratch.
1665 const VkBufferImageCopy& region = p.buffer_image_copies[0];
1666 const ResourceBinding& buffer = upload ? p.source : p.binding;
1667 Depth24Job& job = p.depth24;
1668 job.rgb96 = true;
1669 job.to_float = upload;
1670 job.app = buffer.buffer;
1671 job.app_offset = region.bufferOffset;
1672 job.app_size = buffer.size;
1673 job.width = region.imageExtent.width;
1674 job.height = region.imageExtent.height;
1675 job.slices = region.imageExtent.depth;
1676 job.app_row_words = p.rgb96_row_words;
1677 job.app_slice_words = p.rgb96_slice_words;
1678 if (!vk.depth24_prepare || !vk.depth24_run || !vk.depth24_prepare(job, p.depth24_parts)) return ReplayResult::unsupported;
1679 p.has_depth24 = true;
1637 } 1680 }
1638 } else { 1681 } else {
1639 result = detail::prepare_resource_copy(p); 1682 result = detail::prepare_resource_copy(p);