Commit ab747c6e authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

winevulkan: Separate PE and Unix VkPhysicalDevice strucrts.

parent 9a7a2ab2
...@@ -256,6 +256,7 @@ VkResult WINAPI vkCreateInstance(const VkInstanceCreateInfo *create_info, ...@@ -256,6 +256,7 @@ VkResult WINAPI vkCreateInstance(const VkInstanceCreateInfo *create_info,
{ {
struct vkCreateInstance_params params; struct vkCreateInstance_params params;
struct VkInstance_T *instance; struct VkInstance_T *instance;
uint32_t phys_dev_count = 8, i;
VkResult result; VkResult result;
TRACE("create_info %p, allocator %p, instance %p\n", create_info, allocator, ret); TRACE("create_info %p, allocator %p, instance %p\n", create_info, allocator, ret);
...@@ -263,14 +264,25 @@ VkResult WINAPI vkCreateInstance(const VkInstanceCreateInfo *create_info, ...@@ -263,14 +264,25 @@ VkResult WINAPI vkCreateInstance(const VkInstanceCreateInfo *create_info,
if (!wine_vk_init_once()) if (!wine_vk_init_once())
return VK_ERROR_INITIALIZATION_FAILED; return VK_ERROR_INITIALIZATION_FAILED;
if (!(instance = alloc_vk_object(sizeof(*instance)))) for (;;)
return VK_ERROR_OUT_OF_HOST_MEMORY; {
if (!(instance = alloc_vk_object(FIELD_OFFSET(struct VkInstance_T, phys_devs[phys_dev_count]))))
return VK_ERROR_OUT_OF_HOST_MEMORY;
instance->phys_dev_count = phys_dev_count;
for (i = 0; i < phys_dev_count; i++)
instance->phys_devs[i].base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
params.pCreateInfo = create_info;
params.pAllocator = allocator;
params.pInstance = ret;
params.client_ptr = instance;
result = vk_unix_call(unix_vkCreateInstance, &params);
if (instance->phys_dev_count <= phys_dev_count)
break;
phys_dev_count = instance->phys_dev_count;
free(instance);
}
params.pCreateInfo = create_info;
params.pAllocator = allocator;
params.pInstance = ret;
params.client_ptr = instance;
result = vk_unix_call(unix_vkCreateInstance, &params);
if (!instance->base.unix_handle) if (!instance->base.unix_handle)
free(instance); free(instance);
return result; return result;
......
...@@ -1063,6 +1063,8 @@ class VkHandle(object): ...@@ -1063,6 +1063,8 @@ class VkHandle(object):
return "wine_instance_from_handle({0})->funcs".format(param) return "wine_instance_from_handle({0})->funcs".format(param)
elif self.name == "VkDevice": elif self.name == "VkDevice":
return "wine_device_from_handle({0})->funcs".format(param) return "wine_device_from_handle({0})->funcs".format(param)
elif self.name == "VkPhysicalDevice":
return "wine_phys_dev_from_handle({0})->instance->funcs".format(param)
elif self.name == "VkQueue": elif self.name == "VkQueue":
return "wine_queue_from_handle({0})->device->funcs".format(param) return "wine_queue_from_handle({0})->device->funcs".format(param)
elif self.parent in ["VkInstance", "VkPhysicalDevice"]: elif self.parent in ["VkInstance", "VkPhysicalDevice"]:
...@@ -1106,6 +1108,8 @@ class VkHandle(object): ...@@ -1106,6 +1108,8 @@ class VkHandle(object):
return "wine_device_from_handle({0})->device".format(name) return "wine_device_from_handle({0})->device".format(name)
if self.name == "VkInstance": if self.name == "VkInstance":
return "wine_instance_from_handle({0})->instance".format(name) return "wine_instance_from_handle({0})->instance".format(name)
if self.name == "VkPhysicalDevice":
return "wine_phys_dev_from_handle({0})->phys_dev".format(name)
if self.name == "VkQueue": if self.name == "VkQueue":
return "wine_queue_from_handle({0})->queue".format(name) return "wine_queue_from_handle({0})->queue".format(name)
if self.name == "VkSurfaceKHR": if self.name == "VkSurfaceKHR":
...@@ -1115,8 +1119,6 @@ class VkHandle(object): ...@@ -1115,8 +1119,6 @@ class VkHandle(object):
if self.name == "VkCommandBuffer": if self.name == "VkCommandBuffer":
native_handle_name = "command_buffer" native_handle_name = "command_buffer"
if self.name == "VkPhysicalDevice":
native_handle_name = "phys_dev"
if native_handle_name: if native_handle_name:
return "{0}->{1}".format(name, native_handle_name) return "{0}->{1}".format(name, native_handle_name)
......
...@@ -211,7 +211,7 @@ static VkBool32 debug_report_callback_conversion(VkDebugReportFlagsEXT flags, Vk ...@@ -211,7 +211,7 @@ static VkBool32 debug_report_callback_conversion(VkDebugReportFlagsEXT flags, Vk
&ret_ptr, &ret_len ); &ret_ptr, &ret_len );
} }
static void wine_vk_physical_device_free(struct VkPhysicalDevice_T *phys_dev) static void wine_vk_physical_device_free(struct wine_phys_dev *phys_dev)
{ {
if (!phys_dev) if (!phys_dev)
return; return;
...@@ -221,10 +221,10 @@ static void wine_vk_physical_device_free(struct VkPhysicalDevice_T *phys_dev) ...@@ -221,10 +221,10 @@ static void wine_vk_physical_device_free(struct VkPhysicalDevice_T *phys_dev)
free(phys_dev); free(phys_dev);
} }
static struct VkPhysicalDevice_T *wine_vk_physical_device_alloc(struct wine_instance *instance, static struct wine_phys_dev *wine_vk_physical_device_alloc(struct wine_instance *instance,
VkPhysicalDevice phys_dev) VkPhysicalDevice phys_dev, VkPhysicalDevice handle)
{ {
struct VkPhysicalDevice_T *object; struct wine_phys_dev *object;
uint32_t num_host_properties, num_properties = 0; uint32_t num_host_properties, num_properties = 0;
VkExtensionProperties *host_properties = NULL; VkExtensionProperties *host_properties = NULL;
VkResult res; VkResult res;
...@@ -233,11 +233,12 @@ static struct VkPhysicalDevice_T *wine_vk_physical_device_alloc(struct wine_inst ...@@ -233,11 +233,12 @@ static struct VkPhysicalDevice_T *wine_vk_physical_device_alloc(struct wine_inst
if (!(object = calloc(1, sizeof(*object)))) if (!(object = calloc(1, sizeof(*object))))
return NULL; return NULL;
object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
object->instance = instance; object->instance = instance;
object->handle = handle;
object->phys_dev = phys_dev; object->phys_dev = phys_dev;
WINE_VK_ADD_DISPATCHABLE_MAPPING(instance, object, phys_dev, object); handle->base.unix_handle = (uintptr_t)object;
WINE_VK_ADD_DISPATCHABLE_MAPPING(instance, handle, phys_dev, object);
res = instance->funcs.p_vkEnumerateDeviceExtensionProperties(phys_dev, res = instance->funcs.p_vkEnumerateDeviceExtensionProperties(phys_dev,
NULL, &num_host_properties, NULL); NULL, &num_host_properties, NULL);
...@@ -550,6 +551,13 @@ static VkResult wine_vk_instance_load_physical_devices(struct wine_instance *ins ...@@ -550,6 +551,13 @@ static VkResult wine_vk_instance_load_physical_devices(struct wine_instance *ins
if (!phys_dev_count) if (!phys_dev_count)
return res; return res;
if (phys_dev_count > instance->handle->phys_dev_count)
{
instance->handle->phys_dev_count = phys_dev_count;
return VK_ERROR_OUT_OF_POOL_MEMORY;
}
instance->handle->phys_dev_count = phys_dev_count;
if (!(tmp_phys_devs = calloc(phys_dev_count, sizeof(*tmp_phys_devs)))) if (!(tmp_phys_devs = calloc(phys_dev_count, sizeof(*tmp_phys_devs))))
return VK_ERROR_OUT_OF_HOST_MEMORY; return VK_ERROR_OUT_OF_HOST_MEMORY;
...@@ -570,7 +578,8 @@ static VkResult wine_vk_instance_load_physical_devices(struct wine_instance *ins ...@@ -570,7 +578,8 @@ static VkResult wine_vk_instance_load_physical_devices(struct wine_instance *ins
/* Wrap each native physical device handle into a dispatchable object for the ICD loader. */ /* Wrap each native physical device handle into a dispatchable object for the ICD loader. */
for (i = 0; i < phys_dev_count; i++) for (i = 0; i < phys_dev_count; i++)
{ {
struct VkPhysicalDevice_T *phys_dev = wine_vk_physical_device_alloc(instance, tmp_phys_devs[i]); struct wine_phys_dev *phys_dev = wine_vk_physical_device_alloc(instance, tmp_phys_devs[i],
&instance->handle->phys_devs[i]);
if (!phys_dev) if (!phys_dev)
{ {
ERR("Unable to allocate memory for physical device!\n"); ERR("Unable to allocate memory for physical device!\n");
...@@ -587,14 +596,14 @@ static VkResult wine_vk_instance_load_physical_devices(struct wine_instance *ins ...@@ -587,14 +596,14 @@ static VkResult wine_vk_instance_load_physical_devices(struct wine_instance *ins
return VK_SUCCESS; return VK_SUCCESS;
} }
static struct VkPhysicalDevice_T *wine_vk_instance_wrap_physical_device(struct wine_instance *instance, static struct wine_phys_dev *wine_vk_instance_wrap_physical_device(struct wine_instance *instance,
VkPhysicalDevice physical_device) VkPhysicalDevice physical_device)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < instance->phys_dev_count; ++i) for (i = 0; i < instance->phys_dev_count; ++i)
{ {
struct VkPhysicalDevice_T *current = instance->phys_devs[i]; struct wine_phys_dev *current = instance->phys_devs[i];
if (current->phys_dev == physical_device) if (current->phys_dev == physical_device)
return current; return current;
} }
...@@ -697,7 +706,7 @@ NTSTATUS wine_vkAllocateCommandBuffers(void *args) ...@@ -697,7 +706,7 @@ NTSTATUS wine_vkAllocateCommandBuffers(void *args)
NTSTATUS wine_vkCreateDevice(void *args) NTSTATUS wine_vkCreateDevice(void *args)
{ {
struct vkCreateDevice_params *params = args; struct vkCreateDevice_params *params = args;
VkPhysicalDevice phys_dev = params->physicalDevice; struct wine_phys_dev *phys_dev = wine_phys_dev_from_handle(params->physicalDevice);
const VkDeviceCreateInfo *create_info = params->pCreateInfo; const VkDeviceCreateInfo *create_info = params->pCreateInfo;
const VkAllocationCallbacks *allocator = params->pAllocator; const VkAllocationCallbacks *allocator = params->pAllocator;
VkDevice *ret_device = params->pDevice; VkDevice *ret_device = params->pDevice;
...@@ -911,7 +920,7 @@ NTSTATUS wine_vkDestroyInstance(void *args) ...@@ -911,7 +920,7 @@ NTSTATUS wine_vkDestroyInstance(void *args)
NTSTATUS wine_vkEnumerateDeviceExtensionProperties(void *args) NTSTATUS wine_vkEnumerateDeviceExtensionProperties(void *args)
{ {
struct vkEnumerateDeviceExtensionProperties_params *params = args; struct vkEnumerateDeviceExtensionProperties_params *params = args;
VkPhysicalDevice phys_dev = params->physicalDevice; struct wine_phys_dev *phys_dev = wine_phys_dev_from_handle(params->physicalDevice);
const char *layer_name = params->pLayerName; const char *layer_name = params->pLayerName;
uint32_t *count = params->pPropertyCount; uint32_t *count = params->pPropertyCount;
VkExtensionProperties *properties = params->pProperties; VkExtensionProperties *properties = params->pProperties;
...@@ -1053,7 +1062,7 @@ NTSTATUS wine_vkEnumeratePhysicalDevices(void *args) ...@@ -1053,7 +1062,7 @@ NTSTATUS wine_vkEnumeratePhysicalDevices(void *args)
*count = min(*count, instance->phys_dev_count); *count = min(*count, instance->phys_dev_count);
for (i = 0; i < *count; i++) for (i = 0; i < *count; i++)
{ {
devices[i] = instance->phys_devs[i]; devices[i] = instance->phys_devs[i]->handle;
} }
TRACE("Returning %u devices.\n", *count); TRACE("Returning %u devices.\n", *count);
...@@ -1218,8 +1227,10 @@ static VkResult wine_vk_enumerate_physical_device_groups(struct wine_instance *i ...@@ -1218,8 +1227,10 @@ static VkResult wine_vk_enumerate_physical_device_groups(struct wine_instance *i
for (j = 0; j < current->physicalDeviceCount; ++j) for (j = 0; j < current->physicalDeviceCount; ++j)
{ {
VkPhysicalDevice dev = current->physicalDevices[j]; VkPhysicalDevice dev = current->physicalDevices[j];
if (!(current->physicalDevices[j] = wine_vk_instance_wrap_physical_device(instance, dev))) struct wine_phys_dev *phys_dev = wine_vk_instance_wrap_physical_device(instance, dev);
if (!phys_dev)
return VK_ERROR_INITIALIZATION_FAILED; return VK_ERROR_INITIALIZATION_FAILED;
current->physicalDevices[j] = phys_dev->handle;
} }
} }
...@@ -1434,7 +1445,7 @@ NTSTATUS wine_vkGetCalibratedTimestampsEXT(void *args) ...@@ -1434,7 +1445,7 @@ NTSTATUS wine_vkGetCalibratedTimestampsEXT(void *args)
NTSTATUS wine_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(void *args) NTSTATUS wine_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(void *args)
{ {
struct vkGetPhysicalDeviceCalibrateableTimeDomainsEXT_params *params = args; struct vkGetPhysicalDeviceCalibrateableTimeDomainsEXT_params *params = args;
VkPhysicalDevice phys_dev = params->physicalDevice; struct wine_phys_dev *phys_dev = wine_phys_dev_from_handle(params->physicalDevice);
uint32_t *time_domain_count = params->pTimeDomainCount; uint32_t *time_domain_count = params->pTimeDomainCount;
VkTimeDomainEXT *time_domains = params->pTimeDomains; VkTimeDomainEXT *time_domains = params->pTimeDomains;
BOOL supports_device = FALSE, supports_monotonic = FALSE, supports_monotonic_raw = FALSE; BOOL supports_device = FALSE, supports_monotonic = FALSE, supports_monotonic_raw = FALSE;
...@@ -1591,7 +1602,7 @@ NTSTATUS wine_vkDestroySurfaceKHR(void *args) ...@@ -1591,7 +1602,7 @@ NTSTATUS wine_vkDestroySurfaceKHR(void *args)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static inline void adjust_max_image_count(VkPhysicalDevice phys_dev, VkSurfaceCapabilitiesKHR* capabilities) static inline void adjust_max_image_count(struct wine_phys_dev *phys_dev, VkSurfaceCapabilitiesKHR* capabilities)
{ {
/* Many Windows games, for example Strange Brigade, No Man's Sky, Path of Exile /* Many Windows games, for example Strange Brigade, No Man's Sky, Path of Exile
* and World War Z, do not expect that maxImageCount can be set to 0. * and World War Z, do not expect that maxImageCount can be set to 0.
...@@ -1609,14 +1620,14 @@ static inline void adjust_max_image_count(VkPhysicalDevice phys_dev, VkSurfaceCa ...@@ -1609,14 +1620,14 @@ static inline void adjust_max_image_count(VkPhysicalDevice phys_dev, VkSurfaceCa
NTSTATUS wine_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(void *args) NTSTATUS wine_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(void *args)
{ {
struct vkGetPhysicalDeviceSurfaceCapabilitiesKHR_params *params = args; struct vkGetPhysicalDeviceSurfaceCapabilitiesKHR_params *params = args;
VkPhysicalDevice phys_dev = params->physicalDevice; struct wine_phys_dev *phys_dev = wine_phys_dev_from_handle(params->physicalDevice);
VkSurfaceKHR surface = params->surface; VkSurfaceKHR surface = params->surface;
VkSurfaceCapabilitiesKHR *capabilities = params->pSurfaceCapabilities; VkSurfaceCapabilitiesKHR *capabilities = params->pSurfaceCapabilities;
VkResult res; VkResult res;
TRACE("%p, 0x%s, %p\n", phys_dev, wine_dbgstr_longlong(surface), capabilities); TRACE("%p, 0x%s, %p\n", phys_dev, wine_dbgstr_longlong(surface), capabilities);
res = thunk_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev, surface, capabilities); res = thunk_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev->handle, surface, capabilities);
if (res == VK_SUCCESS) if (res == VK_SUCCESS)
adjust_max_image_count(phys_dev, capabilities); adjust_max_image_count(phys_dev, capabilities);
...@@ -1627,14 +1638,14 @@ NTSTATUS wine_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(void *args) ...@@ -1627,14 +1638,14 @@ NTSTATUS wine_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(void *args)
NTSTATUS wine_vkGetPhysicalDeviceSurfaceCapabilities2KHR(void *args) NTSTATUS wine_vkGetPhysicalDeviceSurfaceCapabilities2KHR(void *args)
{ {
struct vkGetPhysicalDeviceSurfaceCapabilities2KHR_params *params = args; struct vkGetPhysicalDeviceSurfaceCapabilities2KHR_params *params = args;
VkPhysicalDevice phys_dev = params->physicalDevice; struct wine_phys_dev *phys_dev = wine_phys_dev_from_handle(params->physicalDevice);
const VkPhysicalDeviceSurfaceInfo2KHR *surface_info = params->pSurfaceInfo; const VkPhysicalDeviceSurfaceInfo2KHR *surface_info = params->pSurfaceInfo;
VkSurfaceCapabilities2KHR *capabilities = params->pSurfaceCapabilities; VkSurfaceCapabilities2KHR *capabilities = params->pSurfaceCapabilities;
VkResult res; VkResult res;
TRACE("%p, %p, %p\n", phys_dev, surface_info, capabilities); TRACE("%p, %p, %p\n", phys_dev, surface_info, capabilities);
res = thunk_vkGetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev, surface_info, capabilities); res = thunk_vkGetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev->handle, surface_info, capabilities);
if (res == VK_SUCCESS) if (res == VK_SUCCESS)
adjust_max_image_count(phys_dev, &capabilities->surfaceCapabilities); adjust_max_image_count(phys_dev, &capabilities->surfaceCapabilities);
......
...@@ -54,9 +54,16 @@ struct wine_vk_base ...@@ -54,9 +54,16 @@ struct wine_vk_base
UINT64 unix_handle; UINT64 unix_handle;
}; };
struct VkPhysicalDevice_T
{
struct wine_vk_base base;
};
struct VkInstance_T struct VkInstance_T
{ {
struct wine_vk_base base; struct wine_vk_base base;
uint32_t phys_dev_count;
struct VkPhysicalDevice_T phys_devs[1];
}; };
struct VkQueue_T struct VkQueue_T
......
...@@ -56,7 +56,7 @@ struct VkCommandBuffer_T ...@@ -56,7 +56,7 @@ struct VkCommandBuffer_T
struct wine_device struct wine_device
{ {
struct vulkan_device_funcs funcs; struct vulkan_device_funcs funcs;
struct VkPhysicalDevice_T *phys_dev; /* parent */ struct wine_phys_dev *phys_dev; /* parent */
VkDevice handle; /* client device */ VkDevice handle; /* client device */
VkDevice device; /* native device */ VkDevice device; /* native device */
...@@ -96,7 +96,7 @@ struct wine_instance ...@@ -96,7 +96,7 @@ struct wine_instance
/* We cache devices as we need to wrap them as they are /* We cache devices as we need to wrap them as they are
* dispatchable objects. * dispatchable objects.
*/ */
struct VkPhysicalDevice_T **phys_devs; struct wine_phys_dev **phys_devs;
uint32_t phys_dev_count; uint32_t phys_dev_count;
VkBool32 enable_wrapper_list; VkBool32 enable_wrapper_list;
...@@ -118,10 +118,11 @@ static inline struct wine_instance *wine_instance_from_handle(VkInstance handle) ...@@ -118,10 +118,11 @@ static inline struct wine_instance *wine_instance_from_handle(VkInstance handle)
return (struct wine_instance *)(uintptr_t)handle->base.unix_handle; return (struct wine_instance *)(uintptr_t)handle->base.unix_handle;
} }
struct VkPhysicalDevice_T struct wine_phys_dev
{ {
struct wine_vk_base base;
struct wine_instance *instance; /* parent */ struct wine_instance *instance; /* parent */
VkPhysicalDevice handle; /* client physical device */
VkPhysicalDevice phys_dev; /* native physical device */ VkPhysicalDevice phys_dev; /* native physical device */
VkExtensionProperties *extensions; VkExtensionProperties *extensions;
...@@ -130,6 +131,11 @@ struct VkPhysicalDevice_T ...@@ -130,6 +131,11 @@ struct VkPhysicalDevice_T
struct wine_vk_mapping mapping; struct wine_vk_mapping mapping;
}; };
static inline struct wine_phys_dev *wine_phys_dev_from_handle(VkPhysicalDevice handle)
{
return (struct wine_phys_dev *)(uintptr_t)handle->base.unix_handle;
}
struct wine_queue struct wine_queue
{ {
struct wine_device *device; /* parent */ struct wine_device *device; /* parent */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment