gallium/dri2: Support creating multi-planar modifier images

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Jordan Justen 2019-08-02 14:00:08 -07:00
parent fe06655e86
commit 2066966c10
No known key found for this signature in database
GPG Key ID: 37F99F68CAF992EB
1 changed files with 19 additions and 10 deletions

View File

@ -759,12 +759,18 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
for (i = num_handles - 1; i >= 0; i--) { for (i = num_handles - 1; i >= 0; i--) {
struct pipe_resource *tex; struct pipe_resource *tex;
if (whandle[i].modifier == DRM_FORMAT_MOD_INVALID) {
templ.width0 = width >> map->planes[i].width_shift; templ.width0 = width >> map->planes[i].width_shift;
templ.height0 = height >> map->planes[i].height_shift; templ.height0 = height >> map->planes[i].height_shift;
if (is_yuv) if (is_yuv)
templ.format = dri2_get_pipe_format_for_dri_format(map->planes[i].dri_format); templ.format = dri2_get_pipe_format_for_dri_format(map->planes[i].dri_format);
else else
templ.format = map->pipe_format; templ.format = map->pipe_format;
} else {
templ.width0 = width;
templ.height0 = height;
templ.format = map->pipe_format;
}
assert(templ.format != PIPE_FORMAT_NONE); assert(templ.format != PIPE_FORMAT_NONE);
tex = pscreen->resource_from_handle(pscreen, tex = pscreen->resource_from_handle(pscreen,
@ -862,19 +868,22 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
__DRIimage *img = NULL; __DRIimage *img = NULL;
unsigned err = __DRI_IMAGE_ERROR_SUCCESS; unsigned err = __DRI_IMAGE_ERROR_SUCCESS;
int i, expected_num_fds; int i, expected_num_fds;
uint64_t mod_planes = dri2_get_modifier_num_planes(modifier);
if (!map) { if (!map || (modifier != DRM_FORMAT_MOD_INVALID && mod_planes == 0)) {
err = __DRI_IMAGE_ERROR_BAD_MATCH; err = __DRI_IMAGE_ERROR_BAD_MATCH;
goto exit; goto exit;
} }
int num_handles = mod_planes > 0 ? mod_planes : map->nplanes;
switch (fourcc) { switch (fourcc) {
case __DRI_IMAGE_FOURCC_YUYV: case __DRI_IMAGE_FOURCC_YUYV:
case __DRI_IMAGE_FOURCC_UYVY: case __DRI_IMAGE_FOURCC_UYVY:
expected_num_fds = 1; expected_num_fds = 1;
break; break;
default: default:
expected_num_fds = map->nplanes; expected_num_fds = num_handles;
break; break;
} }
@ -885,9 +894,9 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
memset(whandles, 0, sizeof(whandles)); memset(whandles, 0, sizeof(whandles));
for (i = 0; i < map->nplanes; i++) { for (i = 0; i < num_handles; i++) {
int fdnum = i >= num_fds ? 0 : i; int fdnum = i >= num_fds ? 0 : i;
int index = map->planes[i].buffer_index; int index = mod_planes > 0 ? i : map->planes[i].buffer_index;
if (fds[fdnum] < 0) { if (fds[fdnum] < 0) {
err = __DRI_IMAGE_ERROR_BAD_ALLOC; err = __DRI_IMAGE_ERROR_BAD_ALLOC;
goto exit; goto exit;
@ -901,7 +910,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
} }
img = dri2_create_image_from_winsys(_screen, width, height, map, img = dri2_create_image_from_winsys(_screen, width, height, map,
map->nplanes, whandles, loaderPrivate); num_handles, whandles, loaderPrivate);
if(img == NULL) { if(img == NULL) {
err = __DRI_IMAGE_ERROR_BAD_ALLOC; err = __DRI_IMAGE_ERROR_BAD_ALLOC;
goto exit; goto exit;