mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 02:48:06 +02:00
radv: Handle unnormalized samplers in YCbCr lowering
We need to divide these by their divisors and special-case COSITED_EVEN. Fixes NV12 compositing in Gamescope. Fixes:91702374("radv: Add ycbcr lowering pass.") Cc: mesa-stable Signed-off-by: Joshua Ashton <joshua@froggi.es> Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10816> (cherry picked from commit855cb78d46)
This commit is contained in:
parent
85822fb7c1
commit
3514ef15ba
2 changed files with 32 additions and 9 deletions
|
|
@ -31,7 +31,7 @@
|
|||
"description": "radv: Handle unnormalized samplers in YCbCr lowering",
|
||||
"nominated": true,
|
||||
"nomination_type": 1,
|
||||
"resolution": 0,
|
||||
"resolution": 1,
|
||||
"master_sha": null,
|
||||
"because_sha": "91702374d5d70296c967c324fff1844cc2933dd4"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ struct ycbcr_state {
|
|||
nir_tex_instr *origin_tex;
|
||||
nir_deref_instr *tex_deref;
|
||||
const struct radv_sampler_ycbcr_conversion *conversion;
|
||||
bool unnormalized_coordinates;
|
||||
};
|
||||
|
||||
static nir_ssa_def *
|
||||
|
|
@ -67,6 +68,14 @@ implicit_downsampled_coord(nir_builder *b, nir_ssa_def *value, nir_ssa_def *max_
|
|||
nir_fdiv(b, nir_imm_float(b, 1.0f), nir_fmul(b, nir_imm_float(b, div_scale), max_value)));
|
||||
}
|
||||
|
||||
static nir_ssa_def *
|
||||
implicit_downsampled_coord_unnormalized(nir_builder *b, nir_ssa_def *value, int div_scale)
|
||||
{
|
||||
return nir_fadd(
|
||||
b, value,
|
||||
nir_imm_float(b, 1.0f / (float)div_scale));
|
||||
}
|
||||
|
||||
static nir_ssa_def *
|
||||
implicit_downsampled_coords(struct ycbcr_state *state, nir_ssa_def *old_coords)
|
||||
{
|
||||
|
|
@ -82,15 +91,22 @@ implicit_downsampled_coords(struct ycbcr_state *state, nir_ssa_def *old_coords)
|
|||
chroma_format <= PIPE_VIDEO_CHROMA_FORMAT_420 ? 2 : 1};
|
||||
|
||||
for (int c = 0; c < old_coords->num_components; c++) {
|
||||
if (c < ARRAY_SIZE(divisors) && divisors[c] > 1 &&
|
||||
conversion->chroma_offsets[c] == VK_CHROMA_LOCATION_COSITED_EVEN) {
|
||||
if (!image_size)
|
||||
image_size = get_texture_size(state, state->tex_deref);
|
||||
comp[c] = nir_channel(b, old_coords, c);
|
||||
|
||||
comp[c] = implicit_downsampled_coord(b, nir_channel(b, old_coords, c),
|
||||
nir_channel(b, image_size, c), divisors[c]);
|
||||
} else {
|
||||
comp[c] = nir_channel(b, old_coords, c);
|
||||
if (c < ARRAY_SIZE(divisors) && divisors[c] > 1) {
|
||||
if (state->unnormalized_coordinates)
|
||||
comp[c] = nir_fdiv(b, comp[c], nir_imm_float(b, divisors[c]));
|
||||
|
||||
if (conversion->chroma_offsets[c] == VK_CHROMA_LOCATION_COSITED_EVEN) {
|
||||
if (state->unnormalized_coordinates) {
|
||||
comp[c] = implicit_downsampled_coord_unnormalized(b, comp[c], divisors[c]);
|
||||
} else {
|
||||
if (!image_size)
|
||||
image_size = get_texture_size(state, state->tex_deref);
|
||||
|
||||
comp[c] = implicit_downsampled_coord(b, comp[c], nir_channel(b, image_size, c), divisors[c]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -220,6 +236,10 @@ try_lower_tex_ycbcr(const struct radv_pipeline_layout *layout, nir_builder *buil
|
|||
if (!ycbcr_samplers)
|
||||
return false;
|
||||
|
||||
assert(binding->immutable_samplers_offset);
|
||||
const uint32_t *immutable_samplers =
|
||||
radv_immutable_samplers(set_layout, binding);
|
||||
|
||||
/* For the following instructions, we don't apply any change and let the
|
||||
* instruction apply to the first plane.
|
||||
*/
|
||||
|
|
@ -240,11 +260,14 @@ try_lower_tex_ycbcr(const struct radv_pipeline_layout *layout, nir_builder *buil
|
|||
if (ycbcr_sampler->format == VK_FORMAT_UNDEFINED)
|
||||
return false;
|
||||
|
||||
bool unnormalized_coordinates = immutable_samplers[4 * array_index + 0] & S_008F30_FORCE_UNNORMALIZED(1);
|
||||
|
||||
struct ycbcr_state state = {
|
||||
.builder = builder,
|
||||
.origin_tex = tex,
|
||||
.tex_deref = deref,
|
||||
.conversion = ycbcr_sampler,
|
||||
.unnormalized_coordinates = unnormalized_coordinates,
|
||||
};
|
||||
|
||||
builder->cursor = nir_before_instr(&tex->instr);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue