summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_lower_tex.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2018-07-12 18:23:34 -0700
committerEric Anholt <[email protected]>2018-07-13 14:02:18 -0700
commita3150c1d06ae7766c3d3fe3b33432e55c3c7527e (patch)
treee3a36acedd5764ba712d9a84dd56786e5c6f978b /src/compiler/nir/nir_lower_tex.c
parentb52d79514cad56c341235a903c689cf24d6bb95f (diff)
nir/lower_tex: Use nir_format_srgb_to_linear
A while ago, we added a bunch of format conversion helpers; we should use them instead of hand-rolling sRGB conversions. Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_lower_tex.c')
-rw-r--r--src/compiler/nir/nir_lower_tex.c21
1 files changed, 3 insertions, 18 deletions
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 9f550542fa1..dc40d82b27f 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -37,6 +37,7 @@
#include "nir.h"
#include "nir_builder.h"
+#include "nir_format_convert.h"
static void
project_src(nir_builder *b, nir_tex_instr *tex)
@@ -710,24 +711,8 @@ linearize_srgb_result(nir_builder *b, nir_tex_instr *tex)
b->cursor = nir_after_instr(&tex->instr);
- static const unsigned swiz[4] = {0, 1, 2, 0};
- nir_ssa_def *comp = nir_swizzle(b, &tex->dest.ssa, swiz, 3, true);
-
- /* Formula is:
- * (comp <= 0.04045) ?
- * (comp / 12.92) :
- * pow((comp + 0.055) / 1.055, 2.4)
- */
- nir_ssa_def *low = nir_fmul(b, comp, nir_imm_float(b, 1.0 / 12.92));
- nir_ssa_def *high = nir_fpow(b,
- nir_fmul(b,
- nir_fadd(b,
- comp,
- nir_imm_float(b, 0.055)),
- nir_imm_float(b, 1.0 / 1.055)),
- nir_imm_float(b, 2.4));
- nir_ssa_def *cond = nir_fge(b, nir_imm_float(b, 0.04045), comp);
- nir_ssa_def *rgb = nir_bcsel(b, cond, low, high);
+ nir_ssa_def *rgb =
+ nir_format_srgb_to_linear(b, nir_channels(b, &tex->dest.ssa, 0x7));
/* alpha is untouched: */
nir_ssa_def *result = nir_vec4(b,