diff options
| author | totonii <totonicontato@gmail.com> | 2026-11-22 08:33:44 -0300 |
|---|---|---|
| committer | totonii <totonicontato@gmail.com> | 2026-11-22 08:33:44 -0300 |
| commit | 05e2e39db96234459ab8f74cc5e364f7ba01adeb (patch) | |
| tree | 60ddae38ef0a7e74819869bf661a04a7f450561e /runtime/src/vulkan_bindless.h | |
| parent | c2967a5e60060e4068fb992196d8f4b494a5046c (diff) | |
perf(vulkan): zero-copy DescriptorTable staging upload and uint32 wrap guard in read_slots
Diffstat (limited to 'runtime/src/vulkan_bindless.h')
| -rw-r--r-- | runtime/src/vulkan_bindless.h | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/runtime/src/vulkan_bindless.h b/runtime/src/vulkan_bindless.h index 3bf07fa5d..c599eb7c2 100644 --- a/runtime/src/vulkan_bindless.h +++ b/runtime/src/vulkan_bindless.h | |||
| @@ -724,7 +724,7 @@ private: | |||
| 724 | full = true; | 724 | full = true; |
| 725 | grew = true; | 725 | grew = true; |
| 726 | } | 726 | } |
| 727 | const DescriptorTable::Changes changes = table_.take_changes(); | 727 | DescriptorTable::Changes changes = table_.take_changes(); |
| 728 | full = full || changes.all; | 728 | full = full || changes.all; |
| 729 | bool recorded = false; | 729 | bool recorded = false; |
| 730 | // The staging buffer is written only for buffers that were just created (first upload or growth): a later | 730 | // The staging buffer is written only for buffers that were just created (first upload or growth): a later |
| @@ -732,11 +732,11 @@ private: | |||
| 732 | // flight can be reading bytes the CPU rewrites. | 732 | // flight can be reading bytes the CPU rewrites. |
| 733 | const bool fresh = grew || !table_uploaded_; | 733 | const bool fresh = grew || !table_uploaded_; |
| 734 | const auto upload_all = [&]() { | 734 | const auto upload_all = [&]() { |
| 735 | const std::vector<std::uint32_t> words = table_.build_gpu_buffer(); | ||
| 736 | if (fresh) { | 735 | if (fresh) { |
| 737 | std::memcpy(table_buffers_.staging.mapped, words.data(), bytes); | 736 | table_.write_to_buffer(table_buffers_.staging.mapped); |
| 738 | copy_table_range(command_buffer, 0, bytes); | 737 | copy_table_range(command_buffer, 0, bytes); |
| 739 | } else { | 738 | } else { |
| 739 | const std::vector<std::uint32_t> words = table_.build_gpu_buffer(); | ||
| 740 | update_table_range(command_buffer, 0, words.data(), bytes); | 740 | update_table_range(command_buffer, 0, words.data(), bytes); |
| 741 | } | 741 | } |
| 742 | recorded = true; | 742 | recorded = true; |
| @@ -744,15 +744,16 @@ private: | |||
| 744 | if (full) { | 744 | if (full) { |
| 745 | upload_all(); | 745 | upload_all(); |
| 746 | } else if (!changes.slots.empty()) { | 746 | } else if (!changes.slots.empty()) { |
| 747 | std::vector<std::uint32_t> slots = changes.slots; | 747 | std::vector<std::uint32_t> slots = std::move(changes.slots); |
| 748 | std::sort(slots.begin(), slots.end()); | 748 | std::sort(slots.begin(), slots.end()); |
| 749 | slots.erase(std::unique(slots.begin(), slots.end()), slots.end()); | 749 | slots.erase(std::unique(slots.begin(), slots.end()), slots.end()); |
| 750 | std::vector<std::uint32_t> words; | ||
| 750 | bool staged = true; | 751 | bool staged = true; |
| 751 | for (std::size_t first = 0; staged && first < slots.size();) { | 752 | for (std::size_t first = 0; staged && first < slots.size();) { |
| 752 | std::size_t last = first; | 753 | std::size_t last = first; |
| 753 | while (last + 1 < slots.size() && slots[last + 1] == slots[last] + 1) ++last; | 754 | while (last + 1 < slots.size() && slots[last + 1] == slots[last] + 1) ++last; |
| 754 | const std::uint32_t count = std::uint32_t(last - first + 1); | 755 | const std::uint32_t count = std::uint32_t(last - first + 1); |
| 755 | std::vector<std::uint32_t> words(std::size_t(count) * 10); | 756 | words.resize(std::size_t(count) * 10); |
| 756 | staged = table_.read_slots(slots[first], count, words.data()); | 757 | staged = table_.read_slots(slots[first], count, words.data()); |
| 757 | if (staged) { | 758 | if (staged) { |
| 758 | update_table_range(command_buffer, entry_offset(slots[first]), words.data(), | 759 | update_table_range(command_buffer, entry_offset(slots[first]), words.data(), |