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/vulkan_depth24.h | |
| 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/vulkan_depth24.h')
| -rw-r--r-- | runtime/src/vulkan_depth24.h | 32 |
1 files changed, 20 insertions, 12 deletions
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; |