nir/lower_tex: fixes for fp16 yuv lowering
authorRob Clark <robdclark@chromium.org>
Wed, 3 Jun 2020 18:34:09 +0000 (11:34 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 3 Jun 2020 21:24:13 +0000 (21:24 +0000)
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3079
Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5318>

src/compiler/nir/nir_lower_tex.c

index 8f373ddf67a6e83f48e0cfe1ef89687542cdd6cd..46bcc8b6d1fa83718b2b49865e5d604ef6dce978 100644 (file)
@@ -240,7 +240,8 @@ sample_plane(nir_builder *b, nir_tex_instr *tex, int plane,
    plane_tex->texture_index = tex->texture_index;
    plane_tex->sampler_index = tex->sampler_index;
 
-   nir_ssa_dest_init(&plane_tex->instr, &plane_tex->dest, 4, 32, NULL);
+   nir_ssa_dest_init(&plane_tex->instr, &plane_tex->dest, 4,
+         nir_dest_bit_size(tex->dest), NULL);
 
    nir_builder_instr_insert(b, &plane_tex->instr);
 
@@ -262,6 +263,7 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
       { { .f32 = 0.0f        }, { .f32 = -0.39176229f }, { .f32 = 2.01723214f }, { .f32 = 0.0f } },
       { { .f32 = 1.59602678f }, { .f32 = -0.81296764f }, { .f32 = 0.0f        }, { .f32 = 0.0f } },
    };
+   unsigned bit_size = nir_dest_bit_size(tex->dest);
 
    nir_ssa_def *offset =
       nir_vec4(b,
@@ -270,11 +272,14 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
                nir_imm_float(b, -1.085630787f),
                a);
 
+   offset = nir_f2fN(b, offset, bit_size);
+
+   nir_ssa_def *m0 = nir_f2fN(b, nir_build_imm(b, 4, 32, m[0]), bit_size);
+   nir_ssa_def *m1 = nir_f2fN(b, nir_build_imm(b, 4, 32, m[1]), bit_size);
+   nir_ssa_def *m2 = nir_f2fN(b, nir_build_imm(b, 4, 32, m[2]), bit_size);
+
    nir_ssa_def *result =
-      nir_ffma(b, y, nir_build_imm(b, 4, 32, m[0]),
-               nir_ffma(b, u, nir_build_imm(b, 4, 32, m[1]),
-                        nir_ffma(b, v, nir_build_imm(b, 4, 32, m[2]),
-                                 offset)));
+      nir_ffma(b, y, m0, nir_ffma(b, u, m1, nir_ffma(b, v, m2, offset)));
 
    nir_ssa_def_rewrite_uses(&tex->dest.ssa, nir_src_for_ssa(result));
 }