VkResult result;
memset(image, 0, sizeof(*image));
- for (int i = 0; i < ARRAY_SIZE(image->fds); i++)
- image->fds[i] = -1;
+ image->dma_buf_fd = -1;
result = wsi->CreateImage(chain->device, &info->create,
&chain->alloc, &image->image);
{
const struct wsi_device *wsi = chain->wsi;
- for (int p = 0; p < image->num_planes; p++) {
- if (image->fds[p] >= 0)
- close(image->fds[p]);
- }
+ if (image->dma_buf_fd >= 0)
+ close(image->dma_buf_fd);
if (image->buffer.blit_cmd_buffers) {
for (uint32_t i = 0; i < wsi->queue_family_count; i++) {
memset(image->buffer, 0, sizeof (image->buffer));
for (unsigned int i = 0; i < image->base.num_planes; i++) {
- int ret = drmPrimeFDToHandle(wsi->fd, image->base.fds[i],
+ int ret = drmPrimeFDToHandle(wsi->fd, image->base.dma_buf_fd,
&image->buffer[i]);
-
- close(image->base.fds[i]);
- image->base.fds[i] = -1;
if (ret < 0)
goto fail_handle;
}
+ close(image->base.dma_buf_fd);
+ image->base.dma_buf_fd = -1;
image->chain = chain;
image->state = WSI_IMAGE_IDLE;
if (result != VK_SUCCESS)
return result;
- int fd = -1;
if (!wsi->sw) {
const VkMemoryGetFdInfoKHR memory_get_fd_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
};
- result = wsi->GetMemoryFdKHR(chain->device, &memory_get_fd_info, &fd);
+ result = wsi->GetMemoryFdKHR(chain->device, &memory_get_fd_info,
+ &image->dma_buf_fd);
if (result != VK_SUCCESS)
return result;
}
result = wsi->GetImageDrmFormatModifierPropertiesEXT(chain->device,
image->image,
&image_mod_props);
- if (result != VK_SUCCESS) {
- close(fd);
+ if (result != VK_SUCCESS)
return result;
- }
+
image->drm_modifier = image_mod_props.drmFormatModifier;
assert(image->drm_modifier != DRM_FORMAT_MOD_INVALID);
image->sizes[p] = image_layout.size;
image->row_pitches[p] = image_layout.rowPitch;
image->offsets[p] = image_layout.offset;
- if (p == 0) {
- image->fds[p] = fd;
- } else {
- image->fds[p] = os_dupfd_cloexec(fd);
- if (image->fds[p] == -1)
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
}
} else {
const VkImageSubresource image_subresource = {
image->sizes[0] = reqs.size;
image->row_pitches[0] = image_layout.rowPitch;
image->offsets[0] = 0;
- image->fds[0] = fd;
}
return VK_SUCCESS;
.memory = image->buffer.memory,
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
};
- int fd;
- result = wsi->GetMemoryFdKHR(chain->device, &linear_memory_get_fd_info, &fd);
+ result = wsi->GetMemoryFdKHR(chain->device, &linear_memory_get_fd_info,
+ &image->dma_buf_fd);
if (result != VK_SUCCESS)
return result;
image->drm_modifier = info->prime_use_linear_modifier ?
DRM_FORMAT_MOD_LINEAR : DRM_FORMAT_MOD_INVALID;
- image->fds[0] = fd;
return VK_SUCCESS;
}
uint32_t sizes[4];
uint32_t offsets[4];
uint32_t row_pitches[4];
- int fds[4];
+ int dma_buf_fd;
};
struct wsi_swapchain {
for (int i = 0; i < image->base.num_planes; i++) {
zwp_linux_buffer_params_v1_add(params,
- image->base.fds[i],
+ image->base.dma_buf_fd,
i,
image->base.offsets[i],
image->base.row_pitches[i],
image->base.drm_modifier >> 32,
image->base.drm_modifier & 0xffffffff);
- close(image->base.fds[i]);
- image->base.fds[i] = -1;
}
+ close(image->base.dma_buf_fd);
+ image->base.dma_buf_fd = -1;
image->buffer =
zwp_linux_buffer_params_v1_create_immed(params,
#include <xf86drm.h>
#include "drm-uapi/drm_fourcc.h"
#include "util/hash_table.h"
+#include "util/os_file.h"
#include "util/os_time.h"
#include "util/u_debug.h"
#include "util/u_thread.h"
/* If the image has a modifier, we must have DRI3 v1.2. */
assert(chain->has_dri3_modifiers);
+ /* XCB requires an array of file descriptors but we only have one */
+ int fds[4] = { -1, -1, -1, -1 };
+ fds[0] = image->base.dma_buf_fd;
+ for (int i = 1; i < image->base.num_planes; i++) {
+ fds[i] = os_dupfd_cloexec(image->base.dma_buf_fd);
+ if (fds[i] == -1) {
+ for (int j = 1; j < i; j++)
+ close(fds[j]);
+
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
+ }
+ }
+
cookie =
xcb_dri3_pixmap_from_buffers_checked(chain->conn,
image->pixmap,
image->base.offsets[3],
chain->depth, bpp,
image->base.drm_modifier,
- image->base.fds);
+ fds);
} else
#endif
{
pCreateInfo->imageExtent.height,
image->base.row_pitches[0],
chain->depth, bpp,
- image->base.fds[0]);
+ image->base.dma_buf_fd);
}
xcb_discard_reply(chain->conn, cookie.sequence);
- /* XCB has now taken ownership of the FDs. */
- for (int i = 0; i < image->base.num_planes; i++)
- image->base.fds[i] = -1;
+ /* XCB has now taken ownership of the FD. */
+ image->base.dma_buf_fd = -1;
out_fence:
fence_fd = xshmfence_alloc_shm();