diff options
author | Stéphane Marchesin <[email protected]> | 2012-10-01 01:57:33 -0700 |
---|---|---|
committer | Stéphane Marchesin <[email protected]> | 2012-10-02 17:54:50 -0700 |
commit | fe3aeb7ea38770fce59b8261d8e2d37d4f68708f (patch) | |
tree | c69b0655a34f247d4824353fd6176015c39d96e9 /src/gallium/drivers | |
parent | 2acc7193743199701f8f6d1877a59ece0ec4fa5b (diff) |
i915g: Implement srgb textures the easy way.
Since the hw can do it, let's use the hw. It's less accurate
but doesn't have the shader instruction count shortcomings.
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/i915/i915_context.h | 2 | ||||
-rw-r--r-- | src/gallium/drivers/i915/i915_state_emit.c | 101 | ||||
-rw-r--r-- | src/gallium/drivers/i915/i915_state_sampler.c | 8 |
3 files changed, 9 insertions, 102 deletions
diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index c9198e270db..4141a3d4cf3 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -155,8 +155,6 @@ struct i915_state unsigned sampler[I915_TEX_UNITS][3]; unsigned sampler_enable_flags; unsigned sampler_enable_nr; - boolean sampler_srgb[I915_TEX_UNITS]; - int srgb_const_offset; /* texture image buffers */ unsigned texbuffer[I915_TEX_UNITS][2]; diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c index ac999792c06..590a1baa420 100644 --- a/src/gallium/drivers/i915/i915_state_emit.c +++ b/src/gallium/drivers/i915/i915_state_emit.c @@ -314,41 +314,12 @@ emit_sampler(struct i915_context *i915) } } -static boolean is_tex_instruction(uint32_t* instruction) -{ - uint32_t op = instruction[0] &0xFF000000; - return ( (op == T0_TEXLD) || - (op == T0_TEXLDP) || - (op == T0_TEXLDB)); -} - -static uint32_t tex_sampler(uint32_t* instruction) -{ - return ( instruction[0] & T0_SAMPLER_NR_MASK); -} - -static uint additional_constants(struct i915_context *i915) -{ - int i; - - for (i = 0 ; i < i915->fs->program_len; i+=3) { - if ( is_tex_instruction(i915->fs->program + i)) { - int sampler = tex_sampler(i915->fs->program + i); - assert(sampler < I915_TEX_UNITS); - if ( i915->current.sampler_srgb[sampler] ) - return 1; - } - } - return 0; -} - static void validate_constants(struct i915_context *i915, unsigned *batch_space) { int nr = i915->fs->num_constants ? 2 + 4*i915->fs->num_constants : 0; - nr += 4*additional_constants(i915); *batch_space = nr; } @@ -358,11 +329,10 @@ emit_constants(struct i915_context *i915) /* Collate the user-defined constants with the fragment shader's * immediates according to the constant_flags[] array. */ - const uint nr = i915->fs->num_constants + additional_constants(i915); + const uint nr = i915->fs->num_constants; assert(nr < I915_MAX_CONSTANT); if (nr) { - const float srgb_constants[4] = {1.0/1.055, 0.055/1.055, 2.4, 0.0822}; uint i; OUT_BATCH( _3DSTATE_PIXEL_SHADER_CONSTANTS | (nr * 4) ); @@ -375,16 +345,9 @@ emit_constants(struct i915_context *i915) c = (uint *) i915_buffer(i915->constants[PIPE_SHADER_FRAGMENT])->data; c += 4 * i; } - else if (i < i915->fs->num_constants) { + else { /* emit program constant */ c = (uint *) i915->fs->constants[i]; - } else { - /* emit constants for sRGB */ - - /* save const position in context for use in shader emit */ - i915->current.srgb_const_offset = i; - - c = (uint *) srgb_constants; } #if 0 /* debug */ { @@ -405,64 +368,14 @@ emit_constants(struct i915_context *i915) static void validate_program(struct i915_context *i915, unsigned *batch_space) { - uint additional_size = 0, i; + uint additional_size = 0; additional_size += i915->current.target_fixup_format ? 3 : 0; - for (i = 0 ; i < i915->fs->program_len; i+=3) - if ( is_tex_instruction(i915->fs->program + i) && - i915->current.sampler_srgb[tex_sampler(i915->fs->program+i)] ) - additional_size += 3 * 8 /* 8 instructions for srgb emulation */; - - /* we need more batch space if we want to emulate rgba framebuffers - * or sRGB textures */ + /* we need more batch space if we want to emulate rgba framebuffers */ *batch_space = i915->fs->decl_len + i915->fs->program_len + additional_size; } -static void emit_instruction(struct i915_context *i915, - int op, - int dst_mask, - int dst_reg, - int src0_reg, - int src1_reg, - int src2_reg) -{ - OUT_BATCH(op | - dst_mask | - 0 | /* saturate */ - A0_DEST(dst_reg) | - A0_SRC0(src0_reg) - ); - OUT_BATCH(A1_SRC0(src0_reg) | A1_SRC1(src1_reg)); - OUT_BATCH(A2_SRC1(src1_reg) | A2_SRC2(src2_reg)); -} - -static void -emit_srgb_fixup(struct i915_context *i915, - uint *program) -{ - int dst_reg = - (program[0] & UREG_TYPE_NR_MASK) >> UREG_A0_DEST_SHIFT_LEFT; - int dst_mask = program[0] & A0_DEST_CHANNEL_ALL; - int cst_idx = i915->current.srgb_const_offset; - int cst0_reg = swizzle(UREG(REG_TYPE_CONST, cst_idx), X, X, X, X); - int cst1_reg = swizzle(UREG(REG_TYPE_CONST, cst_idx), Y, Y, Y, Y); - int cst2_reg = swizzle(UREG(REG_TYPE_CONST, cst_idx), Z, Z, Z, Z); - int t1_reg = UREG(REG_TYPE_R, 1); - int t1x_reg = swizzle(UREG(REG_TYPE_R, 1), X, X, X, X); - int t1y_reg = swizzle(UREG(REG_TYPE_R, 1), Y, Y, Y, Y); - int t1z_reg = swizzle(UREG(REG_TYPE_R, 1), Z, Z, Z, Z); - - emit_instruction(i915, A0_MAD, A0_DEST_CHANNEL_ALL, t1_reg, dst_reg, cst0_reg, cst1_reg); - emit_instruction(i915, A0_LOG, A0_DEST_CHANNEL_X, t1_reg, t1x_reg, 0, 0); - emit_instruction(i915, A0_LOG, A0_DEST_CHANNEL_Y, t1_reg, t1y_reg, 0, 0); - emit_instruction(i915, A0_LOG, A0_DEST_CHANNEL_Z, t1_reg, t1z_reg, 0, 0); - emit_instruction(i915, A0_MUL, A0_DEST_CHANNEL_ALL, t1_reg, t1_reg, cst2_reg, 0); - emit_instruction(i915, A0_EXP, dst_mask & A0_DEST_CHANNEL_X, dst_reg, t1x_reg, 0, 0); - emit_instruction(i915, A0_EXP, dst_mask & A0_DEST_CHANNEL_Y, dst_reg, t1y_reg, 0, 0); - emit_instruction(i915, A0_EXP, dst_mask & A0_DEST_CHANNEL_Z, dst_reg, t1z_reg, 0, 0); -} - static void emit_program(struct i915_context *i915) { @@ -493,12 +406,6 @@ emit_program(struct i915_context *i915) OUT_BATCH(i915->fs->program[i]); OUT_BATCH(i915->fs->program[i+1]); OUT_BATCH(i915->fs->program[i+2]); - - /* TEX fixup for sRGB */ - if ( is_tex_instruction(i915->fs->program+i) && - i915->current.sampler_srgb[tex_sampler(i915->fs->program+i)] ) - emit_srgb_fixup(i915, i915->fs->program); - } /* we emit an additional mov with swizzle to fake RGBA framebuffers */ diff --git a/src/gallium/drivers/i915/i915_state_sampler.c b/src/gallium/drivers/i915/i915_state_sampler.c index 9aba68afbca..a6e4724c538 100644 --- a/src/gallium/drivers/i915/i915_state_sampler.c +++ b/src/gallium/drivers/i915/i915_state_sampler.c @@ -96,7 +96,11 @@ static void update_sampler(struct i915_context *i915, pt->format == PIPE_FORMAT_YUYV) state[0] |= SS2_COLORSPACE_CONVERSION; - /* 3D textures don't seem to respect the border color. + if (pt->format == PIPE_FORMAT_B8G8R8A8_SRGB || + pt->format == PIPE_FORMAT_L8_SRGB ) + state[0] |= SS2_REVERSE_GAMMA_ENABLE; + + /* 3D textures don't seem to respect the border color. * Fallback if there's ever a danger that they might refer to * it. * @@ -310,8 +314,6 @@ static void update_map(struct i915_context *i915, assert(depth); format = translate_texture_format(pt->format, view); - i915->current.sampler_srgb[unit] = ( pt->format == PIPE_FORMAT_B8G8R8A8_SRGB || - pt->format == PIPE_FORMAT_L8_SRGB ); pitch = tex->stride; assert(format); |