Commit 47586ab5 authored by Eric Anholt's avatar Eric Anholt

v3d: Respect user-passed strides for BO imports.

If the caller has passed in a stride for (linear) BO import, we should use
that stride when rendering to the BO (or, if we some day support texturing
from linear-imported BOs, when doing the linear-to-UIF shadow copy).  This
lets us remove the extra stride-changing relayout in the simulator.
parent 5313fb8a
......@@ -331,7 +331,6 @@ v3d_bo_last_unreference_locked_timed(struct v3d_bo *bo, time_t time)
static struct v3d_bo *
v3d_bo_open_handle(struct v3d_screen *screen,
uint32_t winsys_stride,
uint32_t handle, uint32_t size)
{
struct v3d_bo *bo;
......@@ -355,8 +354,7 @@ v3d_bo_open_handle(struct v3d_screen *screen,
bo->private = false;
#ifdef USE_V3D_SIMULATOR
v3d_simulator_open_from_handle(screen->fd, winsys_stride,
bo->handle, bo->size);
v3d_simulator_open_from_handle(screen->fd, bo->handle, bo->size);
bo->map = malloc(bo->size);
#endif
......@@ -382,8 +380,7 @@ done:
}
struct v3d_bo *
v3d_bo_open_name(struct v3d_screen *screen, uint32_t name,
uint32_t winsys_stride)
v3d_bo_open_name(struct v3d_screen *screen, uint32_t name)
{
struct drm_gem_open o = {
.name = name
......@@ -395,11 +392,11 @@ v3d_bo_open_name(struct v3d_screen *screen, uint32_t name,
return NULL;
}
return v3d_bo_open_handle(screen, winsys_stride, o.handle, o.size);
return v3d_bo_open_handle(screen, o.handle, o.size);
}
struct v3d_bo *
v3d_bo_open_dmabuf(struct v3d_screen *screen, int fd, uint32_t winsys_stride)
v3d_bo_open_dmabuf(struct v3d_screen *screen, int fd)
{
uint32_t handle;
int ret = drmPrimeFDToHandle(screen->fd, fd, &handle);
......@@ -416,7 +413,7 @@ v3d_bo_open_dmabuf(struct v3d_screen *screen, int fd, uint32_t winsys_stride)
return NULL;
}
return v3d_bo_open_handle(screen, winsys_stride, handle, size);
return v3d_bo_open_handle(screen, handle, size);
}
int
......
......@@ -60,10 +60,8 @@ struct v3d_bo *v3d_bo_alloc(struct v3d_screen *screen, uint32_t size,
const char *name);
void v3d_bo_last_unreference(struct v3d_bo *bo);
void v3d_bo_last_unreference_locked_timed(struct v3d_bo *bo, time_t time);
struct v3d_bo *v3d_bo_open_name(struct v3d_screen *screen, uint32_t name,
uint32_t winsys_stride);
struct v3d_bo *v3d_bo_open_dmabuf(struct v3d_screen *screen, int fd,
uint32_t winsys_stride);
struct v3d_bo *v3d_bo_open_name(struct v3d_screen *screen, uint32_t name);
struct v3d_bo *v3d_bo_open_dmabuf(struct v3d_screen *screen, int fd);
bool v3d_bo_flink(struct v3d_bo *bo, uint32_t *name);
int v3d_bo_get_dmabuf(struct v3d_bo *bo);
......
......@@ -480,8 +480,7 @@ int v3d_simulator_flush(struct v3d_context *v3d,
struct drm_v3d_submit_cl *args,
struct v3d_job *job);
int v3d_simulator_ioctl(int fd, unsigned long request, void *arg);
void v3d_simulator_open_from_handle(int fd, uint32_t winsys_stride,
int handle, uint32_t size);
void v3d_simulator_open_from_handle(int fd, int handle, uint32_t size);
static inline int
v3d_ioctl(int fd, unsigned long request, void *arg)
......
......@@ -396,7 +396,7 @@ v3d_get_ub_pad(struct v3d_resource *rsc, uint32_t height)
}
static void
v3d_setup_slices(struct v3d_resource *rsc)
v3d_setup_slices(struct v3d_resource *rsc, uint32_t winsys_stride)
{
struct pipe_resource *prsc = &rsc->base;
uint32_t width = prsc->width0;
......@@ -498,7 +498,10 @@ v3d_setup_slices(struct v3d_resource *rsc)
}
slice->offset = offset;
slice->stride = level_width * rsc->cpp;
if (winsys_stride)
slice->stride = winsys_stride;
else
slice->stride = level_width * rsc->cpp;
slice->padded_height = level_height;
slice->size = level_height * slice->stride;
......@@ -674,7 +677,7 @@ v3d_resource_create_with_modifiers(struct pipe_screen *pscreen,
rsc->internal_format = prsc->format;
v3d_setup_slices(rsc);
v3d_setup_slices(rsc, 0);
if (!v3d_resource_bo_alloc(rsc))
goto fail;
......@@ -730,12 +733,10 @@ v3d_resource_from_handle(struct pipe_screen *pscreen,
switch (whandle->type) {
case WINSYS_HANDLE_TYPE_SHARED:
rsc->bo = v3d_bo_open_name(screen,
whandle->handle, whandle->stride);
rsc->bo = v3d_bo_open_name(screen, whandle->handle);
break;
case WINSYS_HANDLE_TYPE_FD:
rsc->bo = v3d_bo_open_dmabuf(screen,
whandle->handle, whandle->stride);
rsc->bo = v3d_bo_open_dmabuf(screen, whandle->handle);
break;
default:
fprintf(stderr,
......@@ -749,7 +750,7 @@ v3d_resource_from_handle(struct pipe_screen *pscreen,
rsc->internal_format = prsc->format;
v3d_setup_slices(rsc);
v3d_setup_slices(rsc, whandle->stride);
v3d_debug_resource_layout(rsc, "import");
if (whandle->stride != slice->stride) {
......
......@@ -104,9 +104,6 @@ struct v3d_simulator_bo {
uint32_t size;
void *vaddr;
void *winsys_map;
uint32_t winsys_stride;
int handle;
};
......@@ -200,9 +197,6 @@ v3d_free_simulator_bo(struct v3d_simulator_bo *sim_bo)
{
struct v3d_simulator_file *sim_file = sim_bo->file;
if (sim_bo->winsys_map)
munmap(sim_bo->winsys_map, sim_bo->size);
set_gmp_flags(sim_file, sim_bo->block->ofs, sim_bo->size, 0x0);
mtx_lock(&sim_state.mutex);
......@@ -274,30 +268,8 @@ v3d_simulator_flush(struct v3d_context *v3d,
struct v3d_screen *screen = v3d->screen;
int fd = screen->fd;
struct v3d_simulator_file *file = v3d_get_simulator_file_for_fd(fd);
struct v3d_surface *csurf = v3d_surface(v3d->framebuffer.cbufs[0]);
struct v3d_resource *ctex = csurf ? v3d_resource(csurf->base.texture) : NULL;
struct v3d_simulator_bo *csim_bo = ctex ? v3d_get_simulator_bo(file, ctex->bo->handle) : NULL;
uint32_t winsys_stride = ctex ? csim_bo->winsys_stride : 0;
uint32_t sim_stride = ctex ? ctex->slices[0].stride : 0;
uint32_t row_len = MIN2(sim_stride, winsys_stride);
int ret;
if (ctex && csim_bo->winsys_map) {
#if 0
fprintf(stderr, "%dx%d %d %d %d\n",
ctex->base.b.width0, ctex->base.b.height0,
winsys_stride,
sim_stride,
ctex->bo->size);
#endif
for (int y = 0; y < ctex->base.height0; y++) {
memcpy(ctex->bo->map + y * sim_stride,
csim_bo->winsys_map + y * winsys_stride,
row_len);
}
}
ret = v3d_simulator_pin_bos(fd, job);
if (ret)
return ret;
......@@ -311,48 +283,9 @@ v3d_simulator_flush(struct v3d_context *v3d,
if (ret)
return ret;
if (ctex && csim_bo->winsys_map) {
for (int y = 0; y < ctex->base.height0; y++) {
memcpy(csim_bo->winsys_map + y * winsys_stride,
ctex->bo->map + y * sim_stride,
row_len);
}
}
return 0;
}
/**
* Map the underlying GEM object from the real hardware GEM handle.
*/
static void *
v3d_simulator_map_winsys_bo(int fd, struct v3d_simulator_bo *sim_bo)
{
int ret;
void *map;
struct drm_mode_map_dumb map_dumb = {
.handle = sim_bo->handle,
};
ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &map_dumb);
if (ret != 0) {
fprintf(stderr, "map ioctl failure\n");
abort();
}
map = mmap(NULL, sim_bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, map_dumb.offset);
if (map == MAP_FAILED) {
fprintf(stderr,
"mmap of bo %d (offset 0x%016llx, size %d) failed\n",
sim_bo->handle, (long long)map_dumb.offset,
(int)sim_bo->size);
abort();
}
return map;
}
/**
* Do fixups after a BO has been opened from a handle.
*
......@@ -360,14 +293,9 @@ v3d_simulator_map_winsys_bo(int fd, struct v3d_simulator_bo *sim_bo)
* time, but we're still using drmPrimeFDToHandle() so we have this helper to
* be called afterward instead.
*/
void v3d_simulator_open_from_handle(int fd, uint32_t winsys_stride,
int handle, uint32_t size)
void v3d_simulator_open_from_handle(int fd, int handle, uint32_t size)
{
struct v3d_simulator_bo *sim_bo =
v3d_create_simulator_bo(fd, handle, size);
sim_bo->winsys_stride = winsys_stride;
sim_bo->winsys_map = v3d_simulator_map_winsys_bo(fd, sim_bo);
v3d_create_simulator_bo(fd, handle, size);
}
/**
......
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