Re: [Mesa-dev] [PATCH 06/22] anv/wsi/x11: push anv_device out of the init/finish routines

2016-10-18 Thread Jason Ekstrand
Feel free to shove an alloc in wsi_device.  Might make some of this a bit
simpler.  I guess we usually shove one in wsi_implementation so it's not a
big deal.

On Sun, Oct 16, 2016 at 9:24 PM, Dave Airlie  wrote:

> From: Dave Airlie 
>
> ---
>  src/intel/vulkan/anv_wsi.c |  6 +++---
>  src/intel/vulkan/anv_wsi.h |  6 --
>  src/intel/vulkan/anv_wsi_x11.c | 22 --
>  3 files changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
> index 56ed3ec..767fa79 100644
> --- a/src/intel/vulkan/anv_wsi.c
> +++ b/src/intel/vulkan/anv_wsi.c
> @@ -31,7 +31,7 @@ anv_init_wsi(struct anv_physical_device *physical_device)
> memset(physical_device->wsi_device.wsi, 0,
> sizeof(physical_device->wsi_device.wsi));
>
>  #ifdef VK_USE_PLATFORM_XCB_KHR
> -   result = anv_x11_init_wsi(physical_device);
> +   result = anv_x11_init_wsi(_device->wsi_device,
> _device->instance->alloc);
> if (result != VK_SUCCESS)
>return result;
>  #endif
> @@ -40,7 +40,7 @@ anv_init_wsi(struct anv_physical_device *physical_device)
> result = anv_wl_init_wsi(physical_device);
> if (result != VK_SUCCESS) {
>  #ifdef VK_USE_PLATFORM_XCB_KHR
> -  anv_x11_finish_wsi(physical_device);
> +  anv_x11_finish_wsi(_device->wsi_device,
> _device->instance->alloc);
>  #endif
>return result;
> }
> @@ -56,7 +56,7 @@ anv_finish_wsi(struct anv_physical_device
> *physical_device)
> anv_wl_finish_wsi(physical_device);
>  #endif
>  #ifdef VK_USE_PLATFORM_XCB_KHR
> -   anv_x11_finish_wsi(physical_device);
> +   anv_x11_finish_wsi(_device->wsi_device,
> _device->instance->alloc);
>  #endif
>  }
>
> diff --git a/src/intel/vulkan/anv_wsi.h b/src/intel/vulkan/anv_wsi.h
> index 2bb8ee3..e1c8d02 100644
> --- a/src/intel/vulkan/anv_wsi.h
> +++ b/src/intel/vulkan/anv_wsi.h
> @@ -70,8 +70,10 @@ struct anv_swapchain {
>  ANV_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase, VkSurfaceKHR)
>  ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_swapchain, VkSwapchainKHR)
>
> -VkResult anv_x11_init_wsi(struct anv_physical_device *physical_device);
> -void anv_x11_finish_wsi(struct anv_physical_device *physical_device);
> +VkResult anv_x11_init_wsi(struct anv_wsi_device *wsi_device,
> +  const VkAllocationCallbacks *alloc);
> +void anv_x11_finish_wsi(struct anv_wsi_device *wsi_device,
> +const VkAllocationCallbacks *alloc);
>  VkResult anv_wl_init_wsi(struct anv_physical_device *physical_device);
>  void anv_wl_finish_wsi(struct anv_physical_device *physical_device);
>
> diff --git a/src/intel/vulkan/anv_wsi_x11.c b/src/intel/vulkan/anv_wsi_
> x11.c
> index 595c922..ccaabea 100644
> --- a/src/intel/vulkan/anv_wsi_x11.c
> +++ b/src/intel/vulkan/anv_wsi_x11.c
> @@ -897,12 +897,13 @@ fail_register:
>  }
>
>  VkResult
> -anv_x11_init_wsi(struct anv_physical_device *device)
> +anv_x11_init_wsi(struct anv_wsi_device *wsi_device,
> + const VkAllocationCallbacks *alloc)
>  {
> struct wsi_x11 *wsi;
> VkResult result;
>
> -   wsi = vk_alloc(>instance->alloc, sizeof(*wsi), 8,
> +   wsi = vk_alloc(alloc, sizeof(*wsi), 8,
> VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
> if (!wsi) {
>result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
> @@ -934,33 +935,34 @@ anv_x11_init_wsi(struct anv_physical_device *device)
> wsi->base.get_present_modes = x11_surface_get_present_modes;
> wsi->base.create_swapchain = x11_surface_create_swapchain;
>
> -   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XCB] = >base;
> -   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XLIB] = >base;
> +   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB] = >base;
> +   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = >base;
>
> return VK_SUCCESS;
>
>  fail_mutex:
> pthread_mutex_destroy(>mutex);
>  fail_alloc:
> -   vk_free(>instance->alloc, wsi);
> +   vk_free(alloc, wsi);
>  fail:
> -   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
> -   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XLIB] = NULL;
> +   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
> +   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = NULL;
>
> return result;
>  }
>
>  void
> -anv_x11_finish_wsi(struct anv_physical_device *device)
> +anv_x11_finish_wsi(struct anv_wsi_device *wsi_device,
> +   const VkAllocationCallbacks *alloc)
>  {
> struct wsi_x11 *wsi =
> -  (struct wsi_x11 *)device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XCB];
> +  (struct wsi_x11 *)wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB];
>
> if (wsi) {
>_mesa_hash_table_destroy(wsi->connections, NULL);
>
>pthread_mutex_destroy(>mutex);
>
> -  vk_free(>instance->alloc, wsi);
> +  vk_free(alloc, wsi);
> }
>  }
> --
> 2.5.5
>
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>

