Skip to content

Commit

Permalink
vkd3d: enable EXT_device_generated_commands
Browse files Browse the repository at this point in the history
this adds new paths to use the EXT version of the functionality
when available instead of NV, enabling broader support across
drivers/hardware while providing the same functionality

Signed-off-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
Co-authored-by: Hans-Kristian Arntzen <post@arntzen-software.no>
  • Loading branch information
zmike and HansKristian-Work committed Sep 27, 2024
1 parent 3103abb commit 544915b
Show file tree
Hide file tree
Showing 10 changed files with 705 additions and 95 deletions.
729 changes: 643 additions & 86 deletions libs/vkd3d/command.c

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion libs/vkd3d/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] =
VK_EXTENSION(EXT_CONSERVATIVE_RASTERIZATION, EXT_conservative_rasterization),
VK_EXTENSION(EXT_CUSTOM_BORDER_COLOR, EXT_custom_border_color),
VK_EXTENSION(EXT_DEPTH_CLIP_ENABLE, EXT_depth_clip_enable),
VK_EXTENSION(EXT_DEVICE_GENERATED_COMMANDS, EXT_device_generated_commands),
VK_EXTENSION(EXT_IMAGE_VIEW_MIN_LOD, EXT_image_view_min_lod),
VK_EXTENSION(EXT_ROBUSTNESS_2, EXT_robustness2),
VK_EXTENSION(EXT_SHADER_STENCIL_EXPORT, EXT_shader_stencil_export),
Expand Down Expand Up @@ -1628,6 +1629,16 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i
vk_prepend_struct(&info->features2, &info->depth_clip_features);
}

if (vulkan_info->EXT_device_generated_commands)
{
info->device_generated_commands_features_ext.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_FEATURES_EXT;
info->device_generated_commands_properties_ext.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEVICE_GENERATED_COMMANDS_PROPERTIES_EXT;
vk_prepend_struct(&info->features2, &info->device_generated_commands_features_ext);
vk_prepend_struct(&info->properties2, &info->device_generated_commands_properties_ext);
}

