upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 09:15:21 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 09:15:21 -0500
commit959505bae178dd4c2b967c8ae1002f59ea555e8e (patch)
tree429a87e10af1a507c504deb526f89ec48867d7b8 /runtime
parent625a4f72f4a8ac52660b17edefb6f478d6e016ff (diff)
parente2ec3a84489cb796fa843fc94b6e40a9d3288431 (diff)
Merge pull request #1787 from CowDeV
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/d3d12_vulkan_device.cpp32
-rw-r--r--runtime/src/vulkan_bindless.h64
-rw-r--r--runtime/test/bindless_sizing_test.cpp31
3 files changed, 104 insertions, 23 deletions
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp
index 5c5781450..590cab096 100644
--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -381,6 +381,12 @@ struct DeviceState {
381 // True when VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 lacks native STORAGE_IMAGE but mutable R32_UINT+{R32_UINT,E5B9G9R9} 381 // True when VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 lacks native STORAGE_IMAGE but mutable R32_UINT+{R32_UINT,E5B9G9R9}
382 // is supported, so R9G9B9E5_SHAREDEXP UAV textures are backed by R32_UINT with separate storage/sampled views. 382 // is supported, so R9G9B9E5_SHAREDEXP UAV textures are backed by R32_UINT with separate storage/sampled views.
383 bool r9g9b9e5_uav_emulated = false; 383 bool r9g9b9e5_uav_emulated = false;
384 // D3D-219: VK_EXT_image_view_min_lod may select levels with minLodInteger = floor(minLod), the spec's
385 // "alternative", while D3D12's ResourceMinLODClamp is fractional. Intel's integrated GPUs on Windows do: a 0.75
386 // clamp sampled at LOD 0 with point mip filtering reads mip 0 (UHD 770 101.7092, Arrow Lake Xe-LPG; #1015).
387 // bind_image gives such a driver the clamp rounded to the nearest level, which point mip filtering selects
388 // exactly. LEONIDA_MIN_LOD_INTEGER=1 or 0 forces it either way.
389 bool min_lod_integer = false;
384 390
385 // Cached physical-device no-attachment sample counts for D3D12_OPTIONS19. 391 // Cached physical-device no-attachment sample counts for D3D12_OPTIONS19.
386 UINT no_output_sample_counts = 0; 392 UINT no_output_sample_counts = 0;
@@ -790,6 +796,9 @@ struct DeviceState {
790 log_once("SRV requires VK_EXT_image_view_min_lod; first mip", int(image.first_mip)); 796 log_once("SRV requires VK_EXT_image_view_min_lod; first mip", int(image.first_mip));
791 return false; 797 return false;
792 } 798 }
799 // A driver that floors the clamp (min_lod_integer) gets the level point mip filtering picks:
800 // nearest(d') = ceil(d' + 0.5) - 1, the spec's preferred rounding. It stays within the mip range.
801 if (min_lod_integer) clamp.minLod = std::ceil(clamp.minLod + 0.5f) - 1.0f;
793 clamp.pNext = view_info.pNext; 802 clamp.pNext = view_info.pNext;
794 view_info.pNext = &clamp; 803 view_info.pNext = &clamp;
795 } 804 }
@@ -3037,6 +3046,15 @@ public:
3037 VkPhysicalDeviceProperties properties{}; 3046 VkPhysicalDeviceProperties properties{};
3038 device_properties(info.physical, &properties); 3047 device_properties(info.physical, &properties);
3039 state_.max_sampler_lod_bias = properties.limits.maxSamplerLodBias; 3048 state_.max_sampler_lod_bias = properties.limits.maxSamplerLodBias;
3049 {
3050 constexpr std::uint32_t kIntelVendorId = 0x8086;
3051 state_.min_lod_integer = properties.vendorID == kIntelVendorId &&
3052 properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
3053 char text[4] = {};
3054 size_t length = 0;
3055 if (getenv_s(&length, text, "LEONIDA_MIN_LOD_INTEGER") == 0 && length > 1)
3056 state_.min_lod_integer = text[0] != '0';
3057 }
3040 std::uint32_t family_count = 0; 3058 std::uint32_t family_count = 0;
3041 queue_families(info.physical, &family_count, nullptr); 3059 queue_families(info.physical, &family_count, nullptr);
3042 std::vector<VkQueueFamilyProperties> families(family_count); 3060 std::vector<VkQueueFamilyProperties> families(family_count);
@@ -3081,7 +3099,19 @@ public:
3081 get_properties(state_.info.physical, &properties); 3099 get_properties(state_.info.physical, &properties);
3082 features.ms_samples = {VK_SAMPLE_COUNT_4_BIT, state_.ms_fallback_samples(VK_FORMAT_R32_UINT), 3100 features.ms_samples = {VK_SAMPLE_COUNT_4_BIT, state_.ms_fallback_samples(VK_FORMAT_R32_UINT),
3083 state_.ms_fallback_samples(VK_FORMAT_R32_SINT)}; 3101 state_.ms_fallback_samples(VK_FORMAT_R32_SINT)};
3084 if (!leonida::bindless::size_bindings(features, properties.properties.limits, v11, indexed)) 3102 // Past maxPerSetDescriptors, ask the driver about the grown layout (D3D-219: Intel's Xe-LP reports 6159).
3103 const auto layout_support = reinterpret_cast<PFN_vkGetDescriptorSetLayoutSupport>(
3104 get_device(state_.info.device, "vkGetDescriptorSetLayoutSupport"));
3105 std::function<bool(const leonida::BindlessFeatures&)> layout_supported;
3106 if (layout_support)
3107 layout_supported = [&](const leonida::BindlessFeatures& candidate) {
3108 const leonida::bindless::SetLayout layout(candidate);
3109 VkDescriptorSetLayoutSupport support{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_SUPPORT};
3110 layout_support(state_.info.device, &layout.info, &support);
3111 return support.supported == VK_TRUE;
3112 };
3113 if (!leonida::bindless::size_bindings(features, properties.properties.limits, v11, indexed,
3114 layout_supported))
3085 std::fprintf(stderr, "[rt] d3d12: the device's descriptor limits are below the bindless set's default " 3115 std::fprintf(stderr, "[rt] d3d12: the device's descriptor limits are below the bindless set's default "
3086 "sizes; it holds less\n"); 3116 "sizes; it holds less\n");
3087 } 3117 }
diff --git a/runtime/src/vulkan_bindless.h b/runtime/src/vulkan_bindless.h
index c599eb7c2..9111f764c 100644
--- a/runtime/src/vulkan_bindless.h
+++ b/runtime/src/vulkan_bindless.h
@@ -47,6 +47,7 @@
47#include <array> 47#include <array>
48#include <cstdint> 48#include <cstdint>
49#include <cstring> 49#include <cstring>
50#include <functional>
50#include <unordered_map> 51#include <unordered_map>
51#include <vector> 52#include <vector>
52 53
@@ -162,6 +163,35 @@ constexpr std::uint32_t r32ui_binding(ImageDimension dimension) {
162 return dimension == ImageDimension::dim_2d ? 4 : dimension == ImageDimension::dim_3d ? 7 : no_binding; 163 return dimension == ImageDimension::dim_2d ? 4 : dimension == ImageDimension::dim_3d ? 7 : no_binding;
163} 164}
164 165
166// Set 0's descriptor set layout at features' counts: what create_layout creates and what size_bindings'
167// layout_supported asks vkGetDescriptorSetLayoutSupport about. It points into itself, so it is not copied.
168struct SetLayout {
169 std::array<VkDescriptorSetLayoutBinding, binding_count> entries{};
170 std::array<VkDescriptorBindingFlags, binding_count> flags{};
171 VkDescriptorSetLayoutBindingFlagsCreateInfo flags_info{
172 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO};
173 VkDescriptorSetLayoutCreateInfo info{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
174
175 explicit SetLayout(const BindlessFeatures& features) {
176 std::uint32_t count = 0;
177 for (std::uint32_t b = 0; b < binding_count; ++b) {
178 if (!binding_enabled(b, features)) continue;
179 entries[count] = {b, bindings[b].type, features.counts[b], VK_SHADER_STAGE_ALL, nullptr};
180 flags[count] = (features.update_after_bind ? VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT : 0) |
181 (features.partially_bound ? VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT : 0);
182 ++count;
183 }
184 flags_info.bindingCount = count;
185 flags_info.pBindingFlags = flags.data();
186 info.pNext = &flags_info;
187 info.flags = features.update_after_bind ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT : 0;
188 info.bindingCount = count;
189 info.pBindings = entries.data();
190 }
191 SetLayout(const SetLayout&) = delete;
192 SetLayout& operator=(const SetLayout&) = delete;
193};
194
165// What size_bindings() grows to where the device's limits allow. At 32-64 bytes a descriptor the whole set is then 195// What size_bindings() grows to where the device's limits allow. At 32-64 bytes a descriptor the whole set is then
166// 3-6 MiB (93793 descriptors on an RTX 5070). 196// 3-6 MiB (93793 descriptors on an RTX 5070).
167inline constexpr std::uint32_t max_2d_images = 65536; 197inline constexpr std::uint32_t max_2d_images = 65536;
@@ -183,10 +213,14 @@ inline constexpr std::uint32_t growth_headroom = 64;
183// what is sure to work (vkGetDescriptorSetLayoutSupport may allow more), so it never shrinks step 1. 213// what is sure to work (vkGetDescriptorSetLayoutSupport may allow more), so it never shrinks step 1.
184// A storage array holds the smaller of the storage count and its dimension's images: add_image never gives a 214// A storage array holds the smaller of the storage count and its dimension's images: add_image never gives a
185// storage view an index past the sampled array. The other bindings keep their default counts. 215// storage view an index past the sampled array. The other bindings keep their default counts.
216// layout_supported, when given, answers vkGetDescriptorSetLayoutSupport for set 0 at the counts in its argument:
217// step 3 then also grows past maxPerSetDescriptors where the device says the layout works (Intel's Xe-LP reports
218// 6159 and supports the full sizes, D3D-219). It is asked only once the sum is above maxPerSetDescriptors.
186// Sets features.counts; returns false when a count is below its default because the device's limits are. 219// Sets features.counts; returns false when a count is below its default because the device's limits are.
187inline bool size_bindings(BindlessFeatures& features, const VkPhysicalDeviceLimits& limits, 220inline bool size_bindings(BindlessFeatures& features, const VkPhysicalDeviceLimits& limits,
188 const VkPhysicalDeviceVulkan11Properties& v11, 221 const VkPhysicalDeviceVulkan11Properties& v11,
189 const VkPhysicalDeviceVulkan12Properties& v12) { 222 const VkPhysicalDeviceVulkan12Properties& v12,
223 const std::function<bool(const BindlessFeatures&)>& layout_supported = {}) {
190 const bool uab = features.update_after_bind; 224 const bool uab = features.update_after_bind;
191 const std::uint32_t sampled_limit = 225 const std::uint32_t sampled_limit =
192 uab ? std::min(v12.maxPerStageDescriptorUpdateAfterBindSampledImages, 226 uab ? std::min(v12.maxPerStageDescriptorUpdateAfterBindSampledImages,
@@ -233,7 +267,8 @@ inline bool size_bindings(BindlessFeatures& features, const VkPhysicalDeviceLimi
233 const auto within = [&](std::uint64_t n, std::uint32_t limit) { return n + headroom <= limit; }; 267 const auto within = [&](std::uint64_t n, std::uint32_t limit) { return n + headroom <= limit; };
234 const std::uint64_t all = sampled + sampler + stored + buffers; 268 const std::uint64_t all = sampled + sampler + stored + buffers;
235 return within(sampled, sampled_limit) && within(sampler, sampler_limit) && within(stored, storage_limit) && 269 return within(sampled, sampled_limit) && within(sampler, sampler_limit) && within(stored, storage_limit) &&
236 within(sampled + stored + buffers, resource_limit) && all <= pool_limit && all <= set_limit; 270 within(sampled + stored + buffers, resource_limit) && all <= pool_limit &&
271 (all <= set_limit || (layout_supported && layout_supported(features)));
237 }; 272 };
238 // Raises n to the largest value up to `high` that fits; leaves it where it is when none does. 273 // Raises n to the largest value up to `high` that fits; leaves it where it is when none does.
239 const auto grow = [&](std::uint32_t& n, std::uint32_t high, std::uint32_t headroom, std::uint64_t set_limit) { 274 const auto grow = [&](std::uint32_t& n, std::uint32_t high, std::uint32_t headroom, std::uint64_t set_limit) {
@@ -532,27 +567,12 @@ private:
532 } 567 }
533 568
534 bool create_layout() { 569 bool create_layout() {
535 std::array<VkDescriptorSetLayoutBinding, bindless::bindings.size()> entries{}; 570 const bindless::SetLayout layout(features_);
536 std::array<VkDescriptorBindingFlags, bindless::bindings.size()> flags{}; 571 const std::uint32_t count = layout.info.bindingCount;
537 std::array<VkDescriptorPoolSize, bindless::bindings.size()> sizes{}; 572 std::array<VkDescriptorPoolSize, bindless::bindings.size()> sizes{};
538 std::uint32_t count = 0; 573 for (std::uint32_t i = 0; i < count; ++i)
539 for (std::uint32_t b = 0; b < bindless::bindings.size(); ++b) { 574 sizes[i] = {layout.entries[i].descriptorType, layout.entries[i].descriptorCount};
540 if (!bindless::binding_enabled(b, features_)) continue; 575 if (vk_.vkCreateDescriptorSetLayout(device_, &layout.info, nullptr, &layout_) != VK_SUCCESS) return false;
541 entries[count] = {b, bindless::bindings[b].type, features_.counts[b], VK_SHADER_STAGE_ALL, nullptr};
542 flags[count] = (features_.update_after_bind ? VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT : 0) |
543 (features_.partially_bound ? VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT : 0);
544 sizes[count] = {bindless::bindings[b].type, features_.counts[b]};
545 ++count;
546 }
547 VkDescriptorSetLayoutBindingFlagsCreateInfo flags_info{
548 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO};
549 flags_info.bindingCount = count;
550 flags_info.pBindingFlags = flags.data();
551 VkDescriptorSetLayoutCreateInfo layout_info{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, &flags_info};
552 layout_info.flags = features_.update_after_bind ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT : 0;
553 layout_info.bindingCount = count;
554 layout_info.pBindings = entries.data();
555 if (vk_.vkCreateDescriptorSetLayout(device_, &layout_info, nullptr, &layout_) != VK_SUCCESS) return false;
556 576
557 VkDescriptorPoolCreateInfo pool_info{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; 577 VkDescriptorPoolCreateInfo pool_info{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
558 pool_info.flags = features_.update_after_bind ? VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT : 0; 578 pool_info.flags = features_.update_after_bind ? VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT : 0;
diff --git a/runtime/test/bindless_sizing_test.cpp b/runtime/test/bindless_sizing_test.cpp
index 469274d56..07715f01e 100644
--- a/runtime/test/bindless_sizing_test.cpp
+++ b/runtime/test/bindless_sizing_test.cpp
@@ -172,6 +172,37 @@ int main() {
172 EXPECT(totals(f).all <= 30000 && count(f, D::dim_2d) > 4096); 172 EXPECT(totals(f).all <= 30000 && count(f, D::dim_2d) > 4096);
173 } 173 }
174 174
175 // D3D-219: past maxPerSetDescriptors, growth follows layout_supported (vkGetDescriptorSetLayoutSupport), which
176 // is asked only above that limit. Intel's Xe-LP reports 6159 and supports the full sizes.
177 {
178 Device d = uniform(1048576, 1048576);
179 d.v11.maxPerSetDescriptors = 6159;
180 d.limits.maxSamplerAllocationCount = 4000;
181 unsigned asked = 0, asked_within = 0;
182 const auto all_supported = [&](const BindlessFeatures& candidate) {
183 ++asked;
184 asked_within += totals(candidate).all <= 6159;
185 return true;
186 };
187 BindlessFeatures f = with_ms(true);
188 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12, all_supported));
189 EXPECT(asked > 0 && asked_within == 0);
190 EXPECT(count(f, D::dim_2d) == bindless::max_2d_images &&
191 f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers);
192 EXPECT(storage(f, D::dim_2d) == bindless::max_storage_indices && storage_consistent(f));
193
194 // A driver that supports less: growth stops where it says no.
195 const auto up_to_20000 = [&](const BindlessFeatures& candidate) { return totals(candidate).all <= 20000; };
196 f = with_ms(true);
197 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12, up_to_20000));
198 EXPECT(totals(f).all <= 20000 && totals(f).all > 6159 && count(f, D::dim_2d) > 4096);
199
200 // Without the callback, maxPerSetDescriptors still caps growth as before.
201 f = with_ms(true);
202 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12));
203 EXPECT(totals(f).all <= 6159 || (count(f, D::dim_2d) == 4096 && f.counts[bindless::sampler_binding] == 1024));
204 }
205
175 // The default features are today's counts, which the device-less users (vk_image_fuzz) still get. 206 // The default features are today's counts, which the device-less users (vk_image_fuzz) still get.
176 EXPECT(BindlessFeatures{}.counts == defaults); 207 EXPECT(BindlessFeatures{}.counts == defaults);
177 std::printf("bindless sizing: synthetic limits gave the expected counts\n"); 208 std::printf("bindless sizing: synthetic limits gave the expected counts\n");