From 4c6bbce31fc84cf2e8ff9bc2a6063abc62d494de Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 2 Dec 2024 14:32:40 +0100 Subject: [PATCH] vkd3d: Clean up reporting and checking maximum descriptor counts. Signed-off-by: Philip Rebohle --- libs/vkd3d/device.c | 25 ++++++++++++++++++++++--- libs/vkd3d/resource.c | 2 +- libs/vkd3d/state.c | 31 ++++++++++++------------------- libs/vkd3d/vkd3d_private.h | 5 +++++ 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 2f68fecb41..56279c16a7 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -7864,6 +7864,25 @@ static D3D12_SAMPLER_FEEDBACK_TIER d3d12_device_determine_sampler_feedback_tier( return D3D12_SAMPLER_FEEDBACK_TIER_0_9; } +uint32_t d3d12_device_get_max_descriptor_heap_size(struct d3d12_device *device, D3D12_DESCRIPTOR_HEAP_TYPE heap_type) +{ + /* For now, hard-code descriptor counts to the minimum numbers required by D3D12. + * We could support more based on device capabilities, but that would change + * pipeline layouts. */ + switch (heap_type) + { + case D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV: + return VKD3D_MIN_VIEW_DESCRIPTOR_COUNT; + + case D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER: + return VKD3D_MIN_SAMPLER_DESCRIPTOR_COUNT; + + default: + WARN("Unhandled descriptor heap type %u.\n", heap_type); + return 0u; + } +} + static void d3d12_device_caps_init_feature_options(struct d3d12_device *device) { const VkPhysicalDeviceFeatures *features = &device->device_info.features2.features; @@ -8164,9 +8183,9 @@ static void d3d12_device_caps_init_feature_options19(struct d3d12_device *device /* Report legacy D3D12 limits for now. Increasing descriptor count limits * would require changing changing descriptor set layouts, and more samplers * need additional considerations w.r.t. Vulkan device limits. */ - options19->MaxSamplerDescriptorHeapSize = 2048; - options19->MaxSamplerDescriptorHeapSizeWithStaticSamplers = 2048; - options19->MaxViewDescriptorHeapSize = 1000000; + options19->MaxSamplerDescriptorHeapSize = d3d12_device_get_max_descriptor_heap_size(device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); + options19->MaxSamplerDescriptorHeapSizeWithStaticSamplers = options19->MaxSamplerDescriptorHeapSize; + options19->MaxViewDescriptorHeapSize = d3d12_device_get_max_descriptor_heap_size(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); } static void d3d12_device_caps_init_feature_options20(struct d3d12_device *device) diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index fd23802780..e50a28f26d 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -9098,7 +9098,7 @@ HRESULT vkd3d_global_descriptor_buffer_init(struct vkd3d_global_descriptor_buffe * We will not add even more code paths to deal with that. * Non-mutable + descriptor buffer is only relevant on AMD Windows driver for the time being, * and eventually we will make mutable a hard requirement, so don't bother checking that case. */ - VkDeviceSize required_resource_descriptors = 1000000 + 1; /* One magic SSBO for internal VA buffer. */ + VkDeviceSize required_resource_descriptors = VKD3D_MIN_VIEW_DESCRIPTOR_COUNT + 1; /* One magic SSBO for internal VA buffer. */ uint32_t flags = VKD3D_BINDLESS_MUTABLE_TYPE; VkDeviceSize mutable_desc_size; diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 25b8cc8b4f..9c29c2d479 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -6073,22 +6073,15 @@ VkPipeline d3d12_pipeline_state_get_or_create_pipeline(struct d3d12_pipeline_sta return vk_pipeline; } -static uint32_t d3d12_max_descriptor_count_from_heap_type(D3D12_DESCRIPTOR_HEAP_TYPE heap_type) +static uint32_t d3d12_max_descriptor_count_from_heap_type(struct d3d12_device *device, D3D12_DESCRIPTOR_HEAP_TYPE heap_type) { - switch (heap_type) - { - case D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV: - if (vkd3d_descriptor_debug_active_descriptor_qa_checks()) - return 1000000 + VKD3D_DESCRIPTOR_DEBUG_NUM_PAD_DESCRIPTORS; - return 1000000; + uint32_t count = d3d12_device_get_max_descriptor_heap_size(device, heap_type); - case D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER: - return 2048; + if (heap_type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && + vkd3d_descriptor_debug_active_descriptor_qa_checks()) + count += VKD3D_DESCRIPTOR_DEBUG_NUM_PAD_DESCRIPTORS; - default: - ERR("Invalid descriptor heap type %d.\n", heap_type); - return 0; - } + return count; } static uint32_t d3d12_max_host_descriptor_count_from_heap_type(struct d3d12_device *device, D3D12_DESCRIPTOR_HEAP_TYPE heap_type) @@ -6338,7 +6331,7 @@ static HRESULT vkd3d_bindless_state_add_binding(struct vkd3d_bindless_state *bin vk_binding = &vk_binding_info[set_info->binding_index]; vk_binding->binding = set_info->binding_index; vk_binding->descriptorType = set_info->vk_descriptor_type; - vk_binding->descriptorCount = d3d12_max_descriptor_count_from_heap_type(set_info->heap_type); + vk_binding->descriptorCount = d3d12_max_descriptor_count_from_heap_type(device, set_info->heap_type); vk_binding->stageFlags = VK_SHADER_STAGE_ALL; vk_binding->pImmutableSamplers = NULL; @@ -6622,7 +6615,7 @@ static bool vkd3d_bindless_supports_mutable_type(struct d3d12_device *device, ui binding.binding = 0; binding.descriptorType = VK_DESCRIPTOR_TYPE_MUTABLE_EXT; - binding.descriptorCount = d3d12_max_descriptor_count_from_heap_type(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + binding.descriptorCount = d3d12_max_descriptor_count_from_heap_type(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); binding.pImmutableSamplers = NULL; binding.stageFlags = VK_SHADER_STAGE_ALL; @@ -6665,7 +6658,7 @@ static uint32_t vkd3d_bindless_state_get_bindless_flags(struct d3d12_device *dev if (!d3d12_device_uses_descriptor_buffers(device)) { - if (device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindUniformBuffers < 1000000 || + if (device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindUniformBuffers < VKD3D_MIN_VIEW_DESCRIPTOR_COUNT || !device_info->vulkan_1_2_features.descriptorBindingUniformBufferUpdateAfterBind || !device_info->vulkan_1_2_features.shaderUniformBufferArrayNonUniformIndexing) flags |= VKD3D_BINDLESS_CBV_AS_SSBO; @@ -6889,9 +6882,9 @@ HRESULT vkd3d_bindless_state_init(struct vkd3d_bindless_state *bindless_state, if (!d3d12_device_uses_descriptor_buffers(device)) { /* UBO is optional. We can fall back to SSBO if required. */ - if (device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindSampledImages < 1000000 || - device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindStorageImages < 1000000 || - device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindStorageBuffers < 1000000) + if (device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindSampledImages < VKD3D_MIN_VIEW_DESCRIPTOR_COUNT || + device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindStorageImages < VKD3D_MIN_VIEW_DESCRIPTOR_COUNT || + device_info->vulkan_1_2_properties.maxPerStageDescriptorUpdateAfterBindStorageBuffers < VKD3D_MIN_VIEW_DESCRIPTOR_COUNT) { ERR("Insufficient descriptor indexing support.\n"); goto fail; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 14e1b4f3a0..63abb30c19 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -63,6 +63,9 @@ #define VKD3D_MAX_MUTABLE_DESCRIPTOR_TYPES 6u #define VKD3D_MAX_DESCRIPTOR_SIZE 256u /* Maximum allowed value in VK_EXT_descriptor_buffer. */ +#define VKD3D_MIN_VIEW_DESCRIPTOR_COUNT (1000000u) +#define VKD3D_MIN_SAMPLER_DESCRIPTOR_COUNT (2048u) + #define VKD3D_TILE_SIZE 65536 typedef ID3D12Fence1 d3d12_fence_iface; @@ -4997,6 +5000,8 @@ VkPipeline d3d12_device_get_or_create_vertex_input_pipeline(struct d3d12_device VkPipeline d3d12_device_get_or_create_fragment_output_pipeline(struct d3d12_device *device, const struct vkd3d_fragment_output_pipeline_desc *desc); +uint32_t d3d12_device_get_max_descriptor_heap_size(struct d3d12_device *device, D3D12_DESCRIPTOR_HEAP_TYPE heap_type); + static inline struct d3d12_device *unsafe_impl_from_ID3D12Device(d3d12_device_iface *iface) { return CONTAINING_RECORD(iface, struct d3d12_device, ID3D12Device_iface);