<div dir="auto">If we get a nouveauv ever we would have to have this, so not really wanting this.<div dir="auto"><br></div><div dir="auto">Dave.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 28 Sep. 2017 6:01 pm, "Louis-Francis Ratté-Boulianne" <<a href="mailto:lfrb@collabora.com">lfrb@collabora.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
<br>
This is pretty much radv-specific anyway.<br>
<br>
Signed-off-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
---<br>
src/amd/vulkan/radv_wsi.c | 49 +++++++++++++++++++++++-------<wbr>-------<br>
src/intel/vulkan/anv_wsi.c | 23 ++++++++---------<br>
src/vulkan/wsi/wsi_common.h | 4 ++-<br>
src/vulkan/wsi/wsi_common_<wbr>wayland.c | 1 -<br>
src/vulkan/wsi/wsi_common_x11.<wbr>c | 44 ++++++++----------------------<wbr>---<br>
5 files changed, 54 insertions(+), 67 deletions(-)<br>
<br>
diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c<br>
index cd2b36a57f..bcdbd7ffe9 100644<br>
--- a/src/amd/vulkan/radv_wsi.c<br>
+++ b/src/amd/vulkan/radv_wsi.c<br>
@@ -212,35 +212,40 @@ static VkResult<br>
radv_wsi_image_create(VkDevice device_h,<br>
const VkSwapchainCreateInfoKHR *pCreateInfo,<br>
const VkAllocationCallbacks* pAllocator,<br>
- bool should_export,<br>
bool linear,<br>
struct wsi_image_base *wsi_image)<br>
{<br>
VkResult result = VK_SUCCESS;<br>
struct radeon_surf *surface;<br>
- VkImage image_h;<br>
- VkDeviceMemory memory_h;<br>
struct radv_image *image;<br>
<br>
result = radv_wsi_image_alloc(device_h, pCreateInfo, pAllocator,<br>
- linear, &image_h, &memory_h);<br>
+ false, &wsi_image->image,<br>
+ &wsi_image->memory);<br>
if (result != VK_SUCCESS)<br>
return result;<br>
<br>
- image = radv_image_from_handle(image_<wbr>h);<br>
- surface = &image->surface;<br>
-<br>
- if (should_export) {<br>
- RADV_FROM_HANDLE(radv_device, device, device_h);<br>
- RADV_FROM_HANDLE(radv_device_<wbr>memory, memory, memory_h);<br>
- if (!radv_get_memory_fd(device, memory, &wsi_image->fds[0]))<br>
+ if (linear) {<br>
+ result = radv_wsi_image_alloc(device_h, pCreateInfo, pAllocator,<br>
+ true, &wsi_image->linear_image,<br>
+ &wsi_image->linear_memory);<br>
+ if (result != VK_SUCCESS)<br>
goto fail_alloc;<br>
} else {<br>
- wsi_image->fds[0] = -1;<br>
+ wsi_image->linear_image = VK_NULL_HANDLE;<br>
+ wsi_image->linear_memory = VK_NULL_HANDLE;<br>
}<br>
<br>
- wsi_image->image = image_h;<br>
- wsi_image->memory = memory_h;<br>
+ RADV_FROM_HANDLE(radv_device_<wbr>memory, memory,<br>
+ linear ? wsi_image->linear_memory : wsi_image->memory);<br>
+ image = radv_image_from_handle(linear ? wsi_image->linear_image :<br>
+ wsi_image->image);<br>
+ surface = &image->surface;<br>
+<br>
+ RADV_FROM_HANDLE(radv_device, device, device_h);<br>
+ if (!radv_get_memory_fd(device, memory, &wsi_image->fds[0]))<br>
+ goto fail_linear;<br>
+<br>
wsi_image->num_planes = 1;<br>
wsi_image->sizes[0] = image->size;<br>
wsi_image->offsets[0] = image->offset;<br>
@@ -253,9 +258,14 @@ radv_wsi_image_create(VkDevice device_h,<br>
<br>
return VK_SUCCESS;<br>
<br>
- fail_alloc:<br>
- radv_FreeMemory(device_h, memory_h, pAllocator);<br>
- radv_DestroyImage(device_h, image_h, pAllocator);<br>
+fail_linear:<br>
+ if (wsi_image->linear_memory != VK_NULL_HANDLE)<br>
+ radv_FreeMemory(device_h, wsi_image->linear_memory, pAllocator);<br>
+ if (wsi_image->linear_image != VK_NULL_HANDLE)<br>
+ radv_DestroyImage(device_h, wsi_image->linear_image, pAllocator);<br>
+fail_alloc:<br>
+ radv_FreeMemory(device_h, wsi_image->memory, pAllocator);<br>
+ radv_DestroyImage(device_h, wsi_image->image, pAllocator);<br>
return result;<br>
}<br>
<br>
@@ -264,8 +274,11 @@ radv_wsi_image_free(VkDevice device,<br>
const VkAllocationCallbacks* pAllocator,<br>
struct wsi_image_base *wsi_image)<br>
{<br>
+ if (wsi_image->linear_image != VK_NULL_HANDLE)<br>
+ radv_DestroyImage(device, wsi_image->linear_image, pAllocator);<br>
+ if (wsi_image->linear_memory != VK_NULL_HANDLE)<br>
+ radv_FreeMemory(device, wsi_image->linear_memory, pAllocator);<br>
radv_DestroyImage(device, wsi_image->image, pAllocator);<br>
-<br>
radv_FreeMemory(device, wsi_image->memory, pAllocator);<br>
}<br>
<br>
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c<br>
index 4454930d45..f59d349b50 100644<br>
--- a/src/intel/vulkan/anv_wsi.c<br>
+++ b/src/intel/vulkan/anv_wsi.c<br>
@@ -172,7 +172,6 @@ static VkResult<br>
anv_wsi_image_create(VkDevice device_h,<br>
const VkSwapchainCreateInfoKHR *pCreateInfo,<br>
const VkAllocationCallbacks* pAllocator,<br>
- bool should_export,<br>
bool linear,<br>
struct wsi_image_base *wsi_image)<br>
{<br>
@@ -249,22 +248,20 @@ anv_wsi_image_create(VkDevice device_h,<br>
goto fail_alloc_memory;<br>
}<br>
<br>
- int fd;<br>
- if (should_export) {<br>
- fd = anv_gem_handle_to_fd(device, memory->bo->gem_handle);<br>
- if (fd == -1) {<br>
- /* FINISHME: Choose a better error. */<br>
- result = vk_errorf(device->instance, device,<br>
- VK_ERROR_OUT_OF_DEVICE_MEMORY,<br>
- "handle_to_fd failed: %m");<br>
- goto fail_alloc_memory;<br>
- }<br>
- } else {<br>
- fd = -1;<br>
+ int fd = anv_gem_handle_to_fd(device, memory->bo->gem_handle);<br>
+ if (fd == -1) {<br>
+ /* FINISHME: Choose a better error. */<br>
+ result = vk_errorf(device->instance, device,<br>
+ VK_ERROR_OUT_OF_DEVICE_MEMORY,<br>
+ "handle_to_fd failed: %m");<br>
+ goto fail_alloc_memory;<br>
}<br>
<br>
wsi_image->image = image_h;<br>
wsi_image->memory = memory_h;<br>
+ wsi_image->linear_image = VK_NULL_HANDLE;<br>
+ wsi_image->linear_memory = VK_NULL_HANDLE;<br>
+<br>
wsi_image->num_planes = 1;<br>
wsi_image->fds[0] = fd;<br>
wsi_image->sizes[0] = image->size;<br>
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h<br>
index b6c5a438b1..33fa8c2b0d 100644<br>
--- a/src/vulkan/wsi/wsi_common.h<br>
+++ b/src/vulkan/wsi/wsi_common.h<br>
@@ -33,6 +33,9 @@<br>
struct wsi_image_base {<br>
VkImage image;<br>
VkDeviceMemory memory;<br>
+ VkImage linear_image;<br>
+ VkDeviceMemory linear_memory;<br>
+<br>
int num_planes;<br>
uint32_t sizes[4];<br>
uint32_t offsets[4];<br>
@@ -45,7 +48,6 @@ struct wsi_image_fns {<br>
VkResult (*create_wsi_image)(VkDevice device_h,<br>
const VkSwapchainCreateInfoKHR *pCreateInfo,<br>
const VkAllocationCallbacks *pAllocator,<br>
- bool should_export,<br>
bool linear,<br>
struct wsi_image_base *image_p);<br>
void (*free_wsi_image)(VkDevice device,<br>
diff --git a/src/vulkan/wsi/wsi_common_<wbr>wayland.c b/src/vulkan/wsi/wsi_common_<wbr>wayland.c<br>
index a76e29d26e..8df30d993c 100644<br>
--- a/src/vulkan/wsi/wsi_common_<wbr>wayland.c<br>
+++ b/src/vulkan/wsi/wsi_common_<wbr>wayland.c<br>
@@ -730,7 +730,6 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain,<br>
result = chain->base.image_fns->create_<wbr>wsi_image(vk_device,<br>
pCreateInfo,<br>
pAllocator,<br>
- true,<br>
false,<br>
&image->base);<br>
if (result != VK_SUCCESS)<br>
diff --git a/src/vulkan/wsi/wsi_common_<wbr>x11.c b/src/vulkan/wsi/wsi_common_<wbr>x11.c<br>
index f9954d6e37..784d275dc5 100644<br>
--- a/src/vulkan/wsi/wsi_common_<wbr>x11.c<br>
+++ b/src/vulkan/wsi/wsi_common_<wbr>x11.c<br>
@@ -616,7 +616,6 @@ VkResult wsi_create_xlib_surface(const VkAllocationCallbacks *pAllocator,<br>
<br>
struct x11_image {<br>
struct wsi_image_base base;<br>
- struct wsi_image_base linear_base;<br>
xcb_pixmap_t pixmap;<br>
bool busy;<br>
struct xshmfence * shm_fence;<br>
@@ -679,7 +678,7 @@ x11_get_image_and_linear(<wbr>struct wsi_swapchain *drv_chain,<br>
{<br>
struct x11_swapchain *chain = (struct x11_swapchain *)drv_chain;<br>
*image = chain->images[imageIndex].<wbr>base.image;<br>
- *linear_image = chain->images[imageIndex].<wbr>linear_base.image;<br>
+ *linear_image = chain->images[imageIndex].<wbr>base.linear_image;<br>
}<br>
<br>
static VkResult<br>
@@ -962,47 +961,32 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain,<br>
result = chain->base.image_fns->create_<wbr>wsi_image(device_h,<br>
pCreateInfo,<br>
pAllocator,<br>
- !chain->base.needs_linear_<wbr>copy,<br>
- false,<br>
+ chain->base.needs_linear_copy,<br>
&image->base);<br>
if (result != VK_SUCCESS)<br>
return result;<br>
<br>
- if (chain->base.needs_linear_<wbr>copy) {<br>
- result = chain->base.image_fns->create_<wbr>wsi_image(device_h,<br>
- pCreateInfo,<br>
- pAllocator,<br>
- true,<br>
- true,<br>
- &image->linear_base);<br>
-<br>
- if (result != VK_SUCCESS) {<br>
- chain->base.image_fns->free_<wbr>wsi_image(device_h, pAllocator,<br>
- &image->base);<br>
- return result;<br>
- }<br>
- }<br>
+ /* The driver has decided to allocate a linear copy, for whatever reason. */<br>
+ if (image->base.linear_image != VK_NULL_HANDLE)<br>
+ chain->base.needs_linear_copy = true;<br>
<br>
image->pixmap = xcb_generate_id(chain->conn);<br>
<br>
- struct wsi_image_base *image_ws =<br>
- chain->base.needs_linear_copy ? &image->linear_base : &image->base;<br>
-<br>
/* Without passing modifiers, we can't have multi-plane RGB images. */<br>
- assert(image_ws->num_planes == 1);<br>
+ assert(image->base.num_planes == 1);<br>
<br>
cookie =<br>
xcb_dri3_pixmap_from_buffer_<wbr>checked(chain->conn,<br>
image->pixmap,<br>
chain->window,<br>
- image_ws->sizes[0],<br>
+ image->base.sizes[0],<br>
pCreateInfo->imageExtent.<wbr>width,<br>
pCreateInfo->imageExtent.<wbr>height,<br>
- image_ws->row_pitches[0],<br>
+ image->base.row_pitches[0],<br>
chain->depth, bpp,<br>
- image_ws->fds[0]);<br>
+ image->base.fds[0]);<br>
xcb_discard_reply(chain->conn, cookie.sequence);<br>
- image_ws->fds[0] = -1; /* XCB has now taken ownership of the FD */<br>
+ image->base.fds[0] = -1; /* XCB has now taken ownership of the FD */<br>
<br>
int fence_fd = xshmfence_alloc_shm();<br>
if (fence_fd < 0)<br>
@@ -1031,10 +1015,6 @@ fail_pixmap:<br>
cookie = xcb_free_pixmap(chain->conn, image->pixmap);<br>
xcb_discard_reply(chain->conn, cookie.sequence);<br>
<br>
- if (chain->base.needs_linear_<wbr>copy) {<br>
- chain->base.image_fns->free_<wbr>wsi_image(device_h, pAllocator,<br>
- &image->linear_base);<br>
- }<br>
chain->base.image_fns->free_<wbr>wsi_image(device_h, pAllocator, &image->base);<br>
<br>
return result;<br>
@@ -1054,10 +1034,6 @@ x11_image_finish(struct x11_swapchain *chain,<br>
cookie = xcb_free_pixmap(chain->conn, image->pixmap);<br>
xcb_discard_reply(chain->conn, cookie.sequence);<br>
<br>
- if (chain->base.needs_linear_<wbr>copy) {<br>
- chain->base.image_fns->free_<wbr>wsi_image(chain->base.device, pAllocator,<br>
- &image->linear_base);<br>
- }<br>
chain->base.image_fns->free_<wbr>wsi_image(chain->base.device, pAllocator,<br>
&image->base);<br>
}<br>
--<br>
2.13.0<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>
</blockquote></div></div>