const VkAllocationCallbacks* pAllocator,
bool needs_linear_copy,
bool linear,
- VkImage *image_p,
- VkDeviceMemory *memory_p,
- uint32_t *size,
- uint32_t *offset,
- uint32_t *row_pitch, int *fd_p)
+ struct wsi_image *wsi_image)
{
VkResult result = VK_SUCCESS;
struct radeon_surf *surface;
RADV_FROM_HANDLE(radv_device_memory, memory, memory_h);
if (!radv_get_memory_fd(device, memory, &fd))
goto fail_alloc_memory;
- *fd_p = fd;
+ wsi_image->fd = fd;
}
surface = &image->surface;
- *image_p = image_h;
- *memory_p = memory_h;
- *size = image->size;
- *offset = image->offset;
-
+ wsi_image->image = image_h;
+ wsi_image->memory = memory_h;
+ wsi_image->size = image->size;
+ wsi_image->offset = image->offset;
if (device->physical_device->rad_info.chip_class >= GFX9)
- *row_pitch = surface->u.gfx9.surf_pitch * surface->bpe;
+ wsi_image->row_pitch =
+ surface->u.gfx9.surf_pitch * surface->bpe;
else
- *row_pitch = surface->u.legacy.level[0].nblk_x * surface->bpe;
+ wsi_image->row_pitch =
+ surface->u.legacy.level[0].nblk_x * surface->bpe;
+
return VK_SUCCESS;
fail_alloc_memory:
radv_FreeMemory(device_h, memory_h, pAllocator);
static void
radv_wsi_image_free(VkDevice device,
const VkAllocationCallbacks* pAllocator,
- VkImage image_h,
- VkDeviceMemory memory_h)
+ struct wsi_image *wsi_image)
{
- radv_DestroyImage(device, image_h, pAllocator);
+ radv_DestroyImage(device, wsi_image->image, pAllocator);
- radv_FreeMemory(device, memory_h, pAllocator);
+ radv_FreeMemory(device, wsi_image->memory, pAllocator);
}
static const struct wsi_image_fns radv_wsi_image_fns = {
const VkAllocationCallbacks* pAllocator,
bool different_gpu,
bool linear,
- VkImage *image_p,
- VkDeviceMemory *memory_p,
- uint32_t *size,
- uint32_t *offset,
- uint32_t *row_pitch, int *fd_p)
+ struct wsi_image *wsi_image)
{
struct anv_device *device = anv_device_from_handle(device_h);
VkImage image_h;
struct anv_surface *surface = &image->planes[0].surface;
assert(surface->isl.tiling == ISL_TILING_X);
- *row_pitch = surface->isl.row_pitch;
int ret = anv_gem_set_tiling(device, memory->bo->gem_handle,
surface->isl.row_pitch, I915_TILING_X);
if (ret) {
goto fail_alloc_memory;
}
- *image_p = image_h;
- *memory_p = memory_h;
- *fd_p = fd;
- *size = image->size;
- *offset = 0;
+ wsi_image->image = image_h;
+ wsi_image->memory = memory_h;
+ wsi_image->fd = fd;
+ wsi_image->size = image->size;
+ wsi_image->offset = 0;
+ wsi_image->row_pitch = surface->isl.row_pitch;
return VK_SUCCESS;
fail_alloc_memory:
anv_FreeMemory(device_h, memory_h, pAllocator);
static void
anv_wsi_image_free(VkDevice device,
const VkAllocationCallbacks* pAllocator,
- VkImage image_h,
- VkDeviceMemory memory_h)
+ struct wsi_image *wsi_image)
{
- anv_DestroyImage(device, image_h, pAllocator);
+ anv_DestroyImage(device, wsi_image->image, pAllocator);
- anv_FreeMemory(device, memory_h, pAllocator);
+ anv_FreeMemory(device, wsi_image->memory, pAllocator);
}
static const struct wsi_image_fns anv_wsi_image_fns = {
#include <vulkan/vulkan.h>
#include <vulkan/vk_icd.h>
+struct wsi_image {
+ VkImage image;
+ VkDeviceMemory memory;
+ uint32_t size;
+ uint32_t offset;
+ uint32_t row_pitch;
+ int fd;
+};
+
struct wsi_device;
struct wsi_image_fns {
VkResult (*create_wsi_image)(VkDevice device_h,
const VkAllocationCallbacks *pAllocator,
bool needs_linear_copy,
bool linear,
- VkImage *image_p,
- VkDeviceMemory *memory_p,
- uint32_t *size_p,
- uint32_t *offset_p,
- uint32_t *row_pitch_p,
- int *fd_p);
+ struct wsi_image *image_p);
void (*free_wsi_image)(VkDevice device,
const VkAllocationCallbacks *pAllocator,
- VkImage image_h,
- VkDeviceMemory memory_h);
+ struct wsi_image *image);
};
struct wsi_swapchain {
}
struct wsi_wl_image {
- VkImage image;
- VkDeviceMemory memory;
+ struct wsi_image base;
struct wl_buffer * buffer;
bool busy;
};
}
for (uint32_t i = 0; i < ret_count; i++)
- pSwapchainImages[i] = chain->images[i].image;
+ pSwapchainImages[i] = chain->images[i].base.image;
return result;
}
{
VkDevice vk_device = chain->base.device;
VkResult result;
- int fd;
- uint32_t size;
- uint32_t row_pitch;
- uint32_t offset;
+
result = chain->base.image_fns->create_wsi_image(vk_device,
pCreateInfo,
pAllocator,
false,
false,
- &image->image,
- &image->memory,
- &size,
- &offset,
- &row_pitch,
- &fd);
+ &image->base);
if (result != VK_SUCCESS)
return result;
image->buffer = wl_drm_create_prime_buffer(chain->drm_wrapper,
- fd, /* name */
+ image->base.fd, /* name */
chain->extent.width,
chain->extent.height,
chain->drm_format,
- offset,
- row_pitch,
+ image->base.offset,
+ image->base.row_pitch,
0, 0, 0, 0 /* unused */);
- close(fd);
+ close(image->base.fd);
if (!image->buffer)
goto fail_image;
return VK_SUCCESS;
fail_image:
- chain->base.image_fns->free_wsi_image(vk_device, pAllocator,
- image->image, image->memory);
+ chain->base.image_fns->free_wsi_image(vk_device, pAllocator, &image->base);
return result;
}
if (chain->images[i].buffer) {
wl_buffer_destroy(chain->images[i].buffer);
chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator,
- chain->images[i].image,
- chain->images[i].memory);
+ &chain->images[i].base);
}
}
}
struct x11_image {
- VkImage image;
- VkImage linear_image; // for prime
- VkDeviceMemory memory;
- VkDeviceMemory linear_memory; // for prime
+ struct wsi_image base;
+ struct wsi_image linear_base;
xcb_pixmap_t pixmap;
bool busy;
struct xshmfence * shm_fence;
}
for (uint32_t i = 0; i < ret_count; i++)
- pSwapchainImages[i] = chain->images[i].image;
+ pSwapchainImages[i] = chain->images[i].base.image;
return result;
}
int imageIndex, VkImage *image, VkImage *linear_image)
{
struct x11_swapchain *chain = (struct x11_swapchain *)drv_chain;
- *image = chain->images[imageIndex].image;
- *linear_image = chain->images[imageIndex].linear_image;
+ *image = chain->images[imageIndex].base.image;
+ *linear_image = chain->images[imageIndex].linear_base.image;
}
static VkResult
{
xcb_void_cookie_t cookie;
VkResult result;
- uint32_t row_pitch;
- uint32_t offset;
uint32_t bpp = 32;
- int fd;
- uint32_t size;
result = chain->base.image_fns->create_wsi_image(device_h,
pCreateInfo,
pAllocator,
chain->base.needs_linear_copy,
false,
- &image->image,
- &image->memory,
- &size,
- &offset,
- &row_pitch,
- &fd);
+ &image->base);
if (result != VK_SUCCESS)
return result;
pAllocator,
chain->base.needs_linear_copy,
true,
- &image->linear_image,
- &image->linear_memory,
- &size,
- &offset,
- &row_pitch,
- &fd);
+ &image->linear_base);
+
if (result != VK_SUCCESS) {
chain->base.image_fns->free_wsi_image(device_h, pAllocator,
- image->image, image->memory);
+ &image->base);
return result;
}
}
image->pixmap = xcb_generate_id(chain->conn);
+ struct wsi_image *image_ws =
+ chain->base.needs_linear_copy ? &image->linear_base : &image->base;
cookie =
xcb_dri3_pixmap_from_buffer_checked(chain->conn,
image->pixmap,
chain->window,
- size,
+ image_ws->size,
pCreateInfo->imageExtent.width,
pCreateInfo->imageExtent.height,
- row_pitch,
- chain->depth, bpp, fd);
+ image_ws->row_pitch,
+ chain->depth, bpp,
+ image_ws->fd);
xcb_discard_reply(chain->conn, cookie.sequence);
+ image_ws->fd = -1; /* XCB has now taken ownership of the FD */
int fence_fd = xshmfence_alloc_shm();
if (fence_fd < 0)
if (chain->base.needs_linear_copy) {
chain->base.image_fns->free_wsi_image(device_h, pAllocator,
- image->linear_image, image->linear_memory);
+ &image->linear_base);
}
- chain->base.image_fns->free_wsi_image(device_h, pAllocator,
- image->image, image->memory);
+ chain->base.image_fns->free_wsi_image(device_h, pAllocator, &image->base);
return result;
}
if (chain->base.needs_linear_copy) {
chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator,
- image->linear_image, image->linear_memory);
+ &image->linear_base);
}
chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator,
- image->image, image->memory);
+ &image->base);
}
static VkResult