Re: [Mesa-dev] [PATCH 14/22] anv/wsi: move further away from passing anv displays around
On Sun, Oct 16, 2016 at 9:24 PM, Dave Airlie wrote: > From: Dave Airlie > > --- > src/intel/vulkan/anv_wsi.c | 28 +++- > src/intel/vulkan/anv_wsi.h | 3 ++- > src/intel/vulkan/anv_wsi_wayland.c | 21 +++-- > src/intel/vulkan/anv_wsi_x11.c | 22 +++--- > 4 files changed, 35 insertions(+), 39 deletions(-) > > diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c > index 514a29f..89bf780 100644 > --- a/src/intel/vulkan/anv_wsi.c > +++ b/src/intel/vulkan/anv_wsi.c > @@ -253,17 +253,21 @@ VkResult anv_CreateSwapchainKHR( > struct anv_wsi_interface *iface = >device->instance->physicalDevice.wsi_device.wsi[surface->platform]; > struct anv_swapchain *swapchain; > + const VkAllocationCallbacks *alloc; > > - VkResult result = iface->create_swapchain(surface, device, > pCreateInfo, > - pAllocator, > &anv_wsi_image_fns, > + if (pAllocator) > + alloc = pAllocator; > + else > + alloc = &device->alloc; > + VkResult result = iface->create_swapchain(surface, _device, > + &device->instance-> > physicalDevice.wsi_device, > + pCreateInfo, > + alloc, &anv_wsi_image_fns, > &swapchain); > if (result != VK_SUCCESS) >return result; > > - if (pAllocator) > - swapchain->alloc = *pAllocator; > - else > - swapchain->alloc = device->alloc; > + swapchain->alloc = *alloc; > > for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++) >swapchain->fences[i] = VK_NULL_HANDLE; > @@ -274,18 +278,24 @@ VkResult anv_CreateSwapchainKHR( > } > > void anv_DestroySwapchainKHR( > -VkDevice device, > +VkDevice _device, > VkSwapchainKHR _swapchain, > const VkAllocationCallbacks* pAllocator) > { > + ANV_FROM_HANDLE(anv_device, device, _device); > ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain); > + const VkAllocationCallbacks *alloc; > > + if (pAllocator) > + alloc = pAllocator; > + else > + alloc = &device->alloc; > This isn't needed. The client is required to pass the same allocator in (if any) to this function as it does to Create. We can just use swapchain->alloc > for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++) { >if (swapchain->fences[i] != VK_NULL_HANDLE) > - anv_DestroyFence(device, swapchain->fences[i], pAllocator); > + anv_DestroyFence(_device, swapchain->fences[i], pAllocator); > } > > - swapchain->destroy(swapchain, pAllocator); > + swapchain->destroy(swapchain, alloc); > } > > VkResult anv_GetSwapchainImagesKHR( > diff --git a/src/intel/vulkan/anv_wsi.h b/src/intel/vulkan/anv_wsi.h > index 2548e41..236133c 100644 > --- a/src/intel/vulkan/anv_wsi.h > +++ b/src/intel/vulkan/anv_wsi.h > @@ -60,7 +60,8 @@ struct anv_wsi_interface { > uint32_t* pPresentModeCount, > VkPresentModeKHR* pPresentModes); > VkResult (*create_swapchain)(VkIcdSurfaceBase *surface, > -struct anv_device *device, > +VkDevice device, > +struct anv_wsi_device *wsi_device, > const VkSwapchainCreateInfoKHR* > pCreateInfo, > const VkAllocationCallbacks* pAllocator, > const struct anv_wsi_image_fns *image_fns, > diff --git a/src/intel/vulkan/anv_wsi_wayland.c > b/src/intel/vulkan/anv_wsi_wayland.c > index e56b3be..16a9647 100644 > --- a/src/intel/vulkan/anv_wsi_wayland.c > +++ b/src/intel/vulkan/anv_wsi_wayland.c > @@ -422,14 +422,6 @@ wsi_wl_surface_get_present_modes(VkIcdSurfaceBase > *surface, > return VK_SUCCESS; > } > > -static VkResult > -wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *surface, > -struct anv_device *device, > -const VkSwapchainCreateInfoKHR* > pCreateInfo, > -const VkAllocationCallbacks* pAllocator, > -const struct anv_wsi_image_fns *image_fns, > -struct anv_swapchain **swapchain); > - > VkResult anv_CreateWaylandSurfaceKHR( > VkInstance _instance, > const VkWaylandSurfaceCreateInfoKHR*pCreateInfo, > @@ -650,7 +642,7 @@ wsi_wl_swapchain_destroy(struct anv_swapchain > *anv_chain, > const VkAllocationCallbacks *pAllocator) > { > struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)anv_chain; > - struct anv_device *device = anv_device_from
[Mesa-dev] [PATCH 14/22] anv/wsi: move further away from passing anv displays around
From: Dave Airlie --- src/intel/vulkan/anv_wsi.c | 28 +++- src/intel/vulkan/anv_wsi.h | 3 ++- src/intel/vulkan/anv_wsi_wayland.c | 21 +++-- src/intel/vulkan/anv_wsi_x11.c | 22 +++--- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index 514a29f..89bf780 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -253,17 +253,21 @@ VkResult anv_CreateSwapchainKHR( struct anv_wsi_interface *iface = device->instance->physicalDevice.wsi_device.wsi[surface->platform]; struct anv_swapchain *swapchain; + const VkAllocationCallbacks *alloc; - VkResult result = iface->create_swapchain(surface, device, pCreateInfo, - pAllocator, &anv_wsi_image_fns, + if (pAllocator) + alloc = pAllocator; + else + alloc = &device->alloc; + VkResult result = iface->create_swapchain(surface, _device, + &device->instance->physicalDevice.wsi_device, + pCreateInfo, + alloc, &anv_wsi_image_fns, &swapchain); if (result != VK_SUCCESS) return result; - if (pAllocator) - swapchain->alloc = *pAllocator; - else - swapchain->alloc = device->alloc; + swapchain->alloc = *alloc; for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++) swapchain->fences[i] = VK_NULL_HANDLE; @@ -274,18 +278,24 @@ VkResult anv_CreateSwapchainKHR( } void anv_DestroySwapchainKHR( -VkDevice device, +VkDevice _device, VkSwapchainKHR _swapchain, const VkAllocationCallbacks* pAllocator) { + ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain); + const VkAllocationCallbacks *alloc; + if (pAllocator) + alloc = pAllocator; + else + alloc = &device->alloc; for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++) { if (swapchain->fences[i] != VK_NULL_HANDLE) - anv_DestroyFence(device, swapchain->fences[i], pAllocator); + anv_DestroyFence(_device, swapchain->fences[i], pAllocator); } - swapchain->destroy(swapchain, pAllocator); + swapchain->destroy(swapchain, alloc); } VkResult anv_GetSwapchainImagesKHR( diff --git a/src/intel/vulkan/anv_wsi.h b/src/intel/vulkan/anv_wsi.h index 2548e41..236133c 100644 --- a/src/intel/vulkan/anv_wsi.h +++ b/src/intel/vulkan/anv_wsi.h @@ -60,7 +60,8 @@ struct anv_wsi_interface { uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes); VkResult (*create_swapchain)(VkIcdSurfaceBase *surface, -struct anv_device *device, +VkDevice device, +struct anv_wsi_device *wsi_device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, const struct anv_wsi_image_fns *image_fns, diff --git a/src/intel/vulkan/anv_wsi_wayland.c b/src/intel/vulkan/anv_wsi_wayland.c index e56b3be..16a9647 100644 --- a/src/intel/vulkan/anv_wsi_wayland.c +++ b/src/intel/vulkan/anv_wsi_wayland.c @@ -422,14 +422,6 @@ wsi_wl_surface_get_present_modes(VkIcdSurfaceBase *surface, return VK_SUCCESS; } -static VkResult -wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *surface, -struct anv_device *device, -const VkSwapchainCreateInfoKHR* pCreateInfo, -const VkAllocationCallbacks* pAllocator, -const struct anv_wsi_image_fns *image_fns, -struct anv_swapchain **swapchain); - VkResult anv_CreateWaylandSurfaceKHR( VkInstance _instance, const VkWaylandSurfaceCreateInfoKHR*pCreateInfo, @@ -650,7 +642,7 @@ wsi_wl_swapchain_destroy(struct anv_swapchain *anv_chain, const VkAllocationCallbacks *pAllocator) { struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)anv_chain; - struct anv_device *device = anv_device_from_handle(chain->base.device); + for (uint32_t i = 0; i < chain->image_count; i++) { if (chain->images[i].buffer) chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator, @@ -658,14 +650,15 @@ wsi_wl_swapchain_destroy(struct anv_swapchain *anv_chain, chain->images[i].memory); } - vk_free2(&device->alloc, pAllocator, chain); + vk_free