<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 16, 2016 at 9:24 PM, Dave Airlie <span dir="ltr"><<a href="mailto:airlied@gmail.com" target="_blank">airlied@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
<br>
---<br>
src/intel/vulkan/anv_wsi.c | 28 +++++++++++++++++++---------<br>
src/intel/vulkan/anv_wsi.h | 3 ++-<br>
src/intel/vulkan/anv_wsi_<wbr>wayland.c | 21 +++++++--------------<br>
src/intel/vulkan/anv_wsi_x11.c | 22 +++++++---------------<br>
4 files changed, 35 insertions(+), 39 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c<br>
index 514a29f..89bf780 100644<br>
--- a/src/intel/vulkan/anv_wsi.c<br>
+++ b/src/intel/vulkan/anv_wsi.c<br>
@@ -253,17 +253,21 @@ VkResult anv_CreateSwapchainKHR(<br>
struct anv_wsi_interface *iface =<br>
device->instance-><wbr>physicalDevice.wsi_device.wsi[<wbr>surface->platform];<br>
struct anv_swapchain *swapchain;<br>
+ const VkAllocationCallbacks *alloc;<br>
<br>
- VkResult result = iface->create_swapchain(<wbr>surface, device, pCreateInfo,<br>
- pAllocator, &anv_wsi_image_fns,<br>
+ if (pAllocator)<br>
+ alloc = pAllocator;<br>
+ else<br>
+ alloc = &device->alloc;<br>
+ VkResult result = iface->create_swapchain(<wbr>surface, _device,<br>
+ &device->instance-><wbr>physicalDevice.wsi_device,<br>
+ pCreateInfo,<br>
+ alloc, &anv_wsi_image_fns,<br>
&swapchain);<br>
if (result != VK_SUCCESS)<br>
return result;<br>
<br>
- if (pAllocator)<br>
- swapchain->alloc = *pAllocator;<br>
- else<br>
- swapchain->alloc = device->alloc;<br>
+ swapchain->alloc = *alloc;<br>
<br>
for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++)<br>
swapchain->fences[i] = VK_NULL_HANDLE;<br>
@@ -274,18 +278,24 @@ VkResult anv_CreateSwapchainKHR(<br>
}<br>
<br>
void anv_DestroySwapchainKHR(<br>
- VkDevice device,<br>
+ VkDevice _device,<br>
VkSwapchainKHR _swapchain,<br>
const VkAllocationCallbacks* pAllocator)<br>
{<br>
+ ANV_FROM_HANDLE(anv_device, device, _device);<br>
ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain);<br>
+ const VkAllocationCallbacks *alloc;<br>
<br>
+ if (pAllocator)<br>
+ alloc = pAllocator;<br>
+ else<br>
+ alloc = &device->alloc;<br></blockquote><div><br></div><div>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<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++) {<br>
if (swapchain->fences[i] != VK_NULL_HANDLE)<br>
- anv_DestroyFence(device, swapchain->fences[i], pAllocator);<br>
+ anv_DestroyFence(_device, swapchain->fences[i], pAllocator);<br>
}<br>
<br>
- swapchain->destroy(swapchain, pAllocator);<br>
+ swapchain->destroy(swapchain, alloc);<br>
}<br>
<br>
VkResult anv_GetSwapchainImagesKHR(<br>
diff --git a/src/intel/vulkan/anv_wsi.h b/src/intel/vulkan/anv_wsi.h<br>
index 2548e41..236133c 100644<br>
--- a/src/intel/vulkan/anv_wsi.h<br>
+++ b/src/intel/vulkan/anv_wsi.h<br>
@@ -60,7 +60,8 @@ struct anv_wsi_interface {<br>
uint32_t* pPresentModeCount,<br>
VkPresentModeKHR* pPresentModes);<br>
VkResult (*create_swapchain)(<wbr>VkIcdSurfaceBase *surface,<br>
- struct anv_device *device,<br>
+ VkDevice device,<br>
+ struct anv_wsi_device *wsi_device,<br>
const VkSwapchainCreateInfoKHR* pCreateInfo,<br>
const VkAllocationCallbacks* pAllocator,<br>
const struct anv_wsi_image_fns *image_fns,<br>
diff --git a/src/intel/vulkan/anv_wsi_<wbr>wayland.c b/src/intel/vulkan/anv_wsi_<wbr>wayland.c<br>
index e56b3be..16a9647 100644<br>
--- a/src/intel/vulkan/anv_wsi_<wbr>wayland.c<br>
+++ b/src/intel/vulkan/anv_wsi_<wbr>wayland.c<br>
@@ -422,14 +422,6 @@ wsi_wl_surface_get_present_<wbr>modes(VkIcdSurfaceBase *surface,<br>
return VK_SUCCESS;<br>
}<br>
<br>
-static VkResult<br>
-wsi_wl_surface_create_<wbr>swapchain(VkIcdSurfaceBase *surface,<br>
- struct anv_device *device,<br>
- const VkSwapchainCreateInfoKHR* pCreateInfo,<br>
- const VkAllocationCallbacks* pAllocator,<br>
- const struct anv_wsi_image_fns *image_fns,<br>
- struct anv_swapchain **swapchain);<br>
-<br>
VkResult anv_CreateWaylandSurfaceKHR(<br>
VkInstance _instance,<br>
const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,<br>
@@ -650,7 +642,7 @@ wsi_wl_swapchain_destroy(<wbr>struct anv_swapchain *anv_chain,<br>
const VkAllocationCallbacks *pAllocator)<br>
{<br>
struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)anv_chain;<br>
- struct anv_device *device = anv_device_from_handle(chain-><wbr>base.device);<br>
+<br>
for (uint32_t i = 0; i < chain->image_count; i++) {<br>
if (chain->images[i].buffer)<br>
chain->base.image_fns->free_<wbr>wsi_image(chain->base.device, pAllocator,<br>
@@ -658,14 +650,15 @@ wsi_wl_swapchain_destroy(<wbr>struct anv_swapchain *anv_chain,<br>
chain->images[i].memory);<br>
}<br>
<br>
- vk_free2(&device->alloc, pAllocator, chain);<br>
+ vk_free(pAllocator, chain);<br>
<br>
return VK_SUCCESS;<br>
}<br>
<br>
static VkResult<br>
wsi_wl_surface_create_<wbr>swapchain(VkIcdSurfaceBase *icd_surface,<br>
- struct anv_device *device,<br>
+ VkDevice device,<br>
+ struct anv_wsi_device *wsi_device,<br>
const VkSwapchainCreateInfoKHR* pCreateInfo,<br>
const VkAllocationCallbacks* pAllocator,<br>
const struct anv_wsi_image_fns *image_fns,<br>
@@ -691,12 +684,12 @@ wsi_wl_surface_create_<wbr>swapchain(VkIcdSurfaceBase *icd_surface,<br>
num_images = MAX2(num_images, 4);<br>
<br>
size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);<br>
- chain = vk_alloc2(&device->alloc, pAllocator, size, 8,<br>
+ chain = vk_alloc(pAllocator, size, 8,<br>
VK_SYSTEM_ALLOCATION_SCOPE_<wbr>OBJECT);<br>
if (chain == NULL)<br>
return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
<br>
- chain->base.device = anv_device_to_handle(device);<br>
+ chain->base.device = device;<br>
chain->base.destroy = wsi_wl_swapchain_destroy;<br>
chain->base.get_images = wsi_wl_swapchain_get_images;<br>
chain->base.acquire_next_image = wsi_wl_swapchain_acquire_next_<wbr>image;<br>
@@ -719,7 +712,7 @@ wsi_wl_surface_create_<wbr>swapchain(VkIcdSurfaceBase *icd_surface,<br>
chain->images[i].buffer = NULL;<br>
chain->queue = NULL;<br>
<br>
- chain->display = wsi_wl_get_display(&device-><wbr>instance->physicalDevice.wsi_<wbr>device,<br>
+ chain->display = wsi_wl_get_display(wsi_device,<br>
surface->display);<br>
if (!chain->display) {<br>
result = vk_error(VK_ERROR_<wbr>INITIALIZATION_FAILED);<br>
diff --git a/src/intel/vulkan/anv_wsi_<wbr>x11.c b/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
index 54fe057..f56df40 100644<br>
--- a/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
+++ b/src/intel/vulkan/anv_wsi_<wbr>x11.c<br>
@@ -434,14 +434,6 @@ x11_surface_get_present_modes(<wbr>VkIcdSurfaceBase *surface,<br>
return VK_SUCCESS;<br>
}<br>
<br>
-static VkResult<br>
-x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *surface,<br>
- struct anv_device *device,<br>
- const VkSwapchainCreateInfoKHR* pCreateInfo,<br>
- const VkAllocationCallbacks* pAllocator,<br>
- const struct anv_wsi_image_fns *image_fns,<br>
- struct anv_swapchain **swapchain);<br>
-<br>
VkResult anv_CreateXcbSurfaceKHR(<br>
VkInstance _instance,<br>
const VkXcbSurfaceCreateInfoKHR* pCreateInfo,<br>
@@ -747,20 +739,20 @@ x11_swapchain_destroy(struct anv_swapchain *anv_chain,<br>
const VkAllocationCallbacks *pAllocator)<br>
{<br>
struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain;<br>
- struct anv_device *device = anv_device_from_handle(chain-><wbr>base.device);<br>
for (uint32_t i = 0; i < chain->image_count; i++)<br>
x11_image_finish(chain, pAllocator, &chain->images[i]);<br>
<br>
xcb_unregister_for_special_<wbr>event(chain->conn, chain->special_event);<br>
<br>
- vk_free2(&device->alloc, pAllocator, chain);<br>
+ vk_free(pAllocator, chain);<br>
<br>
return VK_SUCCESS;<br>
}<br>
<br>
static VkResult<br>
x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *icd_surface,<br>
- struct anv_device *device,<br>
+ VkDevice device,<br>
+ struct anv_wsi_device *wsi_device,<br>
const VkSwapchainCreateInfoKHR *pCreateInfo,<br>
const VkAllocationCallbacks* pAllocator,<br>
const struct anv_wsi_image_fns *image_fns,<br>
@@ -784,12 +776,12 @@ x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *icd_surface,<br>
num_images = MAX2(num_images, 4);<br>
<br>
size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);<br>
- chain = vk_alloc2(&device->alloc, pAllocator, size, 8,<br>
+ chain = vk_alloc(pAllocator, size, 8,<br>
VK_SYSTEM_ALLOCATION_SCOPE_<wbr>OBJECT);<br>
if (chain == NULL)<br>
return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
<br>
- chain->base.device = anv_device_to_handle(device);<br>
+ chain->base.device = device;<br>
chain->base.destroy = x11_swapchain_destroy;<br>
chain->base.get_images = x11_get_images;<br>
chain->base.acquire_next_image = x11_acquire_next_image;<br>
@@ -830,7 +822,7 @@ x11_surface_create_swapchain(<wbr>VkIcdSurfaceBase *icd_surface,<br>
<br>
uint32_t image = 0;<br>
for (; image < chain->image_count; image++) {<br>
- result = x11_image_init(anv_device_to_<wbr>handle(device), chain, pCreateInfo, pAllocator,<br>
+ result = x11_image_init(device, chain, pCreateInfo, pAllocator,<br>
&chain->images[image]);<br>
if (result != VK_SUCCESS)<br>
goto fail_init_images;<br>
@@ -847,7 +839,7 @@ fail_init_images:<br>
fail_register:<br>
xcb_unregister_for_special_<wbr>event(chain->conn, chain->special_event);<br>
<br>
- vk_free2(&device->alloc, pAllocator, chain);<br>
+ vk_free(pAllocator, chain);<br>
<br>
return result;<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.5<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>