Skip to content

Commit

Permalink
iris: Use Intel GPU for resource allocation in the case of kmsro
Browse files Browse the repository at this point in the history
Now that our virtio-GPU supports importing external buffers, it's
possible to allocate buffers in Intel GPU and share it with virtio-GPU.
In addition, we'd like to share buffers in dGPU local memory to achieve
zero-copy when scanning out with dGPU, making this change a
prerequisite.

Tracked-On: OAM-127438
Signed-off-by: Weifeng Liu <[email protected]>
(cherry picked from commit 2988b19)
Signed-off-by: Lina Sun <[email protected]>
  • Loading branch information
phreer authored and lsun30 committed Dec 6, 2024
1 parent 3646886 commit 0cf63ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 48 deletions.
64 changes: 17 additions & 47 deletions src/gallium/drivers/iris/iris_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,43 +1130,6 @@ iris_resource_create_for_buffer(struct pipe_screen *pscreen,
return &res->base.b;
}

static struct pipe_resource *
iris_resource_create_renderonly(struct pipe_screen *pscreen,
const struct pipe_resource *templ)
{
struct iris_screen *screen = (struct iris_screen *)pscreen;
struct pipe_resource scanout_templat = *templ;
struct renderonly_scanout *scanout;
struct winsys_handle handle;
struct pipe_resource *pres;

if (templ->bind & (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DEPTH_STENCIL)) {
scanout_templat.width0 = align(templ->width0, 16);
scanout_templat.height0 = align(templ->height0, 16);
}

scanout = renderonly_scanout_for_resource(&scanout_templat,
screen->ro, &handle);
if (!scanout)
return NULL;

assert(handle.type == WINSYS_HANDLE_TYPE_FD);
pres = pscreen->resource_from_handle(pscreen, templ, &handle,
PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE);

close(handle.handle);
if (!pres) {
renderonly_scanout_destroy(scanout, screen->ro);
return NULL;
}

struct iris_resource *res = (struct iris_resource *)pres;
res->scanout = scanout;

return pres;
}

static struct pipe_resource *
iris_resource_create_for_image(struct pipe_screen *pscreen,
const struct pipe_resource *templ,
Expand All @@ -1176,16 +1139,6 @@ iris_resource_create_for_image(struct pipe_screen *pscreen,
{
struct iris_screen *screen = (struct iris_screen *)pscreen;
const struct intel_device_info *devinfo = screen->devinfo;
struct pipe_resource *pres;

if (screen->ro &&
(templ->bind & (PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT | PIPE_BIND_SHARED))) {
pres = iris_resource_create_renderonly(pscreen, templ);
if (pres)
return pres;
}

struct iris_resource *res = iris_alloc_resource(pscreen, templ);
if (!res)
return NULL;
Expand Down Expand Up @@ -1278,6 +1231,12 @@ iris_resource_create_for_image(struct pipe_screen *pscreen,
res->base.is_shared = true;
}

if (screen->ro &&
(templ->bind & (PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT | PIPE_BIND_SHARED))) {
res->scanout = renderonly_scanout_for_resource(&res->base.b, screen->ro, NULL);
}

return &res->base.b;

fail:
Expand Down Expand Up @@ -1447,6 +1406,17 @@ iris_resource_from_handle(struct pipe_screen *pscreen,
res->offset = whandle->offset;
res->surf.row_pitch_B = whandle->stride;

if (screen->ro) {
/* Make sure that renderonly has a handle to our buffer in the
* display's fd, so that a later renderonly_get_handle()
* returns correct handles or GEM names.
*/
res->scanout =
renderonly_create_gpu_import_for_resource(&res->base.b,
screen->ro,
NULL);
}

if (whandle->plane == 0) {
/* All planes are present. Fill out the main plane resource(s). */
for (unsigned plane = 0; plane < util_resource_num(templ); plane++) {
Expand Down
2 changes: 1 addition & 1 deletion src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct pipe_screen *kmsro_drm_screen_create(int kms_fd,
#endif
} else if (strcmp(render_dev_name, "i915") == 0) {
#if defined(GALLIUM_IRIS)
ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource,
ro->create_for_resource = renderonly_create_gpu_import_for_resource,
screen = iris_screen_create_renderonly(ro->gpu_fd, ro, config);
#endif
}
Expand Down

0 comments on commit 0cf63ef

Please sign in to comment.