if (vulkan_info->EXT_robustness2)
{
info->robustness2_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
Expand Down Expand Up @@ -3181,6 +3192,17 @@ static HRESULT d3d12_device_create_scratch_buffer(struct d3d12_device *device, e
alloc_info.heap_flags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS | D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
alloc_info.flags = VKD3D_ALLOCATION_FLAG_GLOBAL_BUFFER | VKD3D_ALLOCATION_FLAG_INTERNAL_SCRATCH;
alloc_info.vk_memory_priority = vkd3d_convert_to_vk_prio(D3D12_RESIDENCY_PRIORITY_NORMAL);
if (device->device_info.device_generated_commands_features_ext.deviceGeneratedCommands)
{
/* this flag cannot be used with the existing buffer heaps */
alloc_info.explicit_global_buffer_usage =
VK_BUFFER_USAGE_2_PREPROCESS_BUFFER_BIT_EXT |
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;

/* Need this to override any type flags provided by heap properties.
* BUFFER_USAGE_2_PREPROCESS_BUFFER implies 32-bit only types. */
alloc_info.flags |= VKD3D_ALLOCATION_FLAG_DEDICATED;
}

if (FAILED(hr = vkd3d_allocate_memory(device, &device->memory_allocator,
&alloc_info, &scratch->allocation)))
Expand Down Expand Up @@ -8795,7 +8817,8 @@ static void vkd3d_scratch_pool_init(struct d3d12_device *device)
}

if ((vkd3d_config_flags & VKD3D_CONFIG_FLAG_REQUIRES_COMPUTE_INDIRECT_TEMPLATES) &&
device->device_info.device_generated_commands_compute_features_nv.deviceGeneratedCompute &&
(device->device_info.device_generated_commands_compute_features_nv.deviceGeneratedCompute ||
device->device_info.device_generated_commands_properties_ext.supportedIndirectCommandsShaderStages & VK_SHADER_STAGE_COMPUTE_BIT) &&
device->device_info.vulkan_1_2_properties.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY)
{
/* DGCC preprocess buffers are gigantic on NV. Starfield requires 27 MB for 4096 dispatches ... */
Expand Down
1 change: 1 addition & 0 deletions libs/vkd3d/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ static HRESULT d3d12_heap_init(struct d3d12_heap *heap, struct d3d12_device *dev
alloc_info.heap_desc = heap->desc;
alloc_info.host_ptr = host_address;
alloc_info.extra_allocation_flags = 0;
alloc_info.explicit_global_buffer_usage = 0;

if ((alloc_info.heap_desc.Flags & D3D12_HEAP_FLAG_DENY_BUFFERS) &&
device->d3d12_caps.options.ResourceHeapTier >= D3D12_RESOURCE_HEAP_TIER_2)
Expand Down
2 changes: 2 additions & 0 deletions libs/vkd3d/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,7 @@ static HRESULT vkd3d_memory_allocator_try_add_chunk(struct vkd3d_memory_allocato
alloc_info.flags = VKD3D_ALLOCATION_FLAG_NO_FALLBACK;
alloc_info.optional_memory_properties = optional_properties;
alloc_info.vk_memory_priority = vkd3d_convert_to_vk_prio(D3D12_RESIDENCY_PRIORITY_NORMAL);
alloc_info.explicit_global_buffer_usage = 0;

if (minimum_size < VKD3D_VA_BLOCK_SIZE)
alloc_info.memory_requirements.size = VKD3D_MEMORY_CHUNK_SIZE;
Expand Down Expand Up @@ -1941,6 +1942,7 @@ HRESULT vkd3d_allocate_heap_memory(struct d3d12_device *device, struct vkd3d_mem
alloc_info.heap_flags = info->heap_desc.Flags;
alloc_info.host_ptr = info->host_ptr;
alloc_info.vk_memory_priority = info->vk_memory_priority;
alloc_info.explicit_global_buffer_usage = info->explicit_global_buffer_usage;

alloc_info.flags |= info->extra_allocation_flags;

Expand Down
3 changes: 2 additions & 1 deletion libs/vkd3d/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,8 @@ static HRESULT vkd3d_predicate_ops_init(struct vkd3d_predicate_ops *meta_predica
meta_predicate_ops->data_sizes[i] = spec_data[i].arg_count * sizeof(uint32_t);
}

if (device->device_info.device_generated_commands_features_nv.deviceGeneratedCommands)
if (device->device_info.device_generated_commands_features_nv.deviceGeneratedCommands ||
device->device_info.device_generated_commands_features_ext.deviceGeneratedCommands)
{
uint32_t num_active_words;
spec_info.mapEntryCount = 1;
Expand Down
1 change: 1 addition & 0 deletions libs/vkd3d/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -3565,6 +3565,7 @@ HRESULT d3d12_resource_create_committed(struct d3d12_device *device, const D3D12
memset(&allocate_info, 0, sizeof(allocate_info));
allocate_info.memory_requirements = memory_requirements.memoryRequirements;
allocate_info.heap_flags = heap_flags;
allocate_info.explicit_global_buffer_usage = 0;

if (object->flags & VKD3D_RESOURCE_LINEAR_STAGING_COPY)
{
Expand Down
20 changes: 16 additions & 4 deletions libs/vkd3d/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -6649,6 +6649,13 @@ static bool vkd3d_bindless_supports_mutable_type(struct d3d12_device *device, ui
static uint32_t vkd3d_bindless_state_get_bindless_flags(struct d3d12_device *device)
{
const struct vkd3d_physical_device_info *device_info = &device->device_info;
const VkShaderStageFlags minimum_dgcc_stages =
VK_SHADER_STAGE_VERTEX_BIT |
VK_SHADER_STAGE_FRAGMENT_BIT |
VK_SHADER_STAGE_COMPUTE_BIT;
const VkShaderStageFlags minimum_dgc_stages =
VK_SHADER_STAGE_VERTEX_BIT |
VK_SHADER_STAGE_FRAGMENT_BIT;
uint32_t flags = 0;

if (!d3d12_device_uses_descriptor_buffers(device))
Expand Down Expand Up @@ -6710,18 +6717,23 @@ static uint32_t vkd3d_bindless_state_get_bindless_flags(struct d3d12_device *dev
}

if ((vkd3d_config_flags & VKD3D_CONFIG_FLAG_REQUIRES_COMPUTE_INDIRECT_TEMPLATES) &&
!device->device_info.device_generated_commands_compute_features_nv.deviceGeneratedCompute)
!device->device_info.device_generated_commands_compute_features_nv.deviceGeneratedCompute &&
!(device->device_info.device_generated_commands_properties_ext.supportedIndirectCommandsShaderStages & VK_SHADER_STAGE_COMPUTE_BIT))
{
INFO("Forcing push UBO path for compute root parameters.\n");
flags |= VKD3D_FORCE_COMPUTE_ROOT_PARAMETERS_PUSH_UBO;
}

if (device->device_info.device_generated_commands_compute_features_nv.deviceGeneratedCompute &&
device->device_info.device_generated_commands_features_nv.deviceGeneratedCommands)
if ((device->device_info.device_generated_commands_compute_features_nv.deviceGeneratedCompute &&
device->device_info.device_generated_commands_features_nv.deviceGeneratedCommands) ||
(device->device_info.device_generated_commands_properties_ext.supportedIndirectCommandsShaderStages &
minimum_dgcc_stages) == minimum_dgcc_stages)
{
INFO("Enabling fast paths for advanced ExecuteIndirect() graphics and compute.\n");
}
else if (device->device_info.device_generated_commands_features_nv.deviceGeneratedCommands)
else if (device->device_info.device_generated_commands_features_nv.deviceGeneratedCommands ||
(device->device_info.device_generated_commands_properties_ext.supportedIndirectCommandsShaderStages &
minimum_dgc_stages) == minimum_dgc_stages)
{
INFO("Enabling fast paths for advanced ExecuteIndirect() graphics.\n");
}
Expand Down
10 changes: 8 additions & 2 deletions libs/vkd3d/vkd3d_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ struct vkd3d_vulkan_info
bool EXT_conservative_rasterization;
bool EXT_custom_border_color;
bool EXT_depth_clip_enable;
bool EXT_device_generated_commands;
bool EXT_image_view_min_lod;
bool EXT_robustness2;
bool EXT_shader_stencil_export;
Expand Down Expand Up @@ -710,6 +711,7 @@ struct vkd3d_allocate_heap_memory_info
void *host_ptr;
uint32_t extra_allocation_flags;
float vk_memory_priority;
VkBufferUsageFlags explicit_global_buffer_usage;
};

struct vkd3d_allocate_resource_memory_info
Expand Down Expand Up @@ -3309,8 +3311,10 @@ struct d3d12_command_signature
VkBuffer buffer;
VkDeviceAddress buffer_va;
struct vkd3d_device_memory_allocation memory;
VkIndirectCommandsLayoutNV layout_implicit;
VkIndirectCommandsLayoutNV layout_preprocess;
VkIndirectCommandsLayoutNV layout_implicit_nv;
VkIndirectCommandsLayoutNV layout_preprocess_nv;
VkIndirectCommandsLayoutEXT layout_implicit_ext;
VkIndirectCommandsLayoutEXT layout_preprocess_ext;
uint32_t stride;
struct vkd3d_execute_indirect_info pipeline;
} dgc;
Expand Down Expand Up @@ -4444,6 +4448,7 @@ struct vkd3d_physical_device_info
VkPhysicalDeviceFragmentShadingRatePropertiesKHR fragment_shading_rate_properties;
VkPhysicalDeviceConservativeRasterizationPropertiesEXT conservative_rasterization_properties;
VkPhysicalDeviceDeviceGeneratedCommandsPropertiesNV device_generated_commands_properties_nv;
VkPhysicalDeviceDeviceGeneratedCommandsPropertiesEXT device_generated_commands_properties_ext;
VkPhysicalDeviceMeshShaderPropertiesEXT mesh_shader_properties;
VkPhysicalDeviceShaderModuleIdentifierPropertiesEXT shader_module_identifier_properties;
VkPhysicalDeviceDescriptorBufferPropertiesEXT descriptor_buffer_properties;
Expand Down Expand Up @@ -4481,6 +4486,7 @@ struct vkd3d_physical_device_info
VkPhysicalDeviceCoherentMemoryFeaturesAMD device_coherent_memory_features_amd;
VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR ray_tracing_maintenance1_features;
VkPhysicalDeviceDeviceGeneratedCommandsFeaturesNV device_generated_commands_features_nv;
VkPhysicalDeviceDeviceGeneratedCommandsFeaturesEXT device_generated_commands_features_ext;
VkPhysicalDeviceMeshShaderFeaturesEXT mesh_shader_features;
VkPhysicalDeviceShaderModuleIdentifierFeaturesEXT shader_module_identifier_features;
VkPhysicalDevicePresentIdFeaturesKHR present_id_features;
Expand Down
7 changes: 7 additions & 0 deletions libs/vkd3d/vulkan_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ VK_DEVICE_EXT_PFN(vkGetGeneratedCommandsMemoryRequirementsNV)
VK_DEVICE_EXT_PFN(vkCmdExecuteGeneratedCommandsNV)
VK_DEVICE_EXT_PFN(vkCmdPreprocessGeneratedCommandsNV)

/* VK_EXT_device_generated_commands */
VK_DEVICE_EXT_PFN(vkCreateIndirectCommandsLayoutEXT)
VK_DEVICE_EXT_PFN(vkDestroyIndirectCommandsLayoutEXT)
VK_DEVICE_EXT_PFN(vkGetGeneratedCommandsMemoryRequirementsEXT)
VK_DEVICE_EXT_PFN(vkCmdExecuteGeneratedCommandsEXT)
VK_DEVICE_EXT_PFN(vkCmdPreprocessGeneratedCommandsEXT)

/* VK_EXT_shader_module_identifier */
VK_DEVICE_EXT_PFN(vkGetShaderModuleIdentifierEXT)

Expand Down

0 comments on commit 544915b

Please sign in to comment.