From 2157fe967ab6813d528df058395c877dc95c8f3b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 1 Jul 2019 19:55:00 -0700 Subject: [PATCH] panfrost/midgard: Use fp16 exclusively while blending We now have some preliminary fp16 support available. We're not able to expose this for GLSL quite yet, but for internal blend shaders, we're able to do control bitness ourselves just fine. So let's fp16 that stuff! Signed-off-by: Alyssa Rosenzweig --- .../drivers/panfrost/midgard/nir_lower_blend.c | 14 +++++++------- .../panfrost/midgard/nir_lower_framebuffer.c | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/gallium/drivers/panfrost/midgard/nir_lower_blend.c b/src/gallium/drivers/panfrost/midgard/nir_lower_blend.c index 7a7f0ebabd7..af0a7ac31cf 100644 --- a/src/gallium/drivers/panfrost/midgard/nir_lower_blend.c +++ b/src/gallium/drivers/panfrost/midgard/nir_lower_blend.c @@ -82,7 +82,7 @@ nir_alpha_saturate( { nir_ssa_def *Asrc = nir_channel(b, src, 3); nir_ssa_def *Adst = nir_channel(b, dst, 3); - nir_ssa_def *one = nir_imm_float(b, 1.0); + nir_ssa_def *one = nir_imm_float16(b, 1.0); nir_ssa_def *Adsti = nir_fsub(b, one, Adst); return (chan < 3) ? nir_fmin(b, Asrc, Adsti) : one; @@ -99,7 +99,7 @@ nir_blend_factor_value( { switch (factor) { case BLEND_FACTOR_ZERO: - return nir_imm_float(b, 0.0); + return nir_imm_float16(b, 0.0); case BLEND_FACTOR_SRC_COLOR: return nir_channel(b, src, chan); case BLEND_FACTOR_DST_COLOR: @@ -132,7 +132,7 @@ nir_blend_factor( nir_blend_factor_value(b, src, dst, bconst, chan, factor); if (inverted) - f = nir_fsub(b, nir_imm_float(b, 1.0), f); + f = nir_fsub(b, nir_imm_float16(b, 1.0), f); return nir_fmul(b, raw_scalar, f); } @@ -167,7 +167,7 @@ nir_blend( nir_ssa_def *src, nir_ssa_def *dst) { /* Grab the blend constant ahead of time */ - nir_ssa_def *bconst = nir_load_blend_const_color_rgba(b); + nir_ssa_def *bconst = nir_f2f16(b, nir_load_blend_const_color_rgba(b)); /* We blend per channel and recombine later */ nir_ssa_def *channels[4]; @@ -226,13 +226,13 @@ nir_lower_blend(nir_shader *shader, nir_lower_blend_options options) b.cursor = nir_before_instr(instr); /* Grab the input color */ - nir_ssa_def *src = nir_ssa_for_src(&b, intr->src[1], 4); + nir_ssa_def *src = nir_f2f16(&b, nir_ssa_for_src(&b, intr->src[1], 4)); /* Grab the tilebuffer color - io lowered to load_output */ - nir_ssa_def *dst = nir_load_var(&b, var); + nir_ssa_def *dst = nir_f2f16(&b, nir_load_var(&b, var)); /* Blend the two colors per the passed options */ - nir_ssa_def *blended = nir_blend(&b, options, src, dst); + nir_ssa_def *blended = nir_f2f32(&b, nir_blend(&b, options, src, dst)); /* Write out the final color instead of the input */ nir_instr_rewrite_src(instr, &intr->src[1], diff --git a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c index 9a08a4c43bf..2986c3c3393 100644 --- a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c +++ b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c @@ -60,8 +60,8 @@ nir_float_to_native(nir_builder *b, nir_ssa_def *c_float) static nir_ssa_def * nir_native_to_float(nir_builder *b, nir_ssa_def *c_native) { - /* First, we convert up from u8 to f32 */ - nir_ssa_def *converted = nir_u2f32(b, nir_u2u32(b, c_native)); + /* First, we convert up from u8 to f16 */ + nir_ssa_def *converted = nir_u2f16(b, nir_u2u16(b, c_native)); /* Next, we scale down from [0, 255.0] to [0, 1] */ nir_ssa_def *scaled = nir_fsat(b, nir_fmul_imm(b, converted, 1.0/255.0)); -- 2.30.2