Commit 9c94babf authored by Tomeu Vizoso's avatar Tomeu Vizoso

midgard: Support PIPE_BIND_SHARED resources

This gets EGL clients working in Weston.
Signed-off-by: 's avatarTomeu Vizoso <tomeu.vizoso@collabora.com>
parent ab68601c
......@@ -317,7 +317,8 @@ panfrost_is_scanout(struct panfrost_context *ctx)
return true;
return ctx->pipe_framebuffer.cbufs[0]->texture->bind & PIPE_BIND_DISPLAY_TARGET ||
ctx->pipe_framebuffer.cbufs[0]->texture->bind & PIPE_BIND_SCANOUT;
ctx->pipe_framebuffer.cbufs[0]->texture->bind & PIPE_BIND_SCANOUT ||
ctx->pipe_framebuffer.cbufs[0]->texture->bind & PIPE_BIND_SHARED;
}
/* The above function is for generalised fbd emission, used in both fragment as
......@@ -2109,7 +2110,6 @@ panfrost_create_sampler_view(
{
struct panfrost_sampler_view *so = CALLOC_STRUCT(panfrost_sampler_view);
int bytes_per_pixel = util_format_get_blocksize(texture->format);
int stride = bytes_per_pixel * texture->width0; /* TODO: Alignment? */
pipe_reference(NULL, &texture->reference);
......@@ -2245,7 +2245,8 @@ panfrost_resource_create_front(struct pipe_screen *screen,
if ((template->bind & PIPE_BIND_RENDER_TARGET) || (template->bind & PIPE_BIND_DEPTH_STENCIL)) {
if (template->bind & PIPE_BIND_DISPLAY_TARGET ||
template->bind & PIPE_BIND_SCANOUT) {
template->bind & PIPE_BIND_SCANOUT ||
template->bind & PIPE_BIND_SHARED) {
struct pipe_resource scanout_templat = *template;
struct renderonly_scanout *scanout;
struct winsys_handle handle;
......@@ -2308,6 +2309,8 @@ panfrost_resource_create_front(struct pipe_screen *screen,
}
}
printf("Created resource %p with scanout %p\n", so, so->scanout);
return (struct pipe_resource *)so;
}
......@@ -2363,12 +2366,14 @@ panfrost_transfer_map(struct pipe_context *pctx,
rsrc->mapped_direct = true;
}
if (resource->bind & PIPE_BIND_DISPLAY_TARGET) {
if (resource->bind & PIPE_BIND_DISPLAY_TARGET ||
resource->bind & PIPE_BIND_SCANOUT ||
resource->bind & PIPE_BIND_SHARED) {
/* Mipmapped readpixels?! */
assert(level == 0);
/* Set the CPU mapping to that of the framebuffer in memory, untiled */
rsrc->cpu[level] = ((struct panfrost_resource *) ctx->pipe_framebuffer.cbufs[0]->texture)->cpu[0];
rsrc->cpu[level] = rsrc->cpu[0];
/* Force a flush -- kill the pipeline */
panfrost_flush(pctx, NULL, PIPE_FLUSH_END_OF_FRAME);
......
......@@ -37,6 +37,7 @@
#include "pipe/p_screen.h"
#include "draw/draw_context.h"
#include "state_tracker/winsys_handle.h"
#include <xf86drm.h>
#include <fcntl.h>
......@@ -681,9 +682,11 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
unsigned usage)
{
struct panfrost_screen *screen = pan_screen(pscreen);
struct drm_mode_map_dumb map_arg;
struct panfrost_resource *rsc;
struct pipe_resource *prsc;
int ret;
unsigned gem_handle;
assert(whandle->type == WINSYS_HANDLE_TYPE_FD);
......@@ -711,9 +714,29 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
};
ret = pandev_ioctl(screen->fd, KBASE_IOCTL_MEM_IMPORT, &framebuffer_import);
assert(ret == 0);
rsc->gpu[0] = mmap(NULL, framebuffer_import.out.va_pages * 4096, PROT_READ | PROT_WRITE, MAP_SHARED, screen->fd, framebuffer_import.out.gpu_va);
rsc->cpu[0] = mmap(NULL, framebuffer_import.out.va_pages * 4096, PROT_READ | PROT_WRITE, MAP_SHARED, whandle->handle, 0);
ret = drmPrimeFDToHandle(screen->ro->kms_fd, whandle->handle, &gem_handle);
assert(ret >= 0);
memset(&map_arg, 0, sizeof(map_arg));
map_arg.handle = gem_handle;
ret = drmIoctl(screen->ro->kms_fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
assert(!ret);
rsc->cpu[0] = mmap(NULL, framebuffer_import.out.va_pages * 4096, PROT_READ | PROT_WRITE, MAP_SHARED, screen->ro->kms_fd, map_arg.offset);
u64 addresses[1];
addresses[0] = rsc->gpu[0];
struct kbase_ioctl_sticky_resource_map map = {
.count = 1,
.address = addresses,
};
ret = pandev_ioctl(screen->fd, KBASE_IOCTL_STICKY_RESOURCE_MAP, &map);
assert(ret == 0);
return prsc;
}
......@@ -741,8 +764,7 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen,
if (renderonly_get_handle(scanout, handle)) {
return TRUE;
} else {
printf("Missed nonrenderonly KMS handle\n");
assert(0);
printf("Missed nonrenderonly KMS handle for resource %p with scanout %p\n", pt, scanout);
return FALSE;
}
} else if (handle->type == WINSYS_HANDLE_TYPE_FD) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment