Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use EXT_host_image_copy if supported #1691

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 63 additions & 5 deletions libs/vkd3d/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] =
VK_EXTENSION(EXT_PAGEABLE_DEVICE_LOCAL_MEMORY, EXT_pageable_device_local_memory),
VK_EXTENSION(EXT_MEMORY_PRIORITY, EXT_memory_priority),
VK_EXTENSION(EXT_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS, EXT_dynamic_rendering_unused_attachments),
VK_EXTENSION(EXT_HOST_IMAGE_COPY, EXT_host_image_copy),
/* AMD extensions */
VK_EXTENSION(AMD_BUFFER_MARKER, AMD_buffer_marker),
VK_EXTENSION(AMD_DEVICE_COHERENT_MEMORY, AMD_device_coherent_memory),
Expand Down Expand Up @@ -1373,6 +1374,16 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i
info->features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
info->properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;

/** Some property structs use dynamically sized arrays, so query the required sizes first */
if (vulkan_info->EXT_host_image_copy)
{
info->host_image_copy_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_PROPERTIES_EXT;
vk_prepend_struct(&info->properties2, &info->host_image_copy_properties);
}

if (info->properties2.pNext)
VK_CALL(vkGetPhysicalDeviceProperties2(device->vk_physical_device, &info->properties2));

info->vulkan_1_1_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
vk_prepend_struct(&info->features2, &info->vulkan_1_1_features);
info->vulkan_1_1_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES;
Expand Down Expand Up @@ -1690,10 +1701,26 @@ static void vkd3d_physical_device_info_init(struct vkd3d_physical_device_info *i
vk_prepend_struct(&info->properties2, &info->memory_decompression_properties);
}

if (vulkan_info->EXT_host_image_copy)
{
info->host_image_copy_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT;
vk_prepend_struct(&info->features2, &info->host_image_copy_features);

/* The property struct was added to the pNext chain earlier to query array sizes */
info->host_image_copy_properties.pCopySrcLayouts = vkd3d_calloc(info->host_image_copy_properties.copySrcLayoutCount, sizeof(VkImageLayout));
info->host_image_copy_properties.pCopyDstLayouts = vkd3d_calloc(info->host_image_copy_properties.copyDstLayoutCount, sizeof(VkImageLayout));
}

VK_CALL(vkGetPhysicalDeviceFeatures2(device->vk_physical_device, &info->features2));
VK_CALL(vkGetPhysicalDeviceProperties2(device->vk_physical_device, &info->properties2));
}

static void vkd3d_physical_device_info_cleanup(struct vkd3d_physical_device_info *info)
{
vkd3d_free(info->host_image_copy_properties.pCopySrcLayouts);
vkd3d_free(info->host_image_copy_properties.pCopyDstLayouts);
}

static void vkd3d_trace_physical_device_properties(const VkPhysicalDeviceProperties *properties)
{
TRACE("Device name: %s.\n", properties->deviceName);
Expand Down Expand Up @@ -2648,13 +2675,14 @@ static HRESULT vkd3d_create_vk_device(struct d3d12_device *device,
if (FAILED(hr = vkd3d_init_device_caps(device, create_info, &device->device_info)))
{
vkd3d_free(user_extension_supported);
return hr;
goto cleanup_device_info;
}

if (!(extensions = vkd3d_calloc(extension_count, sizeof(*extensions))))
{
vkd3d_free(user_extension_supported);
return E_OUTOFMEMORY;
hr = E_OUTOFMEMORY;
goto cleanup_device_info;
}

/* Create device */
Expand Down Expand Up @@ -2688,15 +2716,16 @@ static HRESULT vkd3d_create_vk_device(struct d3d12_device *device,
{
ERR("Failed to create Vulkan device, vr %d.\n", vr);
vkd3d_free((void *)extensions);
return hresult_from_vk_result(vr);
hr = hresult_from_vk_result(vr);
goto cleanup_device_info;
}

if (FAILED(hr = vkd3d_load_vk_device_procs(&device->vk_procs, vk_procs, vk_device)))
{
ERR("Failed to load device procs, hr %#x.\n", hr);
if (device->vk_procs.vkDestroyDevice)
device->vk_procs.vkDestroyDevice(vk_device, NULL);
return hr;
goto cleanup_device_info;
}

device->vk_device = vk_device;
Expand All @@ -2705,7 +2734,7 @@ static HRESULT vkd3d_create_vk_device(struct d3d12_device *device,
{
ERR("Failed to create queues, hr %#x.\n", hr);
device->vk_procs.vkDestroyDevice(vk_device, NULL);
return hr;
goto cleanup_device_info;
}

device->vk_info.extension_count = device_info.enabledExtensionCount;
Expand All @@ -2714,6 +2743,10 @@ static HRESULT vkd3d_create_vk_device(struct d3d12_device *device,
TRACE("Created Vulkan device %p.\n", vk_device);

return hr;

cleanup_device_info:
vkd3d_physical_device_info_cleanup(&device->device_info);
return hr;
}

struct d3d12_device_singleton
Expand Down Expand Up @@ -2927,6 +2960,29 @@ uint64_t d3d12_device_get_descriptor_heap_gpu_va(struct d3d12_device *device, D3
return va;
}

bool d3d12_device_supports_host_image_copy(struct d3d12_device *device, VkImageLayout layout)
{
bool supports_layout_src = false;
bool supports_layout_dst = false;

if (!device->device_info.host_image_copy_features.hostImageCopy)
return false;

for (uint32_t i = 0; i < device->device_info.host_image_copy_properties.copySrcLayoutCount; i++)
{
if ((supports_layout_src = (device->device_info.host_image_copy_properties.pCopySrcLayouts[i] == layout)))
break;
}

for (uint32_t i = 0; i < device->device_info.host_image_copy_properties.copyDstLayoutCount; i++)
{
if ((supports_layout_dst = (device->device_info.host_image_copy_properties.pCopyDstLayouts[i] == layout)))
break;
}

return supports_layout_src && supports_layout_dst;
}

void d3d12_device_return_descriptor_heap_gpu_va(struct d3d12_device *device, uint64_t va)
{
/* Fixup the magic shift we used when allocating. */
Expand Down Expand Up @@ -3189,6 +3245,7 @@ static void d3d12_device_destroy(struct d3d12_device *device)
#endif

vkd3d_free((void *)device->vk_info.extension_names);
vkd3d_physical_device_info_cleanup(&device->device_info);
VK_CALL(vkDestroyDevice(device->vk_device, NULL));
rwlock_destroy(&device->fragment_output_lock);
rwlock_destroy(&device->vertex_input_lock);
Expand Down Expand Up @@ -8035,6 +8092,7 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
vkd3d_private_store_destroy(&device->private_store);
out_free_vk_resources:
d3d12_device_destroy_vkd3d_queues(device);
vkd3d_physical_device_info_cleanup(&device->device_info);
vk_procs = &device->vk_procs;
VK_CALL(vkDestroyDevice(device->vk_device, NULL));
out_free_instance:
Expand Down
Loading