diff options
| author | zneel <14263028+zneel@users.noreply.github.com> | 2026-11-22 10:50:10 +0100 |
|---|---|---|
| committer | zneel <14263028+zneel@users.noreply.github.com> | 2026-11-22 11:26:48 +0100 |
| commit | 983862e2a885a3d7082cf9678e863fdce1bd6f4e (patch) | |
| tree | 57ecd89e512f1d7e3fe5e34b37bfce2d0eff7125 /runtime/src | |
| parent | f85582e23d4ab9e19acbf694358f137d6b8531b1 (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.h | 9 | ||||
| -rw-r--r-- | runtime/src/depth24_convert.comp | 22 | ||||
| -rw-r--r-- | runtime/src/depth24_convert.inc | 318 | ||||
| -rw-r--r-- | runtime/src/vulkan_depth24.h | 32 | ||||
| -rw-r--r-- | runtime/src/vulkan_replay.h | 51 |
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). | ||
| 53 | struct Depth24Job { | 57 | struct 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 | ||
| 12 | layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; | 17 | layout(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 | ||
| 17 | layout(push_constant) uniform Push { | 22 | layout(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) { | |||
| 46 | void main() { | 51 | void 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, |
| 2 | 0x00000000,0x00020011,0x00000001,0x0006000b, | 2 | 0x00000000,0x00020011,0x00000001,0x0006000b, |
| 3 | 0x00000001,0x4c534c47,0x6474732e,0x3035342e, | 3 | 0x00000001,0x4c534c47,0x6474732e,0x3035342e, |
| 4 | 0x00000000,0x0003000e,0x00000000,0x00000001, | 4 | 0x00000000,0x0003000e,0x00000000,0x00000001, |
| @@ -17,17 +17,17 @@ | |||
| 17 | 0x00000014,0x00050048,0x00000051,0x00000006, | 17 | 0x00000014,0x00050048,0x00000051,0x00000006, |
| 18 | 0x00000023,0x00000018,0x00050048,0x00000051, | 18 | 0x00000023,0x00000018,0x00050048,0x00000051, |
| 19 | 0x00000007,0x00000023,0x0000001c,0x00040047, | 19 | 0x00000007,0x00000023,0x0000001c,0x00040047, |
| 20 | 0x0000009f,0x00000006,0x00000004,0x00030047, | 20 | 0x000000a8,0x00000006,0x00000004,0x00030047, |
| 21 | 0x000000a0,0x00000002,0x00050048,0x000000a0, | 21 | 0x000000a9,0x00000002,0x00050048,0x000000a9, |
| 22 | 0x00000000,0x00000023,0x00000000,0x00040047, | 22 | 0x00000000,0x00000023,0x00000000,0x00040047, |
| 23 | 0x000000a2,0x00000021,0x00000001,0x00040047, | 23 | 0x000000ab,0x00000021,0x00000001,0x00040047, |
| 24 | 0x000000a2,0x00000022,0x00000000,0x00040047, | 24 | 0x000000ab,0x00000022,0x00000000,0x00040047, |
| 25 | 0x000000a4,0x00000006,0x00000004,0x00030047, | 25 | 0x000000ad,0x00000006,0x00000004,0x00030047, |
| 26 | 0x000000a5,0x00000002,0x00050048,0x000000a5, | 26 | 0x000000ae,0x00000002,0x00050048,0x000000ae, |
| 27 | 0x00000000,0x00000023,0x00000000,0x00040047, | 27 | 0x00000000,0x00000023,0x00000000,0x00040047, |
| 28 | 0x000000a7,0x00000021,0x00000000,0x00040047, | 28 | 0x000000b0,0x00000021,0x00000000,0x00040047, |
| 29 | 0x000000a7,0x00000022,0x00000000,0x00040047, | 29 | 0x000000b0,0x00000022,0x00000000,0x00040047, |
| 30 | 0x000000ba,0x0000000b,0x00000019,0x00020013, | 30 | 0x00000117,0x0000000b,0x00000019,0x00020013, |
| 31 | 0x00000002,0x00030021,0x00000003,0x00000002, | 31 | 0x00000002,0x00030021,0x00000003,0x00000002, |
| 32 | 0x00040015,0x00000006,0x00000020,0x00000000, | 32 | 0x00040015,0x00000006,0x00000020,0x00000000, |
| 33 | 0x00030016,0x00000008,0x00000020,0x0004002b, | 33 | 0x00030016,0x00000008,0x00000020,0x0004002b, |
| @@ -51,27 +51,30 @@ | |||
| 51 | 0x00000019,0x00000054,0x00000000,0x00040020, | 51 | 0x00000019,0x00000054,0x00000000,0x00040020, |
| 52 | 0x00000055,0x00000009,0x00000006,0x0004002b, | 52 | 0x00000055,0x00000009,0x00000006,0x0004002b, |
| 53 | 0x00000019,0x0000005e,0x00000001,0x0004002b, | 53 | 0x00000019,0x0000005e,0x00000001,0x0004002b, |
| 54 | 0x00000006,0x00000066,0x00000002,0x0004002b, | ||
| 54 | 0x00000019,0x00000069,0x00000002,0x0004002b, | 55 | 0x00000019,0x00000069,0x00000002,0x0004002b, |
| 55 | 0x00000019,0x00000072,0x00000004,0x0004002b, | 56 | 0x00000019,0x00000071,0x00000003,0x0004002b, |
| 56 | 0x00000019,0x00000077,0x00000006,0x0004002b, | 57 | 0x00000019,0x00000078,0x00000004,0x0004002b, |
| 57 | 0x00000019,0x0000007e,0x00000005,0x0004002b, | 58 | 0x00000019,0x0000007d,0x00000006,0x0004002b, |
| 58 | 0x00000019,0x00000087,0x00000007,0x0004002b, | 59 | 0x00000019,0x00000084,0x00000005,0x0004002b, |
| 59 | 0x00000019,0x00000099,0x00000003,0x0003001d, | 60 | 0x00000006,0x0000008b,0x00000003,0x0004002b, |
| 60 | 0x0000009f,0x00000006,0x0003001e,0x000000a0, | 61 | 0x00000019,0x0000008f,0x00000007,0x0004002b, |
| 61 | 0x0000009f,0x00040020,0x000000a1,0x0000000c, | 62 | 0x00000006,0x000000a0,0x00000004,0x0003001d, |
| 62 | 0x000000a0,0x0004003b,0x000000a1,0x000000a2, | 63 | 0x000000a8,0x00000006,0x0003001e,0x000000a9, |
| 63 | 0x0000000c,0x0003001d,0x000000a4,0x00000006, | 64 | 0x000000a8,0x00040020,0x000000aa,0x0000000c, |
| 64 | 0x0003001e,0x000000a5,0x000000a4,0x00040020, | 65 | 0x000000a9,0x0004003b,0x000000aa,0x000000ab, |
| 65 | 0x000000a6,0x0000000c,0x000000a5,0x0004003b, | 66 | 0x0000000c,0x0003001d,0x000000ad,0x00000006, |
| 66 | 0x000000a6,0x000000a7,0x0000000c,0x00040020, | 67 | 0x0003001e,0x000000ae,0x000000ad,0x00040020, |
| 67 | 0x000000a9,0x0000000c,0x00000006,0x0004002b, | 68 | 0x000000af,0x0000000c,0x000000ae,0x0004003b, |
| 68 | 0x00000006,0x000000b9,0x00000008,0x0006002c, | 69 | 0x000000af,0x000000b0,0x0000000c,0x00040020, |
| 69 | 0x00000049,0x000000ba,0x000000b9,0x000000b9, | 70 | 0x000000b2,0x0000000c,0x00000006,0x0004002b, |
| 70 | 0x00000026,0x0004002b,0x00000019,0x00000109, | 71 | 0x00000006,0x00000116,0x00000008,0x0006002c, |
| 72 | 0x00000049,0x00000117,0x00000116,0x00000116, | ||
| 73 | 0x00000026,0x0004002b,0x00000019,0x0000016c, | ||
| 71 | 0x00000050,0x00050036,0x00000002,0x00000004, | 74 | 0x00000050,0x00050036,0x00000002,0x00000004, |
| 72 | 0x00000000,0x00000003,0x000200f8,0x00000005, | 75 | 0x00000000,0x00000003,0x000200f8,0x00000005, |
| 73 | 0x000300f7,0x000000bb,0x00000000,0x000300fb, | 76 | 0x000300f7,0x00000118,0x00000000,0x000300fb, |
| 74 | 0x00000012,0x000000bc,0x000200f8,0x000000bc, | 77 | 0x00000012,0x00000119,0x000200f8,0x00000119, |
| 75 | 0x0004003d,0x00000049,0x0000004e,0x0000004d, | 78 | 0x0004003d,0x00000049,0x0000004e,0x0000004d, |
| 76 | 0x00050051,0x00000006,0x00000050,0x0000004e, | 79 | 0x00050051,0x00000006,0x00000050,0x0000004e, |
| 77 | 0x00000000,0x00050041,0x00000055,0x00000056, | 80 | 0x00000000,0x00050041,0x00000055,0x00000056, |
| @@ -87,7 +90,7 @@ | |||
| 87 | 0x00000060,0x0000005f,0x000500ae,0x00000013, | 90 | 0x00000060,0x0000005f,0x000500ae,0x00000013, |
| 88 | 0x00000061,0x0000005d,0x00000060,0x000200f9, | 91 | 0x00000061,0x0000005d,0x00000060,0x000200f9, |
| 89 | 0x0000005b,0x000200f8,0x0000005b,0x000700f5, | 92 | 0x0000005b,0x000200f8,0x0000005b,0x000700f5, |
| 90 | 0x00000013,0x00000062,0x00000058,0x000000bc, | 93 | 0x00000013,0x00000062,0x00000058,0x00000119, |
| 91 | 0x00000061,0x0000005a,0x000400a8,0x00000013, | 94 | 0x00000061,0x0000005a,0x000400a8,0x00000013, |
| 92 | 0x00000063,0x00000062,0x000300f7,0x00000065, | 95 | 0x00000063,0x00000062,0x000300f7,0x00000065, |
| 93 | 0x00000000,0x000400fa,0x00000063,0x00000064, | 96 | 0x00000000,0x000400fa,0x00000063,0x00000064, |
| @@ -101,93 +104,174 @@ | |||
| 101 | 0x0000006d,0x00000062,0x0000005b,0x0000006c, | 104 | 0x0000006d,0x00000062,0x0000005b,0x0000006c, |
| 102 | 0x00000064,0x000300f7,0x0000006f,0x00000000, | 105 | 0x00000064,0x000300f7,0x0000006f,0x00000000, |
| 103 | 0x000400fa,0x0000006d,0x0000006e,0x0000006f, | 106 | 0x000400fa,0x0000006d,0x0000006e,0x0000006f, |
| 104 | 0x000200f8,0x0000006e,0x000200f9,0x000000bb, | 107 | 0x000200f8,0x0000006e,0x000200f9,0x00000118, |
| 105 | 0x000200f8,0x0000006f,0x00050041,0x00000055, | 108 | 0x000200f8,0x0000006f,0x00050041,0x00000055, |
| 106 | 0x00000073,0x00000053,0x00000072,0x0004003d, | 109 | 0x00000072,0x00000053,0x00000071,0x0004003d, |
| 107 | 0x00000006,0x00000074,0x00000073,0x00050051, | 110 | 0x00000006,0x00000073,0x00000072,0x000500ae, |
| 108 | 0x00000006,0x00000076,0x0000004e,0x00000002, | 111 | 0x00000013,0x00000074,0x00000073,0x00000066, |
| 109 | 0x00050041,0x00000055,0x00000078,0x00000053, | 112 | 0x000300f7,0x00000076,0x00000000,0x000400fa, |
| 110 | 0x00000077,0x0004003d,0x00000006,0x00000079, | 113 | 0x00000074,0x00000075,0x00000076,0x000200f8, |
| 111 | 0x00000078,0x00050084,0x00000006,0x0000007a, | 114 | 0x00000075,0x00050041,0x00000055,0x00000079, |
| 112 | 0x00000076,0x00000079,0x00050080,0x00000006, | 115 | 0x00000053,0x00000078,0x0004003d,0x00000006, |
| 113 | 0x0000007b,0x00000074,0x0000007a,0x00050051, | 116 | 0x0000007a,0x00000079,0x00050051,0x00000006, |
| 114 | 0x00000006,0x0000007d,0x0000004e,0x00000001, | 117 | 0x0000007c,0x0000004e,0x00000002,0x00050041, |
| 115 | 0x00050041,0x00000055,0x0000007f,0x00000053, | 118 | 0x00000055,0x0000007e,0x00000053,0x0000007d, |
| 116 | 0x0000007e,0x0004003d,0x00000006,0x00000080, | 119 | 0x0004003d,0x00000006,0x0000007f,0x0000007e, |
| 117 | 0x0000007f,0x00050084,0x00000006,0x00000081, | 120 | 0x00050084,0x00000006,0x00000080,0x0000007c, |
| 118 | 0x0000007d,0x00000080,0x00050080,0x00000006, | 121 | 0x0000007f,0x00050080,0x00000006,0x00000081, |
| 119 | 0x00000082,0x0000007b,0x00000081,0x00050080, | 122 | 0x0000007a,0x00000080,0x00050051,0x00000006, |
| 120 | 0x00000006,0x00000085,0x00000082,0x00000050, | 123 | 0x00000083,0x0000004e,0x00000001,0x00050041, |
| 121 | 0x00050041,0x00000055,0x00000088,0x00000053, | 124 | 0x00000055,0x00000085,0x00000053,0x00000084, |
| 122 | 0x00000087,0x0004003d,0x00000006,0x00000089, | 125 | 0x0004003d,0x00000006,0x00000086,0x00000085, |
| 123 | 0x00000088,0x00050041,0x00000055,0x0000008c, | 126 | 0x00050084,0x00000006,0x00000087,0x00000083, |
| 127 | 0x00000086,0x00050080,0x00000006,0x00000088, | ||
| 128 | 0x00000081,0x00000087,0x00050084,0x00000006, | ||
| 129 | 0x0000008c,0x00000050,0x0000008b,0x00050080, | ||
| 130 | 0x00000006,0x0000008d,0x00000088,0x0000008c, | ||
| 131 | 0x00050041,0x00000055,0x00000090,0x00000053, | ||
| 132 | 0x0000008f,0x0004003d,0x00000006,0x00000091, | ||
| 133 | 0x00000090,0x00050041,0x00000055,0x00000094, | ||
| 124 | 0x00000053,0x0000005e,0x0004003d,0x00000006, | 134 | 0x00000053,0x0000005e,0x0004003d,0x00000006, |
| 125 | 0x0000008d,0x0000008c,0x00050084,0x00000006, | 135 | 0x00000095,0x00000094,0x00050084,0x00000006, |
| 126 | 0x0000008e,0x00000076,0x0000008d,0x00050080, | 136 | 0x00000096,0x0000007c,0x00000095,0x00050080, |
| 127 | 0x00000006,0x00000091,0x0000008e,0x0000007d, | 137 | 0x00000006,0x00000099,0x00000096,0x00000083, |
| 128 | 0x00050084,0x00000006,0x00000094,0x00000091, | 138 | 0x00050084,0x00000006,0x0000009c,0x00000099, |
| 129 | 0x00000057,0x00050080,0x00000006,0x00000095, | 139 | 0x00000057,0x00050080,0x00000006,0x0000009f, |
| 130 | 0x00000089,0x00000094,0x00050080,0x00000006, | 140 | 0x0000009c,0x00000050,0x00050084,0x00000006, |
| 131 | 0x00000098,0x00000095,0x00000050,0x00050041, | 141 | 0x000000a1,0x0000009f,0x000000a0,0x00050080, |
| 132 | 0x00000055,0x0000009a,0x00000053,0x00000099, | 142 | 0x00000006,0x000000a2,0x00000091,0x000000a1, |
| 133 | 0x0004003d,0x00000006,0x0000009b,0x0000009a, | 143 | 0x000500aa,0x00000013,0x000000a5,0x00000073, |
| 134 | 0x000500ab,0x00000013,0x0000009c,0x0000009b, | 144 | 0x0000008b,0x000300f7,0x000000a7,0x00000000, |
| 135 | 0x00000012,0x000300f7,0x0000009e,0x00000000, | 145 | 0x000400fa,0x000000a5,0x000000a6,0x000000c7, |
| 136 | 0x000400fa,0x0000009c,0x0000009d,0x000000b1, | 146 | 0x000200f8,0x000000a6,0x00060041,0x000000b2, |
| 137 | 0x000200f8,0x0000009d,0x00060041,0x000000a9, | 147 | 0x000000b3,0x000000b0,0x00000054,0x0000008d, |
| 138 | 0x000000aa,0x000000a7,0x00000054,0x00000085, | 148 | 0x0004003d,0x00000006,0x000000b4,0x000000b3, |
| 139 | 0x0004003d,0x00000006,0x000000ab,0x000000aa, | 149 | 0x00060041,0x000000b2,0x000000b5,0x000000ab, |
| 140 | 0x000500c7,0x00000006,0x000000ac,0x000000ab, | 150 | 0x00000054,0x000000a2,0x0003003e,0x000000b5, |
| 141 | 0x0000003f,0x000300f7,0x000000e8,0x00000000, | 151 | 0x000000b4,0x00050080,0x00000006,0x000000b7, |
| 142 | 0x000300fb,0x00000012,0x000000d2,0x000200f8, | 152 | 0x000000a2,0x00000026,0x00050080,0x00000006, |
| 143 | 0x000000d2,0x000500aa,0x00000013,0x000000d4, | 153 | 0x000000b9,0x0000008d,0x00000026,0x00060041, |
| 144 | 0x000000ac,0x00000012,0x000300f7,0x000000d6, | 154 | 0x000000b2,0x000000ba,0x000000b0,0x00000054, |
| 145 | 0x00000000,0x000400fa,0x000000d4,0x000000d5, | 155 | 0x000000b9,0x0004003d,0x00000006,0x000000bb, |
| 146 | 0x000000d6,0x000200f8,0x000000d5,0x000200f9, | 156 | 0x000000ba,0x00060041,0x000000b2,0x000000bc, |
| 147 | 0x000000e8,0x000200f8,0x000000d6,0x0006000c, | 157 | 0x000000ab,0x00000054,0x000000b7,0x0003003e, |
| 148 | 0x00000019,0x000000d8,0x00000001,0x0000004b, | 158 | 0x000000bc,0x000000bb,0x00050080,0x00000006, |
| 149 | 0x000000ac,0x00050082,0x00000019,0x000000db, | 159 | 0x000000be,0x000000a2,0x00000066,0x00050080, |
| 150 | 0x00000020,0x000000d8,0x0004007c,0x00000006, | 160 | 0x00000006,0x000000c0,0x0000008d,0x00000066, |
| 151 | 0x000000dc,0x000000db,0x000500c4,0x00000006, | 161 | 0x00060041,0x000000b2,0x000000c1,0x000000b0, |
| 152 | 0x000000dd,0x000000ac,0x000000dc,0x00050080, | 162 | 0x00000054,0x000000c0,0x0004003d,0x00000006, |
| 153 | 0x00000006,0x000000df,0x000000dd,0x00000026, | 163 | 0x000000c2,0x000000c1,0x00060041,0x000000b2, |
| 154 | 0x00040070,0x00000008,0x000000e0,0x000000df, | 164 | 0x000000c3,0x000000ab,0x00000054,0x000000be, |
| 155 | 0x00050080,0x00000019,0x000000e3,0x000000d8, | 165 | 0x0003003e,0x000000c3,0x000000c2,0x00050080, |
| 156 | 0x00000109,0x0004007c,0x00000006,0x000000e4, | 166 | 0x00000006,0x000000c5,0x000000a2,0x0000008b, |
| 157 | 0x000000e3,0x000500c4,0x00000006,0x000000e5, | 167 | 0x00060041,0x000000b2,0x000000c6,0x000000ab, |
| 158 | 0x000000e4,0x00000020,0x0004007c,0x00000008, | 168 | 0x00000054,0x000000c5,0x0003003e,0x000000c6, |
| 159 | 0x000000e6,0x000000e5,0x00050085,0x00000008, | 169 | 0x00000012,0x000200f9,0x000000a7,0x000200f8, |
| 160 | 0x000000e7,0x000000e0,0x000000e6,0x000200f9, | 170 | 0x000000c7,0x00060041,0x000000b2,0x000000ca, |
| 161 | 0x000000e8,0x000200f8,0x000000e8,0x000700f5, | 171 | 0x000000ab,0x00000054,0x000000a2,0x0004003d, |
| 162 | 0x00000008,0x00000108,0x00000017,0x000000d5, | 172 | 0x00000006,0x000000cb,0x000000ca,0x00060041, |
| 163 | 0x000000e7,0x000000d6,0x0004007c,0x00000006, | 173 | 0x000000b2,0x000000cc,0x000000b0,0x00000054, |
| 164 | 0x000000af,0x00000108,0x00060041,0x000000a9, | 174 | 0x0000008d,0x0003003e,0x000000cc,0x000000cb, |
| 165 | 0x000000b0,0x000000a2,0x00000054,0x00000098, | 175 | 0x00050080,0x00000006,0x000000ce,0x0000008d, |
| 166 | 0x0003003e,0x000000b0,0x000000af,0x000200f9, | 176 | 0x00000026,0x00050080,0x00000006,0x000000d0, |
| 167 | 0x0000009e,0x000200f8,0x000000b1,0x00060041, | 177 | 0x000000a2,0x00000026,0x00060041,0x000000b2, |
| 168 | 0x000000a9,0x000000b5,0x000000a2,0x00000054, | 178 | 0x000000d1,0x000000ab,0x00000054,0x000000d0, |
| 169 | 0x00000098,0x0004003d,0x00000006,0x000000b6, | 179 | 0x0004003d,0x00000006,0x000000d2,0x000000d1, |
| 170 | 0x000000b5,0x000300f7,0x000000fc,0x00000000, | 180 | 0x00060041,0x000000b2,0x000000d3,0x000000b0, |
| 171 | 0x000300fb,0x00000012,0x000000ee,0x000200f8, | 181 | 0x00000054,0x000000ce,0x0003003e,0x000000d3, |
| 172 | 0x000000ee,0x000500ac,0x00000013,0x000000f0, | 182 | 0x000000d2,0x00050080,0x00000006,0x000000d5, |
| 173 | 0x000000b6,0x00000035,0x000300f7,0x000000f2, | 183 | 0x0000008d,0x00000066,0x00050080,0x00000006, |
| 174 | 0x00000000,0x000400fa,0x000000f0,0x000000f1, | 184 | 0x000000d7,0x000000a2,0x00000066,0x00060041, |
| 175 | 0x000000f2,0x000200f8,0x000000f1,0x000200f9, | 185 | 0x000000b2,0x000000d8,0x000000ab,0x00000054, |
| 176 | 0x000000fc,0x000200f8,0x000000f2,0x000500ae, | 186 | 0x000000d7,0x0004003d,0x00000006,0x000000d9, |
| 177 | 0x00000013,0x000000f4,0x000000b6,0x0000003b, | 187 | 0x000000d8,0x00060041,0x000000b2,0x000000da, |
| 178 | 0x000300f7,0x000000f6,0x00000000,0x000400fa, | 188 | 0x000000b0,0x00000054,0x000000d5,0x0003003e, |
| 179 | 0x000000f4,0x000000f5,0x000000f6,0x000200f8, | 189 | 0x000000da,0x000000d9,0x000200f9,0x000000a7, |
| 180 | 0x000000f5,0x000200f9,0x000000fc,0x000200f8, | 190 | 0x000200f8,0x000000a7,0x000200f9,0x00000118, |
| 181 | 0x000000f6,0x0004007c,0x00000008,0x000000f8, | 191 | 0x000200f8,0x00000076,0x00050041,0x00000055, |
| 182 | 0x000000b6,0x00050085,0x00000008,0x000000f9, | 192 | 0x000000dd,0x00000053,0x00000078,0x0004003d, |
| 183 | 0x000000f8,0x00000043,0x0006000c,0x00000008, | 193 | 0x00000006,0x000000de,0x000000dd,0x00050051, |
| 184 | 0x000000fa,0x00000001,0x00000002,0x000000f9, | 194 | 0x00000006,0x000000e0,0x0000004e,0x00000002, |
| 185 | 0x0004006d,0x00000006,0x000000fb,0x000000fa, | 195 | 0x00050041,0x00000055,0x000000e1,0x00000053, |
| 186 | 0x000200f9,0x000000fc,0x000200f8,0x000000fc, | 196 | 0x0000007d,0x0004003d,0x00000006,0x000000e2, |
| 187 | 0x000900f5,0x00000006,0x00000107,0x00000012, | 197 | 0x000000e1,0x00050084,0x00000006,0x000000e3, |
| 188 | 0x000000f1,0x0000003f,0x000000f5,0x000000fb, | 198 | 0x000000e0,0x000000e2,0x00050080,0x00000006, |
| 189 | 0x000000f6,0x00060041,0x000000a9,0x000000b8, | 199 | 0x000000e4,0x000000de,0x000000e3,0x00050051, |
| 190 | 0x000000a7,0x00000054,0x00000085,0x0003003e, | 200 | 0x00000006,0x000000e6,0x0000004e,0x00000001, |
| 191 | 0x000000b8,0x00000107,0x000200f9,0x0000009e, | 201 | 0x00050041,0x00000055,0x000000e7,0x00000053, |
| 192 | 0x000200f8,0x0000009e,0x000200f9,0x000000bb, | 202 | 0x00000084,0x0004003d,0x00000006,0x000000e8, |
| 193 | 0x000200f8,0x000000bb,0x000100fd,0x00010038} | 203 | 0x000000e7,0x00050084,0x00000006,0x000000e9, |
| 204 | 0x000000e6,0x000000e8,0x00050080,0x00000006, | ||
| 205 | 0x000000ea,0x000000e4,0x000000e9,0x00050080, | ||
| 206 | 0x00000006,0x000000ed,0x000000ea,0x00000050, | ||
| 207 | 0x00050041,0x00000055,0x000000ef,0x00000053, | ||
| 208 | 0x0000008f,0x0004003d,0x00000006,0x000000f0, | ||
| 209 | 0x000000ef,0x00050041,0x00000055,0x000000f3, | ||
| 210 | 0x00000053,0x0000005e,0x0004003d,0x00000006, | ||
| 211 | 0x000000f4,0x000000f3,0x00050084,0x00000006, | ||
| 212 | 0x000000f5,0x000000e0,0x000000f4,0x00050080, | ||
| 213 | 0x00000006,0x000000f8,0x000000f5,0x000000e6, | ||
| 214 | 0x00050084,0x00000006,0x000000fb,0x000000f8, | ||
| 215 | 0x00000057,0x00050080,0x00000006,0x000000fc, | ||
| 216 | 0x000000f0,0x000000fb,0x00050080,0x00000006, | ||
| 217 | 0x000000ff,0x000000fc,0x00000050,0x000500ab, | ||
| 218 | 0x00000013,0x00000102,0x00000073,0x00000012, | ||
| 219 | 0x000300f7,0x00000104,0x00000000,0x000400fa, | ||
| 220 | 0x00000102,0x00000103,0x0000010e,0x000200f8, | ||
| 221 | 0x00000103,0x00060041,0x000000b2,0x00000107, | ||
| 222 | 0x000000b0,0x00000054,0x000000ed,0x0004003d, | ||
| 223 | 0x00000006,0x00000108,0x00000107,0x000500c7, | ||
| 224 | 0x00000006,0x00000109,0x00000108,0x0000003f, | ||
| 225 | 0x000300f7,0x00000145,0x00000000,0x000300fb, | ||
| 226 | 0x00000012,0x0000012f,0x000200f8,0x0000012f, | ||
| 227 | 0x000500aa,0x00000013,0x00000131,0x00000109, | ||
| 228 | 0x00000012,0x000300f7,0x00000133,0x00000000, | ||
| 229 | 0x000400fa,0x00000131,0x00000132,0x00000133, | ||
| 230 | 0x000200f8,0x00000132,0x000200f9,0x00000145, | ||
| 231 | 0x000200f8,0x00000133,0x0006000c,0x00000019, | ||
| 232 | 0x00000135,0x00000001,0x0000004b,0x00000109, | ||
| 233 | 0x00050082,0x00000019,0x00000138,0x00000020, | ||
| 234 | 0x00000135,0x0004007c,0x00000006,0x00000139, | ||
| 235 | 0x00000138,0x000500c4,0x00000006,0x0000013a, | ||
| 236 | 0x00000109,0x00000139,0x00050080,0x00000006, | ||
| 237 | 0x0000013c,0x0000013a,0x00000026,0x00040070, | ||
| 238 | 0x00000008,0x0000013d,0x0000013c,0x00050080, | ||
| 239 | 0x00000019,0x00000140,0x00000135,0x0000016c, | ||
| 240 | 0x0004007c,0x00000006,0x00000141,0x00000140, | ||
| 241 | 0x000500c4,0x00000006,0x00000142,0x00000141, | ||
| 242 | 0x00000020,0x0004007c,0x00000008,0x00000143, | ||
| 243 | 0x00000142,0x00050085,0x00000008,0x00000144, | ||
| 244 | 0x0000013d,0x00000143,0x000200f9,0x00000145, | ||
| 245 | 0x000200f8,0x00000145,0x000700f5,0x00000008, | ||
| 246 | 0x0000016b,0x00000017,0x00000132,0x00000144, | ||
| 247 | 0x00000133,0x0004007c,0x00000006,0x0000010c, | ||
| 248 | 0x0000016b,0x00060041,0x000000b2,0x0000010d, | ||
| 249 | 0x000000ab,0x00000054,0x000000ff,0x0003003e, | ||
| 250 | 0x0000010d,0x0000010c,0x000200f9,0x00000104, | ||
| 251 | 0x000200f8,0x0000010e,0x00060041,0x000000b2, | ||
| 252 | 0x00000112,0x000000ab,0x00000054,0x000000ff, | ||
| 253 | 0x0004003d,0x00000006,0x00000113,0x00000112, | ||
| 254 | 0x000300f7,0x00000159,0x00000000,0x000300fb, | ||
| 255 | 0x00000012,0x0000014b,0x000200f8,0x0000014b, | ||
| 256 | 0x000500ac,0x00000013,0x0000014d,0x00000113, | ||
| 257 | 0x00000035,0x000300f7,0x0000014f,0x00000000, | ||
| 258 | 0x000400fa,0x0000014d,0x0000014e,0x0000014f, | ||
| 259 | 0x000200f8,0x0000014e,0x000200f9,0x00000159, | ||
| 260 | 0x000200f8,0x0000014f,0x000500ae,0x00000013, | ||
| 261 | 0x00000151,0x00000113,0x0000003b,0x000300f7, | ||
| 262 | 0x00000153,0x00000000,0x000400fa,0x00000151, | ||
| 263 | 0x00000152,0x00000153,0x000200f8,0x00000152, | ||
| 264 | 0x000200f9,0x00000159,0x000200f8,0x00000153, | ||
| 265 | 0x0004007c,0x00000008,0x00000155,0x00000113, | ||
| 266 | 0x00050085,0x00000008,0x00000156,0x00000155, | ||
| 267 | 0x00000043,0x0006000c,0x00000008,0x00000157, | ||
| 268 | 0x00000001,0x00000002,0x00000156,0x0004006d, | ||
| 269 | 0x00000006,0x00000158,0x00000157,0x000200f9, | ||
| 270 | 0x00000159,0x000200f8,0x00000159,0x000900f5, | ||
| 271 | 0x00000006,0x0000016a,0x00000012,0x0000014e, | ||
| 272 | 0x0000003f,0x00000152,0x00000158,0x00000153, | ||
| 273 | 0x00060041,0x000000b2,0x00000115,0x000000b0, | ||
| 274 | 0x00000054,0x000000ed,0x0003003e,0x00000115, | ||
| 275 | 0x0000016a,0x000200f9,0x00000104,0x000200f8, | ||
| 276 | 0x00000104,0x000200f9,0x00000118,0x000200f8, | ||
| 277 | 0x00000118,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. | ||
| 465 | inline constexpr std::uint32_t rgb96_bytes = 12; | ||
| 466 | inline 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 | |||
| 461 | inline bool two_planes(const ResourceBinding& resource) { | 472 | inline 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); |