[PATCH vkd3d 1/2] vkd3d: Use Vulkan null descriptors if EXT_robustness2 is available.
Conor McCarthy
cmccarthy at codeweavers.com
Mon Mar 21 10:25:09 CDT 2022
Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
libs/vkd3d/device.c | 8 +++
libs/vkd3d/resource.c | 101 +++++++++++++++++++++++++++++++++++--
libs/vkd3d/vkd3d_private.h | 5 ++
3 files changed, 109 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index bd471a72..0d2d1696 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -135,6 +135,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] =
VK_EXTENSION(EXT_DEBUG_MARKER, EXT_debug_marker),
VK_EXTENSION(EXT_DEPTH_CLIP_ENABLE, EXT_depth_clip_enable),
VK_EXTENSION(EXT_DESCRIPTOR_INDEXING, EXT_descriptor_indexing),
+ VK_EXTENSION(EXT_ROBUSTNESS_2, EXT_robustness2),
VK_EXTENSION(EXT_SHADER_DEMOTE_TO_HELPER_INVOCATION, EXT_shader_demote_to_helper_invocation),
VK_EXTENSION(EXT_SHADER_STENCIL_EXPORT, EXT_shader_stencil_export),
VK_EXTENSION(EXT_TEXEL_BUFFER_ALIGNMENT, EXT_texel_buffer_alignment),
@@ -797,6 +798,7 @@ struct vkd3d_physical_device_info
VkPhysicalDeviceConditionalRenderingFeaturesEXT conditional_rendering_features;
VkPhysicalDeviceDepthClipEnableFeaturesEXT depth_clip_features;
VkPhysicalDeviceDescriptorIndexingFeaturesEXT descriptor_indexing_features;
+ VkPhysicalDeviceRobustness2FeaturesEXT robustness2_features;
VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT demote_features;
VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT texel_buffer_alignment_features;
VkPhysicalDeviceTransformFeedbackFeaturesEXT xfb_features;
@@ -813,6 +815,7 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i
VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *vertex_divisor_properties;
VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT *buffer_alignment_properties;
VkPhysicalDeviceDescriptorIndexingFeaturesEXT *descriptor_indexing_features;
+ VkPhysicalDeviceRobustness2FeaturesEXT *robustness2_features;
VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *vertex_divisor_features;
VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT *buffer_alignment_features;
VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT *demote_features;
@@ -827,6 +830,7 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i
conditional_rendering_features = &info->conditional_rendering_features;
depth_clip_features = &info->depth_clip_features;
descriptor_indexing_features = &info->descriptor_indexing_features;
+ robustness2_features = &info->robustness2_features;
descriptor_indexing_properties = &info->descriptor_indexing_properties;
maintenance3_properties = &info->maintenance3_properties;
demote_features = &info->demote_features;
@@ -845,6 +849,8 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i
vk_prepend_struct(&info->features2, depth_clip_features);
descriptor_indexing_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT;
vk_prepend_struct(&info->features2, descriptor_indexing_features);
+ robustness2_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
+ vk_prepend_struct(&info->features2, robustness2_features);
demote_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT;
vk_prepend_struct(&info->features2, demote_features);
buffer_alignment_features->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT;
@@ -1577,6 +1583,8 @@ static HRESULT vkd3d_init_device_caps(struct d3d12_device *device,
vulkan_info->EXT_conditional_rendering = false;
if (!physical_device_info->depth_clip_features.depthClipEnable)
vulkan_info->EXT_depth_clip_enable = false;
+ if (!physical_device_info->robustness2_features.nullDescriptor)
+ vulkan_info->EXT_robustness2 = false;
if (!physical_device_info->demote_features.shaderDemoteToHelperInvocation)
vulkan_info->EXT_shader_demote_to_helper_invocation = false;
if (!physical_device_info->texel_buffer_alignment_features.texelBufferAlignment)
diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index cbbd4170..01e0b67a 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -2423,10 +2423,10 @@ bool vkd3d_create_buffer_view(struct d3d12_device *device, VkBuffer vk_buffer, c
VkDeviceSize offset, VkDeviceSize size, struct vkd3d_view **view)
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
+ VkBufferView vk_view = VK_NULL_HANDLE;
struct vkd3d_view *object;
- VkBufferView vk_view;
- if (!vkd3d_create_vk_buffer_view(device, vk_buffer, format, offset, size, &vk_view))
+ if (vk_buffer && !vkd3d_create_vk_buffer_view(device, vk_buffer, format, offset, size, &vk_view))
return false;
if (!(object = vkd3d_view_create(VKD3D_VIEW_TYPE_BUFFER)))
@@ -2782,7 +2782,7 @@ void d3d12_desc_create_cbv(struct d3d12_desc *descriptor,
/* NULL descriptor */
buffer_info->buffer = device->null_resources.vk_buffer;
buffer_info->offset = 0;
- buffer_info->range = VKD3D_NULL_BUFFER_SIZE;
+ buffer_info->range = device->null_resources.vk_buffer ? VKD3D_NULL_BUFFER_SIZE : VK_WHOLE_SIZE;
}
descriptor->magic = VKD3D_DESCRIPTOR_MAGIC_CBV;
@@ -2864,6 +2864,55 @@ static void vkd3d_create_null_srv(struct d3d12_desc *descriptor,
descriptor->u.view_info.written_serial_id = view->serial_id;
}
+static bool vkd3d_create_null_texture_view(const struct d3d12_device *device, struct vkd3d_view **view)
+{
+ struct vkd3d_view *object;
+
+ if (!(object = vkd3d_view_create(VKD3D_VIEW_TYPE_IMAGE)))
+ return false;
+
+ object->u.vk_image_view = VK_NULL_HANDLE;
+ object->format = vkd3d_get_format(device, VKD3D_NULL_VIEW_FORMAT, false);
+ object->info.texture.vk_view_type = VK_IMAGE_VIEW_TYPE_2D;
+ object->info.texture.miplevel_idx = 0;
+ object->info.texture.layer_idx = 0;
+ object->info.texture.layer_count = 1;
+ *view = object;
+ return true;
+}
+
+static void vkd3d_create_vk_null_srv(struct d3d12_desc *descriptor, struct d3d12_device *device,
+ const D3D12_SHADER_RESOURCE_VIEW_DESC *desc)
+{
+ struct vkd3d_view *view;
+
+ if (!desc)
+ {
+ WARN("View desc is required for NULL view.\n");
+ return;
+ }
+
+ if (desc->ViewDimension == D3D12_SRV_DIMENSION_BUFFER)
+ {
+ if (!vkd3d_create_buffer_view(device, VK_NULL_HANDLE, vkd3d_get_format(device, DXGI_FORMAT_R32_UINT, false),
+ 0, VKD3D_NULL_BUFFER_SIZE, &view))
+ {
+ return;
+ }
+ descriptor->vk_descriptor_type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
+ }
+ else
+ {
+ if (!vkd3d_create_null_texture_view(device, &view))
+ return;
+ descriptor->vk_descriptor_type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
+ }
+
+ descriptor->magic = VKD3D_DESCRIPTOR_MAGIC_SRV;
+ descriptor->u.view_info.view = view;
+ descriptor->u.view_info.written_serial_id = view->serial_id;
+}
+
static void vkd3d_create_buffer_srv(struct d3d12_desc *descriptor,
struct d3d12_device *device, struct d3d12_resource *resource,
const D3D12_SHADER_RESOURCE_VIEW_DESC *desc)
@@ -2925,7 +2974,7 @@ void d3d12_desc_create_srv(struct d3d12_desc *descriptor,
if (!resource)
{
- vkd3d_create_null_srv(descriptor, device, desc);
+ device->create_null_srv(descriptor, device, desc);
return;
}
@@ -3101,6 +3150,38 @@ static void vkd3d_create_null_uav(struct d3d12_desc *descriptor,
descriptor->u.view_info.written_serial_id = view->serial_id;
}
+static void vkd3d_create_vk_null_uav(struct d3d12_desc *descriptor, struct d3d12_device *device,
+ const D3D12_UNORDERED_ACCESS_VIEW_DESC *desc)
+{
+ struct vkd3d_view *view;
+
+ if (!desc)
+ {
+ WARN("View desc is required for NULL view.\n");
+ return;
+ }
+
+ if (desc->ViewDimension == D3D12_UAV_DIMENSION_BUFFER)
+ {
+ if (!vkd3d_create_buffer_view(device, VK_NULL_HANDLE, vkd3d_get_format(device, DXGI_FORMAT_R32_UINT, false),
+ 0, VKD3D_NULL_BUFFER_SIZE, &view))
+ {
+ return;
+ }
+ descriptor->vk_descriptor_type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
+ }
+ else
+ {
+ if (!vkd3d_create_null_texture_view(device, &view))
+ return;
+ descriptor->vk_descriptor_type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
+ }
+
+ descriptor->magic = VKD3D_DESCRIPTOR_MAGIC_UAV;
+ descriptor->u.view_info.view = view;
+ descriptor->u.view_info.written_serial_id = view->serial_id;
+}
+
static void vkd3d_create_buffer_uav(struct d3d12_desc *descriptor, struct d3d12_device *device,
struct d3d12_resource *resource, struct d3d12_resource *counter_resource,
const D3D12_UNORDERED_ACCESS_VIEW_DESC *desc)
@@ -3216,7 +3297,7 @@ void d3d12_desc_create_uav(struct d3d12_desc *descriptor, struct d3d12_device *d
{
if (counter_resource)
FIXME("Ignoring counter resource %p.\n", counter_resource);
- vkd3d_create_null_uav(descriptor, device, desc);
+ device->create_null_uav(descriptor, device, desc);
return;
}
@@ -4421,6 +4502,16 @@ HRESULT vkd3d_init_null_resources(struct vkd3d_null_resources *null_resources,
memset(null_resources, 0, sizeof(*null_resources));
+ if (device->vk_info.EXT_robustness2)
+ {
+ device->create_null_srv = vkd3d_create_vk_null_srv;
+ device->create_null_uav = vkd3d_create_vk_null_uav;
+ return S_OK;
+ }
+
+ device->create_null_srv = vkd3d_create_null_srv;
+ device->create_null_uav = vkd3d_create_null_uav;
+
memset(&heap_properties, 0, sizeof(heap_properties));
heap_properties.Type = D3D12_HEAP_TYPE_DEFAULT;
diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h
index c28eb234..ef454fa1 100644
--- a/libs/vkd3d/vkd3d_private.h
+++ b/libs/vkd3d/vkd3d_private.h
@@ -131,6 +131,7 @@ struct vkd3d_vulkan_info
bool EXT_debug_marker;
bool EXT_depth_clip_enable;
bool EXT_descriptor_indexing;
+ bool EXT_robustness2;
bool EXT_shader_demote_to_helper_invocation;
bool EXT_shader_stencil_export;
bool EXT_texel_buffer_alignment;
@@ -1450,6 +1451,10 @@ struct d3d12_device
unsigned int format_compatibility_list_count;
const struct vkd3d_format_compatibility_list *format_compatibility_lists;
struct vkd3d_null_resources null_resources;
+ void (*create_null_srv)(struct d3d12_desc *descriptor, struct d3d12_device *device,
+ const D3D12_SHADER_RESOURCE_VIEW_DESC *desc);
+ void (*create_null_uav)(struct d3d12_desc *descriptor, struct d3d12_device *device,
+ const D3D12_UNORDERED_ACCESS_VIEW_DESC *desc);
struct vkd3d_uav_clear_state uav_clear_state;
VkDescriptorPoolSize vk_pool_sizes[VKD3D_DESCRIPTOR_POOL_COUNT];
--
2.34.1
More information about the wine-devel
mailing list