diff options
author | Alyssa Rosenzweig <[email protected]> | 2019-07-01 17:38:26 -0700 |
---|---|---|
committer | Alyssa Rosenzweig <[email protected]> | 2019-07-10 06:12:04 -0700 |
commit | 954c6afa3e21a91042d705415a1515f1088bdc96 (patch) | |
tree | 7bc296a3d1a8a9e593e2a73506eb6435c71bc453 /src | |
parent | 0ed8cca0082052ba11279c7df28ca231ff7fc731 (diff) |
panfrost/midgard: Implement f2f16/f2f32
These conversions handle half-floats within the shader.
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Diffstat (limited to 'src')
3 files changed, 27 insertions, 3 deletions
diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c index 353875d173f..fc17ad2b051 100644 --- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c +++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c @@ -907,6 +907,24 @@ emit_alu(compiler_context *ctx, nir_alu_instr *instr) break; } + case nir_op_f2f16: { + assert(src_bitsize == 32); + + op = midgard_alu_op_fmov; + dest_override = midgard_dest_override_lower; + break; + } + + case nir_op_f2f32: { + assert(src_bitsize == 16); + + op = midgard_alu_op_fmov; + half_2 = true; + reg_mode++; + break; + } + + /* For greater-or-equal, we lower to less-or-equal and flip the * arguments */ diff --git a/src/gallium/drivers/panfrost/midgard/midgard_nir_algebraic.py b/src/gallium/drivers/panfrost/midgard/midgard_nir_algebraic.py index b05c193e507..871195b48ca 100644 --- a/src/gallium/drivers/panfrost/midgard/midgard_nir_algebraic.py +++ b/src/gallium/drivers/panfrost/midgard/midgard_nir_algebraic.py @@ -53,7 +53,10 @@ converts = [ (('u2u8', 'a@32'), ('u2u8', ('u2u16', a))), (('i2i32', 'a@8'), ('i2i32', ('i2i16', a))), - (('u2u32', 'a@8'), ('u2u32', ('u2u16', a))) + (('u2u32', 'a@8'), ('u2u32', ('u2u16', a))), + + (('f2i32', 'a@16'), ('f2i32', ('f2f32', a))), + (('f2u32', 'a@16'), ('f2u32', ('f2f32', a))), ] # Midgard scales fsin/fcos arguments by pi. diff --git a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c index 5f3115b6ae8..5233fbc9280 100644 --- a/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c +++ b/src/gallium/drivers/panfrost/midgard/nir_lower_framebuffer.c @@ -44,8 +44,11 @@ static nir_ssa_def * nir_float_to_native(nir_builder *b, nir_ssa_def *c_float) { - /* First, we scale from [0, 1] to [0, 255.0] */ - nir_ssa_def *scaled = nir_fmul_imm(b, nir_fsat(b, c_float), 255.0); + /* First, we degrade quality to fp16; we don't need the extra bits */ + nir_ssa_def *degraded = nir_f2f16(b, c_float); + + /* Scale from [0, 1] to [0, 255.0] */ + nir_ssa_def *scaled = nir_fmul_imm(b, nir_fsat(b, degraded), 255.0); /* Next, we type convert */ nir_ssa_def *converted = nir_u2u8(b, nir_f2u32(b, |