[Mesa-dev] [PATCH 06/22] anv/wsi/x11: push anv_device out of the init/finish routines

2016-10-16 Thread Dave Airlie
From: Dave Airlie 

---
 src/intel/vulkan/anv_wsi.c |  6 +++---
 src/intel/vulkan/anv_wsi.h |  6 --
 src/intel/vulkan/anv_wsi_x11.c | 22 --
 3 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index 56ed3ec..767fa79 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -31,7 +31,7 @@ anv_init_wsi(struct anv_physical_device *physical_device)
memset(physical_device->wsi_device.wsi, 0, 
sizeof(physical_device->wsi_device.wsi));
 
 #ifdef VK_USE_PLATFORM_XCB_KHR
-   result = anv_x11_init_wsi(physical_device);
+   result = anv_x11_init_wsi(_device->wsi_device, 
_device->instance->alloc);
if (result != VK_SUCCESS)
   return result;
 #endif
@@ -40,7 +40,7 @@ anv_init_wsi(struct anv_physical_device *physical_device)
result = anv_wl_init_wsi(physical_device);
if (result != VK_SUCCESS) {
 #ifdef VK_USE_PLATFORM_XCB_KHR
-  anv_x11_finish_wsi(physical_device);
+  anv_x11_finish_wsi(_device->wsi_device, 
_device->instance->alloc);
 #endif
   return result;
}
@@ -56,7 +56,7 @@ anv_finish_wsi(struct anv_physical_device *physical_device)
anv_wl_finish_wsi(physical_device);
 #endif
 #ifdef VK_USE_PLATFORM_XCB_KHR
-   anv_x11_finish_wsi(physical_device);
+   anv_x11_finish_wsi(_device->wsi_device, 
_device->instance->alloc);
 #endif
 }
 
diff --git a/src/intel/vulkan/anv_wsi.h b/src/intel/vulkan/anv_wsi.h
index 2bb8ee3..e1c8d02 100644
--- a/src/intel/vulkan/anv_wsi.h
+++ b/src/intel/vulkan/anv_wsi.h
@@ -70,8 +70,10 @@ struct anv_swapchain {
 ANV_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase, VkSurfaceKHR)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_swapchain, VkSwapchainKHR)
 
-VkResult anv_x11_init_wsi(struct anv_physical_device *physical_device);
-void anv_x11_finish_wsi(struct anv_physical_device *physical_device);
+VkResult anv_x11_init_wsi(struct anv_wsi_device *wsi_device,
+  const VkAllocationCallbacks *alloc);
+void anv_x11_finish_wsi(struct anv_wsi_device *wsi_device,
+const VkAllocationCallbacks *alloc);
 VkResult anv_wl_init_wsi(struct anv_physical_device *physical_device);
 void anv_wl_finish_wsi(struct anv_physical_device *physical_device);
 
diff --git a/src/intel/vulkan/anv_wsi_x11.c b/src/intel/vulkan/anv_wsi_x11.c
index 595c922..ccaabea 100644
--- a/src/intel/vulkan/anv_wsi_x11.c
+++ b/src/intel/vulkan/anv_wsi_x11.c
@@ -897,12 +897,13 @@ fail_register:
 }
 
 VkResult
-anv_x11_init_wsi(struct anv_physical_device *device)
+anv_x11_init_wsi(struct anv_wsi_device *wsi_device,
+ const VkAllocationCallbacks *alloc)
 {
struct wsi_x11 *wsi;
VkResult result;
 
-   wsi = vk_alloc(>instance->alloc, sizeof(*wsi), 8,
+   wsi = vk_alloc(alloc, sizeof(*wsi), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!wsi) {
   result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -934,33 +935,34 @@ anv_x11_init_wsi(struct anv_physical_device *device)
wsi->base.get_present_modes = x11_surface_get_present_modes;
wsi->base.create_swapchain = x11_surface_create_swapchain;
 
-   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XCB] = >base;
-   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XLIB] = >base;
+   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB] = >base;
+   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = >base;
 
return VK_SUCCESS;
 
 fail_mutex:
pthread_mutex_destroy(>mutex);
 fail_alloc:
-   vk_free(>instance->alloc, wsi);
+   vk_free(alloc, wsi);
 fail:
-   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
-   device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XLIB] = NULL;
+   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
+   wsi_device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = NULL;
 
return result;
 }
 
 void
-anv_x11_finish_wsi(struct anv_physical_device *device)
+anv_x11_finish_wsi(struct anv_wsi_device *wsi_device,
+   const VkAllocationCallbacks *alloc)
 {
struct wsi_x11 *wsi =
-  (struct wsi_x11 *)device->wsi_device.wsi[VK_ICD_WSI_PLATFORM_XCB];
+  (struct wsi_x11 *)wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB];
 
if (wsi) {
   _mesa_hash_table_destroy(wsi->connections, NULL);
 
   pthread_mutex_destroy(>mutex);
 
-  vk_free(>instance->alloc, wsi);
+  vk_free(alloc, wsi);
}
 }
-- 
2.5.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev