Skip to content

Commit

Permalink
vkd3d: Clean up reporting and checking maximum descriptor counts.
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Rebohle <[email protected]>
  • Loading branch information
doitsujin authored and HansKristian-Work committed Dec 3, 2024
1 parent 8ffeb3a commit 4c6bbce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
25 changes: 22 additions & 3 deletions libs/vkd3d/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libs/vkd3d/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
31 changes: 12 additions & 19 deletions libs/vkd3d/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions libs/vkd3d/vkd3d_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4c6bbce

Please sign in to comment.