From 5e266f70a2688f814a4f0c473d2bad599078702e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Tue, 27 Sep 2016 12:13:37 +0200 Subject: [PATCH] libs/vkd3d: Store VkPhysicalDeviceMemoryProperties in "d3d12_device". --- libs/vkd3d/device.c | 23 +++++++++++++++++++++-- libs/vkd3d/utils.c | 36 ++++++++++++++++++++++++++++++++++++ libs/vkd3d/vkd3d_private.h | 3 +++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 852f23a4..a8db03f6 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -81,12 +81,13 @@ static void vkd3d_instance_destroy(struct vkd3d_instance *instance) static void vkd3d_trace_physical_device(VkPhysicalDevice device, const struct vkd3d_vk_instance_procs *vk_procs) { + VkPhysicalDeviceMemoryProperties memory_properties; VkPhysicalDeviceProperties device_properties; VkQueueFamilyProperties *queue_properties; VkPhysicalDeviceFeatures features; VkPhysicalDeviceLimits *limits; + unsigned int i, j; uint32_t count; - unsigned int i; VK_CALL(vkGetPhysicalDeviceProperties(device, &device_properties)); TRACE("Device name: %s.\n", device_properties.deviceName); @@ -104,13 +105,29 @@ static void vkd3d_trace_physical_device(VkPhysicalDevice device, for (i = 0; i < count; ++i) { - TRACE(" Queue family[%u]: flags %s, count %u, timestamp bits %u, image transfer granularity %s.\n", + TRACE(" Queue family [%u]: flags %s, count %u, timestamp bits %u, image transfer granularity %s.\n", i, debug_vk_queue_flags(queue_properties[i].queueFlags), queue_properties[i].queueCount, queue_properties[i].timestampValidBits, debug_vk_extent_3d(queue_properties[i].minImageTransferGranularity)); } vkd3d_free(queue_properties); + VK_CALL(vkGetPhysicalDeviceMemoryProperties(device, &memory_properties)); + for (i = 0; i < memory_properties.memoryHeapCount; ++i) + { + const VkMemoryHeap *heap = &memory_properties.memoryHeaps[i]; + TRACE("Memory heap [%u]: size %s (%lu MiB), flags %s, memory types:\n", + i, debugstr_uint64(heap->size), (unsigned long)(heap->size / 1024 / 1024), + debug_vk_memory_heap_flags(heap->flags)); + for (j = 0; j < memory_properties.memoryTypeCount; ++j) + { + const VkMemoryType *type = &memory_properties.memoryTypes[j]; + if (type->heapIndex != i) + continue; + TRACE(" Memory type [%u]: flags %s.\n", j, debug_vk_memory_property_flags(type->propertyFlags)); + } + } + limits = &device_properties.limits; TRACE("Device limits:\n"); TRACE(" maxImageDimension1D: %u.\n", limits->maxImageDimension1D); @@ -394,6 +411,8 @@ static HRESULT vkd3d_create_vk_device(struct d3d12_device *device) TRACE("Using queue family %u for direct command queues.\n", direct_queue_family_index); TRACE("Using queue family %u for copy command queues.\n", copy_queue_family_index); + VK_CALL(vkGetPhysicalDeviceMemoryProperties(selected_physical_device, &device->memory_properties)); + /* Create device */ VK_CALL(vkGetPhysicalDeviceFeatures(selected_physical_device, &device_features)); diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index ada10a43..da627c7c 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -95,6 +95,42 @@ const char *debug_vk_queue_flags(VkQueueFlags flags) return vkd3d_dbg_sprintf("%s", &buffer[3]); } +const char *debug_vk_memory_heap_flags(VkMemoryHeapFlags flags) +{ + char buffer[50]; + + buffer[0] = '\0'; +#define FLAG_TO_STR(f) if (flags & f) { strcat(buffer, " | "#f); flags &= ~f; } + FLAG_TO_STR(VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) +#undef FLAG_TO_STR + if (flags) + FIXME("Unrecognized flag(s) %#x.\n", flags); + + if (!buffer[0]) + return "0"; + return vkd3d_dbg_sprintf("%s", &buffer[3]); +} + +const char *debug_vk_memory_property_flags(VkMemoryPropertyFlags flags) +{ + char buffer[200]; + + buffer[0] = '\0'; +#define FLAG_TO_STR(f) if (flags & f) { strcat(buffer, " | "#f); flags &= ~f; } + FLAG_TO_STR(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + FLAG_TO_STR(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) + FLAG_TO_STR(VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) + FLAG_TO_STR(VK_MEMORY_PROPERTY_HOST_CACHED_BIT) + FLAG_TO_STR(VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) +#undef FLAG_TO_STR + if (flags) + FIXME("Unrecognized flag(s) %#x.\n", flags); + + if (!buffer[0]) + return "0"; + return vkd3d_dbg_sprintf("%s", &buffer[3]); +} + HRESULT hresult_from_vk_result(VkResult vr) { switch (vr) diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 951fbbea..cf22303e 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -159,6 +159,7 @@ struct d3d12_device unsigned int direct_queue_family_index; unsigned int copy_queue_family_index; + VkPhysicalDeviceMemoryProperties memory_properties; struct vkd3d_instance vkd3d_instance; }; @@ -173,6 +174,8 @@ HRESULT return_interface(IUnknown *iface, REFIID iface_riid, REFIID requested_riid, void **object) DECLSPEC_HIDDEN; const char *debug_vk_extent_3d(VkExtent3D extent) DECLSPEC_HIDDEN; +const char *debug_vk_memory_heap_flags(VkMemoryHeapFlags flags) DECLSPEC_HIDDEN; +const char *debug_vk_memory_property_flags(VkMemoryPropertyFlags flags) DECLSPEC_HIDDEN; const char *debug_vk_queue_flags(VkQueueFlags flags) DECLSPEC_HIDDEN; static inline void *vkd3d_malloc(size_t size)