diff options
Diffstat (limited to 'runtime/src/vulkan_bindless.h')
| -rw-r--r-- | runtime/src/vulkan_bindless.h | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/runtime/src/vulkan_bindless.h b/runtime/src/vulkan_bindless.h index da6d680f0..fc1b2f555 100644 --- a/runtime/src/vulkan_bindless.h +++ b/runtime/src/vulkan_bindless.h | |||
| @@ -239,14 +239,15 @@ struct SetLayout { | |||
| 239 | SetLayout& operator=(const SetLayout&) = delete; | 239 | SetLayout& operator=(const SetLayout&) = delete; |
| 240 | }; | 240 | }; |
| 241 | 241 | ||
| 242 | // What size_bindings() grows to where the device's limits allow. At 32-64 bytes a descriptor the whole set is then | 242 | // What size_bindings() grows the sampled array of every single-sample dimension (2D, 2D array, 3D and 1D) to where |
| 243 | // 5-10 MiB with 153697 descriptors when all MS classes and array bindings reach their limits (an RTX 5070). | 243 | // the device's limits allow: one size for all of them. Which dimensions its textures have is the title's choice, and |
| 244 | inline constexpr std::uint32_t max_2d_images = 65536; | 244 | // an image keeps its index (one for each distinct T# of it) for as long as the texture lives, so no dimension gets |
| 245 | // The other single-sample dimensions: a title streams far more cube maps and texture arrays (and 1D lookup | 245 | // less room than another: a world run kept 4090 live 1D textures, the whole of the 4096 1D indices the set once |
| 246 | // textures) than the 1024 and 256 of the defaults, each distinct T# of one taking its own index. | 246 | // stopped at, while the 2D arrays had room to spare. The bound is the set's memory, not the device's descriptor |
| 247 | inline constexpr std::uint32_t max_2d_array_images = 16384; | 247 | // limits (8388606 sampled images on RADV): every element of every array is in each generation's descriptor pool, |
| 248 | inline constexpr std::uint32_t max_3d_images = 4096; | 248 | // used or not. At 32-64 bytes a descriptor the whole set is 10-20 MiB with 325729 descriptors when all MS classes |
| 249 | inline constexpr std::uint32_t max_1d_images = 4096; | 249 | // and arrays reach their limits (an RTX 5070). |
| 250 | inline constexpr std::uint32_t max_images = 65536; | ||
| 250 | inline constexpr std::uint32_t max_storage_indices = 4096; // in each storage array, at most its dimension's images | 251 | inline constexpr std::uint32_t max_storage_indices = 4096; // in each storage array, at most its dimension's images |
| 251 | // A full D3D12 shader-visible sampler heap (2048) and room for literal and static S#s, within what the device can | 252 | // A full D3D12 shader-visible sampler heap (2048) and room for literal and static S#s, within what the device can |
| 252 | // create (maxSamplerAllocationCount, at least 4000) less the samplers that are not in the set. | 253 | // create (maxSamplerAllocationCount, at least 4000) less the samplers that are not in the set. |
| @@ -261,7 +262,8 @@ inline constexpr std::uint32_t growth_headroom = 64; | |||
| 261 | // standalone samplers do not, though they count in an update-after-bind pool. | 262 | // standalone samplers do not, though they count in an update-after-bind pool. |
| 262 | // 1. The default counts, or as much of them as the device holds: samplers, then storage, then 2D images. | 263 | // 1. The default counts, or as much of them as the device holds: samplers, then storage, then 2D images. |
| 263 | // 2. The MS pairs that fit beside them (limit_ms_bindings, which may turn classes off). | 264 | // 2. The MS pairs that fit beside them (limit_ms_bindings, which may turn classes off). |
| 264 | // 3. Growth towards the maximums above, in the same order, then the 2D-array, 3D and 1D images, within | 265 | // 3. Growth towards the maximums above, in the same order, then the 2D-array, 3D and 1D images together (one |
| 266 | // count for the three, so a device whose limits stop growth short of max_images favours none of them), within | ||
| 265 | // maxPerSetDescriptors. That limit only says what is sure to work (vkGetDescriptorSetLayoutSupport may allow | 267 | // maxPerSetDescriptors. That limit only says what is sure to work (vkGetDescriptorSetLayoutSupport may allow |
| 266 | // more), so it never shrinks step 1. | 268 | // more), so it never shrinks step 1. |
| 267 | // A storage array holds the smaller of the storage count and its dimension's sampled count: add_image never | 269 | // A storage array holds the smaller of the storage count and its dimension's sampled count: add_image never |
| @@ -363,11 +365,23 @@ inline bool size_bindings(BindlessFeatures& features, const VkPhysicalDeviceLimi | |||
| 363 | const std::uint32_t creatable = | 365 | const std::uint32_t creatable = |
| 364 | limits.maxSamplerAllocationCount - std::min(limits.maxSamplerAllocationCount, reserved_samplers); | 366 | limits.maxSamplerAllocationCount - std::min(limits.maxSamplerAllocationCount, reserved_samplers); |
| 365 | grow(samplers, std::max(samplers, std::min(max_samplers, creatable)), growth_headroom, set_limit); | 367 | grow(samplers, std::max(samplers, std::min(max_samplers, creatable)), growth_headroom, set_limit); |
| 366 | grow(images, std::max(images, max_2d_images), growth_headroom, set_limit); | 368 | grow(images, std::max(images, max_images), growth_headroom, set_limit); |
| 367 | grow(storage, std::max(storage, max_storage_indices), growth_headroom, set_limit); | 369 | grow(storage, std::max(storage, max_storage_indices), growth_headroom, set_limit); |
| 368 | grow(arrays, std::max(arrays, max_2d_array_images), growth_headroom, set_limit); | 370 | // The other three dimensions grow as one: each gets the larger of its count so far and the shared one. |
| 369 | grow(volumes, std::max(volumes, max_3d_images), growth_headroom, set_limit); | 371 | const std::uint32_t arrays_before = arrays, volumes_before = volumes, lines_before = lines; |
| 370 | grow(lines, std::max(lines, max_1d_images), growth_headroom, set_limit); | 372 | std::uint32_t together = 0; |
| 373 | const auto set_together = [&](std::uint32_t n) { | ||
| 374 | arrays = std::max(arrays_before, n); | ||
| 375 | volumes = std::max(volumes_before, n); | ||
| 376 | lines = std::max(lines_before, n); | ||
| 377 | }; | ||
| 378 | for (std::uint32_t high = max_images; together < high;) { | ||
| 379 | const std::uint32_t n = together + (high - together + 1) / 2; | ||
| 380 | set_together(n); | ||
| 381 | if (fits(growth_headroom, set_limit)) together = n; | ||
| 382 | else high = n - 1; | ||
| 383 | } | ||
| 384 | set_together(together); | ||
| 371 | apply(true); | 385 | apply(true); |
| 372 | return full; | 386 | return full; |
| 373 | } | 387 | } |
| @@ -484,7 +498,7 @@ public: | |||
| 484 | StorageViews storage{}; | 498 | StorageViews storage{}; |
| 485 | }; | 499 | }; |
| 486 | 500 | ||
| 487 | // Gives an image an index in its dimension's bindings: 0 when the dimension is full. `sampled` goes to the | 501 | // Gives an image an index in its dimension's bindings: 0 when the dimension is full (image_refusal says why). `sampled` goes to the |
| 488 | // sampled array in `sampled_layout` (the layout the image is in when shaders read it); the storage views go to | 502 | // sampled array in `sampled_layout` (the layout the image is in when shaders read it); the storage views go to |
| 489 | // the storage arrays in GENERAL. For MS views, sampled_class selects the float, uint or sint sampled array. | 503 | // the storage arrays in GENERAL. For MS views, sampled_class selects the float, uint or sint sampled array. |
| 490 | // `mirror` adds the same index in the 2D arrays (a 2D-array or cube image's slice 0): the slot must then be free | 504 | // `mirror` adds the same index in the 2D arrays (a 2D-array or cube image's slice 0): the slot must then be free |
| @@ -553,6 +567,23 @@ public: | |||
| 553 | return index; | 567 | return index; |
| 554 | } | 568 | } |
| 555 | 569 | ||
| 570 | // Why add_image returned 0 for an image of `dimension` (with storage views when `stores`; sampled_class for the | ||
| 571 | // MS dimensions): the set has no array for it; every index of its dimension is taken (array_full: in use, or | ||
| 572 | // removed and held until the next flush that brings the table up to date); or only the storage arrays' shorter | ||
| 573 | // range is, which an image with storage views needs an index in (storage_full). | ||
| 574 | enum class ImageRefusal { no_array, array_full, storage_full }; | ||
| 575 | ImageRefusal image_refusal(ImageDimension dimension, bool stores, std::uint32_t sampled_class = 0) const { | ||
| 576 | if (!stores && bindless::sampled_binding(dimension) == bindless::no_binding) return ImageRefusal::no_array; | ||
| 577 | if (bindless::multisampled(dimension) && (stores || !supports_ms_class(sampled_class))) | ||
| 578 | return ImageRefusal::no_array; | ||
| 579 | const auto& used = image_used_[std::uint32_t(dimension)]; | ||
| 580 | const std::size_t low_end = std::min<std::size_t>(used.size(), storage_capacity(dimension)); | ||
| 581 | const auto storage_end = used.begin() + std::ptrdiff_t(low_end); | ||
| 582 | const bool storage_free = low_end > 1 && std::find(used.begin() + 1, storage_end, std::uint8_t(0)) != storage_end; | ||
| 583 | return stores && !storage_free && free_images(dimension) ? ImageRefusal::storage_full | ||
| 584 | : ImageRefusal::array_full; | ||
| 585 | } | ||
| 586 | |||
| 556 | // New views or a new layout for an index add_image returned (a texture's state changed, say). `mirror` is | 587 | // New views or a new layout for an index add_image returned (a texture's state changed, say). `mirror` is |
| 557 | // refreshed too when the image was added with one (mirror_of says whose 2D slot it is). The slot bookkeeping | 588 | // refreshed too when the image was added with one (mirror_of says whose 2D slot it is). The slot bookkeeping |
| 558 | // follows what was written, and `kind_out`, when given, receives the index's kind word afterwards for a | 589 | // follows what was written, and `kind_out`, when given, receives the index's kind word afterwards for a |