From f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sun, 26 Aug 2012 00:28:38 -0700 Subject: i965: Index sampler program key data by linker-assigned index. Now that most things are based on the linker-assigned index, it makes sense to convert the arrays in the VS/WM program key as well. It seems silly to leave them indexed by texture unit. Signed-off-by: Kenneth Graunke Reviewed-by: Eric Anholt --- src/mesa/drivers/dri/i965/brw_fs.cpp | 2 +- src/mesa/drivers/dri/i965/brw_fs.h | 2 +- src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 22 +++++++++++----------- src/mesa/drivers/dri/i965/brw_program.h | 2 +- src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 7 +++---- src/mesa/drivers/dri/i965/brw_wm.c | 25 +++++++++++++------------ 6 files changed, 30 insertions(+), 30 deletions(-) (limited to 'src/mesa/drivers') diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index ebb52fcef43..d896b008fd7 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -2178,7 +2178,7 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog) key.clamp_fragment_color = true; - for (int i = 0; i < BRW_MAX_TEX_UNIT; i++) { + for (int i = 0; i < MAX_SAMPLERS; i++) { /* FINISHME: depth compares might use (0,0,0,W) for example */ key.tex.swizzles[i] = SWIZZLE_XYZW; } diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index 199237a63a2..e69de31c9c5 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -306,7 +306,7 @@ public: fs_reg *emit_general_interpolation(ir_variable *ir); void emit_interpolation_setup_gen4(); void emit_interpolation_setup_gen6(); - fs_reg emit_texcoord(ir_texture *ir, int sampler); + fs_reg emit_texcoord(ir_texture *ir, int sampler, int texunit); fs_inst *emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate, fs_reg shadow_comp, fs_reg lod, fs_reg lod2); fs_inst *emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate, diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp index e3d3a98bbdf..e8f64b23b98 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp @@ -1166,7 +1166,7 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate, * setting this->result). */ fs_reg -fs_visitor::emit_texcoord(ir_texture *ir, int texunit) +fs_visitor::emit_texcoord(ir_texture *ir, int sampler, int texunit) { fs_inst *inst = NULL; @@ -1186,8 +1186,8 @@ fs_visitor::emit_texcoord(ir_texture *ir, int texunit) */ if (ir->sampler->type->sampler_dimensionality == GLSL_SAMPLER_DIM_RECT && (intel->gen < 6 || - (intel->gen >= 6 && (c->key.tex.gl_clamp_mask[0] & (1 << texunit) || - c->key.tex.gl_clamp_mask[1] & (1 << texunit))))) { + (intel->gen >= 6 && (c->key.tex.gl_clamp_mask[0] & (1 << sampler) || + c->key.tex.gl_clamp_mask[1] & (1 << sampler))))) { struct gl_program_parameter_list *params = c->fp->program.Base.Parameters; int tokens[STATE_LENGTH] = { STATE_INTERNAL, @@ -1239,7 +1239,7 @@ fs_visitor::emit_texcoord(ir_texture *ir, int texunit) needs_gl_clamp = false; for (int i = 0; i < 2; i++) { - if (c->key.tex.gl_clamp_mask[i] & (1 << texunit)) { + if (c->key.tex.gl_clamp_mask[i] & (1 << sampler)) { fs_reg chan = coordinate; chan.reg_offset += i; @@ -1265,7 +1265,7 @@ fs_visitor::emit_texcoord(ir_texture *ir, int texunit) if (ir->coordinate && needs_gl_clamp) { for (unsigned int i = 0; i < MIN2(ir->coordinate->type->vector_elements, 3); i++) { - if (c->key.tex.gl_clamp_mask[i] & (1 << texunit)) { + if (c->key.tex.gl_clamp_mask[i] & (1 << sampler)) { fs_reg chan = coordinate; chan.reg_offset += i; @@ -1292,7 +1292,7 @@ fs_visitor::visit(ir_texture *ir) * done before loading any values into MRFs for the sampler message since * generating these values may involve SEND messages that need the MRFs. */ - fs_reg coordinate = emit_texcoord(ir, texunit); + fs_reg coordinate = emit_texcoord(ir, sampler, texunit); fs_reg shadow_comparitor; if (ir->shadow_comparitor) { @@ -1350,7 +1350,7 @@ fs_visitor::visit(ir_texture *ir) if (ir->shadow_comparitor) inst->shadow_compare = true; - swizzle_result(ir, dst, texunit); + swizzle_result(ir, dst, sampler); } /** @@ -1358,7 +1358,7 @@ fs_visitor::visit(ir_texture *ir) * EXT_texture_swizzle as well as DEPTH_TEXTURE_MODE for shadow comparisons. */ void -fs_visitor::swizzle_result(ir_texture *ir, fs_reg orig_val, int texunit) +fs_visitor::swizzle_result(ir_texture *ir, fs_reg orig_val, int sampler) { this->result = orig_val; @@ -1368,11 +1368,11 @@ fs_visitor::swizzle_result(ir_texture *ir, fs_reg orig_val, int texunit) if (ir->type == glsl_type::float_type) { /* Ignore DEPTH_TEXTURE_MODE swizzling. */ assert(ir->sampler->type->sampler_shadow); - } else if (c->key.tex.swizzles[texunit] != SWIZZLE_NOOP) { + } else if (c->key.tex.swizzles[sampler] != SWIZZLE_NOOP) { fs_reg swizzled_result = fs_reg(this, glsl_type::vec4_type); for (int i = 0; i < 4; i++) { - int swiz = GET_SWZ(c->key.tex.swizzles[texunit], i); + int swiz = GET_SWZ(c->key.tex.swizzles[sampler], i); fs_reg l = swizzled_result; l.reg_offset += i; @@ -1382,7 +1382,7 @@ fs_visitor::swizzle_result(ir_texture *ir, fs_reg orig_val, int texunit) emit(BRW_OPCODE_MOV, l, fs_reg(1.0f)); } else { fs_reg r = orig_val; - r.reg_offset += GET_SWZ(c->key.tex.swizzles[texunit], i); + r.reg_offset += GET_SWZ(c->key.tex.swizzles[sampler], i); emit(BRW_OPCODE_MOV, l, r); } } diff --git a/src/mesa/drivers/dri/i965/brw_program.h b/src/mesa/drivers/dri/i965/brw_program.h index 9fbc201ec9a..10022d48cb4 100644 --- a/src/mesa/drivers/dri/i965/brw_program.h +++ b/src/mesa/drivers/dri/i965/brw_program.h @@ -31,7 +31,7 @@ struct brw_sampler_prog_key_data { /** * EXT_texture_swizzle and DEPTH_TEXTURE_MODE swizzles. */ - uint16_t swizzles[BRW_MAX_TEX_UNIT]; + uint16_t swizzles[MAX_SAMPLERS]; uint16_t gl_clamp_mask[3]; diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp index 629ecb0b6ea..682837ffa6a 100644 --- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp +++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp @@ -1833,7 +1833,6 @@ void vec4_visitor::visit(ir_texture *ir) { int sampler = _mesa_get_sampler_uniform_value(ir->sampler, prog, &vp->Base); - int texunit = vp->Base.SamplerUnits[sampler]; /* Should be lowered by do_lower_texture_projection */ assert(!ir->projector); @@ -1999,15 +1998,15 @@ vec4_visitor::visit(ir_texture *ir) emit(inst); - swizzle_result(ir, src_reg(inst->dst), texunit); + swizzle_result(ir, src_reg(inst->dst), sampler); } void -vec4_visitor::swizzle_result(ir_texture *ir, src_reg orig_val, int texunit) +vec4_visitor::swizzle_result(ir_texture *ir, src_reg orig_val, int sampler) { this->result = orig_val; - int s = c->key.tex.swizzles[texunit]; + int s = c->key.tex.swizzles[sampler]; if (ir->op == ir_txs || ir->type == glsl_type::float_type || s == SWIZZLE_NOOP) diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index ec5eccdc130..817320b8b8f 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -364,7 +364,7 @@ brw_debug_recompile_sampler_key(const struct brw_sampler_prog_key_data *old_key, { bool found = false; - for (unsigned int i = 0; i < BRW_MAX_TEX_UNIT; i++) { + for (unsigned int i = 0; i < MAX_SAMPLERS; i++) { found |= key_debug("EXT_texture_swizzle or DEPTH_TEXTURE_MODE", old_key->swizzles[i], key->swizzles[i]); } @@ -436,18 +436,19 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, const struct gl_program *prog, struct brw_sampler_prog_key_data *key) { - for (int i = 0; i < BRW_MAX_TEX_UNIT; i++) { - key->swizzles[i] = SWIZZLE_NOOP; + for (int s = 0; s < MAX_SAMPLERS; s++) { + key->swizzles[s] = SWIZZLE_NOOP; - if (!prog->TexturesUsed[i]) + if (!(prog->SamplersUsed & (1 << s))) continue; - const struct gl_texture_unit *unit = &ctx->Texture.Unit[i]; + int unit_id = prog->SamplerUnits[s]; + const struct gl_texture_unit *unit = &ctx->Texture.Unit[unit_id]; if (unit->_ReallyEnabled && unit->_Current->Target != GL_TEXTURE_BUFFER) { const struct gl_texture_object *t = unit->_Current; const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; - struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, i); + struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id); int swizzles[SWIZZLE_NIL + 1] = { SWIZZLE_X, SWIZZLE_Y, @@ -493,12 +494,12 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, } if (img->InternalFormat == GL_YCBCR_MESA) { - key->yuvtex_mask |= 1 << i; + key->yuvtex_mask |= 1 << s; if (img->TexFormat == MESA_FORMAT_YCBCR) - key->yuvtex_swap_mask |= 1 << i; + key->yuvtex_swap_mask |= 1 << s; } - key->swizzles[i] = + key->swizzles[s] = MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)], swizzles[GET_SWZ(t->_Swizzle, 1)], swizzles[GET_SWZ(t->_Swizzle, 2)], @@ -507,11 +508,11 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, if (sampler->MinFilter != GL_NEAREST && sampler->MagFilter != GL_NEAREST) { if (sampler->WrapS == GL_CLAMP) - key->gl_clamp_mask[0] |= 1 << i; + key->gl_clamp_mask[0] |= 1 << s; if (sampler->WrapT == GL_CLAMP) - key->gl_clamp_mask[1] |= 1 << i; + key->gl_clamp_mask[1] |= 1 << s; if (sampler->WrapR == GL_CLAMP) - key->gl_clamp_mask[2] |= 1 << i; + key->gl_clamp_mask[2] |= 1 << s; } } } -- cgit v1.2.3