gallium/vl: add chroma_format arg to vl_video_buffer functions
vl_mpeg12_decoder needs to override the chroma_format value to get the
correct size calculated (chroma_format is used by vl_video_buffer_adjust_size).
I'm not sure why it's needed, but this is needed to get correct mpeg decode.
Fixes: 24f2b0a8560 ("gallium/video: remove pipe_video_buffer.chroma_format")
Acked-by: Leo Liu <leo.liu@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6817>
diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
index 5b5c4df..66d8538 100644
--- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
+++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
@@ -983,28 +983,28 @@
nr_of_idct_render_targets = 1;
formats[0] = formats[1] = formats[2] = format_config->idct_source_format;
- assert(pipe_format_to_chroma_format(formats[0]) == dec->base.chroma_format);
memset(&templat, 0, sizeof(templat));
templat.width = dec->base.width / 4;
templat.height = dec->base.height;
dec->idct_source = vl_video_buffer_create_ex
(
dec->context, &templat,
- formats, 1, 1, PIPE_USAGE_DEFAULT
+ formats, 1, 1, PIPE_USAGE_DEFAULT,
+ PIPE_VIDEO_CHROMA_FORMAT_420
);
if (!dec->idct_source)
goto error_idct_source;
formats[0] = formats[1] = formats[2] = format_config->mc_source_format;
- assert(pipe_format_to_chroma_format(formats[0]) == dec->base.chroma_format);
memset(&templat, 0, sizeof(templat));
templat.width = dec->base.width / nr_of_idct_render_targets;
templat.height = dec->base.height / 4;
dec->mc_source = vl_video_buffer_create_ex
(
dec->context, &templat,
- formats, nr_of_idct_render_targets, 1, PIPE_USAGE_DEFAULT
+ formats, nr_of_idct_render_targets, 1, PIPE_USAGE_DEFAULT,
+ PIPE_VIDEO_CHROMA_FORMAT_420
);
if (!dec->mc_source)
@@ -1055,9 +1055,10 @@
dec->mc_source = vl_video_buffer_create_ex
(
dec->context, &templat,
- formats, 1, 1, PIPE_USAGE_DEFAULT
+ formats, 1, 1, PIPE_USAGE_DEFAULT,
+ PIPE_VIDEO_CHROMA_FORMAT_420
);
-
+
return dec->mc_source != NULL;
}
diff --git a/src/gallium/auxiliary/vl/vl_stubs.c b/src/gallium/auxiliary/vl/vl_stubs.c
index befd246..02568ac 100644
--- a/src/gallium/auxiliary/vl/vl_stubs.c
+++ b/src/gallium/auxiliary/vl/vl_stubs.c
@@ -85,7 +85,8 @@
const struct pipe_video_buffer *tmpl,
enum pipe_format resource_format,
unsigned depth, unsigned array_size,
- unsigned usage, unsigned plane)
+ unsigned usage, unsigned plane,
+ enum pipe_video_chroma_format chroma_format)
{
assert(0);
}
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c
index f4fac6c..54cc0c5 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.c
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.c
@@ -169,7 +169,8 @@
const struct pipe_video_buffer *tmpl,
enum pipe_format resource_format,
unsigned depth, unsigned array_size,
- unsigned usage, unsigned plane)
+ unsigned usage, unsigned plane,
+ enum pipe_video_chroma_format chroma_format)
{
unsigned height = tmpl->height;
@@ -188,7 +189,7 @@
templ->usage = usage;
vl_video_buffer_adjust_size(&templ->width0, &height, plane,
- pipe_format_to_chroma_format(tmpl->buffer_format), false);
+ chroma_format, false);
templ->height0 = height;
}
@@ -372,7 +373,8 @@
result = vl_video_buffer_create_ex
(
pipe, &templat, resource_formats,
- 1, tmpl->interlaced ? 2 : 1, PIPE_USAGE_DEFAULT
+ 1, tmpl->interlaced ? 2 : 1, PIPE_USAGE_DEFAULT,
+ pipe_format_to_chroma_format(templat.buffer_format)
);
@@ -386,7 +388,8 @@
vl_video_buffer_create_ex(struct pipe_context *pipe,
const struct pipe_video_buffer *tmpl,
const enum pipe_format resource_formats[VL_NUM_COMPONENTS],
- unsigned depth, unsigned array_size, unsigned usage)
+ unsigned depth, unsigned array_size, unsigned usage,
+ enum pipe_video_chroma_format chroma_format)
{
struct pipe_resource res_tmpl;
struct pipe_resource *resources[VL_NUM_COMPONENTS];
@@ -396,7 +399,8 @@
memset(resources, 0, sizeof resources);
- vl_video_buffer_template(&res_tmpl, tmpl, resource_formats[0], depth, array_size, usage, 0);
+ vl_video_buffer_template(&res_tmpl, tmpl, resource_formats[0], depth, array_size,
+ usage, 0, chroma_format);
resources[0] = pipe->screen->resource_create(pipe->screen, &res_tmpl);
if (!resources[0])
goto error;
@@ -406,7 +410,8 @@
return vl_video_buffer_create_ex2(pipe, tmpl, resources);
}
- vl_video_buffer_template(&res_tmpl, tmpl, resource_formats[1], depth, array_size, usage, 1);
+ vl_video_buffer_template(&res_tmpl, tmpl, resource_formats[1], depth, array_size,
+ usage, 1, chroma_format);
resources[1] = pipe->screen->resource_create(pipe->screen, &res_tmpl);
if (!resources[1])
goto error;
@@ -414,7 +419,8 @@
if (resource_formats[2] == PIPE_FORMAT_NONE)
return vl_video_buffer_create_ex2(pipe, tmpl, resources);
- vl_video_buffer_template(&res_tmpl, tmpl, resource_formats[2], depth, array_size, usage, 2);
+ vl_video_buffer_template(&res_tmpl, tmpl, resource_formats[2], depth, array_size,
+ usage, 2, chroma_format);
resources[2] = pipe->screen->resource_create(pipe->screen, &res_tmpl);
if (!resources[2])
goto error;
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h
index fe92d4c..2045f04 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.h
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.h
@@ -119,7 +119,8 @@
const struct pipe_video_buffer *templat,
enum pipe_format resource_format,
unsigned depth, unsigned array_size,
- unsigned usage, unsigned plane);
+ unsigned usage, unsigned plane,
+ enum pipe_video_chroma_format chroma_format);
/**
* creates a video buffer, can be used as a standard implementation for pipe->create_video_buffer
@@ -135,7 +136,8 @@
vl_video_buffer_create_ex(struct pipe_context *pipe,
const struct pipe_video_buffer *templat,
const enum pipe_format resource_formats[VL_NUM_COMPONENTS],
- unsigned depth, unsigned array_size, unsigned usage);
+ unsigned depth, unsigned array_size, unsigned usage,
+ enum pipe_video_chroma_format chroma_format);
/**
* even more extended create function, provide the pipe_resource for each plane
diff --git a/src/gallium/drivers/r600/r600_uvd.c b/src/gallium/drivers/r600/r600_uvd.c
index 2e7d7ee..18ac073 100644
--- a/src/gallium/drivers/r600/r600_uvd.c
+++ b/src/gallium/drivers/r600/r600_uvd.c
@@ -66,6 +66,8 @@
struct pipe_video_buffer template;
struct pipe_resource templ;
unsigned i, array_size;
+ enum pipe_video_chroma_format chroma_format =
+ pipe_format_to_chroma_format(tmpl->buffer_format);
assert(pipe);
@@ -77,7 +79,8 @@
template.width = align(tmpl->width, VL_MACROBLOCK_WIDTH);
template.height = align(tmpl->height / array_size, VL_MACROBLOCK_HEIGHT);
- vl_video_buffer_template(&templ, &template, resource_formats[0], 1, array_size, PIPE_USAGE_DEFAULT, 0);
+ vl_video_buffer_template(&templ, &template, resource_formats[0], 1, array_size,
+ PIPE_USAGE_DEFAULT, 0, chroma_format);
if (ctx->b.chip_class < EVERGREEN || tmpl->interlaced || !R600_UVD_ENABLE_TILING)
templ.bind = PIPE_BIND_LINEAR;
resources[0] = (struct r600_texture *)
@@ -86,7 +89,8 @@
goto error;
if (resource_formats[1] != PIPE_FORMAT_NONE) {
- vl_video_buffer_template(&templ, &template, resource_formats[1], 1, array_size, PIPE_USAGE_DEFAULT, 1);
+ vl_video_buffer_template(&templ, &template, resource_formats[1], 1, array_size,
+ PIPE_USAGE_DEFAULT, 1, chroma_format);
if (ctx->b.chip_class < EVERGREEN || tmpl->interlaced || !R600_UVD_ENABLE_TILING)
templ.bind = PIPE_BIND_LINEAR;
resources[1] = (struct r600_texture *)
@@ -96,7 +100,8 @@
}
if (resource_formats[2] != PIPE_FORMAT_NONE) {
- vl_video_buffer_template(&templ, &template, resource_formats[2], 1, array_size, PIPE_USAGE_DEFAULT, 2);
+ vl_video_buffer_template(&templ, &template, resource_formats[2], 1, array_size,
+ PIPE_USAGE_DEFAULT, 2, chroma_format);
if (ctx->b.chip_class < EVERGREEN || tmpl->interlaced || !R600_UVD_ENABLE_TILING)
templ.bind = PIPE_BIND_LINEAR;
resources[2] = (struct r600_texture *)