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:
authoraslan2142 <jan.trencansky@protonmail.com>2026-11-25 20:29:08 +0100
committerGitHub <noreply@github.com>2026-11-25 20:29:08 +0100
commitcee965560c09255fc5294e1a78734f4ed5a9fb84 (patch)
treeee4fb5b6c48799a464d17df1191de169807b8bb8 /runtime/src
parent75a41f5dc213a6b1b0e65483140a93f013871277 (diff)
parent926e9d3ef34649d2b39375fd12657d1f700aa779 (diff)
Merge pull request #1814 from timbot103/d3d-clear-uav-3d-slice
D3D-CLEAR-UAV-3D-SLICE: clear selected 3D UAV slices and rectangles
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/command_list.h4
-rw-r--r--runtime/src/gfx10_descriptors.h19
-rw-r--r--runtime/src/vulkan_replay.h71
3 files changed, 72 insertions, 22 deletions
diff --git a/runtime/src/command_list.h b/runtime/src/command_list.h
index 3d7ed093b..b68b413fc 100644
--- a/runtime/src/command_list.h
+++ b/runtime/src/command_list.h
@@ -545,8 +545,8 @@ struct UavView {
545 std::uint64_t size; // buffer: bytes in the view 545 std::uint64_t size; // buffer: bytes in the view
546 std::uint32_t element_size; // buffer: bytes an element (rects count elements), 4 for a raw view 546 std::uint32_t element_size; // buffer: bytes an element (rects count elements), 4 for a raw view
547 std::uint32_t mip; // texture 547 std::uint32_t mip; // texture
548 std::uint32_t first_layer; 548 std::uint32_t first_layer; // 1D/2D array: first slice; 3D volume: FirstWSlice
549 std::uint32_t layer_count; 549 std::uint32_t layer_count; // 1D/2D array: slice count; 3D volume: WSize
550 bool exact_clear_format = false; // newly exposed 1D/3D UAVs: do not clear via a different backing format 550 bool exact_clear_format = false; // newly exposed 1D/3D UAVs: do not clear via a different backing format
551}; 551};
552 552
diff --git a/runtime/src/gfx10_descriptors.h b/runtime/src/gfx10_descriptors.h
index 9dad4ed7a..219e0a8c5 100644
--- a/runtime/src/gfx10_descriptors.h
+++ b/runtime/src/gfx10_descriptors.h
@@ -159,11 +159,24 @@ inline constexpr std::uint32_t packed_uav_flag = 0x00400000;
159inline constexpr std::uint32_t volume_uav_word(std::uint32_t offset, std::uint32_t count) { 159inline constexpr std::uint32_t volume_uav_word(std::uint32_t offset, std::uint32_t count) {
160 return volume_uav_tag | ((count - 1) << 11) | offset; 160 return volume_uav_tag | ((count - 1) << 11) | offset;
161} 161}
162struct VolumeUavRange {
163 std::uint32_t first_w = 0;
164 std::uint32_t w_size = 0;
165};
166// The tag stores the first W slice and the slice count minus one. Bit 22 is independent packed-format metadata.
167inline constexpr bool volume_uav_range(const ImageWords& words, const Image& image, VolumeUavRange& out) {
168 if (image.type != ImageType::image_3d || !(words[4] & volume_uav_flag) ||
169 (words[7] & volume_uav_tag_mask) != volume_uav_tag)
170 return false;
171 out.first_w = words[7] & 0x7ffu;
172 out.w_size = ((words[7] >> 11) & 0x7ffu) + 1u;
173 return true;
174}
162inline constexpr bool partial_volume_uav(const ImageWords& words, const Image& image) { 175inline constexpr bool partial_volume_uav(const ImageWords& words, const Image& image) {
176 VolumeUavRange range{};
177 if (!volume_uav_range(words, image, range)) return false;
163 const auto mip_depth = image.depth >> image.first_mip; 178 const auto mip_depth = image.depth >> image.first_mip;
164 return image.type == ImageType::image_3d && (words[4] & volume_uav_flag) && 179 return range.first_w != 0 || range.w_size != (mip_depth ? mip_depth : 1u);
165 (words[7] & volume_uav_tag_mask) == volume_uav_tag &&
166 (words[7] & ~packed_uav_flag) != volume_uav_word(0, mip_depth ? mip_depth : 1u);
167} 180}
168 181
169inline constexpr float image_min_lod(const ImageWords& words) { 182inline constexpr float image_min_lod(const ImageWords& words) {
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h
index 19c4274f6..5a3e569dd 100644
--- a/runtime/src/vulkan_replay.h
+++ b/runtime/src/vulkan_replay.h
@@ -1327,7 +1327,7 @@ struct Prepared {
1327 // A depth <-> colour copy: the source into `staged` (image to buffer), then `staged` into the destination. 1327 // A depth <-> colour copy: the source into `staged` (image to buffer), then `staged` into the destination.
1328 VkBuffer staged = VK_NULL_HANDLE; 1328 VkBuffer staged = VK_NULL_HANDLE;
1329 std::vector<VkBufferImageCopy> staged_reads, staged_writes; 1329 std::vector<VkBufferImageCopy> staged_reads, staged_writes;
1330 VkDeviceSize clear_pattern_bytes = 0; // rectangular UAV clear on a compute-only queue 1330 VkDeviceSize clear_pattern_bytes = 0; // staged transfer UAV clear (compute-only rects or sliced/rect 3D)
1331 std::vector<VkImageSubresourceRange> discards; // DiscardResource: the subresources to discard 1331 std::vector<VkImageSubresourceRange> discards; // DiscardResource: the subresources to discard
1332 VkBuffer write_buffer = VK_NULL_HANDLE; // WriteBufferImmediate: where the address lands 1332 VkBuffer write_buffer = VK_NULL_HANDLE; // WriteBufferImmediate: where the address lands
1333 VkDeviceSize write_offset = 0; 1333 VkDeviceSize write_offset = 0;
@@ -1612,6 +1612,13 @@ inline VkExtent2D mip_extent(const ResourceBinding& resource, std::uint32_t mip)
1612 return {std::max(1u, resource.width >> mip), std::max(1u, resource.height >> mip)}; 1612 return {std::max(1u, resource.width >> mip), std::max(1u, resource.height >> mip)};
1613} 1613}
1614 1614
1615// Nonempty, clipped rectangle. The entire constant pattern fits in one vkCmdUpdateBuffer for wide texels.
1616inline VkExtent2D volume_clear_tile(VkExtent2D rect, std::uint32_t texel_bytes) {
1617 const std::uint32_t max_texels = 65536 / texel_bytes;
1618 const auto width = std::min(rect.width, max_texels);
1619 return {width, std::min(rect.height, max_texels / width)};
1620}
1621
1615// Into `out`, replacing what it held: a kept PreparedList entry reuses the vector's storage. 1622// Into `out`, replacing what it held: a kept PreparedList entry reuses the vector's storage.
1616inline void clip(std::span<const Rect> rects, VkExtent2D extent, std::uint32_t layers, std::vector<VkClearRect>& out) { 1623inline void clip(std::span<const Rect> rects, VkExtent2D extent, std::uint32_t layers, std::vector<VkClearRect>& out) {
1617 out.clear(); 1624 out.clear();
@@ -3484,36 +3491,46 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun
3484 : view_format != VK_FORMAT_E5B9G9R9_UFLOAT_PACK32; 3491 : view_format != VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
3485 const bool reinterpret = view_format != p.binding.format && attachment && view_attachable && !packed_rgb9e5; 3492 const bool reinterpret = view_format != p.binding.format && attachment && view_attachable && !packed_rgb9e5;
3486 if (view.exact_clear_format && view_format != p.binding.format && !packed_rgb9e5) 3493 if (view.exact_clear_format && view_format != p.binding.format && !packed_rgb9e5)
3487 return ReplayResult::unsupported; 3494 return unsupported_at(__LINE__);
3488 const VkFormat clear_format = reinterpret ? view_format : p.binding.format; 3495 const VkFormat clear_format = reinterpret ? view_format : p.binding.format;
3489 if (!uav_clear::decode(clear_format, p.element, p.clear_color)) 3496 if (!uav_clear::decode(clear_format, p.element, p.clear_color))
3490 return unsupported_at(__LINE__); 3497 return unsupported_at(__LINE__);
3491 if (reinterpret) p.clear_format = view_format; 3498 if (reinterpret) p.clear_format = view_format;
3492 // Compute list barriers have no attachment stages, and a dedicated compute queue cannot render. 3499 // A 3D transfer clear covers a whole mip and a compute-only queue cannot render rectangles.
3493 // Copy the encoded texel bits from a filled buffer. Transfers cannot implement a predicated clear. 3500 // Copy the encoded texel bits instead. These copies cannot implement a predicated clear.
3494 if ((vk.queue_stages & VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT) && 3501 const bool sliced = p.binding.volume && view.layer_count != std::max(1u, p.binding.depth >> view.mip);
3495 (!uav->rects.empty() || reinterpret || predicated)) { 3502 const bool stage_volume = p.binding.volume && (sliced || !uav->rects.empty());
3496 if (predicated || p.binding.volume || !vk.copy_scratch || !vk.fill_buffer || !vk.copy_buffer_to_image || 3503 const bool stage_compute = (vk.queue_stages & VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT) &&
3497 (p.element.size != 1 && p.element.size != 2 && p.element.size != 4)) 3504 (!uav->rects.empty() || reinterpret || predicated);
3498 return ReplayResult::unsupported; 3505 if (stage_volume || stage_compute) {
3506 if (predicated) return unsupported_at(__LINE__);
3507 if (stage_volume && view_format != p.binding.format && !packed_rgb9e5)
3508 return unsupported_at(__LINE__);
3509 if (!vk.copy_scratch || !vk.copy_buffer_to_image ||
3510 (p.element.size <= 4 ? !vk.fill_buffer : (!stage_volume || !vk.update_buffer)))
3511 return unsupported_at(__LINE__);
3499 const auto rects = uav->rects.empty() ? std::span<const Rect>(&whole_view, 1) : 3512 const auto rects = uav->rects.empty() ? std::span<const Rect>(&whole_view, 1) :
3500 std::span<const Rect>(uav->rects); 3513 std::span<const Rect>(uav->rects);
3501 detail::clip(rects, detail::mip_extent(p.binding, view.mip), view.layer_count, p.rects); 3514 detail::clip(rects, detail::mip_extent(p.binding, view.mip), p.range.layerCount, p.rects);
3502 if (p.rects.empty()) { p.skip = true; continue; } 3515 if (p.rects.empty()) { p.skip = true; continue; }
3503 for (const auto& rect : p.rects) { 3516 for (const auto& rect : p.rects) {
3504 VkBufferImageCopy region{}; 3517 VkBufferImageCopy region{};
3505 region.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, view.mip, view.first_layer, view.layer_count}; 3518 region.imageSubresource = {p.range.aspectMask, view.mip, p.range.baseArrayLayer, p.range.layerCount};
3506 region.imageOffset = {rect.rect.offset.x, rect.rect.offset.y, 0}; 3519 region.imageOffset = {rect.rect.offset.x, rect.rect.offset.y, 0};
3507 region.imageExtent = {rect.rect.extent.width, rect.rect.extent.height, 1}; 3520 region.imageExtent = {rect.rect.extent.width, rect.rect.extent.height, 1};
3508 const VkDeviceSize pixels = VkDeviceSize(region.imageExtent.width) * region.imageExtent.height; 3521 const auto tile = stage_volume ? detail::volume_clear_tile(rect.rect.extent, p.element.size)
3509 const VkDeviceSize stride = VkDeviceSize(view.layer_count) * p.element.size; 3522 : rect.rect.extent;
3510 if (pixels > (UINT64_MAX - 3) / stride) return ReplayResult::unsupported; 3523 const VkDeviceSize pixels = VkDeviceSize(tile.width) * tile.height;
3524 const VkDeviceSize stride = VkDeviceSize(p.range.layerCount) * p.element.size;
3525 if (pixels > (UINT64_MAX - 3) / stride) return unsupported_at(__LINE__);
3526 // Pad only the private pattern for vkCmdFillBuffer; copies use the exact image extent.
3511 p.clear_pattern_bytes = std::max(p.clear_pattern_bytes, (pixels * stride + 3) & ~VkDeviceSize(3)); 3527 p.clear_pattern_bytes = std::max(p.clear_pattern_bytes, (pixels * stride + 3) & ~VkDeviceSize(3));
3512 p.staged_writes.push_back(region); 3528 p.staged_writes.push_back(region);
3513 } 3529 }
3514 VkDeviceSize offset = 0; 3530 VkDeviceSize offset = 0;
3515 if (!vk.copy_scratch(p.clear_pattern_bytes, p.staged, offset) || !p.staged || offset % 4) 3531 if (!vk.copy_scratch(p.clear_pattern_bytes, p.staged, offset) || !p.staged ||
3516 return ReplayResult::unsupported; 3532 offset % std::max(4u, p.element.size) || offset > UINT64_MAX - p.clear_pattern_bytes)
3533 return unsupported_at(__LINE__);
3517 for (auto& region : p.staged_writes) region.bufferOffset = offset; 3534 for (auto& region : p.staged_writes) region.bufferOffset = offset;
3518 continue; 3535 continue;
3519 } 3536 }
@@ -4646,7 +4663,27 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_
4646 detail::memory_barrier(vk, command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 4663 detail::memory_barrier(vk, command_buffer, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
4647 VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, 4664 VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT,
4648 VK_PIPELINE_STAGE_TRANSFER_BIT); 4665 VK_PIPELINE_STAGE_TRANSFER_BIT);
4649 vk.copy_buffer_to_image(command_buffer, p.staged, p.binding.image, layout, 1, &region); 4666 if (!p.binding.volume) {
4667 vk.copy_buffer_to_image(command_buffer, p.staged, p.binding.image, layout, 1, &region);
4668 continue;
4669 }
4670 // Tiles within this rectangle are disjoint. Reuse the same scratch texels for every
4671 // tile and W slice; keep only one region per clipped rectangle in the prepared list.
4672 const auto tile = detail::volume_clear_tile({region.imageExtent.width, region.imageExtent.height},
4673 p.element.size);
4674 auto piece = region;
4675 for (std::uint32_t z = 0; z < uav->view.layer_count; ++z) {
4676 piece.imageOffset.z = std::int32_t(uav->view.first_layer + z);
4677 for (std::uint32_t y = 0; y < region.imageExtent.height; y += tile.height) {
4678 piece.imageOffset.y = region.imageOffset.y + std::int32_t(y);
4679 piece.imageExtent.height = std::min(tile.height, region.imageExtent.height - y);
4680 for (std::uint32_t x = 0; x < region.imageExtent.width; x += tile.width) {
4681 piece.imageOffset.x = region.imageOffset.x + std::int32_t(x);
4682 piece.imageExtent.width = std::min(tile.width, region.imageExtent.width - x);
4683 vk.copy_buffer_to_image(command_buffer, p.staged, p.binding.image, layout, 1, &piece);
4684 }
4685 }
4686 }
4650 } 4687 }
4651 }); 4688 });
4652 continue; 4689 continue;