From e5c6a92a12b5cd7db205d72039f58d302b0be9d5 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Tue, 15 Feb 2011 23:30:23 +0100 Subject: mesa: implement clamping controls (ARB_color_buffer_float) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: Author: Marek Olšák mesa: fix getteximage so that it doesn't clamp values mesa: update the compute_version function mesa: add display list support for ARB_color_buffer_float mesa: fix glGet query with GL_ALPHA_TEST_REF and ARB_color_buffer_float commit b2f6ddf907935b2594d2831ddab38cf57a1729ce Author: Luca Barbieri Date: Tue Aug 31 16:50:57 2010 +0200 mesa: document known possible deviations from ARB_color_buffer_float commit 5458935be800c1b19d1c9d1569dc4fa30a97e8b8 Author: Luca Barbieri Date: Tue Aug 24 21:54:56 2010 +0200 mesa: expose GL_ARB_color_buffer_float commit aef5c3c6be6edd076e955e37c80905bc447f8a82 Author: Luca Barbieri Date: Thu Aug 26 18:12:34 2010 +0200 mesa, mesa/st: handle read color clamping properly (I'll squash the st/mesa part to a separate commit. -Marek) We set IMAGE_CLAMP_BIT in the caller based on _ClampReadColor, where the operation mandates it. TODO: did I get the set of operations mandating it right? commit 3a9cb5e59b676b6148c50907ce6eef5441677e36 Author: Luca Barbieri Date: Thu Aug 26 18:09:41 2010 +0200 mesa: respect color clamping in texenv programs (v2) Changes in v2: - Fix attributes other than vertex color sometimes getting clamped commit de26f9e47e886e176aab6e5a2c3d4481efb64362 Author: Luca Barbieri Date: Thu Aug 26 18:05:53 2010 +0200 mesa: restore color clamps on glPopAttrib commit a55ac3c300c189616627c05d924c40a8b55bfafa Author: Luca Barbieri Date: Thu Aug 26 18:04:26 2010 +0200 mesa: clamp color queries if and only if fragment clamping is enabled commit 9940a3e31c2fb76cc3d28b15ea78dde369825107 Author: Luca Barbieri Date: Wed Aug 25 00:00:16 2010 +0200 mesa: introduce derived _ClampXxxColor state resolving FIXED_ONLY To do this, we make ClampColor call FLUSH_VERTICES with the appropriate _NEW flag. We introduce _NEW_FRAG_CLAMP since fragment clamping has wide-ranging effects, despite being in the Color attrib group. This may be easily changed by s/_NEW_FRAG_CLAMP/_NEW_COLOR/g commit 6244c446e3beed5473b4e811d10787e4019f59d6 Author: Luca Barbieri Date: Thu Aug 26 17:58:24 2010 +0200 mesa: add unclamped color parameters --- src/mesa/program/arbprogparse.c | 5 ++++- src/mesa/program/prog_statevars.c | 32 +++++++++++++++++++++++++++++--- src/mesa/program/prog_statevars.h | 1 + src/mesa/program/programopt.c | 5 +++-- src/mesa/program/programopt.h | 2 +- 5 files changed, 38 insertions(+), 7 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/arbprogparse.c b/src/mesa/program/arbprogparse.c index ca63e72c085..7f778c3c381 100644 --- a/src/mesa/program/arbprogparse.c +++ b/src/mesa/program/arbprogparse.c @@ -144,7 +144,10 @@ _mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target, * from the fragment shader. */ if (program->FogOption != GL_NONE) { - _mesa_append_fog_code(ctx, program); + /* XXX: we should somehow recompile this to remove clamping if disabled + * On the ATI driver, this is unclampled if fragment clamping is disabled + */ + _mesa_append_fog_code(ctx, program, GL_TRUE); program->FogOption = GL_NONE; } diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index c310acb01d4..384aa2cb2c6 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -237,11 +237,17 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[], { /* state[1] is the texture unit */ const GLuint unit = (GLuint) state[1]; - COPY_4V(value, ctx->Texture.Unit[unit].EnvColor); + if(ctx->Color._ClampFragmentColor) + COPY_4V(value, ctx->Texture.Unit[unit].EnvColor); + else + COPY_4V(value, ctx->Texture.Unit[unit].EnvColorUnclamped); } return; case STATE_FOG_COLOR: - COPY_4V(value, ctx->Fog.Color); + if(ctx->Color._ClampFragmentColor) + COPY_4V(value, ctx->Fog.Color); + else + COPY_4V(value, ctx->Fog.ColorUnclamped); return; case STATE_FOG_PARAMS: value[0] = ctx->Fog.Density; @@ -399,6 +405,22 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[], } return; + case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: + { + const GLuint idx = (GLuint) state[2]; + if(ctx->Light._ClampVertexColor && + (idx == VERT_ATTRIB_COLOR0 || + idx == VERT_ATTRIB_COLOR1)) { + value[0] = CLAMP(ctx->Current.Attrib[idx][0], 0.0f, 1.0f); + value[1] = CLAMP(ctx->Current.Attrib[idx][1], 0.0f, 1.0f); + value[2] = CLAMP(ctx->Current.Attrib[idx][2], 0.0f, 1.0f); + value[3] = CLAMP(ctx->Current.Attrib[idx][3], 0.0f, 1.0f); + } + else + COPY_4V(value, ctx->Current.Attrib[idx]); + } + return; + case STATE_NORMAL_SCALE: ASSIGN_4V(value, ctx->_ModelViewInvScale, @@ -649,10 +671,12 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH]) return _NEW_LIGHT; case STATE_TEXGEN: - case STATE_TEXENV_COLOR: return _NEW_TEXTURE; + case STATE_TEXENV_COLOR: + return _NEW_TEXTURE | _NEW_BUFFERS | _NEW_FRAG_CLAMP; case STATE_FOG_COLOR: + return _NEW_FOG | _NEW_BUFFERS | _NEW_FRAG_CLAMP; case STATE_FOG_PARAMS: return _NEW_FOG; @@ -688,6 +712,8 @@ _mesa_program_state_flags(const gl_state_index state[STATE_LENGTH]) switch (state[1]) { case STATE_CURRENT_ATTRIB: return _NEW_CURRENT_ATTRIB; + case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED: + return _NEW_CURRENT_ATTRIB | _NEW_LIGHT | _NEW_BUFFERS; case STATE_NORMAL_SCALE: return _NEW_MODELVIEW; diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h index f2407af9c87..9fe8d81b3dd 100644 --- a/src/mesa/program/prog_statevars.h +++ b/src/mesa/program/prog_statevars.h @@ -106,6 +106,7 @@ typedef enum gl_state_index_ { STATE_INTERNAL, /* Mesa additions */ STATE_CURRENT_ATTRIB, /* ctx->Current vertex attrib value */ + STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED, /* ctx->Current vertex attrib value after passthrough vertex processing */ STATE_NORMAL_SCALE, STATE_TEXRECT_SCALE, STATE_FOG_PARAMS_OPTIMIZED, /* for faster fog calc */ diff --git a/src/mesa/program/programopt.c b/src/mesa/program/programopt.c index f92881f8337..5ad9571f757 100644 --- a/src/mesa/program/programopt.c +++ b/src/mesa/program/programopt.c @@ -238,7 +238,7 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog) * to vertex programs too. */ void -_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog) +_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLboolean saturate) { static const gl_state_index fogPStateOpt[STATE_LENGTH] = { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 }; @@ -290,7 +290,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog) /* change the instruction to write to colorTemp w/ clamping */ inst->DstReg.File = PROGRAM_TEMPORARY; inst->DstReg.Index = colorTemp; - inst->SaturateMode = SATURATE_ZERO_ONE; + inst->SaturateMode = saturate; /* don't break (may be several writes to result.color) */ } inst++; @@ -300,6 +300,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog) _mesa_init_instructions(inst, 5); /* emit instructions to compute fog blending factor */ + /* this is always clamped to [0, 1] regardless of fragment clamping */ if (fprog->FogOption == GL_LINEAR) { /* MAD fogFactorTemp.x, fragment.fogcoord.x, fogPRefOpt.x, fogPRefOpt.y; */ inst->Opcode = OPCODE_MAD; diff --git a/src/mesa/program/programopt.h b/src/mesa/program/programopt.h index ef6f1bd0794..79631aa5843 100644 --- a/src/mesa/program/programopt.h +++ b/src/mesa/program/programopt.h @@ -32,7 +32,7 @@ extern void _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog); extern void -_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog); +_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLboolean saturate); extern void _mesa_count_texture_indirections(struct gl_program *prog); -- cgit v1.2.3 From 89d81ab16c05818b290ed735c1343d3abde449bf Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 25 Jan 2011 10:41:20 -0800 Subject: glsl: Calcluate Mesa state slots in front-end instead of back-end This should be the last bit of infrastructure changes before generating GLSL IR for assembly shaders. This commit leaves some odd code formatting in ir_to_mesa and brw_fs. This was done to minimize whitespace changes / reindentation in some loops. The following commit will restore formatting sanity. Reviewed-by: Eric Anholt Reviewed-by: Chad Versace --- src/glsl/ir.h | 26 +++++++++++++++++ src/glsl/ir_clone.cpp | 12 ++++++++ src/glsl/ir_variable.cpp | 46 +++++++++++++++++++++++++++-- src/glsl/linker.cpp | 13 +++++++++ src/mesa/drivers/dri/i965/brw_fs.cpp | 37 ++++-------------------- src/mesa/program/ir_to_mesa.cpp | 56 +++++++++++------------------------- 6 files changed, 117 insertions(+), 73 deletions(-) (limited to 'src/mesa/program') diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 39d4ebc7107..a41984310b3 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -253,6 +253,16 @@ enum ir_depth_layout { const char* depth_layout_string(ir_depth_layout layout); +/** + * Description of built-in state associated with a uniform + * + * \sa ir_variable::state_slots + */ +struct ir_state_slot { + int tokens[5]; + int swizzle; +}; + class ir_variable : public ir_instruction { public: ir_variable(const struct glsl_type *, const char *, ir_variable_mode); @@ -385,6 +395,22 @@ public: */ int location; + /** + * Built-in state that backs this uniform + * + * Once set at variable creation, \c state_slots must remain invariant. + * This is because, ideally, this array would be shared by all clones of + * this variable in the IR tree. In other words, we'd really like for it + * to be a fly-weight. + * + * If the variable is not a uniform, \c num_state_slots will be zero and + * \c state_slots will be \c NULL. + */ + /*@{*/ + unsigned num_state_slots; /**< Number of state slots used */ + ir_state_slot *state_slots; /**< State descriptors. */ + /*@}*/ + /** * Emit a warning if this variable is accessed. */ diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index 2c0574dc6bf..069bb85e8de 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -53,6 +53,18 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const var->origin_upper_left = this->origin_upper_left; var->pixel_center_integer = this->pixel_center_integer; var->explicit_location = this->explicit_location; + + var->num_state_slots = this->num_state_slots; + if (this->state_slots) { + /* FINISHME: This really wants to use something like talloc_reference, but + * FINISHME: ralloc doesn't have any similar function. + */ + var->state_slots = ralloc_array(var, ir_state_slot, + this->num_state_slots); + memcpy(var->state_slots, this->state_slots, + sizeof(this->state_slots[0]) * var->num_state_slots); + } + if (this->explicit_location) var->location = this->location; diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp index c2715254a59..f3577175691 100644 --- a/src/glsl/ir_variable.cpp +++ b/src/glsl/ir_variable.cpp @@ -327,7 +327,43 @@ static ir_variable * add_uniform(exec_list *instructions, glsl_symbol_table *symtab, const char *name, const glsl_type *type) { - return add_variable(instructions, symtab, name, type, ir_var_uniform, -1); + ir_variable *const uni = + add_variable(instructions, symtab, name, type, ir_var_uniform, -1); + + unsigned i; + for (i = 0; _mesa_builtin_uniform_desc[i].name != NULL; i++) { + if (strcmp(_mesa_builtin_uniform_desc[i].name, name) == 0) { + break; + } + } + + assert(_mesa_builtin_uniform_desc[i].name != NULL); + const struct gl_builtin_uniform_desc* const statevar = + &_mesa_builtin_uniform_desc[i]; + + const unsigned array_count = type->is_array() ? type->length : 1; + uni->num_state_slots = array_count * statevar->num_elements; + + ir_state_slot *slots = + ralloc_array(uni, ir_state_slot, uni->num_state_slots); + + uni->state_slots = slots; + + for (unsigned a = 0; a < array_count; a++) { + for (unsigned j = 0; j < statevar->num_elements; j++) { + struct gl_builtin_uniform_element *element = &statevar->elements[j]; + + memcpy(slots->tokens, element->tokens, sizeof(element->tokens)); + if (type->is_array()) { + slots->tokens[1] = a; + } + + slots->swizzle = element->swizzle; + slots++; + } + } + + return uni; } static void @@ -341,8 +377,12 @@ add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab, assert(type != NULL); - add_variable(instructions, symtab, proto->name, type, proto->mode, - proto->slot); + if (proto->mode == ir_var_uniform) { + add_uniform(instructions, symtab, proto->name, type); + } else { + add_variable(instructions, symtab, proto->name, type, proto->mode, + proto->slot); + } } static void diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index 7db5c5e8d53..17492357f2d 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -994,6 +994,19 @@ update_array_sizes(struct gl_shader_program *prog) } if (size + 1 != var->type->fields.array->length) { + /* If this is a built-in uniform (i.e., it's backed by some + * fixed-function state), adjust the number of state slots to + * match the new array size. The number of slots per array entry + * is not known. It seems saft to assume that the total number of + * slots is an integer multiple of the number of array elements. + * Determine the number of slots per array element by dividing by + * the old (total) size. + */ + if (var->num_state_slots > 0) { + var->num_state_slots = (size + 1) + * (var->num_state_slots / var->type->length); + } + var->type = glsl_type::get_array_instance(var->type->fields.array, size + 1); /* FINISHME: We should update the types of array diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index bdf05230032..cf05fb4ee86 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -399,41 +399,16 @@ fs_visitor::setup_uniform_values(int loc, const glsl_type *type) void fs_visitor::setup_builtin_uniform_values(ir_variable *ir) { - const struct gl_builtin_uniform_desc *statevar = NULL; - - for (unsigned int i = 0; _mesa_builtin_uniform_desc[i].name; i++) { - statevar = &_mesa_builtin_uniform_desc[i]; - if (strcmp(ir->name, _mesa_builtin_uniform_desc[i].name) == 0) - break; - } - - if (!statevar->name) { - fail("Failed to find builtin uniform `%s'\n", ir->name); - return; - } - - int array_count; - if (ir->type->is_array()) { - array_count = ir->type->length; - } else { - array_count = 1; - } - - for (int a = 0; a < array_count; a++) { - for (unsigned int i = 0; i < statevar->num_elements; i++) { - struct gl_builtin_uniform_element *element = &statevar->elements[i]; - int tokens[STATE_LENGTH]; - - memcpy(tokens, element->tokens, sizeof(element->tokens)); - if (ir->type->is_array()) { - tokens[1] = a; - } + const ir_state_slot *const slots = ir->state_slots; + assert(ir->state_slots != NULL); + { + for (unsigned int i = 0; i < ir->num_state_slots; i++) { /* This state reference has already been setup by ir_to_mesa, * but we'll get the same index back here. */ int index = _mesa_add_state_reference(this->fp->Base.Parameters, - (gl_state_index *)tokens); + (gl_state_index *)slots[i].tokens); /* Add each of the unique swizzles of the element as a * parameter. This'll end up matching the expected layout of @@ -441,7 +416,7 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir) */ int last_swiz = -1; for (unsigned int j = 0; j < 4; j++) { - int swiz = GET_SWZ(element->swizzle, j); + int swiz = GET_SWZ(slots[i].swizzle, j); if (swiz == last_swiz) break; last_swiz = swiz; diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 17e0f9953f9..4cca2b72460 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -754,27 +754,8 @@ ir_to_mesa_visitor::visit(ir_variable *ir) if (ir->mode == ir_var_uniform && strncmp(ir->name, "gl_", 3) == 0) { unsigned int i; - const struct gl_builtin_uniform_desc *statevar; - - for (i = 0; _mesa_builtin_uniform_desc[i].name; i++) { - if (strcmp(ir->name, _mesa_builtin_uniform_desc[i].name) == 0) - break; - } - - if (!_mesa_builtin_uniform_desc[i].name) { - fail_link(this->shader_program, - "Failed to find builtin uniform `%s'\n", ir->name); - return; - } - - statevar = &_mesa_builtin_uniform_desc[i]; - - int array_count; - if (ir->type->is_array()) { - array_count = ir->type->length; - } else { - array_count = 1; - } + const ir_state_slot *const slots = ir->state_slots; + assert(ir->state_slots != NULL); /* Check if this statevar's setup in the STATE file exactly * matches how we'll want to reference it as a @@ -782,21 +763,27 @@ ir_to_mesa_visitor::visit(ir_variable *ir) * temporary storage and hope that it'll get copy-propagated * out. */ - for (i = 0; i < statevar->num_elements; i++) { - if (statevar->elements[i].swizzle != SWIZZLE_XYZW) { + for (i = 0; i < ir->num_state_slots; i++) { + if (slots[i].swizzle != SWIZZLE_XYZW) { break; } } struct variable_storage *storage; ir_to_mesa_dst_reg dst; - if (i == statevar->num_elements) { + if (i == ir->num_state_slots) { /* We'll set the index later. */ storage = new(mem_ctx) variable_storage(ir, PROGRAM_STATE_VAR, -1); this->variables.push_tail(storage); dst = ir_to_mesa_undef_dst; } else { + /* The variable_storage constructor allocates slots based on the size + * of the type. However, this had better match the number of state + * elements that we're going to copy into the new temporary. + */ + assert(ir->num_state_slots == type_size(ir->type)); + storage = new(mem_ctx) variable_storage(ir, PROGRAM_TEMPORARY, this->next_temp); this->variables.push_tail(storage); @@ -808,29 +795,20 @@ ir_to_mesa_visitor::visit(ir_variable *ir) } - for (int a = 0; a < array_count; a++) { - for (unsigned int i = 0; i < statevar->num_elements; i++) { - struct gl_builtin_uniform_element *element = &statevar->elements[i]; - int tokens[STATE_LENGTH]; - - memcpy(tokens, element->tokens, sizeof(element->tokens)); - if (ir->type->is_array()) { - tokens[1] = a; - } - + { + for (unsigned int i = 0; i < ir->num_state_slots; i++) { int index = _mesa_add_state_reference(this->prog->Parameters, - (gl_state_index *)tokens); + (gl_state_index *)slots[i].tokens); if (storage->file == PROGRAM_STATE_VAR) { if (storage->index == -1) { storage->index = index; } else { - assert(index == - (int)(storage->index + a * statevar->num_elements + i)); + assert(index == storage->index + (int)i); } } else { ir_to_mesa_src_reg src(PROGRAM_STATE_VAR, index, NULL); - src.swizzle = element->swizzle; + src.swizzle = slots[i].swizzle; ir_to_mesa_emit_op1(ir, OPCODE_MOV, dst, src); /* even a float takes up a whole vec4 reg in a struct/array. */ dst.index++; @@ -838,7 +816,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) } } if (storage->file == PROGRAM_TEMPORARY && - dst.index != storage->index + type_size(ir->type)) { + dst.index != storage->index + ir->num_state_slots) { fail_link(this->shader_program, "failed to load builtin uniform `%s' (%d/%d regs loaded)\n", ir->name, dst.index - storage->index, -- cgit v1.2.3 From a99e80d795f7c6aec0e73369a31d1728577b9727 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 24 Mar 2011 18:31:05 -0700 Subject: mesa: Fix ugly indentation left from previous commit Reviewed-by: Eric Anholt Reviewed-by: Chad Versace --- src/mesa/drivers/dri/i965/brw_fs.cpp | 44 +++++++++++++++++------------------- src/mesa/program/ir_to_mesa.cpp | 31 ++++++++++++------------- 2 files changed, 36 insertions(+), 39 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index cf05fb4ee86..bea6b1841f5 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -402,31 +402,29 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir) const ir_state_slot *const slots = ir->state_slots; assert(ir->state_slots != NULL); - { - for (unsigned int i = 0; i < ir->num_state_slots; i++) { - /* This state reference has already been setup by ir_to_mesa, - * but we'll get the same index back here. - */ - int index = _mesa_add_state_reference(this->fp->Base.Parameters, - (gl_state_index *)slots[i].tokens); + for (unsigned int i = 0; i < ir->num_state_slots; i++) { + /* This state reference has already been setup by ir_to_mesa, but we'll + * get the same index back here. + */ + int index = _mesa_add_state_reference(this->fp->Base.Parameters, + (gl_state_index *)slots[i].tokens); - /* Add each of the unique swizzles of the element as a - * parameter. This'll end up matching the expected layout of - * the array/matrix/structure we're trying to fill in. - */ - int last_swiz = -1; - for (unsigned int j = 0; j < 4; j++) { - int swiz = GET_SWZ(slots[i].swizzle, j); - if (swiz == last_swiz) - break; - last_swiz = swiz; + /* Add each of the unique swizzles of the element as a parameter. + * This'll end up matching the expected layout of the + * array/matrix/structure we're trying to fill in. + */ + int last_swiz = -1; + for (unsigned int j = 0; j < 4; j++) { + int swiz = GET_SWZ(slots[i].swizzle, j); + if (swiz == last_swiz) + break; + last_swiz = swiz; - c->prog_data.param_convert[c->prog_data.nr_params] = - PARAM_NO_CONVERT; - this->param_index[c->prog_data.nr_params] = index; - this->param_offset[c->prog_data.nr_params] = swiz; - c->prog_data.nr_params++; - } + c->prog_data.param_convert[c->prog_data.nr_params] = + PARAM_NO_CONVERT; + this->param_index[c->prog_data.nr_params] = index; + this->param_offset[c->prog_data.nr_params] = swiz; + c->prog_data.nr_params++; } } } diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 4cca2b72460..bf2513d4748 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -795,26 +795,25 @@ ir_to_mesa_visitor::visit(ir_variable *ir) } - { - for (unsigned int i = 0; i < ir->num_state_slots; i++) { - int index = _mesa_add_state_reference(this->prog->Parameters, - (gl_state_index *)slots[i].tokens); - - if (storage->file == PROGRAM_STATE_VAR) { - if (storage->index == -1) { - storage->index = index; - } else { - assert(index == storage->index + (int)i); - } + for (unsigned int i = 0; i < ir->num_state_slots; i++) { + int index = _mesa_add_state_reference(this->prog->Parameters, + (gl_state_index *)slots[i].tokens); + + if (storage->file == PROGRAM_STATE_VAR) { + if (storage->index == -1) { + storage->index = index; } else { - ir_to_mesa_src_reg src(PROGRAM_STATE_VAR, index, NULL); - src.swizzle = slots[i].swizzle; - ir_to_mesa_emit_op1(ir, OPCODE_MOV, dst, src); - /* even a float takes up a whole vec4 reg in a struct/array. */ - dst.index++; + assert(index == storage->index + (int)i); } + } else { + ir_to_mesa_src_reg src(PROGRAM_STATE_VAR, index, NULL); + src.swizzle = slots[i].swizzle; + ir_to_mesa_emit_op1(ir, OPCODE_MOV, dst, src); + /* even a float takes up a whole vec4 reg in a struct/array. */ + dst.index++; } } + if (storage->file == PROGRAM_TEMPORARY && dst.index != storage->index + ir->num_state_slots) { fail_link(this->shader_program, -- cgit v1.2.3 From 18dcbd358f1d4fd5e4a40fa26c6d3bf99485884e Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Sun, 27 Mar 2011 01:17:43 -0700 Subject: prog_optimize: Fix reallocating registers for shaders with loops Registers that are used inside of loops need to be considered live starting with the first instruction of the outermost loop. https://bugs.freedesktop.org/show_bug.cgi?id=34370 NOTE: This is a candidate for the 7.9 and 7.10 branches. Reviewed-by: Eric Anholt --- src/mesa/program/prog_optimize.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/prog_optimize.c b/src/mesa/program/prog_optimize.c index 96971f2eda4..164297a3474 100644 --- a/src/mesa/program/prog_optimize.c +++ b/src/mesa/program/prog_optimize.c @@ -937,24 +937,35 @@ update_interval(GLint intBegin[], GLint intEnd[], GLuint index, GLuint ic) { int i; + GLuint begin = ic; + GLuint end = ic; /* If the register is used in a loop, extend its lifetime through the end * of the outermost loop that doesn't contain its definition. */ for (i = 0; i < loopStackDepth; i++) { if (intBegin[index] < loopStack[i].Start) { - ic = loopStack[i].End; + end = loopStack[i].End; break; } } + /* Variables that are live at the end of a loop will also be live at the + * beginning, so an instruction inside of a loop should have its live + * interval begin at the start of the outermost loop. + */ + if (loopStackDepth > 0 && ic > loopStack[0].Start && ic < loopStack[0].End) { + begin = loopStack[0].Start; + } + ASSERT(index < REG_ALLOCATE_MAX_PROGRAM_TEMPS); if (intBegin[index] == -1) { ASSERT(intEnd[index] == -1); - intBegin[index] = intEnd[index] = ic; + intBegin[index] = begin; + intEnd[index] = end; } else { - intEnd[index] = ic; + intEnd[index] = end; } } -- cgit v1.2.3 From 9996a86085edb2bdbcb165d985203ee8ce6a9b22 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 4 Apr 2011 13:35:26 -0700 Subject: ir_to_mesa: Handle shadow compare w/projection and LOD bias correctly The code would previously handle the projection, then swizzle the shadow comparitor into place. However, when the projection is done "by hand," as in the TXB case, the unprojected shadow comparitor would over-write the projected shadow comparitor. Shadow comparison with projection and LOD is an extremely rare case in real application code, so it shouldn't matter that we don't handle that case with the greatest efficiency. NOTE: This is a candidate for the stable branches. Reviewed-by: Brian Paul References: https://bugs.freedesktop.org/show_bug.cgi?id=32395 --- src/mesa/program/ir_to_mesa.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index bf2513d4748..7c1ae46ff33 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -2084,15 +2084,39 @@ ir_to_mesa_visitor::visit(ir_texture *ir) coord_dst.writemask = WRITEMASK_W; ir_to_mesa_emit_op1(ir, OPCODE_RCP, coord_dst, projector); + /* In the case where we have to project the coordinates "by hand," + * the shadow comparitor value must also be projected. + */ + ir_to_mesa_src_reg tmp_src = coord; + if (ir->shadow_comparitor) { + /* Slot the shadow value in as the second to last component of the + * coord. + */ + ir->shadow_comparitor->accept(this); + + tmp_src = get_temp(glsl_type::vec4_type); + ir_to_mesa_dst_reg tmp_dst = ir_to_mesa_dst_reg_from_src(tmp_src); + + tmp_dst.writemask = WRITEMASK_Z; + ir_to_mesa_emit_op1(ir, OPCODE_MOV, tmp_dst, this->result); + + tmp_dst.writemask = WRITEMASK_XY; + ir_to_mesa_emit_op1(ir, OPCODE_MOV, tmp_dst, coord); + } + coord_dst.writemask = WRITEMASK_XYZ; - ir_to_mesa_emit_op2(ir, OPCODE_MUL, coord_dst, coord, coord_w); + ir_to_mesa_emit_op2(ir, OPCODE_MUL, coord_dst, tmp_src, coord_w); coord_dst.writemask = WRITEMASK_XYZW; coord.swizzle = SWIZZLE_XYZW; } } - if (ir->shadow_comparitor) { + /* If projection is done and the opcode is not OPCODE_TXP, then the shadow + * comparitor was put in the correct place (and projected) by the code, + * above, that handles by-hand projection. + */ + if (ir->shadow_comparitor && (!ir->projector || opcode == OPCODE_TXP)) { /* Slot the shadow value in as the second to last component of the * coord. */ -- cgit v1.2.3 From 461273e9105b8d0d53c26854ac5ba68814c31a67 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Apr 2011 11:30:36 -0700 Subject: ir_to_mesa: Rename src_reg and dst_reg variables to src and dst. This is in preparation from removing the "ir_to_mesa_" prefix on the src_reg and dst_reg types, which would cause a naming conflict. Reviewed-by: Ian Romanick --- src/mesa/program/ir_to_mesa.cpp | 205 ++++++++++++++++++++-------------------- 1 file changed, 101 insertions(+), 104 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 7c1ae46ff33..8cbb877d3aa 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -118,8 +118,8 @@ public: } enum prog_opcode op; - ir_to_mesa_dst_reg dst_reg; - ir_to_mesa_src_reg src_reg[3]; + ir_to_mesa_dst_reg dst; + ir_to_mesa_src_reg src[3]; /** Pointer to the ir source this tree came from for debugging */ ir_instruction *ir; GLboolean cond_update; @@ -371,10 +371,10 @@ ir_to_mesa_visitor::ir_to_mesa_emit_op3(ir_instruction *ir, assert(num_reladdr == 0); inst->op = op; - inst->dst_reg = dst; - inst->src_reg[0] = src0; - inst->src_reg[1] = src1; - inst->src_reg[2] = src2; + inst->dst = dst; + inst->src[0] = src0; + inst->src[1] = src1; + inst->src[2] = src2; inst->ir = ir; inst->function = NULL; @@ -434,15 +434,15 @@ ir_to_mesa_visitor::ir_to_mesa_emit_dp(ir_instruction *ir, inline ir_to_mesa_dst_reg ir_to_mesa_dst_reg_from_src(ir_to_mesa_src_reg reg) { - ir_to_mesa_dst_reg dst_reg; + ir_to_mesa_dst_reg dst; - dst_reg.file = reg.file; - dst_reg.index = reg.index; - dst_reg.writemask = WRITEMASK_XYZW; - dst_reg.cond_mask = COND_TR; - dst_reg.reladdr = reg.reladdr; + dst.file = reg.file; + dst.index = reg.index; + dst.writemask = WRITEMASK_XYZW; + dst.cond_mask = COND_TR; + dst.reladdr = reg.reladdr; - return dst_reg; + return dst; } inline ir_to_mesa_src_reg @@ -504,7 +504,7 @@ ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op2(ir_instruction *ir, dst, src0, src1); - inst->dst_reg.writemask = this_mask; + inst->dst.writemask = this_mask; done_mask |= this_mask; } } @@ -597,7 +597,7 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, /* Emit the SCS instruction. */ inst = ir_to_mesa_emit_op1(ir, OPCODE_SCS, tmp_dst, src0); - inst->dst_reg.writemask = scs_mask; + inst->dst.writemask = scs_mask; /* Move the result of the SCS instruction to the desired location in * the destination. @@ -605,13 +605,13 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, tmp.swizzle = MAKE_SWIZZLE4(component, component, component, component); inst = ir_to_mesa_emit_op1(ir, OPCODE_SCS, dst, tmp); - inst->dst_reg.writemask = this_mask; + inst->dst.writemask = this_mask; } else { /* Emit the SCS instruction to write directly to the destination. */ ir_to_mesa_instruction *inst = ir_to_mesa_emit_op1(ir, OPCODE_SCS, dst, src0); - inst->dst_reg.writemask = scs_mask; + inst->dst.writemask = scs_mask; } done_mask |= this_mask; @@ -621,12 +621,12 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, struct ir_to_mesa_src_reg ir_to_mesa_visitor::src_reg_for_float(float val) { - ir_to_mesa_src_reg src_reg(PROGRAM_CONSTANT, -1, NULL); + ir_to_mesa_src_reg src(PROGRAM_CONSTANT, -1, NULL); - src_reg.index = _mesa_add_unnamed_constant(this->prog->Parameters, - &val, 1, &src_reg.swizzle); + src.index = _mesa_add_unnamed_constant(this->prog->Parameters, + &val, 1, &src.swizzle); - return src_reg; + return src; } static int @@ -679,28 +679,28 @@ type_size(const struct glsl_type *type) ir_to_mesa_src_reg ir_to_mesa_visitor::get_temp(const glsl_type *type) { - ir_to_mesa_src_reg src_reg; + ir_to_mesa_src_reg src; int swizzle[4]; int i; - src_reg.file = PROGRAM_TEMPORARY; - src_reg.index = next_temp; - src_reg.reladdr = NULL; + src.file = PROGRAM_TEMPORARY; + src.index = next_temp; + src.reladdr = NULL; next_temp += type_size(type); if (type->is_array() || type->is_record()) { - src_reg.swizzle = SWIZZLE_NOOP; + src.swizzle = SWIZZLE_NOOP; } else { for (i = 0; i < type->vector_elements; i++) swizzle[i] = i; for (; i < 4; i++) swizzle[i] = type->vector_elements - 1; - src_reg.swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], - swizzle[2], swizzle[3]); + src.swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], + swizzle[2], swizzle[3]); } - src_reg.negate = 0; + src.negate = 0; - return src_reg; + return src; } variable_storage * @@ -1403,7 +1403,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) void ir_to_mesa_visitor::visit(ir_swizzle *ir) { - ir_to_mesa_src_reg src_reg; + ir_to_mesa_src_reg src; int i; int swizzle[4]; @@ -1413,23 +1413,23 @@ ir_to_mesa_visitor::visit(ir_swizzle *ir) */ ir->val->accept(this); - src_reg = this->result; - assert(src_reg.file != PROGRAM_UNDEFINED); + src = this->result; + assert(src.file != PROGRAM_UNDEFINED); for (i = 0; i < 4; i++) { if (i < ir->type->vector_elements) { switch (i) { case 0: - swizzle[i] = GET_SWZ(src_reg.swizzle, ir->mask.x); + swizzle[i] = GET_SWZ(src.swizzle, ir->mask.x); break; case 1: - swizzle[i] = GET_SWZ(src_reg.swizzle, ir->mask.y); + swizzle[i] = GET_SWZ(src.swizzle, ir->mask.y); break; case 2: - swizzle[i] = GET_SWZ(src_reg.swizzle, ir->mask.z); + swizzle[i] = GET_SWZ(src.swizzle, ir->mask.z); break; case 3: - swizzle[i] = GET_SWZ(src_reg.swizzle, ir->mask.w); + swizzle[i] = GET_SWZ(src.swizzle, ir->mask.w); break; } } else { @@ -1440,12 +1440,9 @@ ir_to_mesa_visitor::visit(ir_swizzle *ir) } } - src_reg.swizzle = MAKE_SWIZZLE4(swizzle[0], - swizzle[1], - swizzle[2], - swizzle[3]); + src.swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], swizzle[3]); - this->result = src_reg; + this->result = src; } void @@ -1517,16 +1514,16 @@ void ir_to_mesa_visitor::visit(ir_dereference_array *ir) { ir_constant *index; - ir_to_mesa_src_reg src_reg; + ir_to_mesa_src_reg src; int element_size = type_size(ir->type); index = ir->array_index->constant_expression_value(); ir->array->accept(this); - src_reg = this->result; + src = this->result; if (index) { - src_reg.index += index->value.i[0] * element_size; + src.index += index->value.i[0] * element_size; } else { ir_to_mesa_src_reg array_base = this->result; /* Variable index array dereference. It eats the "vec4" of the @@ -1547,17 +1544,17 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir) this->result, src_reg_for_float(element_size)); } - src_reg.reladdr = ralloc(mem_ctx, ir_to_mesa_src_reg); - memcpy(src_reg.reladdr, &index_reg, sizeof(index_reg)); + src.reladdr = ralloc(mem_ctx, ir_to_mesa_src_reg); + memcpy(src.reladdr, &index_reg, sizeof(index_reg)); } /* If the type is smaller than a vec4, replicate the last channel out. */ if (ir->type->is_scalar() || ir->type->is_vector()) - src_reg.swizzle = swizzle_for_size(ir->type->vector_elements); + src.swizzle = swizzle_for_size(ir->type->vector_elements); else - src_reg.swizzle = SWIZZLE_NOOP; + src.swizzle = SWIZZLE_NOOP; - this->result = src_reg; + this->result = src; } void @@ -1783,7 +1780,7 @@ ir_to_mesa_visitor::visit(ir_assignment *ir) void ir_to_mesa_visitor::visit(ir_constant *ir) { - ir_to_mesa_src_reg src_reg; + ir_to_mesa_src_reg src; GLfloat stack_vals[4] = { 0 }; GLfloat *values = stack_vals; unsigned int i; @@ -1805,12 +1802,12 @@ ir_to_mesa_visitor::visit(ir_constant *ir) assert(size > 0); field_value->accept(this); - src_reg = this->result; + src = this->result; for (i = 0; i < (unsigned int)size; i++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, temp, src_reg); + ir_to_mesa_emit_op1(ir, OPCODE_MOV, temp, src); - src_reg.index++; + src.index++; temp.index++; } } @@ -1827,11 +1824,11 @@ ir_to_mesa_visitor::visit(ir_constant *ir) for (i = 0; i < ir->type->length; i++) { ir->array_elements[i]->accept(this); - src_reg = this->result; + src = this->result; for (int j = 0; j < size; j++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, temp, src_reg); + ir_to_mesa_emit_op1(ir, OPCODE_MOV, temp, src); - src_reg.index++; + src.index++; temp.index++; } } @@ -1847,12 +1844,12 @@ ir_to_mesa_visitor::visit(ir_constant *ir) assert(ir->type->base_type == GLSL_TYPE_FLOAT); values = &ir->value.f[i * ir->type->vector_elements]; - src_reg = ir_to_mesa_src_reg(PROGRAM_CONSTANT, -1, NULL); - src_reg.index = _mesa_add_unnamed_constant(this->prog->Parameters, + src = ir_to_mesa_src_reg(PROGRAM_CONSTANT, -1, NULL); + src.index = _mesa_add_unnamed_constant(this->prog->Parameters, values, ir->type->vector_elements, - &src_reg.swizzle); - ir_to_mesa_emit_op1(ir, OPCODE_MOV, mat_column, src_reg); + &src.swizzle); + ir_to_mesa_emit_op1(ir, OPCODE_MOV, mat_column, src); mat_column.index++; } @@ -1861,7 +1858,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) return; } - src_reg.file = PROGRAM_CONSTANT; + src.file = PROGRAM_CONSTANT; switch (ir->type->base_type) { case GLSL_TYPE_FLOAT: values = &ir->value.f[0]; @@ -2239,7 +2236,7 @@ ir_to_mesa_visitor::visit(ir_if *ir) cond_inst->cond_update = GL_TRUE; if_inst = ir_to_mesa_emit_op0(ir->condition, OPCODE_IF); - if_inst->dst_reg.cond_mask = COND_NE; + if_inst->dst.cond_mask = COND_NE; } else { if_inst = ir_to_mesa_emit_op1(ir->condition, OPCODE_IF, ir_to_mesa_undef_dst, @@ -2731,17 +2728,17 @@ ir_to_mesa_visitor::copy_propagate(void) foreach_iter(exec_list_iterator, iter, this->instructions) { ir_to_mesa_instruction *inst = (ir_to_mesa_instruction *)iter.get(); - assert(inst->dst_reg.file != PROGRAM_TEMPORARY - || inst->dst_reg.index < this->next_temp); + assert(inst->dst.file != PROGRAM_TEMPORARY + || inst->dst.index < this->next_temp); /* First, do any copy propagation possible into the src regs. */ for (int r = 0; r < 3; r++) { ir_to_mesa_instruction *first = NULL; bool good = true; - int acp_base = inst->src_reg[r].index * 4; + int acp_base = inst->src[r].index * 4; - if (inst->src_reg[r].file != PROGRAM_TEMPORARY || - inst->src_reg[r].reladdr) + if (inst->src[r].file != PROGRAM_TEMPORARY || + inst->src[r].reladdr) continue; /* See if we can find entries in the ACP consisting of MOVs @@ -2749,7 +2746,7 @@ ir_to_mesa_visitor::copy_propagate(void) * of this src register reference. */ for (int i = 0; i < 4; i++) { - int src_chan = GET_SWZ(inst->src_reg[r].swizzle, i); + int src_chan = GET_SWZ(inst->src[r].swizzle, i); ir_to_mesa_instruction *copy_chan = acp[acp_base + src_chan]; if (!copy_chan) { @@ -2762,8 +2759,8 @@ ir_to_mesa_visitor::copy_propagate(void) if (!first) { first = copy_chan; } else { - if (first->src_reg[0].file != copy_chan->src_reg[0].file || - first->src_reg[0].index != copy_chan->src_reg[0].index) { + if (first->src[0].file != copy_chan->src[0].file || + first->src[0].index != copy_chan->src[0].index) { good = false; break; } @@ -2774,17 +2771,17 @@ ir_to_mesa_visitor::copy_propagate(void) /* We've now validated that we can copy-propagate to * replace this src register reference. Do it. */ - inst->src_reg[r].file = first->src_reg[0].file; - inst->src_reg[r].index = first->src_reg[0].index; + inst->src[r].file = first->src[0].file; + inst->src[r].index = first->src[0].index; int swizzle = 0; for (int i = 0; i < 4; i++) { - int src_chan = GET_SWZ(inst->src_reg[r].swizzle, i); + int src_chan = GET_SWZ(inst->src[r].swizzle, i); ir_to_mesa_instruction *copy_inst = acp[acp_base + src_chan]; - swizzle |= (GET_SWZ(copy_inst->src_reg[0].swizzle, src_chan) << + swizzle |= (GET_SWZ(copy_inst->src[0].swizzle, src_chan) << (3 * i)); } - inst->src_reg[r].swizzle = swizzle; + inst->src[r].swizzle = swizzle; } } @@ -2821,13 +2818,13 @@ ir_to_mesa_visitor::copy_propagate(void) /* Continuing the block, clear any written channels from * the ACP. */ - if (inst->dst_reg.file == PROGRAM_TEMPORARY && inst->dst_reg.reladdr) { + if (inst->dst.file == PROGRAM_TEMPORARY && inst->dst.reladdr) { /* Any temporary might be written, so no copy propagation * across this instruction. */ memset(acp, 0, sizeof(*acp) * this->next_temp * 4); - } else if (inst->dst_reg.file == PROGRAM_OUTPUT && - inst->dst_reg.reladdr) { + } else if (inst->dst.file == PROGRAM_OUTPUT && + inst->dst.reladdr) { /* Any output might be written, so no copy propagation * from outputs across this instruction. */ @@ -2836,17 +2833,17 @@ ir_to_mesa_visitor::copy_propagate(void) if (!acp[4 * r + c]) continue; - if (acp[4 * r + c]->src_reg[0].file == PROGRAM_OUTPUT) + if (acp[4 * r + c]->src[0].file == PROGRAM_OUTPUT) acp[4 * r + c] = NULL; } } - } else if (inst->dst_reg.file == PROGRAM_TEMPORARY || - inst->dst_reg.file == PROGRAM_OUTPUT) { + } else if (inst->dst.file == PROGRAM_TEMPORARY || + inst->dst.file == PROGRAM_OUTPUT) { /* Clear where it's used as dst. */ - if (inst->dst_reg.file == PROGRAM_TEMPORARY) { + if (inst->dst.file == PROGRAM_TEMPORARY) { for (int c = 0; c < 4; c++) { - if (inst->dst_reg.writemask & (1 << c)) { - acp[4 * inst->dst_reg.index + c] = NULL; + if (inst->dst.writemask & (1 << c)) { + acp[4 * inst->dst.index + c] = NULL; } } } @@ -2857,11 +2854,11 @@ ir_to_mesa_visitor::copy_propagate(void) if (!acp[4 * r + c]) continue; - int src_chan = GET_SWZ(acp[4 * r + c]->src_reg[0].swizzle, c); + int src_chan = GET_SWZ(acp[4 * r + c]->src[0].swizzle, c); - if (acp[4 * r + c]->src_reg[0].file == inst->dst_reg.file && - acp[4 * r + c]->src_reg[0].index == inst->dst_reg.index && - inst->dst_reg.writemask & (1 << src_chan)) + if (acp[4 * r + c]->src[0].file == inst->dst.file && + acp[4 * r + c]->src[0].index == inst->dst.index && + inst->dst.writemask & (1 << src_chan)) { acp[4 * r + c] = NULL; } @@ -2873,15 +2870,15 @@ ir_to_mesa_visitor::copy_propagate(void) /* If this is a copy, add it to the ACP. */ if (inst->op == OPCODE_MOV && - inst->dst_reg.file == PROGRAM_TEMPORARY && - !inst->dst_reg.reladdr && + inst->dst.file == PROGRAM_TEMPORARY && + !inst->dst.reladdr && !inst->saturate && - !inst->src_reg[0].reladdr && - !inst->src_reg[0].negate) { + !inst->src[0].reladdr && + !inst->src[0].negate) { for (int i = 0; i < 4; i++) { - if (inst->dst_reg.writemask & (1 << i)) { - acp[4 * inst->dst_reg.index + i] = inst; - acp_level[4 * inst->dst_reg.index + i] = level; + if (inst->dst.writemask & (1 << i)) { + acp[4 * inst->dst.index + i] = inst; + acp_level[4 * inst->dst.index + i] = level; } } } @@ -3003,14 +3000,14 @@ get_mesa_program(struct gl_context *ctx, mesa_inst->CondUpdate = inst->cond_update; if (inst->saturate) mesa_inst->SaturateMode = SATURATE_ZERO_ONE; - mesa_inst->DstReg.File = inst->dst_reg.file; - mesa_inst->DstReg.Index = inst->dst_reg.index; - mesa_inst->DstReg.CondMask = inst->dst_reg.cond_mask; - mesa_inst->DstReg.WriteMask = inst->dst_reg.writemask; - mesa_inst->DstReg.RelAddr = inst->dst_reg.reladdr != NULL; - mesa_inst->SrcReg[0] = mesa_src_reg_from_ir_src_reg(inst->src_reg[0]); - mesa_inst->SrcReg[1] = mesa_src_reg_from_ir_src_reg(inst->src_reg[1]); - mesa_inst->SrcReg[2] = mesa_src_reg_from_ir_src_reg(inst->src_reg[2]); + mesa_inst->DstReg.File = inst->dst.file; + mesa_inst->DstReg.Index = inst->dst.index; + mesa_inst->DstReg.CondMask = inst->dst.cond_mask; + mesa_inst->DstReg.WriteMask = inst->dst.writemask; + mesa_inst->DstReg.RelAddr = inst->dst.reladdr != NULL; + mesa_inst->SrcReg[0] = mesa_src_reg_from_ir_src_reg(inst->src[0]); + mesa_inst->SrcReg[1] = mesa_src_reg_from_ir_src_reg(inst->src[1]); + mesa_inst->SrcReg[2] = mesa_src_reg_from_ir_src_reg(inst->src[2]); mesa_inst->TexSrcUnit = inst->sampler; mesa_inst->TexSrcTarget = inst->tex_target; mesa_inst->TexShadow = inst->tex_shadow; -- cgit v1.2.3 From fc6b4332c32461d0e092c908a0f3d9d44d1452a9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Apr 2011 11:43:21 -0700 Subject: ir_to_mesa: Remove the "ir_to_mesa_" prefix on src_reg/dst_reg types. Both classes are completely private to ir_to_mesa.cpp, so there won't be any name conflicts with other parts of Mesa. The prefix simply makes it harder to read. Also, use a class rather than typedef structs. Reviewed-by: Ian Romanick --- src/mesa/program/ir_to_mesa.cpp | 242 ++++++++++++++++++++-------------------- 1 file changed, 121 insertions(+), 121 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 8cbb877d3aa..8eec5bf5339 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -62,8 +62,9 @@ static int swizzle_for_size(int size); * This struct is a corresponding struct to Mesa prog_src_register, with * wider fields. */ -typedef struct ir_to_mesa_src_reg { - ir_to_mesa_src_reg(int file, int index, const glsl_type *type) +class src_reg { +public: + src_reg(int file, int index, const glsl_type *type) { this->file = (gl_register_file) file; this->index = index; @@ -75,7 +76,7 @@ typedef struct ir_to_mesa_src_reg { this->reladdr = NULL; } - ir_to_mesa_src_reg() + src_reg() { this->file = PROGRAM_UNDEFINED; this->index = 0; @@ -89,19 +90,20 @@ typedef struct ir_to_mesa_src_reg { GLuint swizzle; /**< SWIZZLE_XYZWONEZERO swizzles from Mesa. */ int negate; /**< NEGATE_XYZW mask from mesa */ /** Register index should be offset by the integer in this reg. */ - ir_to_mesa_src_reg *reladdr; -} ir_to_mesa_src_reg; + src_reg *reladdr; +}; -typedef struct ir_to_mesa_dst_reg { +class dst_reg { +public: int file; /**< PROGRAM_* from Mesa */ int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */ int writemask; /**< Bitfield of WRITEMASK_[XYZW] */ GLuint cond_mask:4; /** Register index should be offset by the integer in this reg. */ - ir_to_mesa_src_reg *reladdr; -} ir_to_mesa_dst_reg; + src_reg *reladdr; +}; -extern ir_to_mesa_src_reg ir_to_mesa_undef; +extern src_reg ir_to_mesa_undef; class ir_to_mesa_instruction : public exec_node { public: @@ -118,8 +120,8 @@ public: } enum prog_opcode op; - ir_to_mesa_dst_reg dst; - ir_to_mesa_src_reg src[3]; + dst_reg dst; + src_reg src[3]; /** Pointer to the ir source this tree came from for debugging */ ir_instruction *ir; GLboolean cond_update; @@ -174,7 +176,7 @@ public: int inst; /** Storage for the return value. */ - ir_to_mesa_src_reg return_reg; + src_reg return_reg; }; class ir_to_mesa_visitor : public ir_visitor { @@ -195,11 +197,10 @@ public: function_entry *get_function_signature(ir_function_signature *sig); - ir_to_mesa_src_reg get_temp(const glsl_type *type); - void reladdr_to_temp(ir_instruction *ir, - ir_to_mesa_src_reg *reg, int *num_reladdr); + src_reg get_temp(const glsl_type *type); + void reladdr_to_temp(ir_instruction *ir, src_reg *reg, int *num_reladdr); - struct ir_to_mesa_src_reg src_reg_for_float(float val); + src_reg src_reg_for_float(float val); /** * \name Visit methods @@ -228,7 +229,7 @@ public: virtual void visit(ir_if *); /*@}*/ - struct ir_to_mesa_src_reg result; + src_reg result; /** List of variable_storage */ exec_list variables; @@ -245,21 +246,21 @@ public: ir_to_mesa_instruction *ir_to_mesa_emit_op1(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0); + dst_reg dst, + src_reg src0); ir_to_mesa_instruction *ir_to_mesa_emit_op2(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0, - ir_to_mesa_src_reg src1); + dst_reg dst, + src_reg src0, + src_reg src1); ir_to_mesa_instruction *ir_to_mesa_emit_op3(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0, - ir_to_mesa_src_reg src1, - ir_to_mesa_src_reg src2); + dst_reg dst, + src_reg src0, + src_reg src1, + src_reg src2); /** * Emit the correct dot-product instruction for the type of arguments @@ -267,25 +268,24 @@ public: * \sa ir_to_mesa_emit_op2 */ void ir_to_mesa_emit_dp(ir_instruction *ir, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0, - ir_to_mesa_src_reg src1, + dst_reg dst, + src_reg src0, + src_reg src1, unsigned elements); void ir_to_mesa_emit_scalar_op1(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0); + dst_reg dst, + src_reg src0); void ir_to_mesa_emit_scalar_op2(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0, - ir_to_mesa_src_reg src1); + dst_reg dst, + src_reg src0, + src_reg src1); void emit_scs(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - const ir_to_mesa_src_reg &src); + dst_reg dst, const src_reg &src); GLboolean try_emit_mad(ir_expression *ir, int mul_operand); @@ -300,13 +300,13 @@ public: void *mem_ctx; }; -ir_to_mesa_src_reg ir_to_mesa_undef = ir_to_mesa_src_reg(PROGRAM_UNDEFINED, 0, NULL); +src_reg ir_to_mesa_undef = src_reg(PROGRAM_UNDEFINED, 0, NULL); -ir_to_mesa_dst_reg ir_to_mesa_undef_dst = { +dst_reg ir_to_mesa_undef_dst = { PROGRAM_UNDEFINED, 0, SWIZZLE_NOOP, COND_TR, NULL, }; -ir_to_mesa_dst_reg ir_to_mesa_address_reg = { +dst_reg ir_to_mesa_address_reg = { PROGRAM_ADDRESS, 0, WRITEMASK_X, COND_TR, NULL }; @@ -341,10 +341,10 @@ swizzle_for_size(int size) ir_to_mesa_instruction * ir_to_mesa_visitor::ir_to_mesa_emit_op3(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0, - ir_to_mesa_src_reg src1, - ir_to_mesa_src_reg src2) + dst_reg dst, + src_reg src0, + src_reg src1, + src_reg src2) { ir_to_mesa_instruction *inst = new(mem_ctx) ir_to_mesa_instruction(); int num_reladdr = 0; @@ -388,9 +388,9 @@ ir_to_mesa_visitor::ir_to_mesa_emit_op3(ir_instruction *ir, ir_to_mesa_instruction * ir_to_mesa_visitor::ir_to_mesa_emit_op2(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0, - ir_to_mesa_src_reg src1) + dst_reg dst, + src_reg src0, + src_reg src1) { return ir_to_mesa_emit_op3(ir, op, dst, src0, src1, ir_to_mesa_undef); } @@ -398,8 +398,8 @@ ir_to_mesa_visitor::ir_to_mesa_emit_op2(ir_instruction *ir, ir_to_mesa_instruction * ir_to_mesa_visitor::ir_to_mesa_emit_op1(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0) + dst_reg dst, + src_reg src0) { assert(dst.writemask != 0); return ir_to_mesa_emit_op3(ir, op, dst, @@ -418,9 +418,9 @@ ir_to_mesa_visitor::ir_to_mesa_emit_op0(ir_instruction *ir, void ir_to_mesa_visitor::ir_to_mesa_emit_dp(ir_instruction *ir, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0, - ir_to_mesa_src_reg src1, + dst_reg dst, + src_reg src0, + src_reg src1, unsigned elements) { static const gl_inst_opcode dot_opcodes[] = { @@ -431,10 +431,10 @@ ir_to_mesa_visitor::ir_to_mesa_emit_dp(ir_instruction *ir, dst, src0, src1, ir_to_mesa_undef); } -inline ir_to_mesa_dst_reg -ir_to_mesa_dst_reg_from_src(ir_to_mesa_src_reg reg) +inline dst_reg +ir_to_mesa_dst_reg_from_src(src_reg reg) { - ir_to_mesa_dst_reg dst; + dst_reg dst; dst.file = reg.file; dst.index = reg.index; @@ -445,10 +445,10 @@ ir_to_mesa_dst_reg_from_src(ir_to_mesa_src_reg reg) return dst; } -inline ir_to_mesa_src_reg -ir_to_mesa_src_reg_from_dst(ir_to_mesa_dst_reg reg) +inline src_reg +ir_to_mesa_src_reg_from_dst(dst_reg reg) { - return ir_to_mesa_src_reg(reg.file, reg.index, NULL); + return src_reg(reg.file, reg.index, NULL); } /** @@ -462,9 +462,9 @@ ir_to_mesa_src_reg_from_dst(ir_to_mesa_dst_reg reg) void ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op2(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg orig_src0, - ir_to_mesa_src_reg orig_src1) + dst_reg dst, + src_reg orig_src0, + src_reg orig_src1) { int i, j; int done_mask = ~dst.writemask; @@ -476,8 +476,8 @@ ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op2(ir_instruction *ir, for (i = 0; i < 4; i++) { GLuint this_mask = (1 << i); ir_to_mesa_instruction *inst; - ir_to_mesa_src_reg src0 = orig_src0; - ir_to_mesa_src_reg src1 = orig_src1; + src_reg src0 = orig_src0; + src_reg src1 = orig_src1; if (done_mask & this_mask) continue; @@ -512,10 +512,10 @@ ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op2(ir_instruction *ir, void ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op1(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - ir_to_mesa_src_reg src0) + dst_reg dst, + src_reg src0) { - ir_to_mesa_src_reg undef = ir_to_mesa_undef; + src_reg undef = ir_to_mesa_undef; undef.swizzle = SWIZZLE_XXXX; @@ -538,8 +538,8 @@ ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op1(ir_instruction *ir, */ void ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, - ir_to_mesa_dst_reg dst, - const ir_to_mesa_src_reg &src) + dst_reg dst, + const src_reg &src) { /* Vertex programs cannot use the SCS opcode. */ @@ -551,7 +551,7 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, const unsigned component = (op == OPCODE_SIN) ? 0 : 1; const unsigned scs_mask = (1U << component); int done_mask = ~dst.writemask; - ir_to_mesa_src_reg tmp; + src_reg tmp; assert(op == OPCODE_SIN || op == OPCODE_COS); @@ -564,7 +564,7 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, for (unsigned i = 0; i < 4; i++) { unsigned this_mask = (1U << i); - ir_to_mesa_src_reg src0 = src; + src_reg src0 = src; if ((done_mask & this_mask) != 0) continue; @@ -592,7 +592,7 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, if (this_mask != scs_mask) { ir_to_mesa_instruction *inst; - ir_to_mesa_dst_reg tmp_dst = ir_to_mesa_dst_reg_from_src(tmp); + dst_reg tmp_dst = ir_to_mesa_dst_reg_from_src(tmp); /* Emit the SCS instruction. */ @@ -618,10 +618,10 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, } } -struct ir_to_mesa_src_reg +struct src_reg ir_to_mesa_visitor::src_reg_for_float(float val) { - ir_to_mesa_src_reg src(PROGRAM_CONSTANT, -1, NULL); + src_reg src(PROGRAM_CONSTANT, -1, NULL); src.index = _mesa_add_unnamed_constant(this->prog->Parameters, &val, 1, &src.swizzle); @@ -676,10 +676,10 @@ type_size(const struct glsl_type *type) * storage). Actual register allocation for the Mesa VM occurs in a * pass over the Mesa IR later. */ -ir_to_mesa_src_reg +src_reg ir_to_mesa_visitor::get_temp(const glsl_type *type) { - ir_to_mesa_src_reg src; + src_reg src; int swizzle[4]; int i; @@ -770,7 +770,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) } struct variable_storage *storage; - ir_to_mesa_dst_reg dst; + dst_reg dst; if (i == ir->num_state_slots) { /* We'll set the index later. */ storage = new(mem_ctx) variable_storage(ir, PROGRAM_STATE_VAR, -1); @@ -789,9 +789,9 @@ ir_to_mesa_visitor::visit(ir_variable *ir) this->variables.push_tail(storage); this->next_temp += type_size(ir->type); - dst = ir_to_mesa_dst_reg_from_src(ir_to_mesa_src_reg(PROGRAM_TEMPORARY, - storage->index, - NULL)); + dst = ir_to_mesa_dst_reg_from_src(src_reg(PROGRAM_TEMPORARY, + storage->index, + NULL)); } @@ -806,7 +806,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) assert(index == storage->index + (int)i); } } else { - ir_to_mesa_src_reg src(PROGRAM_STATE_VAR, index, NULL); + src_reg src(PROGRAM_STATE_VAR, index, NULL); src.swizzle = slots[i].swizzle; ir_to_mesa_emit_op1(ir, OPCODE_MOV, dst, src); /* even a float takes up a whole vec4 reg in a struct/array. */ @@ -924,7 +924,7 @@ GLboolean ir_to_mesa_visitor::try_emit_mad(ir_expression *ir, int mul_operand) { int nonmul_operand = 1 - mul_operand; - ir_to_mesa_src_reg a, b, c; + src_reg a, b, c; ir_expression *expr = ir->operands[mul_operand]->as_expression(); if (!expr || expr->operation != ir_binop_mul) @@ -958,7 +958,7 @@ ir_to_mesa_visitor::try_emit_sat(ir_expression *ir) return false; sat_src->accept(this); - ir_to_mesa_src_reg src = this->result; + src_reg src = this->result; this->result = get_temp(ir->type); ir_to_mesa_instruction *inst; @@ -972,7 +972,7 @@ ir_to_mesa_visitor::try_emit_sat(ir_expression *ir) void ir_to_mesa_visitor::reladdr_to_temp(ir_instruction *ir, - ir_to_mesa_src_reg *reg, int *num_reladdr) + src_reg *reg, int *num_reladdr) { if (!reg->reladdr) return; @@ -980,7 +980,7 @@ ir_to_mesa_visitor::reladdr_to_temp(ir_instruction *ir, ir_to_mesa_emit_op1(ir, OPCODE_ARL, ir_to_mesa_address_reg, *reg->reladdr); if (*num_reladdr != 1) { - ir_to_mesa_src_reg temp = get_temp(glsl_type::vec4_type); + src_reg temp = get_temp(glsl_type::vec4_type); ir_to_mesa_emit_op1(ir, OPCODE_MOV, ir_to_mesa_dst_reg_from_src(temp), *reg); @@ -1079,7 +1079,7 @@ ir_to_mesa_visitor::emit_swz(ir_expression *ir) exit(1); } - ir_to_mesa_src_reg src; + src_reg src; src = this->result; src.swizzle = MAKE_SWIZZLE4(components[0], @@ -1094,8 +1094,8 @@ ir_to_mesa_visitor::emit_swz(ir_expression *ir) /* Storage for our result. Ideally for an assignment we'd be using the * actual storage for the result here, instead. */ - const ir_to_mesa_src_reg result_src = get_temp(ir->type); - ir_to_mesa_dst_reg result_dst = ir_to_mesa_dst_reg_from_src(result_src); + const src_reg result_src = get_temp(ir->type); + dst_reg result_dst = ir_to_mesa_dst_reg_from_src(result_src); /* Limit writes to the channels that will be used by result_src later. * This does limit this temp's use as a temporary for multi-instruction @@ -1111,9 +1111,9 @@ void ir_to_mesa_visitor::visit(ir_expression *ir) { unsigned int operand; - struct ir_to_mesa_src_reg op[Elements(ir->operands)]; - struct ir_to_mesa_src_reg result_src; - struct ir_to_mesa_dst_reg result_dst; + src_reg op[Elements(ir->operands)]; + src_reg result_src; + dst_reg result_dst; /* Quick peephole: Emit OPCODE_MAD(a, b, c) instead of ADD(MUL(a, b), c) */ @@ -1265,7 +1265,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) /* "==" operator producing a scalar boolean. */ if (ir->operands[0]->type->is_vector() || ir->operands[1]->type->is_vector()) { - ir_to_mesa_src_reg temp = get_temp(glsl_type::vec4_type); + src_reg temp = get_temp(glsl_type::vec4_type); ir_to_mesa_emit_op2(ir, OPCODE_SNE, ir_to_mesa_dst_reg_from_src(temp), op[0], op[1]); ir_to_mesa_emit_dp(ir, result_dst, temp, temp, vector_elements); @@ -1279,7 +1279,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) /* "!=" operator producing a scalar boolean. */ if (ir->operands[0]->type->is_vector() || ir->operands[1]->type->is_vector()) { - ir_to_mesa_src_reg temp = get_temp(glsl_type::vec4_type); + src_reg temp = get_temp(glsl_type::vec4_type); ir_to_mesa_emit_op2(ir, OPCODE_SNE, ir_to_mesa_dst_reg_from_src(temp), op[0], op[1]); ir_to_mesa_emit_dp(ir, result_dst, temp, temp, vector_elements); @@ -1403,7 +1403,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) void ir_to_mesa_visitor::visit(ir_swizzle *ir) { - ir_to_mesa_src_reg src; + src_reg src; int i; int swizzle[4]; @@ -1507,14 +1507,14 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir) } } - this->result = ir_to_mesa_src_reg(entry->file, entry->index, var->type); + this->result = src_reg(entry->file, entry->index, var->type); } void ir_to_mesa_visitor::visit(ir_dereference_array *ir) { ir_constant *index; - ir_to_mesa_src_reg src; + src_reg src; int element_size = type_size(ir->type); index = ir->array_index->constant_expression_value(); @@ -1525,14 +1525,14 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir) if (index) { src.index += index->value.i[0] * element_size; } else { - ir_to_mesa_src_reg array_base = this->result; + src_reg array_base = this->result; /* Variable index array dereference. It eats the "vec4" of the * base of the array and an index that offsets the Mesa register * index. */ ir->array_index->accept(this); - ir_to_mesa_src_reg index_reg; + src_reg index_reg; if (element_size == 1) { index_reg = this->result; @@ -1544,7 +1544,7 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir) this->result, src_reg_for_float(element_size)); } - src.reladdr = ralloc(mem_ctx, ir_to_mesa_src_reg); + src.reladdr = ralloc(mem_ctx, src_reg); memcpy(src.reladdr, &index_reg, sizeof(index_reg)); } @@ -1586,7 +1586,7 @@ ir_to_mesa_visitor::visit(ir_dereference_record *ir) * instead of potentially using a temporary like we might with the * ir_dereference handler. */ -static struct ir_to_mesa_dst_reg +static dst_reg get_assignment_lhs(ir_dereference *ir, ir_to_mesa_visitor *v) { /* The LHS must be a dereference. If the LHS is a variable indexed array @@ -1696,8 +1696,8 @@ ir_to_mesa_visitor::process_move_condition(ir_rvalue *ir) void ir_to_mesa_visitor::visit(ir_assignment *ir) { - struct ir_to_mesa_dst_reg l; - struct ir_to_mesa_src_reg r; + dst_reg l; + src_reg r; int i; ir->rhs->accept(this); @@ -1753,7 +1753,7 @@ ir_to_mesa_visitor::visit(ir_assignment *ir) if (ir->condition) { const bool switch_order = this->process_move_condition(ir->condition); - ir_to_mesa_src_reg condition = this->result; + src_reg condition = this->result; for (i = 0; i < type_size(ir->lhs->type); i++) { if (switch_order) { @@ -1780,7 +1780,7 @@ ir_to_mesa_visitor::visit(ir_assignment *ir) void ir_to_mesa_visitor::visit(ir_constant *ir) { - ir_to_mesa_src_reg src; + src_reg src; GLfloat stack_vals[4] = { 0 }; GLfloat *values = stack_vals; unsigned int i; @@ -1792,8 +1792,8 @@ ir_to_mesa_visitor::visit(ir_constant *ir) */ if (ir->type->base_type == GLSL_TYPE_STRUCT) { - ir_to_mesa_src_reg temp_base = get_temp(ir->type); - ir_to_mesa_dst_reg temp = ir_to_mesa_dst_reg_from_src(temp_base); + src_reg temp_base = get_temp(ir->type); + dst_reg temp = ir_to_mesa_dst_reg_from_src(temp_base); foreach_iter(exec_list_iterator, iter, ir->components) { ir_constant *field_value = (ir_constant *)iter.get(); @@ -1816,8 +1816,8 @@ ir_to_mesa_visitor::visit(ir_constant *ir) } if (ir->type->is_array()) { - ir_to_mesa_src_reg temp_base = get_temp(ir->type); - ir_to_mesa_dst_reg temp = ir_to_mesa_dst_reg_from_src(temp_base); + src_reg temp_base = get_temp(ir->type); + dst_reg temp = ir_to_mesa_dst_reg_from_src(temp_base); int size = type_size(ir->type->fields.array); assert(size > 0); @@ -1837,14 +1837,14 @@ ir_to_mesa_visitor::visit(ir_constant *ir) } if (ir->type->is_matrix()) { - ir_to_mesa_src_reg mat = get_temp(ir->type); - ir_to_mesa_dst_reg mat_column = ir_to_mesa_dst_reg_from_src(mat); + src_reg mat = get_temp(ir->type); + dst_reg mat_column = ir_to_mesa_dst_reg_from_src(mat); for (i = 0; i < ir->type->matrix_columns; i++) { assert(ir->type->base_type == GLSL_TYPE_FLOAT); values = &ir->value.f[i * ir->type->vector_elements]; - src = ir_to_mesa_src_reg(PROGRAM_CONSTANT, -1, NULL); + src = src_reg(PROGRAM_CONSTANT, -1, NULL); src.index = _mesa_add_unnamed_constant(this->prog->Parameters, values, ir->type->vector_elements, @@ -1882,7 +1882,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) assert(!"Non-float/uint/int/bool constant"); } - this->result = ir_to_mesa_src_reg(PROGRAM_CONSTANT, -1, ir->type); + this->result = src_reg(PROGRAM_CONSTANT, -1, ir->type); this->result.index = _mesa_add_unnamed_constant(this->prog->Parameters, values, ir->type->vector_elements, @@ -1951,9 +1951,9 @@ ir_to_mesa_visitor::visit(ir_call *ir) assert(storage); param_rval->accept(this); - ir_to_mesa_src_reg r = this->result; + src_reg r = this->result; - ir_to_mesa_dst_reg l; + dst_reg l; l.file = storage->file; l.index = storage->index; l.reladdr = NULL; @@ -1987,7 +1987,7 @@ ir_to_mesa_visitor::visit(ir_call *ir) variable_storage *storage = find_variable_storage(param); assert(storage); - ir_to_mesa_src_reg r; + src_reg r; r.file = storage->file; r.index = storage->index; r.reladdr = NULL; @@ -1995,7 +1995,7 @@ ir_to_mesa_visitor::visit(ir_call *ir) r.negate = 0; param_rval->accept(this); - ir_to_mesa_dst_reg l = ir_to_mesa_dst_reg_from_src(this->result); + dst_reg l = ir_to_mesa_dst_reg_from_src(this->result); for (i = 0; i < type_size(param->type); i++) { ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); @@ -2015,8 +2015,8 @@ ir_to_mesa_visitor::visit(ir_call *ir) void ir_to_mesa_visitor::visit(ir_texture *ir) { - ir_to_mesa_src_reg result_src, coord, lod_info, projector; - ir_to_mesa_dst_reg result_dst, coord_dst; + src_reg result_src, coord, lod_info, projector; + dst_reg result_dst, coord_dst; ir_to_mesa_instruction *inst = NULL; prog_opcode opcode = OPCODE_NOP; @@ -2071,7 +2071,7 @@ ir_to_mesa_visitor::visit(ir_texture *ir) coord_dst.writemask = WRITEMASK_XYZW; opcode = OPCODE_TXP; } else { - ir_to_mesa_src_reg coord_w = coord; + src_reg coord_w = coord; coord_w.swizzle = SWIZZLE_WWWW; /* For the other TEX opcodes there's no projective version @@ -2173,13 +2173,13 @@ void ir_to_mesa_visitor::visit(ir_return *ir) { if (ir->get_value()) { - ir_to_mesa_dst_reg l; + dst_reg l; int i; assert(current_function); ir->get_value()->accept(this); - ir_to_mesa_src_reg r = this->result; + src_reg r = this->result; l = ir_to_mesa_dst_reg_from_src(current_function->return_reg); @@ -2228,7 +2228,7 @@ ir_to_mesa_visitor::visit(ir_if *ir) * have something to set cond_update on. */ if (cond_inst == prev_inst) { - ir_to_mesa_src_reg temp = get_temp(glsl_type::bool_type); + src_reg temp = get_temp(glsl_type::bool_type); cond_inst = ir_to_mesa_emit_op1(ir->condition, OPCODE_MOV, ir_to_mesa_dst_reg_from_src(temp), result); @@ -2271,7 +2271,7 @@ ir_to_mesa_visitor::~ir_to_mesa_visitor() } static struct prog_src_register -mesa_src_reg_from_ir_src_reg(ir_to_mesa_src_reg reg) +mesa_src_reg_from_ir_src_reg(src_reg reg) { struct prog_src_register mesa_reg; -- cgit v1.2.3 From cb21fa91b8e8f46d7d27604b9cb77fba031567f4 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Apr 2011 12:01:59 -0700 Subject: ir_to_mesa: Use constructors to convert between src_reg and dst_reg. Rather than ir_to_mesa_dst_reg_from_src and ir_to_mesa_src_reg_from_dst. The new constructors are marked 'explicit' so that the compiler can catch cases where source and destination registers were accidentally interchanged. This also necessitated using constructors to initialize the undef and address registers, as well as adding a default constructor. Reviewed-by: Ian Romanick --- src/mesa/program/ir_to_mesa.cpp | 117 ++++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 51 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 8eec5bf5339..588348062b3 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -56,6 +56,9 @@ extern "C" { #include "program/sampler.h" } +class src_reg; +class dst_reg; + static int swizzle_for_size(int size); /** @@ -85,6 +88,8 @@ public: this->reladdr = NULL; } + explicit src_reg(dst_reg reg); + gl_register_file file; /**< PROGRAM_* from Mesa */ int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */ GLuint swizzle; /**< SWIZZLE_XYZWONEZERO swizzles from Mesa. */ @@ -95,6 +100,26 @@ public: class dst_reg { public: + dst_reg(int file, int writemask) + { + this->file = file; + this->index = 0; + this->writemask = writemask; + this->cond_mask = COND_TR; + this->reladdr = NULL; + } + + dst_reg() + { + this->file = PROGRAM_UNDEFINED; + this->index = 0; + this->writemask = 0; + this->cond_mask = COND_TR; + this->reladdr = NULL; + } + + explicit dst_reg(src_reg reg); + int file; /**< PROGRAM_* from Mesa */ int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */ int writemask; /**< Bitfield of WRITEMASK_[XYZW] */ @@ -103,6 +128,24 @@ public: src_reg *reladdr; }; +src_reg::src_reg(dst_reg reg) +{ + this->file = (gl_register_file) reg.file; + this->index = reg.index; + this->swizzle = SWIZZLE_XYZW; + this->negate = 0; + this->reladdr = NULL; +} + +dst_reg::dst_reg(src_reg reg) +{ + this->file = reg.file; + this->index = reg.index; + this->writemask = WRITEMASK_XYZW; + this->cond_mask = COND_TR; + this->reladdr = reg.reladdr; +} + extern src_reg ir_to_mesa_undef; class ir_to_mesa_instruction : public exec_node { @@ -302,13 +345,9 @@ public: src_reg ir_to_mesa_undef = src_reg(PROGRAM_UNDEFINED, 0, NULL); -dst_reg ir_to_mesa_undef_dst = { - PROGRAM_UNDEFINED, 0, SWIZZLE_NOOP, COND_TR, NULL, -}; +dst_reg ir_to_mesa_undef_dst = dst_reg(PROGRAM_UNDEFINED, SWIZZLE_NOOP); -dst_reg ir_to_mesa_address_reg = { - PROGRAM_ADDRESS, 0, WRITEMASK_X, COND_TR, NULL -}; +dst_reg ir_to_mesa_address_reg = dst_reg(PROGRAM_ADDRESS, WRITEMASK_X); static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3); @@ -431,26 +470,6 @@ ir_to_mesa_visitor::ir_to_mesa_emit_dp(ir_instruction *ir, dst, src0, src1, ir_to_mesa_undef); } -inline dst_reg -ir_to_mesa_dst_reg_from_src(src_reg reg) -{ - dst_reg dst; - - dst.file = reg.file; - dst.index = reg.index; - dst.writemask = WRITEMASK_XYZW; - dst.cond_mask = COND_TR; - dst.reladdr = reg.reladdr; - - return dst; -} - -inline src_reg -ir_to_mesa_src_reg_from_dst(dst_reg reg) -{ - return src_reg(reg.file, reg.index, NULL); -} - /** * Emits Mesa scalar opcodes to produce unique answers across channels. * @@ -592,7 +611,7 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, if (this_mask != scs_mask) { ir_to_mesa_instruction *inst; - dst_reg tmp_dst = ir_to_mesa_dst_reg_from_src(tmp); + dst_reg tmp_dst = dst_reg(tmp); /* Emit the SCS instruction. */ @@ -789,9 +808,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) this->variables.push_tail(storage); this->next_temp += type_size(ir->type); - dst = ir_to_mesa_dst_reg_from_src(src_reg(PROGRAM_TEMPORARY, - storage->index, - NULL)); + dst = dst_reg(src_reg(PROGRAM_TEMPORARY, storage->index, NULL)); } @@ -939,7 +956,7 @@ ir_to_mesa_visitor::try_emit_mad(ir_expression *ir, int mul_operand) this->result = get_temp(ir->type); ir_to_mesa_emit_op3(ir, OPCODE_MAD, - ir_to_mesa_dst_reg_from_src(this->result), a, b, c); + dst_reg(this->result), a, b, c); return true; } @@ -963,7 +980,7 @@ ir_to_mesa_visitor::try_emit_sat(ir_expression *ir) this->result = get_temp(ir->type); ir_to_mesa_instruction *inst; inst = ir_to_mesa_emit_op1(ir, OPCODE_MOV, - ir_to_mesa_dst_reg_from_src(this->result), + dst_reg(this->result), src); inst->saturate = true; @@ -983,7 +1000,7 @@ ir_to_mesa_visitor::reladdr_to_temp(ir_instruction *ir, src_reg temp = get_temp(glsl_type::vec4_type); ir_to_mesa_emit_op1(ir, OPCODE_MOV, - ir_to_mesa_dst_reg_from_src(temp), *reg); + dst_reg(temp), *reg); *reg = temp; } @@ -1095,7 +1112,7 @@ ir_to_mesa_visitor::emit_swz(ir_expression *ir) * actual storage for the result here, instead. */ const src_reg result_src = get_temp(ir->type); - dst_reg result_dst = ir_to_mesa_dst_reg_from_src(result_src); + dst_reg result_dst = dst_reg(result_src); /* Limit writes to the channels that will be used by result_src later. * This does limit this temp's use as a temporary for multi-instruction @@ -1161,7 +1178,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) */ result_src = get_temp(ir->type); /* convenience for the emit functions below. */ - result_dst = ir_to_mesa_dst_reg_from_src(result_src); + result_dst = dst_reg(result_src); /* Limit writes to the channels that will be used by result_src later. * This does limit this temp's use as a temporary for multi-instruction * sequences. @@ -1267,7 +1284,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) ir->operands[1]->type->is_vector()) { src_reg temp = get_temp(glsl_type::vec4_type); ir_to_mesa_emit_op2(ir, OPCODE_SNE, - ir_to_mesa_dst_reg_from_src(temp), op[0], op[1]); + dst_reg(temp), op[0], op[1]); ir_to_mesa_emit_dp(ir, result_dst, temp, temp, vector_elements); ir_to_mesa_emit_op2(ir, OPCODE_SEQ, result_dst, result_src, src_reg_for_float(0.0)); @@ -1281,7 +1298,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) ir->operands[1]->type->is_vector()) { src_reg temp = get_temp(glsl_type::vec4_type); ir_to_mesa_emit_op2(ir, OPCODE_SNE, - ir_to_mesa_dst_reg_from_src(temp), op[0], op[1]); + dst_reg(temp), op[0], op[1]); ir_to_mesa_emit_dp(ir, result_dst, temp, temp, vector_elements); ir_to_mesa_emit_op2(ir, OPCODE_SNE, result_dst, result_src, src_reg_for_float(0.0)); @@ -1540,7 +1557,7 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir) index_reg = get_temp(glsl_type::float_type); ir_to_mesa_emit_op2(ir, OPCODE_MUL, - ir_to_mesa_dst_reg_from_src(index_reg), + dst_reg(index_reg), this->result, src_reg_for_float(element_size)); } @@ -1603,7 +1620,7 @@ get_assignment_lhs(ir_dereference *ir, ir_to_mesa_visitor *v) * swizzles in it and write swizzles using writemask, though. */ ir->accept(v); - return ir_to_mesa_dst_reg_from_src(v->result); + return dst_reg(v->result); } /** @@ -1757,11 +1774,9 @@ ir_to_mesa_visitor::visit(ir_assignment *ir) for (i = 0; i < type_size(ir->lhs->type); i++) { if (switch_order) { - ir_to_mesa_emit_op3(ir, OPCODE_CMP, l, - condition, ir_to_mesa_src_reg_from_dst(l), r); + ir_to_mesa_emit_op3(ir, OPCODE_CMP, l, condition, src_reg(l), r); } else { - ir_to_mesa_emit_op3(ir, OPCODE_CMP, l, - condition, r, ir_to_mesa_src_reg_from_dst(l)); + ir_to_mesa_emit_op3(ir, OPCODE_CMP, l, condition, r, src_reg(l)); } l.index++; @@ -1793,7 +1808,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) if (ir->type->base_type == GLSL_TYPE_STRUCT) { src_reg temp_base = get_temp(ir->type); - dst_reg temp = ir_to_mesa_dst_reg_from_src(temp_base); + dst_reg temp = dst_reg(temp_base); foreach_iter(exec_list_iterator, iter, ir->components) { ir_constant *field_value = (ir_constant *)iter.get(); @@ -1817,7 +1832,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) if (ir->type->is_array()) { src_reg temp_base = get_temp(ir->type); - dst_reg temp = ir_to_mesa_dst_reg_from_src(temp_base); + dst_reg temp = dst_reg(temp_base); int size = type_size(ir->type->fields.array); assert(size > 0); @@ -1838,7 +1853,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) if (ir->type->is_matrix()) { src_reg mat = get_temp(ir->type); - dst_reg mat_column = ir_to_mesa_dst_reg_from_src(mat); + dst_reg mat_column = dst_reg(mat); for (i = 0; i < ir->type->matrix_columns; i++) { assert(ir->type->base_type == GLSL_TYPE_FLOAT); @@ -1995,7 +2010,7 @@ ir_to_mesa_visitor::visit(ir_call *ir) r.negate = 0; param_rval->accept(this); - dst_reg l = ir_to_mesa_dst_reg_from_src(this->result); + dst_reg l = dst_reg(this->result); for (i = 0; i < type_size(param->type); i++) { ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); @@ -2028,7 +2043,7 @@ ir_to_mesa_visitor::visit(ir_texture *ir) * handle cleaning up our mess in that case. */ coord = get_temp(glsl_type::vec4_type); - coord_dst = ir_to_mesa_dst_reg_from_src(coord); + coord_dst = dst_reg(coord); ir_to_mesa_emit_op1(ir, OPCODE_MOV, coord_dst, this->result); @@ -2041,7 +2056,7 @@ ir_to_mesa_visitor::visit(ir_texture *ir) * the actual storage for the result here, instead. */ result_src = get_temp(glsl_type::vec4_type); - result_dst = ir_to_mesa_dst_reg_from_src(result_src); + result_dst = dst_reg(result_src); switch (ir->op) { case ir_tex: @@ -2181,7 +2196,7 @@ ir_to_mesa_visitor::visit(ir_return *ir) ir->get_value()->accept(this); src_reg r = this->result; - l = ir_to_mesa_dst_reg_from_src(current_function->return_reg); + l = dst_reg(current_function->return_reg); for (i = 0; i < type_size(current_function->sig->return_type); i++) { ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); @@ -2230,7 +2245,7 @@ ir_to_mesa_visitor::visit(ir_if *ir) if (cond_inst == prev_inst) { src_reg temp = get_temp(glsl_type::bool_type); cond_inst = ir_to_mesa_emit_op1(ir->condition, OPCODE_MOV, - ir_to_mesa_dst_reg_from_src(temp), + dst_reg(temp), result); } cond_inst->cond_update = GL_TRUE; -- cgit v1.2.3 From 01e19fcf1f36cea40cc5efc48796d4e153a20f2f Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Apr 2011 12:16:57 -0700 Subject: ir_to_mesa: Rename ir_to_mesa_emit_*_opX methods to emit_*. There's really no need for a prefix on member functions, and overloading takes care of the _op1/_op2 distinction quite nicely. Eric already made a similar change in the i965 FS backend. Reviewed-by: Ian Romanick --- src/mesa/program/ir_to_mesa.cpp | 358 +++++++++++++++++----------------------- 1 file changed, 147 insertions(+), 211 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 588348062b3..52e250e458c 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -284,48 +284,32 @@ public: /** List of ir_to_mesa_instruction */ exec_list instructions; - ir_to_mesa_instruction *ir_to_mesa_emit_op0(ir_instruction *ir, - enum prog_opcode op); - - ir_to_mesa_instruction *ir_to_mesa_emit_op1(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0); - - ir_to_mesa_instruction *ir_to_mesa_emit_op2(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0, - src_reg src1); - - ir_to_mesa_instruction *ir_to_mesa_emit_op3(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0, - src_reg src1, - src_reg src2); + ir_to_mesa_instruction *emit(ir_instruction *ir, enum prog_opcode op); + + ir_to_mesa_instruction *emit(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, src_reg src0); + + ir_to_mesa_instruction *emit(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, src_reg src0, src_reg src1); + + ir_to_mesa_instruction *emit(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, + src_reg src0, src_reg src1, src_reg src2); /** * Emit the correct dot-product instruction for the type of arguments - * - * \sa ir_to_mesa_emit_op2 */ - void ir_to_mesa_emit_dp(ir_instruction *ir, - dst_reg dst, - src_reg src0, - src_reg src1, - unsigned elements); - - void ir_to_mesa_emit_scalar_op1(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0); - - void ir_to_mesa_emit_scalar_op2(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0, - src_reg src1); + void emit_dp(ir_instruction *ir, + dst_reg dst, + src_reg src0, + src_reg src1, + unsigned elements); + + void emit_scalar(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, src_reg src0); + + void emit_scalar(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, src_reg src0, src_reg src1); void emit_scs(ir_instruction *ir, enum prog_opcode op, dst_reg dst, const src_reg &src); @@ -378,12 +362,9 @@ swizzle_for_size(int size) } ir_to_mesa_instruction * -ir_to_mesa_visitor::ir_to_mesa_emit_op3(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0, - src_reg src1, - src_reg src2) +ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, + src_reg src0, src_reg src1, src_reg src2) { ir_to_mesa_instruction *inst = new(mem_ctx) ir_to_mesa_instruction(); int num_reladdr = 0; @@ -402,9 +383,7 @@ ir_to_mesa_visitor::ir_to_mesa_emit_op3(ir_instruction *ir, reladdr_to_temp(ir, &src0, &num_reladdr); if (dst.reladdr) { - ir_to_mesa_emit_op1(ir, OPCODE_ARL, ir_to_mesa_address_reg, - *dst.reladdr); - + emit(ir, OPCODE_ARL, ir_to_mesa_address_reg, *dst.reladdr); num_reladdr--; } assert(num_reladdr == 0); @@ -425,49 +404,37 @@ ir_to_mesa_visitor::ir_to_mesa_emit_op3(ir_instruction *ir, ir_to_mesa_instruction * -ir_to_mesa_visitor::ir_to_mesa_emit_op2(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0, - src_reg src1) +ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, src_reg src0, src_reg src1) { - return ir_to_mesa_emit_op3(ir, op, dst, src0, src1, ir_to_mesa_undef); + return emit(ir, op, dst, src0, src1, ir_to_mesa_undef); } ir_to_mesa_instruction * -ir_to_mesa_visitor::ir_to_mesa_emit_op1(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0) +ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, src_reg src0) { assert(dst.writemask != 0); - return ir_to_mesa_emit_op3(ir, op, dst, - src0, ir_to_mesa_undef, ir_to_mesa_undef); + return emit(ir, op, dst, src0, ir_to_mesa_undef, ir_to_mesa_undef); } ir_to_mesa_instruction * -ir_to_mesa_visitor::ir_to_mesa_emit_op0(ir_instruction *ir, - enum prog_opcode op) +ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op) { - return ir_to_mesa_emit_op3(ir, op, ir_to_mesa_undef_dst, - ir_to_mesa_undef, - ir_to_mesa_undef, - ir_to_mesa_undef); + return emit(ir, op, ir_to_mesa_undef_dst, + ir_to_mesa_undef, ir_to_mesa_undef, ir_to_mesa_undef); } void -ir_to_mesa_visitor::ir_to_mesa_emit_dp(ir_instruction *ir, - dst_reg dst, - src_reg src0, - src_reg src1, - unsigned elements) +ir_to_mesa_visitor::emit_dp(ir_instruction *ir, + dst_reg dst, src_reg src0, src_reg src1, + unsigned elements) { static const gl_inst_opcode dot_opcodes[] = { OPCODE_DP2, OPCODE_DP3, OPCODE_DP4 }; - ir_to_mesa_emit_op3(ir, dot_opcodes[elements - 2], - dst, src0, src1, ir_to_mesa_undef); + emit(ir, dot_opcodes[elements - 2], dst, src0, src1, ir_to_mesa_undef); } /** @@ -479,11 +446,9 @@ ir_to_mesa_visitor::ir_to_mesa_emit_dp(ir_instruction *ir, * to produce dest channels. */ void -ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op2(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg orig_src0, - src_reg orig_src1) +ir_to_mesa_visitor::emit_scalar(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, + src_reg orig_src0, src_reg orig_src1) { int i, j; int done_mask = ~dst.writemask; @@ -519,26 +484,21 @@ ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op2(ir_instruction *ir, src1.swizzle = MAKE_SWIZZLE4(src1_swiz, src1_swiz, src1_swiz, src1_swiz); - inst = ir_to_mesa_emit_op2(ir, op, - dst, - src0, - src1); + inst = emit(ir, op, dst, src0, src1); inst->dst.writemask = this_mask; done_mask |= this_mask; } } void -ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op1(ir_instruction *ir, - enum prog_opcode op, - dst_reg dst, - src_reg src0) +ir_to_mesa_visitor::emit_scalar(ir_instruction *ir, enum prog_opcode op, + dst_reg dst, src_reg src0) { src_reg undef = ir_to_mesa_undef; undef.swizzle = SWIZZLE_XXXX; - ir_to_mesa_emit_scalar_op2(ir, op, dst, src0, undef); + emit_scalar(ir, op, dst, src0, undef); } /** @@ -563,7 +523,7 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, /* Vertex programs cannot use the SCS opcode. */ if (this->prog->Target == GL_VERTEX_PROGRAM_ARB) { - ir_to_mesa_emit_scalar_op1(ir, op, dst, src); + emit_scalar(ir, op, dst, src); return; } @@ -615,7 +575,7 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, /* Emit the SCS instruction. */ - inst = ir_to_mesa_emit_op1(ir, OPCODE_SCS, tmp_dst, src0); + inst = emit(ir, OPCODE_SCS, tmp_dst, src0); inst->dst.writemask = scs_mask; /* Move the result of the SCS instruction to the desired location in @@ -623,13 +583,12 @@ ir_to_mesa_visitor::emit_scs(ir_instruction *ir, enum prog_opcode op, */ tmp.swizzle = MAKE_SWIZZLE4(component, component, component, component); - inst = ir_to_mesa_emit_op1(ir, OPCODE_SCS, dst, tmp); + inst = emit(ir, OPCODE_SCS, dst, tmp); inst->dst.writemask = this_mask; } else { /* Emit the SCS instruction to write directly to the destination. */ - ir_to_mesa_instruction *inst = - ir_to_mesa_emit_op1(ir, OPCODE_SCS, dst, src0); + ir_to_mesa_instruction *inst = emit(ir, OPCODE_SCS, dst, src0); inst->dst.writemask = scs_mask; } @@ -825,7 +784,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) } else { src_reg src(PROGRAM_STATE_VAR, index, NULL); src.swizzle = slots[i].swizzle; - ir_to_mesa_emit_op1(ir, OPCODE_MOV, dst, src); + emit(ir, OPCODE_MOV, dst, src); /* even a float takes up a whole vec4 reg in a struct/array. */ dst.index++; } @@ -858,7 +817,7 @@ ir_to_mesa_visitor::visit(ir_loop *ir) delete a; } - ir_to_mesa_emit_op0(NULL, OPCODE_BGNLOOP); + emit(NULL, OPCODE_BGNLOOP); if (ir->to) { ir_expression *e = @@ -891,7 +850,7 @@ ir_to_mesa_visitor::visit(ir_loop *ir) delete e; } - ir_to_mesa_emit_op0(NULL, OPCODE_ENDLOOP); + emit(NULL, OPCODE_ENDLOOP); } void @@ -899,10 +858,10 @@ ir_to_mesa_visitor::visit(ir_loop_jump *ir) { switch (ir->mode) { case ir_loop_jump::jump_break: - ir_to_mesa_emit_op0(NULL, OPCODE_BRK); + emit(NULL, OPCODE_BRK); break; case ir_loop_jump::jump_continue: - ir_to_mesa_emit_op0(NULL, OPCODE_CONT); + emit(NULL, OPCODE_CONT); break; } } @@ -955,8 +914,7 @@ ir_to_mesa_visitor::try_emit_mad(ir_expression *ir, int mul_operand) c = this->result; this->result = get_temp(ir->type); - ir_to_mesa_emit_op3(ir, OPCODE_MAD, - dst_reg(this->result), a, b, c); + emit(ir, OPCODE_MAD, dst_reg(this->result), a, b, c); return true; } @@ -979,9 +937,7 @@ ir_to_mesa_visitor::try_emit_sat(ir_expression *ir) this->result = get_temp(ir->type); ir_to_mesa_instruction *inst; - inst = ir_to_mesa_emit_op1(ir, OPCODE_MOV, - dst_reg(this->result), - src); + inst = emit(ir, OPCODE_MOV, dst_reg(this->result), src); inst->saturate = true; return true; @@ -994,13 +950,12 @@ ir_to_mesa_visitor::reladdr_to_temp(ir_instruction *ir, if (!reg->reladdr) return; - ir_to_mesa_emit_op1(ir, OPCODE_ARL, ir_to_mesa_address_reg, *reg->reladdr); + emit(ir, OPCODE_ARL, ir_to_mesa_address_reg, *reg->reladdr); if (*num_reladdr != 1) { src_reg temp = get_temp(glsl_type::vec4_type); - ir_to_mesa_emit_op1(ir, OPCODE_MOV, - dst_reg(temp), *reg); + emit(ir, OPCODE_MOV, dst_reg(temp), *reg); *reg = temp; } @@ -1120,7 +1075,7 @@ ir_to_mesa_visitor::emit_swz(ir_expression *ir) */ result_dst.writemask = (1 << ir->type->vector_elements) - 1; - ir_to_mesa_emit_op1(ir, OPCODE_SWZ, result_dst, src); + emit(ir, OPCODE_SWZ, result_dst, src); this->result = result_src; } @@ -1187,38 +1142,37 @@ ir_to_mesa_visitor::visit(ir_expression *ir) switch (ir->operation) { case ir_unop_logic_not: - ir_to_mesa_emit_op2(ir, OPCODE_SEQ, result_dst, - op[0], src_reg_for_float(0.0)); + emit(ir, OPCODE_SEQ, result_dst, op[0], src_reg_for_float(0.0)); break; case ir_unop_neg: op[0].negate = ~op[0].negate; result_src = op[0]; break; case ir_unop_abs: - ir_to_mesa_emit_op1(ir, OPCODE_ABS, result_dst, op[0]); + emit(ir, OPCODE_ABS, result_dst, op[0]); break; case ir_unop_sign: - ir_to_mesa_emit_op1(ir, OPCODE_SSG, result_dst, op[0]); + emit(ir, OPCODE_SSG, result_dst, op[0]); break; case ir_unop_rcp: - ir_to_mesa_emit_scalar_op1(ir, OPCODE_RCP, result_dst, op[0]); + emit_scalar(ir, OPCODE_RCP, result_dst, op[0]); break; case ir_unop_exp2: - ir_to_mesa_emit_scalar_op1(ir, OPCODE_EX2, result_dst, op[0]); + emit_scalar(ir, OPCODE_EX2, result_dst, op[0]); break; case ir_unop_exp: case ir_unop_log: assert(!"not reached: should be handled by ir_explog_to_explog2"); break; case ir_unop_log2: - ir_to_mesa_emit_scalar_op1(ir, OPCODE_LG2, result_dst, op[0]); + emit_scalar(ir, OPCODE_LG2, result_dst, op[0]); break; case ir_unop_sin: - ir_to_mesa_emit_scalar_op1(ir, OPCODE_SIN, result_dst, op[0]); + emit_scalar(ir, OPCODE_SIN, result_dst, op[0]); break; case ir_unop_cos: - ir_to_mesa_emit_scalar_op1(ir, OPCODE_COS, result_dst, op[0]); + emit_scalar(ir, OPCODE_COS, result_dst, op[0]); break; case ir_unop_sin_reduced: emit_scs(ir, OPCODE_SIN, result_dst, op[0]); @@ -1228,10 +1182,10 @@ ir_to_mesa_visitor::visit(ir_expression *ir) break; case ir_unop_dFdx: - ir_to_mesa_emit_op1(ir, OPCODE_DDX, result_dst, op[0]); + emit(ir, OPCODE_DDX, result_dst, op[0]); break; case ir_unop_dFdy: - ir_to_mesa_emit_op1(ir, OPCODE_DDY, result_dst, op[0]); + emit(ir, OPCODE_DDY, result_dst, op[0]); break; case ir_unop_noise: { @@ -1240,19 +1194,19 @@ ir_to_mesa_visitor::visit(ir_expression *ir) + (ir->operands[0]->type->vector_elements) - 1); assert((opcode >= OPCODE_NOISE1) && (opcode <= OPCODE_NOISE4)); - ir_to_mesa_emit_op1(ir, opcode, result_dst, op[0]); + emit(ir, opcode, result_dst, op[0]); break; } case ir_binop_add: - ir_to_mesa_emit_op2(ir, OPCODE_ADD, result_dst, op[0], op[1]); + emit(ir, OPCODE_ADD, result_dst, op[0], op[1]); break; case ir_binop_sub: - ir_to_mesa_emit_op2(ir, OPCODE_SUB, result_dst, op[0], op[1]); + emit(ir, OPCODE_SUB, result_dst, op[0], op[1]); break; case ir_binop_mul: - ir_to_mesa_emit_op2(ir, OPCODE_MUL, result_dst, op[0], op[1]); + emit(ir, OPCODE_MUL, result_dst, op[0], op[1]); break; case ir_binop_div: assert(!"not reached: should be handled by ir_div_to_mul_rcp"); @@ -1261,35 +1215,33 @@ ir_to_mesa_visitor::visit(ir_expression *ir) break; case ir_binop_less: - ir_to_mesa_emit_op2(ir, OPCODE_SLT, result_dst, op[0], op[1]); + emit(ir, OPCODE_SLT, result_dst, op[0], op[1]); break; case ir_binop_greater: - ir_to_mesa_emit_op2(ir, OPCODE_SGT, result_dst, op[0], op[1]); + emit(ir, OPCODE_SGT, result_dst, op[0], op[1]); break; case ir_binop_lequal: - ir_to_mesa_emit_op2(ir, OPCODE_SLE, result_dst, op[0], op[1]); + emit(ir, OPCODE_SLE, result_dst, op[0], op[1]); break; case ir_binop_gequal: - ir_to_mesa_emit_op2(ir, OPCODE_SGE, result_dst, op[0], op[1]); + emit(ir, OPCODE_SGE, result_dst, op[0], op[1]); break; case ir_binop_equal: - ir_to_mesa_emit_op2(ir, OPCODE_SEQ, result_dst, op[0], op[1]); + emit(ir, OPCODE_SEQ, result_dst, op[0], op[1]); break; case ir_binop_nequal: - ir_to_mesa_emit_op2(ir, OPCODE_SNE, result_dst, op[0], op[1]); + emit(ir, OPCODE_SNE, result_dst, op[0], op[1]); break; case ir_binop_all_equal: /* "==" operator producing a scalar boolean. */ if (ir->operands[0]->type->is_vector() || ir->operands[1]->type->is_vector()) { src_reg temp = get_temp(glsl_type::vec4_type); - ir_to_mesa_emit_op2(ir, OPCODE_SNE, - dst_reg(temp), op[0], op[1]); - ir_to_mesa_emit_dp(ir, result_dst, temp, temp, vector_elements); - ir_to_mesa_emit_op2(ir, OPCODE_SEQ, - result_dst, result_src, src_reg_for_float(0.0)); + emit(ir, OPCODE_SNE, dst_reg(temp), op[0], op[1]); + emit_dp(ir, result_dst, temp, temp, vector_elements); + emit(ir, OPCODE_SEQ, result_dst, result_src, src_reg_for_float(0.0)); } else { - ir_to_mesa_emit_op2(ir, OPCODE_SEQ, result_dst, op[0], op[1]); + emit(ir, OPCODE_SEQ, result_dst, op[0], op[1]); } break; case ir_binop_any_nequal: @@ -1297,64 +1249,54 @@ ir_to_mesa_visitor::visit(ir_expression *ir) if (ir->operands[0]->type->is_vector() || ir->operands[1]->type->is_vector()) { src_reg temp = get_temp(glsl_type::vec4_type); - ir_to_mesa_emit_op2(ir, OPCODE_SNE, - dst_reg(temp), op[0], op[1]); - ir_to_mesa_emit_dp(ir, result_dst, temp, temp, vector_elements); - ir_to_mesa_emit_op2(ir, OPCODE_SNE, - result_dst, result_src, src_reg_for_float(0.0)); + emit(ir, OPCODE_SNE, dst_reg(temp), op[0], op[1]); + emit_dp(ir, result_dst, temp, temp, vector_elements); + emit(ir, OPCODE_SNE, result_dst, result_src, src_reg_for_float(0.0)); } else { - ir_to_mesa_emit_op2(ir, OPCODE_SNE, result_dst, op[0], op[1]); + emit(ir, OPCODE_SNE, result_dst, op[0], op[1]); } break; case ir_unop_any: assert(ir->operands[0]->type->is_vector()); - ir_to_mesa_emit_dp(ir, result_dst, op[0], op[0], - ir->operands[0]->type->vector_elements); - ir_to_mesa_emit_op2(ir, OPCODE_SNE, - result_dst, result_src, src_reg_for_float(0.0)); + emit_dp(ir, result_dst, op[0], op[0], + ir->operands[0]->type->vector_elements); + emit(ir, OPCODE_SNE, result_dst, result_src, src_reg_for_float(0.0)); break; case ir_binop_logic_xor: - ir_to_mesa_emit_op2(ir, OPCODE_SNE, result_dst, op[0], op[1]); + emit(ir, OPCODE_SNE, result_dst, op[0], op[1]); break; case ir_binop_logic_or: /* This could be a saturated add and skip the SNE. */ - ir_to_mesa_emit_op2(ir, OPCODE_ADD, - result_dst, - op[0], op[1]); - - ir_to_mesa_emit_op2(ir, OPCODE_SNE, - result_dst, - result_src, src_reg_for_float(0.0)); + emit(ir, OPCODE_ADD, result_dst, op[0], op[1]); + emit(ir, OPCODE_SNE, result_dst, result_src, src_reg_for_float(0.0)); break; case ir_binop_logic_and: /* the bool args are stored as float 0.0 or 1.0, so "mul" gives us "and". */ - ir_to_mesa_emit_op2(ir, OPCODE_MUL, - result_dst, - op[0], op[1]); + emit(ir, OPCODE_MUL, result_dst, op[0], op[1]); break; case ir_binop_dot: assert(ir->operands[0]->type->is_vector()); assert(ir->operands[0]->type == ir->operands[1]->type); - ir_to_mesa_emit_dp(ir, result_dst, op[0], op[1], - ir->operands[0]->type->vector_elements); + emit_dp(ir, result_dst, op[0], op[1], + ir->operands[0]->type->vector_elements); break; case ir_unop_sqrt: /* sqrt(x) = x * rsq(x). */ - ir_to_mesa_emit_scalar_op1(ir, OPCODE_RSQ, result_dst, op[0]); - ir_to_mesa_emit_op2(ir, OPCODE_MUL, result_dst, result_src, op[0]); + emit_scalar(ir, OPCODE_RSQ, result_dst, op[0]); + emit(ir, OPCODE_MUL, result_dst, result_src, op[0]); /* For incoming channels <= 0, set the result to 0. */ op[0].negate = ~op[0].negate; - ir_to_mesa_emit_op3(ir, OPCODE_CMP, result_dst, + emit(ir, OPCODE_CMP, result_dst, op[0], result_src, src_reg_for_float(0.0)); break; case ir_unop_rsq: - ir_to_mesa_emit_scalar_op1(ir, OPCODE_RSQ, result_dst, op[0]); + emit_scalar(ir, OPCODE_RSQ, result_dst, op[0]); break; case ir_unop_i2f: case ir_unop_b2f: @@ -1363,36 +1305,36 @@ ir_to_mesa_visitor::visit(ir_expression *ir) result_src = op[0]; break; case ir_unop_f2i: - ir_to_mesa_emit_op1(ir, OPCODE_TRUNC, result_dst, op[0]); + emit(ir, OPCODE_TRUNC, result_dst, op[0]); break; case ir_unop_f2b: case ir_unop_i2b: - ir_to_mesa_emit_op2(ir, OPCODE_SNE, result_dst, + emit(ir, OPCODE_SNE, result_dst, op[0], src_reg_for_float(0.0)); break; case ir_unop_trunc: - ir_to_mesa_emit_op1(ir, OPCODE_TRUNC, result_dst, op[0]); + emit(ir, OPCODE_TRUNC, result_dst, op[0]); break; case ir_unop_ceil: op[0].negate = ~op[0].negate; - ir_to_mesa_emit_op1(ir, OPCODE_FLR, result_dst, op[0]); + emit(ir, OPCODE_FLR, result_dst, op[0]); result_src.negate = ~result_src.negate; break; case ir_unop_floor: - ir_to_mesa_emit_op1(ir, OPCODE_FLR, result_dst, op[0]); + emit(ir, OPCODE_FLR, result_dst, op[0]); break; case ir_unop_fract: - ir_to_mesa_emit_op1(ir, OPCODE_FRC, result_dst, op[0]); + emit(ir, OPCODE_FRC, result_dst, op[0]); break; case ir_binop_min: - ir_to_mesa_emit_op2(ir, OPCODE_MIN, result_dst, op[0], op[1]); + emit(ir, OPCODE_MIN, result_dst, op[0], op[1]); break; case ir_binop_max: - ir_to_mesa_emit_op2(ir, OPCODE_MAX, result_dst, op[0], op[1]); + emit(ir, OPCODE_MAX, result_dst, op[0], op[1]); break; case ir_binop_pow: - ir_to_mesa_emit_scalar_op2(ir, OPCODE_POW, result_dst, op[0], op[1]); + emit_scalar(ir, OPCODE_POW, result_dst, op[0], op[1]); break; case ir_unop_bit_not: @@ -1556,9 +1498,8 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir) } else { index_reg = get_temp(glsl_type::float_type); - ir_to_mesa_emit_op2(ir, OPCODE_MUL, - dst_reg(index_reg), - this->result, src_reg_for_float(element_size)); + emit(ir, OPCODE_MUL, dst_reg(index_reg), + this->result, src_reg_for_float(element_size)); } src.reladdr = ralloc(mem_ctx, src_reg); @@ -1774,9 +1715,9 @@ ir_to_mesa_visitor::visit(ir_assignment *ir) for (i = 0; i < type_size(ir->lhs->type); i++) { if (switch_order) { - ir_to_mesa_emit_op3(ir, OPCODE_CMP, l, condition, src_reg(l), r); + emit(ir, OPCODE_CMP, l, condition, src_reg(l), r); } else { - ir_to_mesa_emit_op3(ir, OPCODE_CMP, l, condition, r, src_reg(l)); + emit(ir, OPCODE_CMP, l, condition, r, src_reg(l)); } l.index++; @@ -1784,7 +1725,7 @@ ir_to_mesa_visitor::visit(ir_assignment *ir) } } else { for (i = 0; i < type_size(ir->lhs->type); i++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); + emit(ir, OPCODE_MOV, l, r); l.index++; r.index++; } @@ -1820,7 +1761,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) src = this->result; for (i = 0; i < (unsigned int)size; i++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, temp, src); + emit(ir, OPCODE_MOV, temp, src); src.index++; temp.index++; @@ -1841,7 +1782,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) ir->array_elements[i]->accept(this); src = this->result; for (int j = 0; j < size; j++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, temp, src); + emit(ir, OPCODE_MOV, temp, src); src.index++; temp.index++; @@ -1864,7 +1805,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir) values, ir->type->vector_elements, &src.swizzle); - ir_to_mesa_emit_op1(ir, OPCODE_MOV, mat_column, src); + emit(ir, OPCODE_MOV, mat_column, src); mat_column.index++; } @@ -1976,7 +1917,7 @@ ir_to_mesa_visitor::visit(ir_call *ir) l.cond_mask = COND_TR; for (i = 0; i < type_size(param->type); i++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); + emit(ir, OPCODE_MOV, l, r); l.index++; r.index++; } @@ -1987,8 +1928,7 @@ ir_to_mesa_visitor::visit(ir_call *ir) assert(!sig_iter.has_next()); /* Emit call instruction */ - call_inst = ir_to_mesa_emit_op1(ir, OPCODE_CAL, - ir_to_mesa_undef_dst, ir_to_mesa_undef); + call_inst = emit(ir, OPCODE_CAL, ir_to_mesa_undef_dst, ir_to_mesa_undef); call_inst->function = entry; /* Process out parameters. */ @@ -2013,7 +1953,7 @@ ir_to_mesa_visitor::visit(ir_call *ir) dst_reg l = dst_reg(this->result); for (i = 0; i < type_size(param->type); i++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); + emit(ir, OPCODE_MOV, l, r); l.index++; r.index++; } @@ -2044,8 +1984,7 @@ ir_to_mesa_visitor::visit(ir_texture *ir) */ coord = get_temp(glsl_type::vec4_type); coord_dst = dst_reg(coord); - ir_to_mesa_emit_op1(ir, OPCODE_MOV, coord_dst, - this->result); + emit(ir, OPCODE_MOV, coord_dst, this->result); if (ir->projector) { ir->projector->accept(this); @@ -2082,7 +2021,7 @@ ir_to_mesa_visitor::visit(ir_texture *ir) if (opcode == OPCODE_TEX) { /* Slot the projector in as the last component of the coord. */ coord_dst.writemask = WRITEMASK_W; - ir_to_mesa_emit_op1(ir, OPCODE_MOV, coord_dst, projector); + emit(ir, OPCODE_MOV, coord_dst, projector); coord_dst.writemask = WRITEMASK_XYZW; opcode = OPCODE_TXP; } else { @@ -2094,12 +2033,12 @@ ir_to_mesa_visitor::visit(ir_texture *ir) * projective divide now. */ coord_dst.writemask = WRITEMASK_W; - ir_to_mesa_emit_op1(ir, OPCODE_RCP, coord_dst, projector); + emit(ir, OPCODE_RCP, coord_dst, projector); /* In the case where we have to project the coordinates "by hand," * the shadow comparitor value must also be projected. */ - ir_to_mesa_src_reg tmp_src = coord; + src_reg tmp_src = coord; if (ir->shadow_comparitor) { /* Slot the shadow value in as the second to last component of the * coord. @@ -2107,17 +2046,17 @@ ir_to_mesa_visitor::visit(ir_texture *ir) ir->shadow_comparitor->accept(this); tmp_src = get_temp(glsl_type::vec4_type); - ir_to_mesa_dst_reg tmp_dst = ir_to_mesa_dst_reg_from_src(tmp_src); + dst_reg tmp_dst = dst_reg(tmp_src); tmp_dst.writemask = WRITEMASK_Z; - ir_to_mesa_emit_op1(ir, OPCODE_MOV, tmp_dst, this->result); + emit(ir, OPCODE_MOV, tmp_dst, this->result); tmp_dst.writemask = WRITEMASK_XY; - ir_to_mesa_emit_op1(ir, OPCODE_MOV, tmp_dst, coord); + emit(ir, OPCODE_MOV, tmp_dst, coord); } coord_dst.writemask = WRITEMASK_XYZ; - ir_to_mesa_emit_op2(ir, OPCODE_MUL, coord_dst, tmp_src, coord_w); + emit(ir, OPCODE_MUL, coord_dst, tmp_src, coord_w); coord_dst.writemask = WRITEMASK_XYZW; coord.swizzle = SWIZZLE_XYZW; @@ -2134,18 +2073,18 @@ ir_to_mesa_visitor::visit(ir_texture *ir) */ ir->shadow_comparitor->accept(this); coord_dst.writemask = WRITEMASK_Z; - ir_to_mesa_emit_op1(ir, OPCODE_MOV, coord_dst, this->result); + emit(ir, OPCODE_MOV, coord_dst, this->result); coord_dst.writemask = WRITEMASK_XYZW; } if (opcode == OPCODE_TXL || opcode == OPCODE_TXB) { /* Mesa IR stores lod or lod bias in the last channel of the coords. */ coord_dst.writemask = WRITEMASK_W; - ir_to_mesa_emit_op1(ir, OPCODE_MOV, coord_dst, lod_info); + emit(ir, OPCODE_MOV, coord_dst, lod_info); coord_dst.writemask = WRITEMASK_XYZW; } - inst = ir_to_mesa_emit_op1(ir, opcode, result_dst, coord); + inst = emit(ir, opcode, result_dst, coord); if (ir->shadow_comparitor) inst->tex_shadow = GL_TRUE; @@ -2199,13 +2138,13 @@ ir_to_mesa_visitor::visit(ir_return *ir) l = dst_reg(current_function->return_reg); for (i = 0; i < type_size(current_function->sig->return_type); i++) { - ir_to_mesa_emit_op1(ir, OPCODE_MOV, l, r); + emit(ir, OPCODE_MOV, l, r); l.index++; r.index++; } } - ir_to_mesa_emit_op0(ir, OPCODE_RET); + emit(ir, OPCODE_RET); } void @@ -2216,9 +2155,9 @@ ir_to_mesa_visitor::visit(ir_discard *ir) if (ir->condition) { ir->condition->accept(this); this->result.negate = ~this->result.negate; - ir_to_mesa_emit_op1(ir, OPCODE_KIL, ir_to_mesa_undef_dst, this->result); + emit(ir, OPCODE_KIL, ir_to_mesa_undef_dst, this->result); } else { - ir_to_mesa_emit_op0(ir, OPCODE_KIL_NV); + emit(ir, OPCODE_KIL_NV); } fp->UsesKill = GL_TRUE; @@ -2244,18 +2183,15 @@ ir_to_mesa_visitor::visit(ir_if *ir) */ if (cond_inst == prev_inst) { src_reg temp = get_temp(glsl_type::bool_type); - cond_inst = ir_to_mesa_emit_op1(ir->condition, OPCODE_MOV, - dst_reg(temp), - result); + cond_inst = emit(ir->condition, OPCODE_MOV, dst_reg(temp), result); } cond_inst->cond_update = GL_TRUE; - if_inst = ir_to_mesa_emit_op0(ir->condition, OPCODE_IF); + if_inst = emit(ir->condition, OPCODE_IF); if_inst->dst.cond_mask = COND_NE; } else { - if_inst = ir_to_mesa_emit_op1(ir->condition, - OPCODE_IF, ir_to_mesa_undef_dst, - this->result); + if_inst = emit(ir->condition, OPCODE_IF, ir_to_mesa_undef_dst, + this->result); } this->instructions.push_tail(if_inst); @@ -2263,12 +2199,12 @@ ir_to_mesa_visitor::visit(ir_if *ir) visit_exec_list(&ir->then_instructions, this); if (!ir->else_instructions.is_empty()) { - else_inst = ir_to_mesa_emit_op0(ir->condition, OPCODE_ELSE); + else_inst = emit(ir->condition, OPCODE_ELSE); visit_exec_list(&ir->else_instructions, this); } - if_inst = ir_to_mesa_emit_op1(ir->condition, OPCODE_ENDIF, - ir_to_mesa_undef_dst, ir_to_mesa_undef); + if_inst = emit(ir->condition, OPCODE_ENDIF, + ir_to_mesa_undef_dst, ir_to_mesa_undef); } ir_to_mesa_visitor::ir_to_mesa_visitor() @@ -2958,7 +2894,7 @@ get_mesa_program(struct gl_context *ctx, /* Emit Mesa IR for main(). */ visit_exec_list(shader->ir, &v); - v.ir_to_mesa_emit_op0(NULL, OPCODE_END); + v.emit(NULL, OPCODE_END); /* Now emit bodies for any functions that were used. */ do { @@ -2970,7 +2906,7 @@ get_mesa_program(struct gl_context *ctx, if (!entry->bgn_inst) { v.current_function = entry; - entry->bgn_inst = v.ir_to_mesa_emit_op0(NULL, OPCODE_BGNSUB); + entry->bgn_inst = v.emit(NULL, OPCODE_BGNSUB); entry->bgn_inst->function = entry; visit_exec_list(&entry->sig->body, &v); @@ -2978,10 +2914,10 @@ get_mesa_program(struct gl_context *ctx, ir_to_mesa_instruction *last; last = (ir_to_mesa_instruction *)v.instructions.get_tail(); if (last->op != OPCODE_RET) - v.ir_to_mesa_emit_op0(NULL, OPCODE_RET); + v.emit(NULL, OPCODE_RET); ir_to_mesa_instruction *end; - end = v.ir_to_mesa_emit_op0(NULL, OPCODE_ENDSUB); + end = v.emit(NULL, OPCODE_ENDSUB); end->function = entry; progress = GL_TRUE; -- cgit v1.2.3 From 5d9718f0dbe1bb9b25324c43ed0fa631735c6a51 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Apr 2011 12:22:42 -0700 Subject: ir_to_mesa: Use emit overloads to avoid passing undef registers. Makes the code just a little bit cleaner. Reviewed-by: Ian Romanick --- src/mesa/program/ir_to_mesa.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 52e250e458c..23f273130d1 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -434,7 +434,7 @@ ir_to_mesa_visitor::emit_dp(ir_instruction *ir, OPCODE_DP2, OPCODE_DP3, OPCODE_DP4 }; - emit(ir, dot_opcodes[elements - 2], dst, src0, src1, ir_to_mesa_undef); + emit(ir, dot_opcodes[elements - 2], dst, src0, src1); } /** @@ -1928,7 +1928,7 @@ ir_to_mesa_visitor::visit(ir_call *ir) assert(!sig_iter.has_next()); /* Emit call instruction */ - call_inst = emit(ir, OPCODE_CAL, ir_to_mesa_undef_dst, ir_to_mesa_undef); + call_inst = emit(ir, OPCODE_CAL); call_inst->function = entry; /* Process out parameters. */ @@ -2203,8 +2203,7 @@ ir_to_mesa_visitor::visit(ir_if *ir) visit_exec_list(&ir->else_instructions, this); } - if_inst = emit(ir->condition, OPCODE_ENDIF, - ir_to_mesa_undef_dst, ir_to_mesa_undef); + if_inst = emit(ir->condition, OPCODE_ENDIF); } ir_to_mesa_visitor::ir_to_mesa_visitor() -- cgit v1.2.3 From ce5d969adf4db6e95e7f1abb0a5532311d1c3c28 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Apr 2011 13:19:50 -0700 Subject: ir_to_mesa: Unprefix ir_to_mesa_undef* and ir_to_mesa_address_reg. Rename ir_to_mesa_undef to undef_src, for clarity. Reviewed-by: Ian Romanick --- src/mesa/program/ir_to_mesa.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 23f273130d1..6a4e48417c1 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -146,8 +146,6 @@ dst_reg::dst_reg(src_reg reg) this->reladdr = reg.reladdr; } -extern src_reg ir_to_mesa_undef; - class ir_to_mesa_instruction : public exec_node { public: /* Callers of this ralloc-based new need not call delete. It's @@ -327,11 +325,11 @@ public: void *mem_ctx; }; -src_reg ir_to_mesa_undef = src_reg(PROGRAM_UNDEFINED, 0, NULL); +src_reg undef_src = src_reg(PROGRAM_UNDEFINED, 0, NULL); -dst_reg ir_to_mesa_undef_dst = dst_reg(PROGRAM_UNDEFINED, SWIZZLE_NOOP); +dst_reg undef_dst = dst_reg(PROGRAM_UNDEFINED, SWIZZLE_NOOP); -dst_reg ir_to_mesa_address_reg = dst_reg(PROGRAM_ADDRESS, WRITEMASK_X); +dst_reg address_reg = dst_reg(PROGRAM_ADDRESS, WRITEMASK_X); static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3); @@ -383,7 +381,7 @@ ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op, reladdr_to_temp(ir, &src0, &num_reladdr); if (dst.reladdr) { - emit(ir, OPCODE_ARL, ir_to_mesa_address_reg, *dst.reladdr); + emit(ir, OPCODE_ARL, address_reg, *dst.reladdr); num_reladdr--; } assert(num_reladdr == 0); @@ -407,7 +405,7 @@ ir_to_mesa_instruction * ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op, dst_reg dst, src_reg src0, src_reg src1) { - return emit(ir, op, dst, src0, src1, ir_to_mesa_undef); + return emit(ir, op, dst, src0, src1, undef_src); } ir_to_mesa_instruction * @@ -415,14 +413,13 @@ ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op, dst_reg dst, src_reg src0) { assert(dst.writemask != 0); - return emit(ir, op, dst, src0, ir_to_mesa_undef, ir_to_mesa_undef); + return emit(ir, op, dst, src0, undef_src, undef_src); } ir_to_mesa_instruction * ir_to_mesa_visitor::emit(ir_instruction *ir, enum prog_opcode op) { - return emit(ir, op, ir_to_mesa_undef_dst, - ir_to_mesa_undef, ir_to_mesa_undef, ir_to_mesa_undef); + return emit(ir, op, undef_dst, undef_src, undef_src, undef_src); } void @@ -494,7 +491,7 @@ void ir_to_mesa_visitor::emit_scalar(ir_instruction *ir, enum prog_opcode op, dst_reg dst, src_reg src0) { - src_reg undef = ir_to_mesa_undef; + src_reg undef = undef_src; undef.swizzle = SWIZZLE_XXXX; @@ -754,7 +751,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) storage = new(mem_ctx) variable_storage(ir, PROGRAM_STATE_VAR, -1); this->variables.push_tail(storage); - dst = ir_to_mesa_undef_dst; + dst = undef_dst; } else { /* The variable_storage constructor allocates slots based on the size * of the type. However, this had better match the number of state @@ -950,7 +947,7 @@ ir_to_mesa_visitor::reladdr_to_temp(ir_instruction *ir, if (!reg->reladdr) return; - emit(ir, OPCODE_ARL, ir_to_mesa_address_reg, *reg->reladdr); + emit(ir, OPCODE_ARL, address_reg, *reg->reladdr); if (*num_reladdr != 1) { src_reg temp = get_temp(glsl_type::vec4_type); @@ -1880,7 +1877,7 @@ ir_to_mesa_visitor::get_function_signature(ir_function_signature *sig) if (!sig->return_type->is_void()) { entry->return_reg = get_temp(sig->return_type); } else { - entry->return_reg = ir_to_mesa_undef; + entry->return_reg = undef_src; } this->function_signatures.push_tail(entry); @@ -2155,7 +2152,7 @@ ir_to_mesa_visitor::visit(ir_discard *ir) if (ir->condition) { ir->condition->accept(this); this->result.negate = ~this->result.negate; - emit(ir, OPCODE_KIL, ir_to_mesa_undef_dst, this->result); + emit(ir, OPCODE_KIL, undef_dst, this->result); } else { emit(ir, OPCODE_KIL_NV); } @@ -2190,8 +2187,7 @@ ir_to_mesa_visitor::visit(ir_if *ir) if_inst = emit(ir->condition, OPCODE_IF); if_inst->dst.cond_mask = COND_NE; } else { - if_inst = emit(ir->condition, OPCODE_IF, ir_to_mesa_undef_dst, - this->result); + if_inst = emit(ir->condition, OPCODE_IF, undef_dst, this->result); } this->instructions.push_tail(if_inst); -- cgit v1.2.3 From b4dfb7473efd378c51b955a856eaef69312c1f9f Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Apr 2011 13:22:30 -0700 Subject: ir_to_mesa: Use gl_register_file enum type rather than 'int'. src_reg already used this; make dst_reg use it too. Reviewed-by: Ian Romanick --- src/mesa/program/ir_to_mesa.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 6a4e48417c1..107bfc7957e 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -67,9 +67,9 @@ static int swizzle_for_size(int size); */ class src_reg { public: - src_reg(int file, int index, const glsl_type *type) + src_reg(gl_register_file file, int index, const glsl_type *type) { - this->file = (gl_register_file) file; + this->file = file; this->index = index; if (type && (type->is_scalar() || type->is_vector() || type->is_matrix())) this->swizzle = swizzle_for_size(type->vector_elements); @@ -100,7 +100,7 @@ public: class dst_reg { public: - dst_reg(int file, int writemask) + dst_reg(gl_register_file file, int writemask) { this->file = file; this->index = 0; @@ -120,7 +120,7 @@ public: explicit dst_reg(src_reg reg); - int file; /**< PROGRAM_* from Mesa */ + gl_register_file file; /**< PROGRAM_* from Mesa */ int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */ int writemask; /**< Bitfield of WRITEMASK_[XYZW] */ GLuint cond_mask:4; @@ -130,7 +130,7 @@ public: src_reg::src_reg(dst_reg reg) { - this->file = (gl_register_file) reg.file; + this->file = reg.file; this->index = reg.index; this->swizzle = SWIZZLE_XYZW; this->negate = 0; -- cgit v1.2.3 From 874a2c0b7da62f4dd08dedcec221f55b22e40e95 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 5 Apr 2011 19:02:07 -0600 Subject: mesa: core support for GL_ARB_texture_buffer_object No GLSL or driver support yet. --- src/mesa/main/api_exec.c | 3 + src/mesa/main/bufferobj.c | 5 + src/mesa/main/context.c | 1 + src/mesa/main/get.c | 36 +++++ src/mesa/main/mtypes.h | 10 ++ src/mesa/main/shared.c | 2 + src/mesa/main/teximage.c | 282 ++++++++++++++++++++++++++++++++- src/mesa/main/teximage.h | 5 + src/mesa/main/texobj.c | 9 +- src/mesa/main/texstate.c | 3 +- src/mesa/program/program.c | 4 +- src/mesa/state_tracker/st_cb_texture.c | 3 + 12 files changed, 357 insertions(+), 6 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/main/api_exec.c b/src/mesa/main/api_exec.c index f7603705b72..91cdea5bb98 100644 --- a/src/mesa/main/api_exec.c +++ b/src/mesa/main/api_exec.c @@ -726,6 +726,9 @@ _mesa_create_exec_table(void) /* GL_NV_texture_barrier */ SET_TextureBarrierNV(exec, _mesa_TextureBarrierNV); + /* GL_ARB_texture_buffer_object */ + SET_TexBufferARB(exec, _mesa_TexBuffer); + return exec; } diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index c969a8da47d..78105883c97 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -93,6 +93,11 @@ get_buffer_target(struct gl_context *ctx, GLenum target) } break; #endif + case GL_TEXTURE_BUFFER: + if (ctx->Extensions.ARB_texture_buffer_object) { + return &ctx->Texture.BufferObject; + } + break; default: return NULL; } diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index ca74284ca89..9eb1eacba36 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -567,6 +567,7 @@ _mesa_init_constants(struct gl_context *ctx) ctx->Const.MaxTextureImageUnits); ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY; ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS; + ctx->Const.MaxTextureBufferSize = 65536; ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE; ctx->Const.SubPixelBits = SUB_PIXEL_BITS; ctx->Const.MinPointSize = MIN_POINT_SIZE; diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 9090ca661e3..6ef8c8792e6 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -323,6 +323,7 @@ EXTRA_EXT(ARB_vertex_buffer_object); EXTRA_EXT(ARB_geometry_shader4); EXTRA_EXT(ARB_copy_buffer); EXTRA_EXT(EXT_framebuffer_sRGB); +EXTRA_EXT(ARB_texture_buffer_object); static const int extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = { @@ -1236,6 +1237,18 @@ static const struct value_desc values[] = { CONTEXT_INT(Const.MaxProgramTexelOffset), extra_EXT_gpu_shader4 }, + /* GL_ARB_texture_buffer_object */ + { GL_MAX_TEXTURE_BUFFER_SIZE_ARB, CONTEXT_INT(Const.MaxTextureBufferSize), + extra_ARB_texture_buffer_object }, + { GL_TEXTURE_BINDING_BUFFER_ARB, LOC_CUSTOM, TYPE_INT, 0, + extra_ARB_texture_buffer_object }, + { GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB, LOC_CUSTOM, TYPE_INT, + TEXTURE_BUFFER_INDEX, extra_ARB_texture_buffer_object }, + { GL_TEXTURE_BUFFER_FORMAT_ARB, LOC_CUSTOM, TYPE_INT, 0, + extra_ARB_texture_buffer_object }, + { GL_TEXTURE_BUFFER_ARB, LOC_CUSTOM, TYPE_INT, 0, + extra_ARB_texture_buffer_object }, + /* GL 3.0 */ { GL_NUM_EXTENSIONS, LOC_CUSTOM, TYPE_INT, 0, extra_version_30 }, { GL_MAJOR_VERSION, CONTEXT_INT(VersionMajor), extra_version_30 }, @@ -1673,6 +1686,29 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu case GL_MAX_FRAGMENT_UNIFORM_VECTORS: v->value_int = ctx->Const.FragmentProgram.MaxUniformComponents / 4; break; + + /* GL_ARB_texture_buffer_object */ + case GL_TEXTURE_BUFFER_ARB: + v->value_int = ctx->Texture.BufferObject->Name; + break; + case GL_TEXTURE_BINDING_BUFFER_ARB: + unit = ctx->Texture.CurrentUnit; + v->value_int = + ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name; + break; + case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB: + { + struct gl_buffer_object *buf = + ctx->Texture.Unit[ctx->Texture.CurrentUnit] + .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject; + v->value_int = buf ? buf->Name : 0; + } + break; + case GL_TEXTURE_BUFFER_FORMAT_ARB: + v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit] + .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat; + break; + } } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 02676006a9f..13e4325ee45 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1139,6 +1139,7 @@ struct gl_stencil_attrib */ typedef enum { + TEXTURE_BUFFER_INDEX, TEXTURE_2D_ARRAY_INDEX, TEXTURE_1D_ARRAY_INDEX, TEXTURE_CUBE_INDEX, @@ -1155,6 +1156,7 @@ typedef enum * Used for Texture.Unit[]._ReallyEnabled flags. */ /*@{*/ +#define TEXTURE_BUFFER_BIT (1 << TEXTURE_BUFFER_INDEX) #define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX) #define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX) #define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX) @@ -1348,6 +1350,10 @@ struct gl_texture_object /** Actual texture images, indexed by [cube face] and [mipmap level] */ struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS]; + /** GL_ARB_texture_buffer_object */ + struct gl_buffer_object *BufferObject; + GLenum BufferObjectFormat; + /** GL_EXT_paletted_texture */ struct gl_color_table Palette; @@ -1458,6 +1464,9 @@ struct gl_texture_attrib struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS]; + /** GL_ARB_texture_buffer_object */ + struct gl_buffer_object *BufferObject; + /** GL_ARB_seamless_cubemap */ GLboolean CubeMapSeamless; @@ -2630,6 +2639,7 @@ struct gl_constants GLuint MaxTextureUnits; /**< = MIN(CoordUnits, ImageUnits) */ GLfloat MaxTextureMaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */ GLfloat MaxTextureLodBias; /**< GL_EXT_texture_lod_bias */ + GLuint MaxTextureBufferSize; /**< GL_ARB_texture_buffer_object */ GLuint MaxArrayLockSize; diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index ce9fc4de327..6604ed07d53 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -98,6 +98,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx) for (i = 0; i < NUM_TEXTURE_TARGETS; i++) { /* NOTE: the order of these enums matches the TEXTURE_x_INDEX values */ static const GLenum targets[NUM_TEXTURE_TARGETS] = { + GL_TEXTURE_BUFFER, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_1D_ARRAY_EXT, GL_TEXTURE_CUBE_MAP, @@ -106,6 +107,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx) GL_TEXTURE_2D, GL_TEXTURE_1D }; + assert(Elements(targets) == NUM_TEXTURE_TARGETS); shared->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]); } diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 6161eb41456..c5c454336fa 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -681,8 +681,10 @@ _mesa_delete_texture_image(struct gl_context *ctx, GLboolean _mesa_is_proxy_texture(GLenum target) { - /* NUM_TEXTURE_TARGETS should match number of terms below */ - assert(NUM_TEXTURE_TARGETS == 7); + /* NUM_TEXTURE_TARGETS should match number of terms below, + * except there's no proxy for GL_TEXTURE_BUFFER. + */ + assert(NUM_TEXTURE_TARGETS == 8); return (target == GL_PROXY_TEXTURE_1D || target == GL_PROXY_TEXTURE_2D || @@ -794,6 +796,9 @@ _mesa_select_tex_object(struct gl_context *ctx, return arrayTex ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL; case GL_PROXY_TEXTURE_2D_ARRAY_EXT: return arrayTex ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL; + case GL_TEXTURE_BUFFER: + return ctx->Extensions.ARB_texture_buffer_object + ? texUnit->CurrentTex[TEXTURE_BUFFER_INDEX] : NULL; default: _mesa_problem(NULL, "bad target in _mesa_select_tex_object()"); return NULL; @@ -981,6 +986,8 @@ _mesa_max_texture_levels(struct gl_context *ctx, GLenum target) return (ctx->Extensions.MESA_texture_array || ctx->Extensions.EXT_texture_array) ? ctx->Const.MaxTextureLevels : 0; + case GL_TEXTURE_BUFFER: + /* fall-through */ default: return 0; /* bad target */ } @@ -1017,6 +1024,8 @@ _mesa_get_texture_dimensions(GLenum target) case GL_TEXTURE_2D_ARRAY: case GL_PROXY_TEXTURE_2D_ARRAY: return 3; + case GL_TEXTURE_BUFFER: + /* fall-through */ default: _mesa_problem(NULL, "invalid target 0x%x in get_texture_dimensions()", target); @@ -3551,3 +3560,272 @@ _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, compressed_tex_sub_image(3, target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data); } + + +/** + * Helper for glTexBuffer(). Check if internalFormat is legal. If so, + * return the basic data type and number of components for the format. + * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise + */ +static GLboolean +get_sized_format_info(const struct gl_context *ctx, GLenum internalFormat, + GLenum *datatype, GLuint *components) +{ + switch (internalFormat) { + case GL_ALPHA8: + *datatype = GL_UNSIGNED_BYTE; + *components = 1; + break; + case GL_ALPHA16: + *datatype = GL_UNSIGNED_SHORT; + *components = 1; + break; + case GL_ALPHA16F_ARB: + *datatype = GL_HALF_FLOAT; + *components = 1; + break; + case GL_ALPHA32F_ARB: + *datatype = GL_FLOAT; + *components = 1; + break; + case GL_ALPHA8I_EXT: + *datatype = GL_BYTE; + *components = 1; + break; + case GL_ALPHA16I_EXT: + *datatype = GL_SHORT; + *components = 1; + break; + case GL_ALPHA32I_EXT: + *datatype = GL_INT; + *components = 1; + break; + case GL_ALPHA8UI_EXT: + *datatype = GL_UNSIGNED_BYTE; + *components = 1; + break; + case GL_ALPHA16UI_EXT: + *datatype = GL_UNSIGNED_SHORT; + *components = 1; + break; + case GL_ALPHA32UI_EXT: + *datatype = GL_UNSIGNED_INT; + *components = 1; + break; + case GL_LUMINANCE8: + *datatype = GL_UNSIGNED_BYTE; + *components = 1; + break; + case GL_LUMINANCE16: + *datatype = GL_UNSIGNED_SHORT; + *components = 1; + break; + case GL_LUMINANCE16F_ARB: + *datatype = GL_HALF_FLOAT; + *components = 1; + break; + case GL_LUMINANCE32F_ARB: + *datatype = GL_FLOAT; + *components = 1; + break; + case GL_LUMINANCE8I_EXT: + *datatype = GL_BYTE; + *components = 1; + break; + case GL_LUMINANCE16I_EXT: + *datatype = GL_SHORT; + *components = 1; + break; + case GL_LUMINANCE32I_EXT: + *datatype = GL_INT; + *components = 1; + break; + case GL_LUMINANCE8UI_EXT: + *datatype = GL_UNSIGNED_BYTE; + *components = 1; + break; + case GL_LUMINANCE16UI_EXT: + *datatype = GL_UNSIGNED_SHORT; + *components = 1; + break; + case GL_LUMINANCE32UI_EXT: + *datatype = GL_UNSIGNED_INT; + *components = 1; + break; + case GL_LUMINANCE8_ALPHA8: + *datatype = GL_UNSIGNED_BYTE; + *components = 2; + break; + case GL_LUMINANCE16_ALPHA16: + *datatype = GL_UNSIGNED_SHORT; + *components = 2; + break; + case GL_LUMINANCE_ALPHA16F_ARB: + *datatype = GL_HALF_FLOAT; + *components = 2; + break; + case GL_LUMINANCE_ALPHA32F_ARB: + *datatype = GL_FLOAT; + *components = 2; + break; + case GL_LUMINANCE_ALPHA8I_EXT: + *datatype = GL_BYTE; + *components = 2; + break; + case GL_LUMINANCE_ALPHA16I_EXT: + *datatype = GL_SHORT; + *components = 2; + break; + case GL_LUMINANCE_ALPHA32I_EXT: + *datatype = GL_INT; + *components = 2; + break; + case GL_LUMINANCE_ALPHA8UI_EXT: + *datatype = GL_UNSIGNED_BYTE; + *components = 2; + break; + case GL_LUMINANCE_ALPHA16UI_EXT: + *datatype = GL_UNSIGNED_SHORT; + *components = 2; + break; + case GL_LUMINANCE_ALPHA32UI_EXT: + *datatype = GL_UNSIGNED_INT; + *components = 2; + break; + case GL_INTENSITY8: + *datatype = GL_UNSIGNED_BYTE; + *components = 1; + break; + case GL_INTENSITY16: + *datatype = GL_UNSIGNED_SHORT; + *components = 1; + break; + case GL_INTENSITY16F_ARB: + *datatype = GL_HALF_FLOAT; + *components = 1; + break; + case GL_INTENSITY32F_ARB: + *datatype = GL_FLOAT; + *components = 1; + break; + case GL_INTENSITY8I_EXT: + *datatype = GL_BYTE; + *components = 1; + break; + case GL_INTENSITY16I_EXT: + *datatype = GL_SHORT; + *components = 1; + break; + case GL_INTENSITY32I_EXT: + *datatype = GL_INT; + *components = 1; + break; + case GL_INTENSITY8UI_EXT: + *datatype = GL_UNSIGNED_BYTE; + *components = 1; + break; + case GL_INTENSITY16UI_EXT: + *datatype = GL_UNSIGNED_SHORT; + *components = 1; + break; + case GL_INTENSITY32UI_EXT: + *datatype = GL_UNSIGNED_INT; + *components = 1; + break; + case GL_RGBA8: + *datatype = GL_UNSIGNED_BYTE; + *components = 4; + break; + case GL_RGBA16: + *datatype = GL_UNSIGNED_SHORT; + *components = 4; + break; + case GL_RGBA16F_ARB: + *datatype = GL_HALF_FLOAT; + *components = 4; + break; + case GL_RGBA32F_ARB: + *datatype = GL_FLOAT; + *components = 4; + break; + case GL_RGBA8I_EXT: + *datatype = GL_BYTE; + *components = 4; + break; + case GL_RGBA16I_EXT: + *datatype = GL_SHORT; + *components = 4; + break; + case GL_RGBA32I_EXT: + *datatype = GL_INT; + *components = 4; + break; + case GL_RGBA8UI_EXT: + *datatype = GL_UNSIGNED_BYTE; + *components = 4; + break; + case GL_RGBA16UI_EXT: + *datatype = GL_UNSIGNED_SHORT; + *components = 4; + break; + case GL_RGBA32UI_EXT: + *datatype = GL_UNSIGNED_INT; + *components = 4; + break; + default: + return GL_FALSE; + } + + if (*datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float) + return GL_FALSE; + + if (*datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel) + return GL_FALSE; + + return GL_TRUE; +} + + +/** GL_ARB_texture_buffer_object */ +void GLAPIENTRY +_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer) +{ + struct gl_texture_object *texObj; + struct gl_buffer_object *bufObj; + GLenum dataType; + GLuint comps; + + GET_CURRENT_CONTEXT(ctx); + ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + if (!ctx->Extensions.ARB_texture_buffer_object) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer"); + return; + } + + if (target != GL_TEXTURE_BUFFER_ARB) { + _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(target)"); + return; + } + + if (!get_sized_format_info(ctx, internalFormat, &dataType, &comps)) { + _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(internalFormat 0x%x)", + internalFormat); + return; + } + + bufObj = _mesa_lookup_bufferobj(ctx, buffer); + if (buffer && !bufObj) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBuffer(buffer %u)", buffer); + return; + } + + texObj = _mesa_get_current_tex_object(ctx, target); + + _mesa_lock_texture(ctx, texObj); + { + _mesa_reference_buffer_object(ctx, &texObj->BufferObject, bufObj); + texObj->BufferObjectFormat = internalFormat; + } + _mesa_unlock_texture(ctx, texObj); +} diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h index 252d80afc0f..19abc649898 100644 --- a/src/mesa/main/teximage.h +++ b/src/mesa/main/teximage.h @@ -275,6 +275,11 @@ _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); + +extern void GLAPIENTRY +_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer); + + /*@}*/ #endif diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index c1e3e4dec79..61b9bc70d77 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -29,6 +29,7 @@ #include "mfeatures.h" +#include "bufferobj.h" #include "colortab.h" #include "context.h" #include "enums.h" @@ -105,7 +106,8 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj, target == GL_TEXTURE_CUBE_MAP_ARB || target == GL_TEXTURE_RECTANGLE_NV || target == GL_TEXTURE_1D_ARRAY_EXT || - target == GL_TEXTURE_2D_ARRAY_EXT); + target == GL_TEXTURE_2D_ARRAY_EXT || + target == GL_TEXTURE_BUFFER); memset(obj, 0, sizeof(*obj)); /* init the non-zero fields */ @@ -204,6 +206,8 @@ _mesa_delete_texture_object(struct gl_context *ctx, } } + _mesa_reference_buffer_object(ctx, &texObj->BufferObject, NULL); + /* destroy the mutex -- it may have allocated memory (eg on bsd) */ _glthread_DESTROY_MUTEX(texObj->Mutex); @@ -299,6 +303,7 @@ valid_texture_object(const struct gl_texture_object *tex) case GL_TEXTURE_RECTANGLE_NV: case GL_TEXTURE_1D_ARRAY_EXT: case GL_TEXTURE_2D_ARRAY_EXT: + case GL_TEXTURE_BUFFER: return GL_TRUE; case 0x99: _mesa_problem(NULL, "invalid reference to a deleted texture object"); @@ -989,6 +994,8 @@ target_enum_to_index(GLenum target) return TEXTURE_1D_ARRAY_INDEX; case GL_TEXTURE_2D_ARRAY_EXT: return TEXTURE_2D_ARRAY_INDEX; + case GL_TEXTURE_BUFFER_ARB: + return TEXTURE_BUFFER_INDEX; default: return -1; } diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index 41d531f5976..72f80508db7 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -692,7 +692,8 @@ alloc_proxy_textures( struct gl_context *ctx ) GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_1D_ARRAY_EXT, - GL_TEXTURE_2D_ARRAY_EXT + GL_TEXTURE_2D_ARRAY_EXT, + GL_TEXTURE_BUFFER }; GLint tgt; diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c index 79034ab26f2..5b014872ed4 100644 --- a/src/mesa/program/program.c +++ b/src/mesa/program/program.c @@ -75,10 +75,10 @@ _mesa_init_program(struct gl_context *ctx) ASSERT(ctx->Const.FragmentProgram.MaxAddressOffset <= (1 << INST_INDEX_BITS)); /* If this fails, increase prog_instruction::TexSrcUnit size */ - ASSERT(MAX_TEXTURE_UNITS < (1 << 5)); + ASSERT(MAX_TEXTURE_UNITS <= (1 << 5)); /* If this fails, increase prog_instruction::TexSrcTarget size */ - ASSERT(NUM_TEXTURE_TARGETS < (1 << 3)); + ASSERT(NUM_TEXTURE_TARGETS <= (1 << 3)); ctx->Program.ErrorPos = -1; ctx->Program.ErrorString = _mesa_strdup(""); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 9d5eb113ff7..302f2e1fa17 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -87,6 +87,8 @@ gl_target_to_pipe(GLenum target) return PIPE_TEXTURE_1D_ARRAY; case GL_TEXTURE_2D_ARRAY_EXT: return PIPE_TEXTURE_2D_ARRAY; + case GL_TEXTURE_BUFFER: + return PIPE_BUFFER; default: assert(0); return 0; @@ -245,6 +247,7 @@ get_texture_dims(GLenum target) switch (target) { case GL_TEXTURE_1D: case GL_TEXTURE_1D_ARRAY_EXT: + case GL_TEXTURE_BUFFER: return 1; case GL_TEXTURE_2D: case GL_TEXTURE_CUBE_MAP_ARB: -- cgit v1.2.3 From ecfaab88b2577bd0395bc05d75a036126806a9c4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sun, 10 Apr 2011 12:44:46 -0600 Subject: mesa: move sampler state into new gl_sampler_object type gl_texture_object contains an instance of this type for the regular texture object sampling state. glGenSamplers() generates new instances of gl_sampler_object which can override that state with glBindSampler(). --- src/mesa/drivers/common/meta.c | 18 +- src/mesa/drivers/dri/common/texmem.c | 7 +- src/mesa/drivers/dri/i810/i810tex.c | 12 +- src/mesa/drivers/dri/i915/i830_texstate.c | 24 +-- src/mesa/drivers/dri/i915/i915_texstate.c | 38 ++-- src/mesa/drivers/dri/i965/brw_draw.c | 12 +- src/mesa/drivers/dri/i965/brw_wm.c | 8 +- src/mesa/drivers/dri/i965/brw_wm_sampler_state.c | 34 +-- src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 5 +- src/mesa/drivers/dri/intel/intel_tex_image.c | 4 +- src/mesa/drivers/dri/intel/intel_tex_validate.c | 2 +- src/mesa/drivers/dri/mach64/mach64_tex.c | 12 +- src/mesa/drivers/dri/mga/mgatex.c | 12 +- src/mesa/drivers/dri/nouveau/nouveau_texture.c | 4 +- src/mesa/drivers/dri/nouveau/nv04_state_tex.c | 12 +- src/mesa/drivers/dri/nouveau/nv10_state_tex.c | 12 +- src/mesa/drivers/dri/nouveau/nv20_state_tex.c | 14 +- src/mesa/drivers/dri/r128/r128_tex.c | 12 +- src/mesa/drivers/dri/r200/r200_tex.c | 18 +- src/mesa/drivers/dri/r300/r300_fragprog_common.c | 4 +- src/mesa/drivers/dri/r300/r300_state.c | 4 +- src/mesa/drivers/dri/r300/r300_tex.c | 18 +- src/mesa/drivers/dri/r300/r300_texstate.c | 2 +- src/mesa/drivers/dri/r600/evergreen_tex.c | 16 +- src/mesa/drivers/dri/r600/r600_tex.c | 16 +- src/mesa/drivers/dri/r600/r700_chip.c | 4 +- src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c | 6 +- src/mesa/drivers/dri/radeon/radeon_tex.c | 18 +- src/mesa/drivers/dri/savage/savagerender.c | 12 +- src/mesa/drivers/dri/savage/savagetex.c | 12 +- src/mesa/drivers/dri/sis/sis_texstate.c | 22 +- src/mesa/drivers/dri/tdfx/tdfx_tex.c | 8 +- src/mesa/drivers/dri/unichrome/via_state.c | 32 +-- src/mesa/drivers/dri/unichrome/via_tex.c | 6 +- src/mesa/main/attrib.c | 25 ++- src/mesa/main/ff_fragment_shader.cpp | 7 +- src/mesa/main/mtypes.h | 60 ++++-- src/mesa/main/texfetch.c | 2 +- src/mesa/main/texobj.c | 90 ++++---- src/mesa/main/texparam.c | 160 +++++++------- src/mesa/main/texstate.c | 8 +- src/mesa/program/prog_statevars.c | 2 +- src/mesa/state_tracker/st_atom_sampler.c | 31 +-- src/mesa/state_tracker/st_atom_texture.c | 18 +- src/mesa/state_tracker/st_cb_texture.c | 12 +- src/mesa/state_tracker/st_texture.h | 15 ++ src/mesa/swrast/s_fragprog.c | 6 +- src/mesa/swrast/s_span.c | 2 +- src/mesa/swrast/s_texcombine.c | 22 +- src/mesa/swrast/s_texfilter.c | 255 ++++++++++++----------- src/mesa/swrast/s_triangle.c | 12 +- 51 files changed, 620 insertions(+), 547 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 2b00e8979d2..c92bf29c30f 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -1124,12 +1124,12 @@ blitframebuffer_texture(struct gl_context *ctx, if (readAtt && readAtt->Texture) { const struct gl_texture_object *texObj = readAtt->Texture; const GLuint srcLevel = readAtt->TextureLevel; - const GLenum minFilterSave = texObj->MinFilter; - const GLenum magFilterSave = texObj->MagFilter; + const GLenum minFilterSave = texObj->Sampler.MinFilter; + const GLenum magFilterSave = texObj->Sampler.MagFilter; const GLint baseLevelSave = texObj->BaseLevel; const GLint maxLevelSave = texObj->MaxLevel; - const GLenum wrapSSave = texObj->WrapS; - const GLenum wrapTSave = texObj->WrapT; + const GLenum wrapSSave = texObj->Sampler.WrapS; + const GLenum wrapTSave = texObj->Sampler.WrapT; const GLenum target = texObj->Target; if (drawAtt->Texture == readAtt->Texture) { @@ -2259,13 +2259,13 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target, struct vertex verts[4]; const GLuint baseLevel = texObj->BaseLevel; const GLuint maxLevel = texObj->MaxLevel; - const GLenum minFilterSave = texObj->MinFilter; - const GLenum magFilterSave = texObj->MagFilter; + const GLenum minFilterSave = texObj->Sampler.MinFilter; + const GLenum magFilterSave = texObj->Sampler.MagFilter; const GLint maxLevelSave = texObj->MaxLevel; const GLboolean genMipmapSave = texObj->GenerateMipmap; - const GLenum wrapSSave = texObj->WrapS; - const GLenum wrapTSave = texObj->WrapT; - const GLenum wrapRSave = texObj->WrapR; + const GLenum wrapSSave = texObj->Sampler.WrapS; + const GLenum wrapTSave = texObj->Sampler.WrapT; + const GLenum wrapRSave = texObj->Sampler.WrapR; const GLuint fboSave = ctx->DrawBuffer->Name; const GLuint original_active_unit = ctx->Texture.CurrentUnit; GLenum faceTarget; diff --git a/src/mesa/drivers/dri/common/texmem.c b/src/mesa/drivers/dri/common/texmem.c index 8eec07d5bcc..e927cf0addd 100644 --- a/src/mesa/drivers/dri/common/texmem.c +++ b/src/mesa/drivers/dri/common/texmem.c @@ -1264,17 +1264,18 @@ driCalculateTextureFirstLastLevel( driTextureObject * t ) case GL_TEXTURE_2D: case GL_TEXTURE_3D: case GL_TEXTURE_CUBE_MAP: - if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) { + if (tObj->Sampler.MinFilter == GL_NEAREST || + tObj->Sampler.MinFilter == GL_LINEAR) { /* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL. */ firstLevel = lastLevel = tObj->BaseLevel; } else { - firstLevel = tObj->BaseLevel + (GLint)(tObj->MinLod + 0.5); + firstLevel = tObj->BaseLevel + (GLint)(tObj->Sampler.MinLod + 0.5); firstLevel = MAX2(firstLevel, tObj->BaseLevel); firstLevel = MIN2(firstLevel, tObj->BaseLevel + baseImage->MaxLog2); - lastLevel = tObj->BaseLevel + (GLint)(tObj->MaxLod + 0.5); + lastLevel = tObj->BaseLevel + (GLint)(tObj->Sampler.MaxLod + 0.5); lastLevel = MAX2(lastLevel, t->tObj->BaseLevel); lastLevel = MIN2(lastLevel, t->tObj->BaseLevel + baseImage->MaxLog2); lastLevel = MIN2(lastLevel, t->tObj->MaxLevel); diff --git a/src/mesa/drivers/dri/i810/i810tex.c b/src/mesa/drivers/dri/i810/i810tex.c index 49364aeb225..dba4ebaa5c7 100644 --- a/src/mesa/drivers/dri/i810/i810tex.c +++ b/src/mesa/drivers/dri/i810/i810tex.c @@ -204,10 +204,10 @@ i810AllocTexObj( struct gl_context *ctx, struct gl_texture_object *texObj ) make_empty_list( & t->base ); - i810SetTexWrapping( t, texObj->WrapS, texObj->WrapT ); + i810SetTexWrapping( t, texObj->Sampler.WrapS, texObj->Sampler.WrapT ); /*i830SetTexMaxAnisotropy( t, texObj->MaxAnisotropy );*/ - i810SetTexFilter( imesa, t, texObj->MinFilter, texObj->MagFilter, bias ); - i810SetTexBorderColor( t, texObj->BorderColor.f ); + i810SetTexFilter( imesa, t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter, bias ); + i810SetTexBorderColor( t, texObj->Sampler.BorderColor.f ); } return t; @@ -238,17 +238,17 @@ static void i810TexParameter( struct gl_context *ctx, GLenum target, case GL_TEXTURE_MAG_FILTER: { GLfloat bias = ctx->Texture.Unit[ctx->Texture.CurrentUnit].LodBias; - i810SetTexFilter( imesa, t, tObj->MinFilter, tObj->MagFilter, bias ); + i810SetTexFilter( imesa, t, tObj->Sampler.MinFilter, tObj->Sampler.MagFilter, bias ); } break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: - i810SetTexWrapping( t, tObj->WrapS, tObj->WrapT ); + i810SetTexWrapping( t, tObj->Sampler.WrapS, tObj->Sampler.WrapT ); break; case GL_TEXTURE_BORDER_COLOR: - i810SetTexBorderColor( t, tObj->BorderColor.f ); + i810SetTexBorderColor( t, tObj->Sampler.BorderColor.f ); break; case GL_TEXTURE_BASE_LEVEL: diff --git a/src/mesa/drivers/dri/i915/i830_texstate.c b/src/mesa/drivers/dri/i915/i830_texstate.c index c35b4b5ed06..7554bd5e7b9 100644 --- a/src/mesa/drivers/dri/i915/i830_texstate.c +++ b/src/mesa/drivers/dri/i915/i830_texstate.c @@ -193,7 +193,7 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) float maxlod; uint32_t minlod_fixed, maxlod_fixed; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: minFilt = FILTER_NEAREST; mipFilt = MIPFILTER_NONE; @@ -222,12 +222,12 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) return GL_FALSE; } - if (tObj->MaxAnisotropy > 1.0) { + if (tObj->Sampler.MaxAnisotropy > 1.0) { minFilt = FILTER_ANISOTROPIC; magFilt = FILTER_ANISOTROPIC; } else { - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: magFilt = FILTER_NEAREST; break; @@ -239,7 +239,7 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) } } - lodbias = (int) ((tUnit->LodBias + tObj->LodBias) * 16.0); + lodbias = (int) ((tUnit->LodBias + tObj->Sampler.LodBias) * 16.0); if (lodbias < -64) lodbias = -64; if (lodbias > 63) @@ -259,8 +259,8 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) * addressable (smallest resolution) LOD. Use it to cover both * MAX_LEVEL and MAX_LOD. */ - minlod_fixed = U_FIXED(CLAMP(tObj->MinLod, 0.0, 11), 4); - maxlod = MIN2(tObj->MaxLod, tObj->_MaxLevel - tObj->BaseLevel); + minlod_fixed = U_FIXED(CLAMP(tObj->Sampler.MinLod, 0.0, 11), 4); + maxlod = MIN2(tObj->Sampler.MaxLod, tObj->_MaxLevel - tObj->BaseLevel); if (intel->intelScreen->deviceID == PCI_CHIP_I855_GM || intel->intelScreen->deviceID == PCI_CHIP_I865_G) { maxlod_fixed = U_FIXED(CLAMP(maxlod, 0.0, 11.75), 2); @@ -279,8 +279,8 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) } { - GLenum ws = tObj->WrapS; - GLenum wt = tObj->WrapT; + GLenum ws = tObj->Sampler.WrapS; + GLenum wt = tObj->Sampler.WrapT; /* 3D textures not available on i830 @@ -300,10 +300,10 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) } /* convert border color from float to ubyte */ - CLAMPED_FLOAT_TO_UBYTE(border[0], tObj->BorderColor.f[0]); - CLAMPED_FLOAT_TO_UBYTE(border[1], tObj->BorderColor.f[1]); - CLAMPED_FLOAT_TO_UBYTE(border[2], tObj->BorderColor.f[2]); - CLAMPED_FLOAT_TO_UBYTE(border[3], tObj->BorderColor.f[3]); + CLAMPED_FLOAT_TO_UBYTE(border[0], tObj->Sampler.BorderColor.f[0]); + CLAMPED_FLOAT_TO_UBYTE(border[1], tObj->Sampler.BorderColor.f[1]); + CLAMPED_FLOAT_TO_UBYTE(border[2], tObj->Sampler.BorderColor.f[2]); + CLAMPED_FLOAT_TO_UBYTE(border[3], tObj->Sampler.BorderColor.f[3]); state[I830_TEXREG_TM0S4] = PACK_COLOR_8888(border[3], border[0], diff --git a/src/mesa/drivers/dri/i915/i915_texstate.c b/src/mesa/drivers/dri/i915/i915_texstate.c index af140c85f50..742bb994adb 100644 --- a/src/mesa/drivers/dri/i915/i915_texstate.c +++ b/src/mesa/drivers/dri/i915/i915_texstate.c @@ -164,7 +164,7 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) format = translate_texture_format(firstImage->TexFormat, firstImage->InternalFormat, - tObj->DepthMode); + tObj->Sampler.DepthMode); pitch = intelObj->mt->region->pitch * intelObj->mt->cpp; state[I915_TEXREG_MS3] = @@ -181,7 +181,7 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) * (lowest resolution) LOD. Use it to cover both MAX_LEVEL and * MAX_LOD. */ - maxlod = MIN2(tObj->MaxLod, tObj->_MaxLevel - tObj->BaseLevel); + maxlod = MIN2(tObj->Sampler.MaxLod, tObj->_MaxLevel - tObj->BaseLevel); state[I915_TEXREG_MS4] = ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) | MS4_CUBE_FACE_ENA_MASK | @@ -192,7 +192,7 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) { GLuint minFilt, mipFilt, magFilt; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: minFilt = FILTER_NEAREST; mipFilt = MIPFILTER_NONE; @@ -221,16 +221,16 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) return GL_FALSE; } - if (tObj->MaxAnisotropy > 1.0) { + if (tObj->Sampler.MaxAnisotropy > 1.0) { minFilt = FILTER_ANISOTROPIC; magFilt = FILTER_ANISOTROPIC; - if (tObj->MaxAnisotropy > 2.0) + if (tObj->Sampler.MaxAnisotropy > 2.0) aniso = SS2_MAX_ANISO_4; else aniso = SS2_MAX_ANISO_2; } else { - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: magFilt = FILTER_NEAREST; break; @@ -242,7 +242,7 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) } } - lodbias = (int) ((tUnit->LodBias + tObj->LodBias) * 16.0); + lodbias = (int) ((tUnit->LodBias + tObj->Sampler.LodBias) * 16.0); if (lodbias < -256) lodbias = -256; if (lodbias > 255) @@ -258,14 +258,14 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) /* Shadow: */ - if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB && + if (tObj->Sampler.CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB && tObj->Target != GL_TEXTURE_3D) { if (tObj->Target == GL_TEXTURE_1D) return GL_FALSE; state[I915_TEXREG_SS2] |= (SS2_SHADOW_ENABLE | - intel_translate_shadow_compare_func(tObj->CompareFunc)); + intel_translate_shadow_compare_func(tObj->Sampler.CompareFunc)); minFilt = FILTER_4X4_FLAT; magFilt = FILTER_4X4_FLAT; @@ -278,9 +278,9 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) } { - GLenum ws = tObj->WrapS; - GLenum wt = tObj->WrapT; - GLenum wr = tObj->WrapR; + GLenum ws = tObj->Sampler.WrapS; + GLenum wt = tObj->Sampler.WrapT; + GLenum wr = tObj->Sampler.WrapR; float minlod; /* We program 1D textures as 2D textures, so the 2D texcoord could @@ -298,8 +298,8 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) * clamp_to_border. */ if (tObj->Target == GL_TEXTURE_3D && - (tObj->MinFilter != GL_NEAREST || - tObj->MagFilter != GL_NEAREST) && + (tObj->Sampler.MinFilter != GL_NEAREST || + tObj->Sampler.MagFilter != GL_NEAREST) && (ws == GL_CLAMP || wt == GL_CLAMP || wr == GL_CLAMP || @@ -322,7 +322,7 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) | (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT)); - minlod = MIN2(tObj->MinLod, tObj->_MaxLevel - tObj->BaseLevel); + minlod = MIN2(tObj->Sampler.MinLod, tObj->_MaxLevel - tObj->BaseLevel); state[I915_TEXREG_SS3] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT); state[I915_TEXREG_SS3] |= (U_FIXED(CLAMP(minlod, 0.0, 11.0), 4) << SS3_MIN_LOD_SHIFT); @@ -330,10 +330,10 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) } /* convert border color from float to ubyte */ - CLAMPED_FLOAT_TO_UBYTE(border[0], tObj->BorderColor.f[0]); - CLAMPED_FLOAT_TO_UBYTE(border[1], tObj->BorderColor.f[1]); - CLAMPED_FLOAT_TO_UBYTE(border[2], tObj->BorderColor.f[2]); - CLAMPED_FLOAT_TO_UBYTE(border[3], tObj->BorderColor.f[3]); + CLAMPED_FLOAT_TO_UBYTE(border[0], tObj->Sampler.BorderColor.f[0]); + CLAMPED_FLOAT_TO_UBYTE(border[1], tObj->Sampler.BorderColor.f[1]); + CLAMPED_FLOAT_TO_UBYTE(border[2], tObj->Sampler.BorderColor.f[2]); + CLAMPED_FLOAT_TO_UBYTE(border[3], tObj->Sampler.BorderColor.f[3]); if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) { /* GL specs that border color for depth textures is taken from the diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c index f5abe021c43..63ae28f8575 100644 --- a/src/mesa/drivers/dri/i965/brw_draw.c +++ b/src/mesa/drivers/dri/i965/brw_draw.c @@ -271,20 +271,20 @@ static GLboolean check_fallbacks( struct brw_context *brw, struct gl_texture_unit *texUnit = &ctx->Texture.Unit[u]; if (texUnit->Enabled) { if (texUnit->Enabled & TEXTURE_1D_BIT) { - if (texUnit->CurrentTex[TEXTURE_1D_INDEX]->WrapS == GL_CLAMP) { + if (texUnit->CurrentTex[TEXTURE_1D_INDEX]->Sampler.WrapS == GL_CLAMP) { return GL_TRUE; } } if (texUnit->Enabled & TEXTURE_2D_BIT) { - if (texUnit->CurrentTex[TEXTURE_2D_INDEX]->WrapS == GL_CLAMP || - texUnit->CurrentTex[TEXTURE_2D_INDEX]->WrapT == GL_CLAMP) { + if (texUnit->CurrentTex[TEXTURE_2D_INDEX]->Sampler.WrapS == GL_CLAMP || + texUnit->CurrentTex[TEXTURE_2D_INDEX]->Sampler.WrapT == GL_CLAMP) { return GL_TRUE; } } if (texUnit->Enabled & TEXTURE_3D_BIT) { - if (texUnit->CurrentTex[TEXTURE_3D_INDEX]->WrapS == GL_CLAMP || - texUnit->CurrentTex[TEXTURE_3D_INDEX]->WrapT == GL_CLAMP || - texUnit->CurrentTex[TEXTURE_3D_INDEX]->WrapR == GL_CLAMP) { + if (texUnit->CurrentTex[TEXTURE_3D_INDEX]->Sampler.WrapS == GL_CLAMP || + texUnit->CurrentTex[TEXTURE_3D_INDEX]->Sampler.WrapT == GL_CLAMP || + texUnit->CurrentTex[TEXTURE_3D_INDEX]->Sampler.WrapR == GL_CLAMP) { return GL_TRUE; } } diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index ca51d1599a4..2dd28fd1c58 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -370,14 +370,14 @@ static void brw_wm_populate_key( struct brw_context *brw, * well and our shadow compares always return the result in * all 4 channels. */ - if (t->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { - if (t->DepthMode == GL_ALPHA) { + if (t->Sampler.CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { + if (t->Sampler.DepthMode == GL_ALPHA) { swizzles[0] = SWIZZLE_ZERO; swizzles[1] = SWIZZLE_ZERO; swizzles[2] = SWIZZLE_ZERO; - } else if (t->DepthMode == GL_LUMINANCE) { + } else if (t->Sampler.DepthMode == GL_LUMINANCE) { swizzles[3] = SWIZZLE_ONE; - } else if (t->DepthMode == GL_RED) { + } else if (t->Sampler.DepthMode == GL_RED) { /* See table 3.23 of the GL 3.0 spec. */ swizzles[1] = SWIZZLE_ZERO; swizzles[2] = SWIZZLE_ZERO; diff --git a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c index 30672b4251b..cfc30d8613f 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c @@ -288,26 +288,26 @@ brw_wm_sampler_populate_key(struct brw_context *brw, entry->seamless_cube_map = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? ctx->Texture.CubeMapSeamless : GL_FALSE; - entry->wrap_r = texObj->WrapR; - entry->wrap_s = texObj->WrapS; - entry->wrap_t = texObj->WrapT; - - entry->maxlod = texObj->MaxLod; - entry->minlod = texObj->MinLod; - entry->lod_bias = texUnit->LodBias + texObj->LodBias; - entry->max_aniso = texObj->MaxAnisotropy; - entry->minfilter = texObj->MinFilter; - entry->magfilter = texObj->MagFilter; - entry->comparemode = texObj->CompareMode; - entry->comparefunc = texObj->CompareFunc; + entry->wrap_r = texObj->Sampler.WrapR; + entry->wrap_s = texObj->Sampler.WrapS; + entry->wrap_t = texObj->Sampler.WrapT; + + entry->maxlod = texObj->Sampler.MaxLod; + entry->minlod = texObj->Sampler.MinLod; + entry->lod_bias = texUnit->LodBias + texObj->Sampler.LodBias; + entry->max_aniso = texObj->Sampler.MaxAnisotropy; + entry->minfilter = texObj->Sampler.MinFilter; + entry->magfilter = texObj->Sampler.MagFilter; + entry->comparemode = texObj->Sampler.CompareMode; + entry->comparefunc = texObj->Sampler.CompareFunc; drm_intel_bo_unreference(brw->wm.sdc_bo[unit]); if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) { float bordercolor[4] = { - texObj->BorderColor.f[0], - texObj->BorderColor.f[0], - texObj->BorderColor.f[0], - texObj->BorderColor.f[0] + texObj->Sampler.BorderColor.f[0], + texObj->Sampler.BorderColor.f[0], + texObj->Sampler.BorderColor.f[0], + texObj->Sampler.BorderColor.f[0] }; /* GL specs that border color for depth textures is taken from the * R channel, while the hardware uses A. Spam R into all the @@ -316,7 +316,7 @@ brw_wm_sampler_populate_key(struct brw_context *brw, brw->wm.sdc_bo[unit] = upload_default_color(brw, bordercolor); } else { brw->wm.sdc_bo[unit] = upload_default_color(brw, - texObj->BorderColor.f); + texObj->Sampler.BorderColor.f); } key->sampler_count = unit + 1; } diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index aeda4d5ce4e..5a478a76e5c 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -201,8 +201,9 @@ brw_update_texture_surface( struct gl_context *ctx, GLuint unit ) surf->ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; surf->ss0.surface_type = translate_tex_target(tObj->Target); surf->ss0.surface_format = translate_tex_format(firstImage->TexFormat, - firstImage->InternalFormat, - tObj->DepthMode, tObj->sRGBDecode); + firstImage->InternalFormat, + tObj->Sampler.DepthMode, + tObj->Sampler.sRGBDecode); /* This is ok for all textures with channel width 8bit or less: */ diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c index b3a2b1b0c85..775fd1008f9 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_image.c +++ b/src/mesa/drivers/dri/intel/intel_tex_image.c @@ -112,8 +112,8 @@ intel_miptree_create_for_teximage(struct intel_context *intel, * resizable buffers, or require that buffers implement lazy * pagetable arrangements. */ - if ((intelObj->base.MinFilter == GL_NEAREST || - intelObj->base.MinFilter == GL_LINEAR) && + if ((intelObj->base.Sampler.MinFilter == GL_NEAREST || + intelObj->base.Sampler.MinFilter == GL_LINEAR) && intelImage->level == firstLevel && (intel->gen < 4 || firstLevel == 0)) { lastLevel = firstLevel; diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c index a11b07ed09d..5e705c93619 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_validate.c +++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c @@ -18,7 +18,7 @@ intel_update_max_level(struct intel_context *intel, { struct gl_texture_object *tObj = &intelObj->base; - if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) { + if (tObj->Sampler.MinFilter == GL_NEAREST || tObj->Sampler.MinFilter == GL_LINEAR) { intelObj->_MaxLevel = tObj->BaseLevel; } else { intelObj->_MaxLevel = tObj->_MaxLevel; diff --git a/src/mesa/drivers/dri/mach64/mach64_tex.c b/src/mesa/drivers/dri/mach64/mach64_tex.c index 68d273a3e75..8e10b314b64 100644 --- a/src/mesa/drivers/dri/mach64/mach64_tex.c +++ b/src/mesa/drivers/dri/mach64/mach64_tex.c @@ -123,9 +123,9 @@ mach64AllocTexObj( struct gl_texture_object *texObj ) make_empty_list( (driTextureObject *) t ); - mach64SetTexWrap( t, texObj->WrapS, texObj->WrapT ); - mach64SetTexFilter( t, texObj->MinFilter, texObj->MagFilter ); - mach64SetTexBorderColor( t, texObj->BorderColor.f ); + mach64SetTexWrap( t, texObj->Sampler.WrapS, texObj->Sampler.WrapT ); + mach64SetTexFilter( t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter ); + mach64SetTexBorderColor( t, texObj->Sampler.BorderColor.f ); return t; } @@ -454,18 +454,18 @@ static void mach64DDTexParameter( struct gl_context *ctx, GLenum target, case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: if ( t->base.bound ) FLUSH_BATCH( mmesa ); - mach64SetTexFilter( t, tObj->MinFilter, tObj->MagFilter ); + mach64SetTexFilter( t, tObj->Sampler.MinFilter, tObj->Sampler.MagFilter ); break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: if ( t->base.bound ) FLUSH_BATCH( mmesa ); - mach64SetTexWrap( t, tObj->WrapS, tObj->WrapT ); + mach64SetTexWrap( t, tObj->Sampler.WrapS, tObj->Sampler.WrapT ); break; case GL_TEXTURE_BORDER_COLOR: if ( t->base.bound ) FLUSH_BATCH( mmesa ); - mach64SetTexBorderColor( t, tObj->BorderColor.f ); + mach64SetTexBorderColor( t, tObj->Sampler.BorderColor.f ); break; case GL_TEXTURE_BASE_LEVEL: diff --git a/src/mesa/drivers/dri/mga/mgatex.c b/src/mesa/drivers/dri/mga/mgatex.c index 11ab9b6117d..ebbfec36556 100644 --- a/src/mesa/drivers/dri/mga/mgatex.c +++ b/src/mesa/drivers/dri/mga/mgatex.c @@ -327,9 +327,9 @@ mgaAllocTexObj( struct gl_texture_object *tObj ) make_empty_list( & t->base ); - mgaSetTexWrapping( t, tObj->WrapS, tObj->WrapT ); - mgaSetTexFilter( t, tObj->MinFilter, tObj->MagFilter ); - mgaSetTexBorderColor( t, tObj->BorderColor.f ); + mgaSetTexWrapping( t, tObj->Sampler.WrapS, tObj->Sampler.WrapT ); + mgaSetTexFilter( t, tObj->Sampler.MinFilter, tObj->Sampler.MagFilter ); + mgaSetTexBorderColor( t, tObj->Sampler.BorderColor.f ); } return( t ); @@ -447,18 +447,18 @@ mgaTexParameter( struct gl_context *ctx, GLenum target, /* FALLTHROUGH */ case GL_TEXTURE_MAG_FILTER: FLUSH_BATCH(mmesa); - mgaSetTexFilter( t, tObj->MinFilter, tObj->MagFilter ); + mgaSetTexFilter( t, tObj->Sampler.MinFilter, tObj->Sampler.MagFilter ); break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: FLUSH_BATCH(mmesa); - mgaSetTexWrapping(t,tObj->WrapS,tObj->WrapT); + mgaSetTexWrapping(t,tObj->Sampler.WrapS,tObj->Sampler.WrapT); break; case GL_TEXTURE_BORDER_COLOR: FLUSH_BATCH(mmesa); - mgaSetTexBorderColor(t, tObj->BorderColor.f); + mgaSetTexBorderColor(t, tObj->Sampler.BorderColor.f); break; case GL_TEXTURE_BASE_LEVEL: diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c index 1a1e10e0b3a..36e68c99181 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c @@ -270,8 +270,8 @@ get_last_level(struct gl_texture_object *t) { struct gl_texture_image *base = t->Image[0][t->BaseLevel]; - if (t->MinFilter == GL_NEAREST || - t->MinFilter == GL_LINEAR || !base) + if (t->Sampler.MinFilter == GL_NEAREST || + t->Sampler.MinFilter == GL_LINEAR || !base) return t->BaseLevel; else return MIN2(t->BaseLevel + base->MaxLog2, t->MaxLevel); diff --git a/src/mesa/drivers/dri/nouveau/nv04_state_tex.c b/src/mesa/drivers/dri/nouveau/nv04_state_tex.c index 5ed8b147559..6c96e580013 100644 --- a/src/mesa/drivers/dri/nouveau/nv04_state_tex.c +++ b/src/mesa/drivers/dri/nouveau/nv04_state_tex.c @@ -80,8 +80,8 @@ nv04_emit_tex_obj(struct gl_context *ctx, int emit) s = &to_nouveau_texture(t)->surfaces[t->BaseLevel]; - if (t->MinFilter != GL_NEAREST && - t->MinFilter != GL_LINEAR) { + if (t->Sampler.MinFilter != GL_NEAREST && + t->Sampler.MinFilter != GL_LINEAR) { lod_max = CLAMP(MIN2(t->MaxLod, t->_MaxLambda), 0, 15) + 1; @@ -89,17 +89,17 @@ nv04_emit_tex_obj(struct gl_context *ctx, int emit) t->LodBias, -16, 15) * 8; } - format |= nvgl_wrap_mode(t->WrapT) << 28 | - nvgl_wrap_mode(t->WrapS) << 24 | + format |= nvgl_wrap_mode(t->Sampler.WrapT) << 28 | + nvgl_wrap_mode(t->Sampler.WrapS) << 24 | ti->HeightLog2 << 20 | ti->WidthLog2 << 16 | lod_max << 12 | get_tex_format(ti); filter |= log2i(t->MaxAnisotropy) << 31 | - nvgl_filter_mode(t->MagFilter) << 28 | + nvgl_filter_mode(t->Sampler.MagFilter) << 28 | log2i(t->MaxAnisotropy) << 27 | - nvgl_filter_mode(t->MinFilter) << 24 | + nvgl_filter_mode(t->Sampler.MinFilter) << 24 | (lod_bias & 0xff) << 16; } else { diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_tex.c b/src/mesa/drivers/dri/nouveau/nv10_state_tex.c index fda67b15073..1d98b1970ef 100644 --- a/src/mesa/drivers/dri/nouveau/nv10_state_tex.c +++ b/src/mesa/drivers/dri/nouveau/nv10_state_tex.c @@ -173,14 +173,14 @@ nv10_emit_tex_obj(struct gl_context *ctx, int emit) return; /* Recompute the texturing registers. */ - tx_format = nvgl_wrap_mode(t->WrapT) << 28 - | nvgl_wrap_mode(t->WrapS) << 24 + tx_format = nvgl_wrap_mode(t->Sampler.WrapT) << 28 + | nvgl_wrap_mode(t->Sampler.WrapS) << 24 | ti->HeightLog2 << 20 | ti->WidthLog2 << 16 | 5 << 4 | 1 << 12; - tx_filter = nvgl_filter_mode(t->MagFilter) << 28 - | nvgl_filter_mode(t->MinFilter) << 24; + tx_filter = nvgl_filter_mode(t->Sampler.MagFilter) << 28 + | nvgl_filter_mode(t->Sampler.MinFilter) << 24; tx_enable = NV10_3D_TEX_ENABLE_ENABLE | log2i(t->MaxAnisotropy) << 4; @@ -196,8 +196,8 @@ nv10_emit_tex_obj(struct gl_context *ctx, int emit) tx_format |= get_tex_format_pot(ti); } - if (t->MinFilter != GL_NEAREST && - t->MinFilter != GL_LINEAR) { + if (t->Sampler.MinFilter != GL_NEAREST && + t->Sampler.MinFilter != GL_LINEAR) { int lod_min = t->MinLod; int lod_max = MIN2(t->MaxLod, t->_MaxLambda); int lod_bias = t->LodBias diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_tex.c b/src/mesa/drivers/dri/nouveau/nv20_state_tex.c index c362aca0fdb..fdbfdf42595 100644 --- a/src/mesa/drivers/dri/nouveau/nv20_state_tex.c +++ b/src/mesa/drivers/dri/nouveau/nv20_state_tex.c @@ -186,12 +186,12 @@ nv20_emit_tex_obj(struct gl_context *ctx, int emit) | NV20_3D_TEX_FORMAT_NO_BORDER | 1 << 16; - tx_wrap = nvgl_wrap_mode(t->WrapR) << 16 - | nvgl_wrap_mode(t->WrapT) << 8 - | nvgl_wrap_mode(t->WrapS) << 0; + tx_wrap = nvgl_wrap_mode(t->Sampler.WrapR) << 16 + | nvgl_wrap_mode(t->Sampler.WrapT) << 8 + | nvgl_wrap_mode(t->Sampler.WrapS) << 0; - tx_filter = nvgl_filter_mode(t->MagFilter) << 24 - | nvgl_filter_mode(t->MinFilter) << 16 + tx_filter = nvgl_filter_mode(t->Sampler.MagFilter) << 24 + | nvgl_filter_mode(t->Sampler.MinFilter) << 16 | 2 << 12; tx_enable = NV20_3D_TEX_ENABLE_ENABLE @@ -208,8 +208,8 @@ nv20_emit_tex_obj(struct gl_context *ctx, int emit) tx_format |= get_tex_format_pot(ti); } - if (t->MinFilter != GL_NEAREST && - t->MinFilter != GL_LINEAR) { + if (t->Sampler.MinFilter != GL_NEAREST && + t->Sampler.MinFilter != GL_LINEAR) { int lod_min = t->MinLod; int lod_max = MIN2(t->MaxLod, t->_MaxLambda); int lod_bias = t->LodBias diff --git a/src/mesa/drivers/dri/r128/r128_tex.c b/src/mesa/drivers/dri/r128/r128_tex.c index ba3305e076e..a3f6ce8edeb 100644 --- a/src/mesa/drivers/dri/r128/r128_tex.c +++ b/src/mesa/drivers/dri/r128/r128_tex.c @@ -162,9 +162,9 @@ static r128TexObjPtr r128AllocTexObj( struct gl_texture_object *texObj ) make_empty_list( (driTextureObject *) t ); - r128SetTexWrap( t, texObj->WrapS, texObj->WrapT ); - r128SetTexFilter( t, texObj->MinFilter, texObj->MagFilter ); - r128SetTexBorderColor( t, texObj->BorderColor.f ); + r128SetTexWrap( t, texObj->Sampler.WrapS, texObj->Sampler.WrapT ); + r128SetTexFilter( t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter ); + r128SetTexBorderColor( t, texObj->Sampler.BorderColor.f ); } return t; @@ -519,18 +519,18 @@ static void r128TexParameter( struct gl_context *ctx, GLenum target, case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: if ( t->base.bound ) FLUSH_BATCH( rmesa ); - r128SetTexFilter( t, tObj->MinFilter, tObj->MagFilter ); + r128SetTexFilter( t, tObj->Sampler.MinFilter, tObj->Sampler.MagFilter ); break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: if ( t->base.bound ) FLUSH_BATCH( rmesa ); - r128SetTexWrap( t, tObj->WrapS, tObj->WrapT ); + r128SetTexWrap( t, tObj->Sampler.WrapS, tObj->Sampler.WrapT ); break; case GL_TEXTURE_BORDER_COLOR: if ( t->base.bound ) FLUSH_BATCH( rmesa ); - r128SetTexBorderColor( t, tObj->BorderColor.f ); + r128SetTexBorderColor( t, tObj->Sampler.BorderColor.f ); break; case GL_TEXTURE_BASE_LEVEL: diff --git a/src/mesa/drivers/dri/r200/r200_tex.c b/src/mesa/drivers/dri/r200/r200_tex.c index 092b7575831..d42e8f12041 100644 --- a/src/mesa/drivers/dri/r200/r200_tex.c +++ b/src/mesa/drivers/dri/r200/r200_tex.c @@ -383,18 +383,18 @@ static void r200TexParameter( struct gl_context *ctx, GLenum target, case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MAX_ANISOTROPY_EXT: - r200SetTexMaxAnisotropy( t, texObj->MaxAnisotropy ); - r200SetTexFilter( t, texObj->MinFilter, texObj->MagFilter ); + r200SetTexMaxAnisotropy( t, texObj->Sampler.MaxAnisotropy ); + r200SetTexFilter( t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter ); break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: case GL_TEXTURE_WRAP_R: - r200SetTexWrap( t, texObj->WrapS, texObj->WrapT, texObj->WrapR ); + r200SetTexWrap( t, texObj->Sampler.WrapS, texObj->Sampler.WrapT, texObj->Sampler.WrapR ); break; case GL_TEXTURE_BORDER_COLOR: - r200SetTexBorderColor( t, texObj->BorderColor.f ); + r200SetTexBorderColor( t, texObj->Sampler.BorderColor.f ); break; case GL_TEXTURE_BASE_LEVEL: @@ -479,13 +479,13 @@ static struct gl_texture_object *r200NewTextureObject(struct gl_context * ctx, _mesa_lookup_enum_by_nr(target), t); _mesa_initialize_texture_object(&t->base, name, target); - t->base.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy; + t->base.Sampler.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy; /* Initialize hardware state */ - r200SetTexWrap( t, t->base.WrapS, t->base.WrapT, t->base.WrapR ); - r200SetTexMaxAnisotropy( t, t->base.MaxAnisotropy ); - r200SetTexFilter(t, t->base.MinFilter, t->base.MagFilter); - r200SetTexBorderColor(t, t->base.BorderColor.f); + r200SetTexWrap( t, t->base.Sampler.WrapS, t->base.Sampler.WrapT, t->base.Sampler.WrapR ); + r200SetTexMaxAnisotropy( t, t->base.Sampler.MaxAnisotropy ); + r200SetTexFilter(t, t->base.Sampler.MinFilter, t->base.Sampler.MagFilter); + r200SetTexBorderColor(t, t->base.Sampler.BorderColor.f); return &t->base; } diff --git a/src/mesa/drivers/dri/r300/r300_fragprog_common.c b/src/mesa/drivers/dri/r300/r300_fragprog_common.c index 50cf8d6f9db..f0d960dca54 100644 --- a/src/mesa/drivers/dri/r300/r300_fragprog_common.c +++ b/src/mesa/drivers/dri/r300/r300_fragprog_common.c @@ -77,8 +77,8 @@ static void build_state( if (fp->Base.ShadowSamplers & (1 << unit)) { struct gl_texture_object* tex = r300->radeon.glCtx->Texture.Unit[unit]._Current; - state->unit[unit].texture_swizzle = build_dts(tex->DepthMode); - state->unit[unit].texture_compare_func = build_func(tex->CompareFunc); + state->unit[unit].texture_swizzle = build_dts(tex->Sampler.DepthMode); + state->unit[unit].texture_compare_func = build_func(tex->Sampler.CompareFunc); } } } diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index 51989c6b224..da6c8b602e1 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -1343,7 +1343,7 @@ static void r300SetupTextures(struct gl_context * ctx) */ r300->hw.tex.filter_1.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->pp_txfilter_1 | - translate_lod_bias(ctx->Texture.Unit[i].LodBias + t->base.LodBias); + translate_lod_bias(ctx->Texture.Unit[i].LodBias + t->base.Sampler.LodBias); r300->hw.tex.size.cmd[R300_TEX_VALUE_0 + hw_tmu] = t->pp_txsize; r300->hw.tex.format.cmd[R300_TEX_VALUE_0 + @@ -2014,7 +2014,7 @@ static const GLfloat *get_fragmentprogram_constant(struct gl_context *ctx, GLuin buffer[0] = buffer[1] = buffer[2] = - buffer[3] = texObj->CompareFailValue; + buffer[3] = texObj->Sampler.CompareFailValue; } return buffer; } diff --git a/src/mesa/drivers/dri/r300/r300_tex.c b/src/mesa/drivers/dri/r300/r300_tex.c index f930b4d06bf..590d9afe14a 100644 --- a/src/mesa/drivers/dri/r300/r300_tex.c +++ b/src/mesa/drivers/dri/r300/r300_tex.c @@ -81,13 +81,13 @@ static void r300UpdateTexWrap(radeonTexObjPtr t) t->pp_txfilter &= ~(R300_TX_WRAP_S_MASK | R300_TX_WRAP_T_MASK | R300_TX_WRAP_R_MASK); - t->pp_txfilter |= translate_wrap_mode(tObj->WrapS) << R300_TX_WRAP_S_SHIFT; + t->pp_txfilter |= translate_wrap_mode(tObj->Sampler.WrapS) << R300_TX_WRAP_S_SHIFT; if (tObj->Target != GL_TEXTURE_1D) { - t->pp_txfilter |= translate_wrap_mode(tObj->WrapT) << R300_TX_WRAP_T_SHIFT; + t->pp_txfilter |= translate_wrap_mode(tObj->Sampler.WrapT) << R300_TX_WRAP_T_SHIFT; if (tObj->Target == GL_TEXTURE_3D) - t->pp_txfilter |= translate_wrap_mode(tObj->WrapR) << R300_TX_WRAP_R_SHIFT; + t->pp_txfilter |= translate_wrap_mode(tObj->Sampler.WrapR) << R300_TX_WRAP_R_SHIFT; } } @@ -202,7 +202,7 @@ static void r300TexParameter(struct gl_context * ctx, GLenum target, case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MAX_ANISOTROPY_EXT: - r300SetTexFilter(t, texObj->MinFilter, texObj->MagFilter, texObj->MaxAnisotropy); + r300SetTexFilter(t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter, texObj->Sampler.MaxAnisotropy); break; case GL_TEXTURE_WRAP_S: @@ -212,7 +212,7 @@ static void r300TexParameter(struct gl_context * ctx, GLenum target, break; case GL_TEXTURE_BORDER_COLOR: - r300SetTexBorderColor(t, texObj->BorderColor.f); + r300SetTexBorderColor(t, texObj->Sampler.BorderColor.f); break; case GL_TEXTURE_BASE_LEVEL: @@ -299,12 +299,14 @@ static struct gl_texture_object *r300NewTextureObject(struct gl_context * ctx, } _mesa_initialize_texture_object(&t->base, name, target); - t->base.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy; + t->base.Sampler.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy; /* Initialize hardware state */ r300UpdateTexWrap(t); - r300SetTexFilter(t, t->base.MinFilter, t->base.MagFilter, t->base.MaxAnisotropy); - r300SetTexBorderColor(t, t->base.BorderColor.f); + r300SetTexFilter(t, t->base.Sampler.MinFilter, + t->base.Sampler.MagFilter, + t->base.Sampler.MaxAnisotropy); + r300SetTexBorderColor(t, t->base.Sampler.BorderColor.f); return &t->base; } diff --git a/src/mesa/drivers/dri/r300/r300_texstate.c b/src/mesa/drivers/dri/r300/r300_texstate.c index ed9955b05d8..e24ad6f088d 100644 --- a/src/mesa/drivers/dri/r300/r300_texstate.c +++ b/src/mesa/drivers/dri/r300/r300_texstate.c @@ -216,7 +216,7 @@ void r300SetDepthTexMode(struct gl_texture_object *tObj) return; } - switch (tObj->DepthMode) { + switch (tObj->Sampler.DepthMode) { case GL_LUMINANCE: t->pp_txformat = format[0]; break; diff --git a/src/mesa/drivers/dri/r600/evergreen_tex.c b/src/mesa/drivers/dri/r600/evergreen_tex.c index 3b5448a0e4e..5fdb91a63d1 100644 --- a/src/mesa/drivers/dri/r600/evergreen_tex.c +++ b/src/mesa/drivers/dri/r600/evergreen_tex.c @@ -699,18 +699,18 @@ static void evergreenUpdateTexWrap(radeonTexObjPtr t) { struct gl_texture_object *tObj = &t->base; - SETfield(t->SQ_TEX_SAMPLER0, evergreen_translate_wrap_mode(tObj->WrapS), + SETfield(t->SQ_TEX_SAMPLER0, evergreen_translate_wrap_mode(tObj->Sampler.WrapS), EG_SQ_TEX_SAMPLER_WORD0_0__CLAMP_X_shift, EG_SQ_TEX_SAMPLER_WORD0_0__CLAMP_X_mask); if (tObj->Target != GL_TEXTURE_1D) { - SETfield(t->SQ_TEX_SAMPLER0, evergreen_translate_wrap_mode(tObj->WrapT), + SETfield(t->SQ_TEX_SAMPLER0, evergreen_translate_wrap_mode(tObj->Sampler.WrapT), EG_SQ_TEX_SAMPLER_WORD0_0__CLAMP_Y_shift, EG_SQ_TEX_SAMPLER_WORD0_0__CLAMP_Y_mask); if (tObj->Target == GL_TEXTURE_3D) - SETfield(t->SQ_TEX_SAMPLER0, evergreen_translate_wrap_mode(tObj->WrapR), + SETfield(t->SQ_TEX_SAMPLER0, evergreen_translate_wrap_mode(tObj->Sampler.WrapR), EG_SQ_TEX_SAMPLER_WORD0_0__CLAMP_Z_shift, EG_SQ_TEX_SAMPLER_WORD0_0__CLAMP_Z_mask); } @@ -901,7 +901,7 @@ static void evergreenSetTexFilter(radeonTexObjPtr t, GLenum minf, GLenum magf, G } } -static void evergreenSetTexBorderColor(radeonTexObjPtr t, const GLfloat color[4]) +static void evergreenSetTexSampler.BorderColor(radeonTexObjPtr t, const GLfloat color[4]) { t->TD_PS_SAMPLER0_BORDER_ALPHA = *((uint32_t*)&(color[3])); t->TD_PS_SAMPLER0_BORDER_RED = *((uint32_t*)&(color[2])); @@ -1424,8 +1424,8 @@ static struct gl_texture_object *evergreenNewTextureObject(struct gl_context * c evergreenSetTexDefaultState(t); evergreenUpdateTexWrap(t); - evergreenSetTexFilter(t, t->base.MinFilter, t->base.MagFilter, t->base.MaxAnisotropy); - evergreenSetTexBorderColor(t, t->base.BorderColor.f); + evergreenSetTexFilter(t, t->base.Sampler.MinFilter, t->base.Sampler.MagFilter, t->base.MaxAnisotropy); + evergreenSetTexSampler.BorderColor(t, t->base.Sampler.BorderColor.f); return &t->base; } @@ -1475,7 +1475,7 @@ static void evergreenTexParameter(struct gl_context * ctx, GLenum target, case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MAX_ANISOTROPY_EXT: - evergreenSetTexFilter(t, texObj->MinFilter, texObj->MagFilter, texObj->MaxAnisotropy); + evergreenSetTexFilter(t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter, texObj->MaxAnisotropy); break; case GL_TEXTURE_WRAP_S: @@ -1485,7 +1485,7 @@ static void evergreenTexParameter(struct gl_context * ctx, GLenum target, break; case GL_TEXTURE_BORDER_COLOR: - evergreenSetTexBorderColor(t, texObj->BorderColor.f); + evergreenSetTexSampler.BorderColor(t, texObj->Sampler.BorderColor.f); break; case GL_TEXTURE_BASE_LEVEL: diff --git a/src/mesa/drivers/dri/r600/r600_tex.c b/src/mesa/drivers/dri/r600/r600_tex.c index fe4f0e48661..07f6de7ad49 100644 --- a/src/mesa/drivers/dri/r600/r600_tex.c +++ b/src/mesa/drivers/dri/r600/r600_tex.c @@ -78,15 +78,15 @@ static void r600UpdateTexWrap(radeonTexObjPtr t) { struct gl_texture_object *tObj = &t->base; - SETfield(t->SQ_TEX_SAMPLER0, translate_wrap_mode(tObj->WrapS), + SETfield(t->SQ_TEX_SAMPLER0, translate_wrap_mode(tObj->Sampler.WrapS), SQ_TEX_SAMPLER_WORD0_0__CLAMP_X_shift, SQ_TEX_SAMPLER_WORD0_0__CLAMP_X_mask); if (tObj->Target != GL_TEXTURE_1D) { - SETfield(t->SQ_TEX_SAMPLER0, translate_wrap_mode(tObj->WrapT), + SETfield(t->SQ_TEX_SAMPLER0, translate_wrap_mode(tObj->Sampler.WrapT), CLAMP_Y_shift, CLAMP_Y_mask); if (tObj->Target == GL_TEXTURE_3D) - SETfield(t->SQ_TEX_SAMPLER0, translate_wrap_mode(tObj->WrapR), + SETfield(t->SQ_TEX_SAMPLER0, translate_wrap_mode(tObj->Sampler.WrapR), CLAMP_Z_shift, CLAMP_Z_mask); } } @@ -262,7 +262,7 @@ static void r600SetTexFilter(radeonTexObjPtr t, GLenum minf, GLenum magf, GLfloa } } -static void r600SetTexBorderColor(radeonTexObjPtr t, const GLfloat color[4]) +static void r600SetTexSampler.BorderColor(radeonTexObjPtr t, const GLfloat color[4]) { t->TD_PS_SAMPLER0_BORDER_ALPHA = *((uint32_t*)&(color[3])); t->TD_PS_SAMPLER0_BORDER_BLUE = *((uint32_t*)&(color[2])); @@ -292,7 +292,7 @@ static void r600TexParameter(struct gl_context * ctx, GLenum target, case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MAX_ANISOTROPY_EXT: - r600SetTexFilter(t, texObj->MinFilter, texObj->MagFilter, texObj->MaxAnisotropy); + r600SetTexFilter(t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter, texObj->MaxAnisotropy); break; case GL_TEXTURE_WRAP_S: @@ -302,7 +302,7 @@ static void r600TexParameter(struct gl_context * ctx, GLenum target, break; case GL_TEXTURE_BORDER_COLOR: - r600SetTexBorderColor(t, texObj->BorderColor.f); + r600SetTexSampler.BorderColor(t, texObj->Sampler.BorderColor.f); break; case GL_TEXTURE_BASE_LEVEL: @@ -387,8 +387,8 @@ static struct gl_texture_object *r600NewTextureObject(struct gl_context * ctx, /* Initialize hardware state */ r600SetTexDefaultState(t); r600UpdateTexWrap(t); - r600SetTexFilter(t, t->base.MinFilter, t->base.MagFilter, t->base.MaxAnisotropy); - r600SetTexBorderColor(t, t->base.BorderColor.f); + r600SetTexFilter(t, t->base.Sampler.MinFilter, t->base.Sampler.MagFilter, t->base.MaxAnisotropy); + r600SetTexSampler.BorderColor(t, t->base.Sampler.BorderColor.f); return &t->base; } diff --git a/src/mesa/drivers/dri/r600/r700_chip.c b/src/mesa/drivers/dri/r600/r700_chip.c index 4ec2845ab44..ff456c67e2e 100644 --- a/src/mesa/drivers/dri/r600/r700_chip.c +++ b/src/mesa/drivers/dri/r600/r700_chip.c @@ -141,7 +141,7 @@ static void r700SendTexSamplerState(struct gl_context *ctx, struct radeon_state_ } } -static void r700SendTexBorderColorState(struct gl_context *ctx, struct radeon_state_atom *atom) +static void r700SendTexSampler.BorderColorState(struct gl_context *ctx, struct radeon_state_atom *atom) { context_t *context = R700_CONTEXT(ctx); R700_CHIP_CONTEXT *r700 = (R700_CHIP_CONTEXT*)(&context->hw); @@ -1640,7 +1640,7 @@ void r600InitAtoms(context_t *context) ALLOC_STATE(vtx, vtx, (VERT_ATTRIB_MAX * 18), r700SendVTXState); ALLOC_STATE(tx, tx, (R700_TEXTURE_NUMBERUNITS * 20), r700SendTexState); ALLOC_STATE(tx_smplr, tx, (R700_TEXTURE_NUMBERUNITS * 5), r700SendTexSamplerState); - ALLOC_STATE(tx_brdr_clr, tx, (R700_TEXTURE_NUMBERUNITS * 6), r700SendTexBorderColorState); + ALLOC_STATE(tx_brdr_clr, tx, (R700_TEXTURE_NUMBERUNITS * 6), r700SendTexSampler.BorderColorState); r600_init_query_stateobj(&context->radeon, 6 * 2); context->radeon.hw.is_dirty = GL_TRUE; diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c index 1fadad2756b..03d9b264367 100644 --- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c +++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c @@ -296,15 +296,15 @@ static void calculate_min_max_lod(struct gl_texture_object *tObj, case GL_TEXTURE_2D: case GL_TEXTURE_3D: case GL_TEXTURE_CUBE_MAP: - if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) { + if (tObj->Sampler.MinFilter == GL_NEAREST || tObj->Sampler.MinFilter == GL_LINEAR) { /* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL. */ minLod = maxLod = tObj->BaseLevel; } else { - minLod = tObj->BaseLevel + (GLint)(tObj->MinLod); + minLod = tObj->BaseLevel + (GLint)(tObj->Sampler.MinLod); minLod = MAX2(minLod, tObj->BaseLevel); minLod = MIN2(minLod, tObj->MaxLevel); - maxLod = tObj->BaseLevel + (GLint)(tObj->MaxLod + 0.5); + maxLod = tObj->BaseLevel + (GLint)(tObj->Sampler.MaxLod + 0.5); maxLod = MIN2(maxLod, tObj->MaxLevel); maxLod = MIN2(maxLod, tObj->Image[0][minLod]->MaxLog2 + minLod); maxLod = MAX2(maxLod, minLod); /* need at least one level */ diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.c b/src/mesa/drivers/dri/radeon/radeon_tex.c index 8a35c7d2d27..25a8ddf7b6a 100644 --- a/src/mesa/drivers/dri/radeon/radeon_tex.c +++ b/src/mesa/drivers/dri/radeon/radeon_tex.c @@ -330,17 +330,17 @@ static void radeonTexParameter( struct gl_context *ctx, GLenum target, case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MAX_ANISOTROPY_EXT: - radeonSetTexMaxAnisotropy( t, texObj->MaxAnisotropy ); - radeonSetTexFilter( t, texObj->MinFilter, texObj->MagFilter ); + radeonSetTexMaxAnisotropy( t, texObj->Sampler.MaxAnisotropy ); + radeonSetTexFilter( t, texObj->Sampler.MinFilter, texObj->Sampler.MagFilter ); break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: - radeonSetTexWrap( t, texObj->WrapS, texObj->WrapT ); + radeonSetTexWrap( t, texObj->Sampler.WrapS, texObj->Sampler.WrapT ); break; case GL_TEXTURE_BORDER_COLOR: - radeonSetTexBorderColor( t, texObj->BorderColor.f ); + radeonSetTexBorderColor( t, texObj->Sampler.BorderColor.f ); break; case GL_TEXTURE_BASE_LEVEL: @@ -416,7 +416,7 @@ radeonNewTextureObject( struct gl_context *ctx, GLuint name, GLenum target ) radeonTexObj* t = CALLOC_STRUCT(radeon_tex_obj); _mesa_initialize_texture_object(&t->base, name, target); - t->base.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy; + t->base.Sampler.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy; t->border_fallback = GL_FALSE; @@ -424,10 +424,10 @@ radeonNewTextureObject( struct gl_context *ctx, GLuint name, GLenum target ) t->pp_txformat = (RADEON_TXFORMAT_ENDIAN_NO_SWAP | RADEON_TXFORMAT_PERSPECTIVE_ENABLE); - radeonSetTexWrap( t, t->base.WrapS, t->base.WrapT ); - radeonSetTexMaxAnisotropy( t, t->base.MaxAnisotropy ); - radeonSetTexFilter( t, t->base.MinFilter, t->base.MagFilter ); - radeonSetTexBorderColor( t, t->base.BorderColor.f ); + radeonSetTexWrap( t, t->base.Sampler.WrapS, t->base.Sampler.WrapT ); + radeonSetTexMaxAnisotropy( t, t->base.Sampler.MaxAnisotropy ); + radeonSetTexFilter( t, t->base.Sampler.MinFilter, t->base.Sampler.MagFilter ); + radeonSetTexBorderColor( t, t->base.Sampler.BorderColor.f ); return &t->base; } diff --git a/src/mesa/drivers/dri/savage/savagerender.c b/src/mesa/drivers/dri/savage/savagerender.c index 8cc448ad4f7..6687dc5f466 100644 --- a/src/mesa/drivers/dri/savage/savagerender.c +++ b/src/mesa/drivers/dri/savage/savagerender.c @@ -250,9 +250,9 @@ static GLboolean run_texnorm_stage( struct gl_context *ctx, const GLbitfield reallyEnabled = ctx->Texture.Unit[i]._ReallyEnabled; if (reallyEnabled) { const struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current; - const GLboolean normalizeS = (texObj->WrapS == GL_REPEAT); + const GLboolean normalizeS = (texObj->Sampler.WrapS == GL_REPEAT); const GLboolean normalizeT = (reallyEnabled & TEXTURE_2D_BIT) && - (texObj->WrapT == GL_REPEAT); + (texObj->Sampler.WrapT == GL_REPEAT); const GLfloat *in = (GLfloat *)VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]->data; const GLint instride = VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]->stride; GLfloat (*out)[4] = store->texcoord[i].data; @@ -332,15 +332,15 @@ static void validate_texnorm( struct gl_context *ctx, GLuint flags = 0; if (((ctx->Texture.Unit[0]._ReallyEnabled & (TEXTURE_1D_BIT|TEXTURE_2D_BIT)) && - (ctx->Texture.Unit[0]._Current->WrapS == GL_REPEAT)) || + (ctx->Texture.Unit[0]._Current->Sampler.WrapS == GL_REPEAT)) || ((ctx->Texture.Unit[0]._ReallyEnabled & TEXTURE_2D_BIT) && - (ctx->Texture.Unit[0]._Current->WrapT == GL_REPEAT))) + (ctx->Texture.Unit[0]._Current->Sampler.WrapT == GL_REPEAT))) flags |= VERT_BIT_TEX0; if (((ctx->Texture.Unit[1]._ReallyEnabled & (TEXTURE_1D_BIT|TEXTURE_2D_BIT)) && - (ctx->Texture.Unit[1]._Current->WrapS == GL_REPEAT)) || + (ctx->Texture.Unit[1]._Current->Sampler.WrapS == GL_REPEAT)) || ((ctx->Texture.Unit[1]._ReallyEnabled & TEXTURE_2D_BIT) && - (ctx->Texture.Unit[1]._Current->WrapT == GL_REPEAT))) + (ctx->Texture.Unit[1]._Current->Sampler.WrapT == GL_REPEAT))) flags |= VERT_BIT_TEX1; store->active = (flags != 0); diff --git a/src/mesa/drivers/dri/savage/savagetex.c b/src/mesa/drivers/dri/savage/savagetex.c index 3aece732c99..9486c12c158 100644 --- a/src/mesa/drivers/dri/savage/savagetex.c +++ b/src/mesa/drivers/dri/savage/savagetex.c @@ -502,9 +502,9 @@ savageAllocTexObj( struct gl_texture_object *texObj ) make_empty_list( &t->base ); - savageSetTexWrapping(t,texObj->WrapS,texObj->WrapT); - savageSetTexFilter(t,texObj->MinFilter,texObj->MagFilter); - savageSetTexBorderColor(t,texObj->BorderColor.f); + savageSetTexWrapping(t,texObj->Sampler.WrapS,texObj->Sampler.WrapT); + savageSetTexFilter(t,texObj->Sampler.MinFilter,texObj->Sampler.MagFilter); + savageSetTexBorderColor(t,texObj->Sampler.BorderColor.f); } return t; @@ -2031,16 +2031,16 @@ static void savageTexParameter( struct gl_context *ctx, GLenum target, switch (pname) { case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: - savageSetTexFilter(t,tObj->MinFilter,tObj->MagFilter); + savageSetTexFilter(t,tObj->Sampler.MinFilter,tObj->Sampler.MagFilter); break; case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: - savageSetTexWrapping(t,tObj->WrapS,tObj->WrapT); + savageSetTexWrapping(t,tObj->Sampler.WrapS,tObj->Sampler.WrapT); break; case GL_TEXTURE_BORDER_COLOR: - savageSetTexBorderColor(t,tObj->BorderColor.f); + savageSetTexBorderColor(t,tObj->Sampler.BorderColor.f); break; default: diff --git a/src/mesa/drivers/dri/sis/sis_texstate.c b/src/mesa/drivers/dri/sis/sis_texstate.c index daec2393211..6580f155bae 100644 --- a/src/mesa/drivers/dri/sis/sis_texstate.c +++ b/src/mesa/drivers/dri/sis/sis_texstate.c @@ -335,7 +335,7 @@ sis_set_texobj_parm( struct gl_context *ctx, struct gl_texture_object *texObj, current->texture[hw_unit].hwTextureMip = 0UL; current->texture[hw_unit].hwTextureSet = t->hwformat; - if ((texObj->MinFilter == GL_NEAREST) || (texObj->MinFilter == GL_LINEAR)) { + if ((texObj->Sampler.MinFilter == GL_NEAREST) || (texObj->Sampler.MinFilter == GL_LINEAR)) { firstLevel = lastLevel = texObj->BaseLevel; } else { /* Compute which mipmap levels we really want to send to the hardware. @@ -344,9 +344,9 @@ sis_set_texobj_parm( struct gl_context *ctx, struct gl_texture_object *texObj, * Yes, this looks overly complicated, but it's all needed. */ - firstLevel = texObj->BaseLevel + (GLint)(texObj->MinLod + 0.5); + firstLevel = texObj->BaseLevel + (GLint)(texObj->Sampler.MinLod + 0.5); firstLevel = MAX2(firstLevel, texObj->BaseLevel); - lastLevel = texObj->BaseLevel + (GLint)(texObj->MaxLod + 0.5); + lastLevel = texObj->BaseLevel + (GLint)(texObj->Sampler.MaxLod + 0.5); lastLevel = MAX2(lastLevel, texObj->BaseLevel); lastLevel = MIN2(lastLevel, texObj->BaseLevel + texObj->Image[0][texObj->BaseLevel]->MaxLog2); @@ -356,7 +356,7 @@ sis_set_texobj_parm( struct gl_context *ctx, struct gl_texture_object *texObj, current->texture[hw_unit].hwTextureSet |= (lastLevel << 8); - switch (texObj->MagFilter) + switch (texObj->Sampler.MagFilter) { case GL_NEAREST: current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_NEAREST; @@ -382,7 +382,7 @@ sis_set_texobj_parm( struct gl_context *ctx, struct gl_texture_object *texObj, MASK_TextureMipmapLodBias); } - switch (texObj->MinFilter) + switch (texObj->Sampler.MinFilter) { case GL_NEAREST: current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_NEAREST; @@ -408,7 +408,7 @@ sis_set_texobj_parm( struct gl_context *ctx, struct gl_texture_object *texObj, break; } - switch (texObj->WrapS) + switch (texObj->Sampler.WrapS) { case GL_REPEAT: current->texture[hw_unit].hwTextureSet |= MASK_TextureWrapU; @@ -431,7 +431,7 @@ sis_set_texobj_parm( struct gl_context *ctx, struct gl_texture_object *texObj, break; } - switch (texObj->WrapT) + switch (texObj->Sampler.WrapT) { case GL_REPEAT: current->texture[hw_unit].hwTextureSet |= MASK_TextureWrapV; @@ -456,10 +456,10 @@ sis_set_texobj_parm( struct gl_context *ctx, struct gl_texture_object *texObj, { GLubyte c[4]; - CLAMPED_FLOAT_TO_UBYTE(c[0], texObj->BorderColor.f[0]); - CLAMPED_FLOAT_TO_UBYTE(c[1], texObj->BorderColor.f[1]); - CLAMPED_FLOAT_TO_UBYTE(c[2], texObj->BorderColor.f[2]); - CLAMPED_FLOAT_TO_UBYTE(c[3], texObj->BorderColor.f[3]); + CLAMPED_FLOAT_TO_UBYTE(c[0], texObj->Sampler.BorderColor.f[0]); + CLAMPED_FLOAT_TO_UBYTE(c[1], texObj->Sampler.BorderColor.f[1]); + CLAMPED_FLOAT_TO_UBYTE(c[2], texObj->Sampler.BorderColor.f[2]); + CLAMPED_FLOAT_TO_UBYTE(c[3], texObj->Sampler.BorderColor.f[3]); current->texture[hw_unit].hwTextureBorderColor = PACK_COLOR_8888(c[3], c[0], c[1], c[2]); diff --git a/src/mesa/drivers/dri/tdfx/tdfx_tex.c b/src/mesa/drivers/dri/tdfx/tdfx_tex.c index 4cca243d076..d74ddb24005 100644 --- a/src/mesa/drivers/dri/tdfx/tdfx_tex.c +++ b/src/mesa/drivers/dri/tdfx/tdfx_tex.c @@ -327,7 +327,7 @@ static void RevalidateTexture(struct gl_context *ctx, struct gl_texture_object * &(ti->sScale), &(ti->tScale), NULL, NULL); } - if (tObj->Image[0][maxl] && (tObj->MinFilter != GL_NEAREST) && (tObj->MinFilter != GL_LINEAR)) { + if (tObj->Image[0][maxl] && (tObj->Sampler.MinFilter != GL_NEAREST) && (tObj->Sampler.MinFilter != GL_LINEAR)) { /* mipmapping: need to compute smallLodLog2 */ tdfxTexGetInfo(ctx, tObj->Image[0][maxl]->Width, tObj->Image[0][maxl]->Height, @@ -1786,12 +1786,12 @@ tdfxTestProxyTexImage(struct gl_context *ctx, GLenum target, #endif if (level == 0) { /* don't use mipmap levels > 0 */ - tObj->MinFilter = tObj->MagFilter = GL_NEAREST; + tObj->Sampler.MinFilter = tObj->Sampler.MagFilter = GL_NEAREST; } else { /* test with all mipmap levels */ - tObj->MinFilter = GL_LINEAR_MIPMAP_LINEAR; - tObj->MagFilter = GL_NEAREST; + tObj->Sampler.MinFilter = GL_LINEAR_MIPMAP_LINEAR; + tObj->Sampler.MagFilter = GL_NEAREST; } RevalidateTexture(ctx, tObj); diff --git a/src/mesa/drivers/dri/unichrome/via_state.c b/src/mesa/drivers/dri/unichrome/via_state.c index 774f439bfb6..3b270e02a97 100644 --- a/src/mesa/drivers/dri/unichrome/via_state.c +++ b/src/mesa/drivers/dri/unichrome/via_state.c @@ -877,21 +877,21 @@ static GLboolean viaChooseTextureState(struct gl_context *ctx) if (texUnit0->_ReallyEnabled) { struct gl_texture_object *texObj = texUnit0->_Current; - vmesa->regHTXnTB[0] = get_minmag_filter( texObj->MinFilter, - texObj->MagFilter ); + vmesa->regHTXnTB[0] = get_minmag_filter( texObj->Sampler.MinFilter, + texObj->Sampler.MagFilter ); vmesa->regHTXnMPMD[0] &= ~(HC_HTXnMPMD_SMASK | HC_HTXnMPMD_TMASK); - vmesa->regHTXnMPMD[0] |= get_wrap_mode( texObj->WrapS, - texObj->WrapT ); + vmesa->regHTXnMPMD[0] |= get_wrap_mode( texObj->Sampler.WrapS, + texObj->Sampler.WrapT ); vmesa->regHTXnTB[0] &= ~(HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); if (texObj->Image[0][texObj->BaseLevel]->Border > 0) { vmesa->regHTXnTB[0] |= (HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); vmesa->regHTXnTBC[0] = - PACK_COLOR_888(FLOAT_TO_UBYTE(texObj->BorderColor.f[0]), - FLOAT_TO_UBYTE(texObj->BorderColor.f[1]), - FLOAT_TO_UBYTE(texObj->BorderColor.f[2])); - vmesa->regHTXnTRAH[0] = FLOAT_TO_UBYTE(texObj->BorderColor.f[3]); + PACK_COLOR_888(FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[0]), + FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[1]), + FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[2])); + vmesa->regHTXnTRAH[0] = FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[3]); } if (texUnit0->LodBias != 0.0f) { @@ -911,20 +911,20 @@ static GLboolean viaChooseTextureState(struct gl_context *ctx) if (texUnit1->_ReallyEnabled) { struct gl_texture_object *texObj = texUnit1->_Current; - vmesa->regHTXnTB[1] = get_minmag_filter( texObj->MinFilter, - texObj->MagFilter ); + vmesa->regHTXnTB[1] = get_minmag_filter( texObj->Sampler.MinFilter, + texObj->Sampler.MagFilter ); vmesa->regHTXnMPMD[1] &= ~(HC_HTXnMPMD_SMASK | HC_HTXnMPMD_TMASK); - vmesa->regHTXnMPMD[1] |= get_wrap_mode( texObj->WrapS, - texObj->WrapT ); + vmesa->regHTXnMPMD[1] |= get_wrap_mode( texObj->Sampler.WrapS, + texObj->Sampler.WrapT ); vmesa->regHTXnTB[1] &= ~(HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); if (texObj->Image[0][texObj->BaseLevel]->Border > 0) { vmesa->regHTXnTB[1] |= (HC_HTXnTB_TBC_S | HC_HTXnTB_TBC_T); vmesa->regHTXnTBC[1] = - PACK_COLOR_888(FLOAT_TO_UBYTE(texObj->BorderColor.f[0]), - FLOAT_TO_UBYTE(texObj->BorderColor.f[1]), - FLOAT_TO_UBYTE(texObj->BorderColor.f[2])); - vmesa->regHTXnTRAH[1] = FLOAT_TO_UBYTE(texObj->BorderColor.f[3]); + PACK_COLOR_888(FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[0]), + FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[1]), + FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[2])); + vmesa->regHTXnTRAH[1] = FLOAT_TO_UBYTE(texObj->Sampler.BorderColor.f[3]); } diff --git a/src/mesa/drivers/dri/unichrome/via_tex.c b/src/mesa/drivers/dri/unichrome/via_tex.c index a2fb010e142..1a0d1eaf070 100644 --- a/src/mesa/drivers/dri/unichrome/via_tex.c +++ b/src/mesa/drivers/dri/unichrome/via_tex.c @@ -495,13 +495,13 @@ static GLboolean viaSetTexImages(struct gl_context *ctx, * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL. * Yes, this looks overly complicated, but it's all needed. */ - if (texObj->MinFilter == GL_LINEAR || texObj->MinFilter == GL_NEAREST) { + if (texObj->Sampler.MinFilter == GL_LINEAR || texObj->Sampler.MinFilter == GL_NEAREST) { firstLevel = lastLevel = texObj->BaseLevel; } else { - firstLevel = texObj->BaseLevel + (GLint)(texObj->MinLod + 0.5); + firstLevel = texObj->BaseLevel + (GLint)(texObj->Sampler.MinLod + 0.5); firstLevel = MAX2(firstLevel, texObj->BaseLevel); - lastLevel = texObj->BaseLevel + (GLint)(texObj->MaxLod + 0.5); + lastLevel = texObj->BaseLevel + (GLint)(texObj->Sampler.MaxLod + 0.5); lastLevel = MAX2(lastLevel, texObj->BaseLevel); lastLevel = MIN2(lastLevel, texObj->BaseLevel + baseImage->image.MaxLog2); lastLevel = MIN2(lastLevel, texObj->MaxLevel); diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index 6a2f4870db9..57310040235 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -770,6 +770,7 @@ pop_texture_group(struct gl_context *ctx, struct texture_state *texstate) /* Restore texture object state for each target */ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { const struct gl_texture_object *obj = NULL; + const struct gl_sampler_object *samp; GLenum target; obj = &texstate->SavedObj[u][tgt]; @@ -797,26 +798,28 @@ pop_texture_group(struct gl_context *ctx, struct texture_state *texstate) _mesa_BindTexture(target, obj->Name); - _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, obj->BorderColor.f); + samp = &obj->Sampler; + + _mesa_TexParameterfv(target, GL_TEXTURE_BORDER_COLOR, samp->BorderColor.f); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, samp->WrapS); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, samp->WrapT); + _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, samp->WrapR); + _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, samp->MinFilter); + _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, samp->MagFilter); + _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, samp->MinLod); + _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, samp->MaxLod); + _mesa_TexParameterf(target, GL_TEXTURE_LOD_BIAS, samp->LodBias); _mesa_TexParameterf(target, GL_TEXTURE_PRIORITY, obj->Priority); - _mesa_TexParameteri(target, GL_TEXTURE_WRAP_S, obj->WrapS); - _mesa_TexParameteri(target, GL_TEXTURE_WRAP_T, obj->WrapT); - _mesa_TexParameteri(target, GL_TEXTURE_WRAP_R, obj->WrapR); - _mesa_TexParameteri(target, GL_TEXTURE_MIN_FILTER, obj->MinFilter); - _mesa_TexParameteri(target, GL_TEXTURE_MAG_FILTER, obj->MagFilter); - _mesa_TexParameterf(target, GL_TEXTURE_MIN_LOD, obj->MinLod); - _mesa_TexParameterf(target, GL_TEXTURE_MAX_LOD, obj->MaxLod); - _mesa_TexParameterf(target, GL_TEXTURE_LOD_BIAS, obj->LodBias); _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, obj->BaseLevel); if (target != GL_TEXTURE_RECTANGLE_ARB) _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, obj->MaxLevel); if (ctx->Extensions.EXT_texture_filter_anisotropic) { _mesa_TexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, - obj->MaxAnisotropy); + samp->MaxAnisotropy); } if (ctx->Extensions.ARB_shadow_ambient) { _mesa_TexParameterf(target, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, - obj->CompareFailValue); + samp->CompareFailValue); } } diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp index bf65a4f6485..43930a4b30e 100644 --- a/src/mesa/main/ff_fragment_shader.cpp +++ b/src/mesa/main/ff_fragment_shader.cpp @@ -439,9 +439,10 @@ static GLuint make_state_key( struct gl_context *ctx, struct state_key *key ) key->unit[i].source_index = translate_tex_src_bit(texUnit->_ReallyEnabled); - key->unit[i].shadow = ((texObj->CompareMode == GL_COMPARE_R_TO_TEXTURE) && - ((format == GL_DEPTH_COMPONENT) || - (format == GL_DEPTH_STENCIL_EXT))); + key->unit[i].shadow = + ((texObj->Sampler.CompareMode == GL_COMPARE_R_TO_TEXTURE) && + ((format == GL_DEPTH_COMPONENT) || + (format == GL_DEPTH_STENCIL_EXT))); key->unit[i].NumArgsRGB = comb->_NumArgsRGB; key->unit[i].NumArgsA = comb->_NumArgsA; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 13e4325ee45..9e2905ab2b1 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1305,37 +1305,58 @@ typedef enum /** - * Texture object state. Contains the array of mipmap images, border color, - * wrap modes, filter modes, shadow/texcompare state, and the per-texture - * color palette. + * Sampler object state. These objects are new with GL_ARB_sampler_objects + * and OpenGL 3.3. Legacy texture objects also contain a sampler object. */ -struct gl_texture_object +struct gl_sampler_object { - _glthread_Mutex Mutex; /**< for thread safety */ - GLint RefCount; /**< reference count */ - GLuint Name; /**< the user-visible texture object ID */ - GLenum Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */ - GLfloat Priority; /**< in [0,1] */ - union { - GLfloat f[4]; - GLuint ui[4]; - GLint i[4]; - } BorderColor; /**< Interpreted according to texture format */ + GLuint Name; + GLint RefCount; + GLenum WrapS; /**< S-axis texture image wrap mode */ GLenum WrapT; /**< T-axis texture image wrap mode */ GLenum WrapR; /**< R-axis texture image wrap mode */ GLenum MinFilter; /**< minification filter */ GLenum MagFilter; /**< magnification filter */ + union { + GLfloat f[4]; + GLuint ui[4]; + GLint i[4]; + } BorderColor; /**< Interpreted according to texture format */ GLfloat MinLod; /**< min lambda, OpenGL 1.2 */ GLfloat MaxLod; /**< max lambda, OpenGL 1.2 */ GLfloat LodBias; /**< OpenGL 1.4 */ - GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */ - GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */ GLfloat MaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */ GLenum CompareMode; /**< GL_ARB_shadow */ GLenum CompareFunc; /**< GL_ARB_shadow */ GLfloat CompareFailValue; /**< GL_ARB_shadow_ambient */ + GLenum sRGBDecode; /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */ + + /* deprecated sampler state */ GLenum DepthMode; /**< GL_ARB_depth_texture */ + + /** Is the texture object complete with respect to this sampler? */ + GLboolean _CompleteTexture; +}; + + +/** + * Texture object state. Contains the array of mipmap images, border color, + * wrap modes, filter modes, shadow/texcompare state, and the per-texture + * color palette. + */ +struct gl_texture_object +{ + _glthread_Mutex Mutex; /**< for thread safety */ + GLint RefCount; /**< reference count */ + GLuint Name; /**< the user-visible texture object ID */ + GLenum Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */ + + struct gl_sampler_object Sampler; + + GLfloat Priority; /**< in [0,1] */ + GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */ + GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */ GLint _MaxLevel; /**< actual max mipmap level (q in the spec) */ GLfloat _MaxLambda; /**< = _MaxLevel - BaseLevel (q - b in spec) */ GLint CropRect[4]; /**< GL_OES_draw_texture */ @@ -1345,7 +1366,6 @@ struct gl_texture_object GLboolean _Complete; /**< Is texture object complete? */ GLboolean _RenderToTexture; /**< Any rendering to this texture? */ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */ - GLenum sRGBDecode; /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */ /** Actual texture images, indexed by [cube face] and [mipmap level] */ struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS]; @@ -1429,6 +1449,9 @@ struct gl_texture_unit GLenum BumpTarget; GLfloat RotMatrix[4]; /* 2x2 matrix */ + /** Current sampler object (GL_ARB_sampler_objects) */ + struct gl_sampler_object *Sampler; + /** * \name GL_EXT_texture_env_combine */ @@ -2363,6 +2386,9 @@ struct gl_shared_state /* GL_ARB_sync */ struct simple_node SyncObjects; + /** GL_ARB_sampler_objects */ + struct _mesa_HashTable *SamplerObjects; + void *DriverData; /**< Device driver shared state */ }; diff --git a/src/mesa/main/texfetch.c b/src/mesa/main/texfetch.c index b2181af2931..caabc19bb17 100644 --- a/src/mesa/main/texfetch.c +++ b/src/mesa/main/texfetch.c @@ -975,7 +975,7 @@ _mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims) ASSERT(dims == 1 || dims == 2 || dims == 3); - if (texImage->TexObject->sRGBDecode == GL_SKIP_DECODE_EXT && + if (texImage->TexObject->Sampler.sRGBDecode == GL_SKIP_DECODE_EXT && _mesa_get_format_color_encoding(format) == GL_SRGB) { format = _mesa_get_srgb_format_linear(format); } diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index 61b9bc70d77..43d6e52dfe9 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -116,35 +116,37 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj, obj->Name = name; obj->Target = target; obj->Priority = 1.0F; + obj->BaseLevel = 0; + obj->MaxLevel = 1000; + + /* sampler state */ if (target == GL_TEXTURE_RECTANGLE_NV) { - obj->WrapS = GL_CLAMP_TO_EDGE; - obj->WrapT = GL_CLAMP_TO_EDGE; - obj->WrapR = GL_CLAMP_TO_EDGE; - obj->MinFilter = GL_LINEAR; + obj->Sampler.WrapS = GL_CLAMP_TO_EDGE; + obj->Sampler.WrapT = GL_CLAMP_TO_EDGE; + obj->Sampler.WrapR = GL_CLAMP_TO_EDGE; + obj->Sampler.MinFilter = GL_LINEAR; } else { - obj->WrapS = GL_REPEAT; - obj->WrapT = GL_REPEAT; - obj->WrapR = GL_REPEAT; - obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR; + obj->Sampler.WrapS = GL_REPEAT; + obj->Sampler.WrapT = GL_REPEAT; + obj->Sampler.WrapR = GL_REPEAT; + obj->Sampler.MinFilter = GL_NEAREST_MIPMAP_LINEAR; } - obj->MagFilter = GL_LINEAR; - obj->MinLod = -1000.0; - obj->MaxLod = 1000.0; - obj->LodBias = 0.0; - obj->BaseLevel = 0; - obj->MaxLevel = 1000; - obj->MaxAnisotropy = 1.0; - obj->CompareMode = GL_NONE; /* ARB_shadow */ - obj->CompareFunc = GL_LEQUAL; /* ARB_shadow */ - obj->CompareFailValue = 0.0F; /* ARB_shadow_ambient */ - obj->DepthMode = GL_LUMINANCE; /* ARB_depth_texture */ + obj->Sampler.MagFilter = GL_LINEAR; + obj->Sampler.MinLod = -1000.0; + obj->Sampler.MaxLod = 1000.0; + obj->Sampler.LodBias = 0.0; + obj->Sampler.MaxAnisotropy = 1.0; + obj->Sampler.CompareMode = GL_NONE; /* ARB_shadow */ + obj->Sampler.CompareFunc = GL_LEQUAL; /* ARB_shadow */ + obj->Sampler.CompareFailValue = 0.0F; /* ARB_shadow_ambient */ + obj->Sampler.DepthMode = GL_LUMINANCE; /* ARB_depth_texture */ obj->Swizzle[0] = GL_RED; obj->Swizzle[1] = GL_GREEN; obj->Swizzle[2] = GL_BLUE; obj->Swizzle[3] = GL_ALPHA; obj->_Swizzle = SWIZZLE_NOOP; - obj->sRGBDecode = GL_DECODE_EXT; + obj->Sampler.sRGBDecode = GL_DECODE_EXT; } @@ -160,10 +162,10 @@ finish_texture_init(struct gl_context *ctx, GLenum target, if (target == GL_TEXTURE_RECTANGLE_NV) { /* have to init wrap and filter state here - kind of klunky */ - obj->WrapS = GL_CLAMP_TO_EDGE; - obj->WrapT = GL_CLAMP_TO_EDGE; - obj->WrapR = GL_CLAMP_TO_EDGE; - obj->MinFilter = GL_LINEAR; + obj->Sampler.WrapS = GL_CLAMP_TO_EDGE; + obj->Sampler.WrapT = GL_CLAMP_TO_EDGE; + obj->Sampler.WrapR = GL_CLAMP_TO_EDGE; + obj->Sampler.MinFilter = GL_LINEAR; if (ctx->Driver.TexParameter) { static const GLfloat fparam_wrap[1] = {(GLfloat) GL_CLAMP_TO_EDGE}; static const GLfloat fparam_filter[1] = {(GLfloat) GL_LINEAR}; @@ -231,25 +233,25 @@ _mesa_copy_texture_object( struct gl_texture_object *dest, dest->Target = src->Target; dest->Name = src->Name; dest->Priority = src->Priority; - dest->BorderColor.f[0] = src->BorderColor.f[0]; - dest->BorderColor.f[1] = src->BorderColor.f[1]; - dest->BorderColor.f[2] = src->BorderColor.f[2]; - dest->BorderColor.f[3] = src->BorderColor.f[3]; - dest->WrapS = src->WrapS; - dest->WrapT = src->WrapT; - dest->WrapR = src->WrapR; - dest->MinFilter = src->MinFilter; - dest->MagFilter = src->MagFilter; - dest->MinLod = src->MinLod; - dest->MaxLod = src->MaxLod; - dest->LodBias = src->LodBias; + dest->Sampler.BorderColor.f[0] = src->Sampler.BorderColor.f[0]; + dest->Sampler.BorderColor.f[1] = src->Sampler.BorderColor.f[1]; + dest->Sampler.BorderColor.f[2] = src->Sampler.BorderColor.f[2]; + dest->Sampler.BorderColor.f[3] = src->Sampler.BorderColor.f[3]; + dest->Sampler.WrapS = src->Sampler.WrapS; + dest->Sampler.WrapT = src->Sampler.WrapT; + dest->Sampler.WrapR = src->Sampler.WrapR; + dest->Sampler.MinFilter = src->Sampler.MinFilter; + dest->Sampler.MagFilter = src->Sampler.MagFilter; + dest->Sampler.MinLod = src->Sampler.MinLod; + dest->Sampler.MaxLod = src->Sampler.MaxLod; + dest->Sampler.LodBias = src->Sampler.LodBias; dest->BaseLevel = src->BaseLevel; dest->MaxLevel = src->MaxLevel; - dest->MaxAnisotropy = src->MaxAnisotropy; - dest->CompareMode = src->CompareMode; - dest->CompareFunc = src->CompareFunc; - dest->CompareFailValue = src->CompareFailValue; - dest->DepthMode = src->DepthMode; + dest->Sampler.MaxAnisotropy = src->Sampler.MaxAnisotropy; + dest->Sampler.CompareMode = src->Sampler.CompareMode; + dest->Sampler.CompareFunc = src->Sampler.CompareFunc; + dest->Sampler.CompareFailValue = src->Sampler.CompareFailValue; + dest->Sampler.DepthMode = src->Sampler.DepthMode; dest->_MaxLevel = src->_MaxLevel; dest->_MaxLambda = src->_MaxLambda; dest->GenerateMipmap = src->GenerateMipmap; @@ -506,7 +508,7 @@ _mesa_test_texobj_completeness( const struct gl_context *ctx, } /* extra checking for mipmaps */ - if (t->MinFilter != GL_NEAREST && t->MinFilter != GL_LINEAR) { + if (t->Sampler.MinFilter != GL_NEAREST && t->Sampler.MinFilter != GL_LINEAR) { /* * Mipmapping: determine if we have a complete set of mipmaps */ @@ -761,8 +763,8 @@ _mesa_get_fallback_texture(struct gl_context *ctx) /* create texture object */ texObj = ctx->Driver.NewTextureObject(ctx, 0, GL_TEXTURE_2D); assert(texObj->RefCount == 1); - texObj->MinFilter = GL_NEAREST; - texObj->MagFilter = GL_NEAREST; + texObj->Sampler.MinFilter = GL_NEAREST; + texObj->Sampler.MagFilter = GL_NEAREST; /* create level[0] texture image */ texImage = _mesa_get_tex_image(ctx, texObj, GL_TEXTURE_2D, 0); diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index 34b6addb9b0..3d56dac3f91 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -216,13 +216,13 @@ set_tex_parameteri(struct gl_context *ctx, { switch (pname) { case GL_TEXTURE_MIN_FILTER: - if (texObj->MinFilter == params[0]) + if (texObj->Sampler.MinFilter == params[0]) return GL_FALSE; switch (params[0]) { case GL_NEAREST: case GL_LINEAR: incomplete(ctx, texObj); - texObj->MinFilter = params[0]; + texObj->Sampler.MinFilter = params[0]; return GL_TRUE; case GL_NEAREST_MIPMAP_NEAREST: case GL_LINEAR_MIPMAP_NEAREST: @@ -230,7 +230,7 @@ set_tex_parameteri(struct gl_context *ctx, case GL_LINEAR_MIPMAP_LINEAR: if (texObj->Target != GL_TEXTURE_RECTANGLE_NV) { incomplete(ctx, texObj); - texObj->MinFilter = params[0]; + texObj->Sampler.MinFilter = params[0]; return GL_TRUE; } /* fall-through */ @@ -240,13 +240,13 @@ set_tex_parameteri(struct gl_context *ctx, return GL_FALSE; case GL_TEXTURE_MAG_FILTER: - if (texObj->MagFilter == params[0]) + if (texObj->Sampler.MagFilter == params[0]) return GL_FALSE; switch (params[0]) { case GL_NEAREST: case GL_LINEAR: flush(ctx); /* does not effect completeness */ - texObj->MagFilter = params[0]; + texObj->Sampler.MagFilter = params[0]; return GL_TRUE; default: goto invalid_param; @@ -254,31 +254,31 @@ set_tex_parameteri(struct gl_context *ctx, return GL_FALSE; case GL_TEXTURE_WRAP_S: - if (texObj->WrapS == params[0]) + if (texObj->Sampler.WrapS == params[0]) return GL_FALSE; if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) { flush(ctx); - texObj->WrapS = params[0]; + texObj->Sampler.WrapS = params[0]; return GL_TRUE; } return GL_FALSE; case GL_TEXTURE_WRAP_T: - if (texObj->WrapT == params[0]) + if (texObj->Sampler.WrapT == params[0]) return GL_FALSE; if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) { flush(ctx); - texObj->WrapT = params[0]; + texObj->Sampler.WrapT = params[0]; return GL_TRUE; } return GL_FALSE; case GL_TEXTURE_WRAP_R: - if (texObj->WrapR == params[0]) + if (texObj->Sampler.WrapR == params[0]) return GL_FALSE; if (validate_texture_wrap_mode(ctx, texObj->Target, params[0])) { flush(ctx); - texObj->WrapR = params[0]; + texObj->Sampler.WrapR = params[0]; return GL_TRUE; } return GL_FALSE; @@ -318,12 +318,12 @@ set_tex_parameteri(struct gl_context *ctx, case GL_TEXTURE_COMPARE_MODE_ARB: if (ctx->Extensions.ARB_shadow) { - if (texObj->CompareMode == params[0]) + if (texObj->Sampler.CompareMode == params[0]) return GL_FALSE; if (params[0] == GL_NONE || params[0] == GL_COMPARE_R_TO_TEXTURE_ARB) { flush(ctx); - texObj->CompareMode = params[0]; + texObj->Sampler.CompareMode = params[0]; return GL_TRUE; } goto invalid_param; @@ -332,13 +332,13 @@ set_tex_parameteri(struct gl_context *ctx, case GL_TEXTURE_COMPARE_FUNC_ARB: if (ctx->Extensions.ARB_shadow) { - if (texObj->CompareFunc == params[0]) + if (texObj->Sampler.CompareFunc == params[0]) return GL_FALSE; switch (params[0]) { case GL_LEQUAL: case GL_GEQUAL: flush(ctx); - texObj->CompareFunc = params[0]; + texObj->Sampler.CompareFunc = params[0]; return GL_TRUE; case GL_EQUAL: case GL_NOTEQUAL: @@ -348,7 +348,7 @@ set_tex_parameteri(struct gl_context *ctx, case GL_NEVER: if (ctx->Extensions.EXT_shadow_funcs) { flush(ctx); - texObj->CompareFunc = params[0]; + texObj->Sampler.CompareFunc = params[0]; return GL_TRUE; } /* fall-through */ @@ -360,14 +360,14 @@ set_tex_parameteri(struct gl_context *ctx, case GL_DEPTH_TEXTURE_MODE_ARB: if (ctx->Extensions.ARB_depth_texture) { - if (texObj->DepthMode == params[0]) + if (texObj->Sampler.DepthMode == params[0]) return GL_FALSE; if (params[0] == GL_LUMINANCE || params[0] == GL_INTENSITY || params[0] == GL_ALPHA || (ctx->Extensions.ARB_texture_rg && params[0] == GL_RED)) { flush(ctx); - texObj->DepthMode = params[0]; + texObj->Sampler.DepthMode = params[0]; return GL_TRUE; } goto invalid_param; @@ -429,9 +429,9 @@ set_tex_parameteri(struct gl_context *ctx, if (ctx->Extensions.EXT_texture_sRGB_decode) { GLenum decode = params[0]; if (decode == GL_DECODE_EXT || decode == GL_SKIP_DECODE_EXT) { - if (texObj->sRGBDecode != decode) { + if (texObj->Sampler.sRGBDecode != decode) { flush(ctx); - texObj->sRGBDecode = decode; + texObj->Sampler.sRGBDecode = decode; _mesa_update_fetch_functions(texObj); } return GL_TRUE; @@ -466,17 +466,17 @@ set_tex_parameterf(struct gl_context *ctx, { switch (pname) { case GL_TEXTURE_MIN_LOD: - if (texObj->MinLod == params[0]) + if (texObj->Sampler.MinLod == params[0]) return GL_FALSE; flush(ctx); - texObj->MinLod = params[0]; + texObj->Sampler.MinLod = params[0]; return GL_TRUE; case GL_TEXTURE_MAX_LOD: - if (texObj->MaxLod == params[0]) + if (texObj->Sampler.MaxLod == params[0]) return GL_FALSE; flush(ctx); - texObj->MaxLod = params[0]; + texObj->Sampler.MaxLod = params[0]; return GL_TRUE; case GL_TEXTURE_PRIORITY: @@ -486,7 +486,7 @@ set_tex_parameterf(struct gl_context *ctx, case GL_TEXTURE_MAX_ANISOTROPY_EXT: if (ctx->Extensions.EXT_texture_filter_anisotropic) { - if (texObj->MaxAnisotropy == params[0]) + if (texObj->Sampler.MaxAnisotropy == params[0]) return GL_FALSE; if (params[0] < 1.0) { _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" ); @@ -494,7 +494,7 @@ set_tex_parameterf(struct gl_context *ctx, } flush(ctx); /* clamp to max, that's what NVIDIA does */ - texObj->MaxAnisotropy = MIN2(params[0], + texObj->Sampler.MaxAnisotropy = MIN2(params[0], ctx->Const.MaxTextureMaxAnisotropy); return GL_TRUE; } @@ -508,9 +508,9 @@ set_tex_parameterf(struct gl_context *ctx, case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB: if (ctx->Extensions.ARB_shadow_ambient) { - if (texObj->CompareFailValue != params[0]) { + if (texObj->Sampler.CompareFailValue != params[0]) { flush(ctx); - texObj->CompareFailValue = CLAMP(params[0], 0.0F, 1.0F); + texObj->Sampler.CompareFailValue = CLAMP(params[0], 0.0F, 1.0F); return GL_TRUE; } } @@ -523,9 +523,9 @@ set_tex_parameterf(struct gl_context *ctx, case GL_TEXTURE_LOD_BIAS: /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias */ if (ctx->Extensions.EXT_texture_lod_bias) { - if (texObj->LodBias != params[0]) { + if (texObj->Sampler.LodBias != params[0]) { flush(ctx); - texObj->LodBias = params[0]; + texObj->Sampler.LodBias = params[0]; return GL_TRUE; } return GL_FALSE; @@ -536,15 +536,15 @@ set_tex_parameterf(struct gl_context *ctx, flush(ctx); /* ARB_texture_float disables clamping */ if (ctx->Extensions.ARB_texture_float) { - texObj->BorderColor.f[RCOMP] = params[0]; - texObj->BorderColor.f[GCOMP] = params[1]; - texObj->BorderColor.f[BCOMP] = params[2]; - texObj->BorderColor.f[ACOMP] = params[3]; + texObj->Sampler.BorderColor.f[RCOMP] = params[0]; + texObj->Sampler.BorderColor.f[GCOMP] = params[1]; + texObj->Sampler.BorderColor.f[BCOMP] = params[2]; + texObj->Sampler.BorderColor.f[ACOMP] = params[3]; } else { - texObj->BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F); - texObj->BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F); - texObj->BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F); - texObj->BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F); + texObj->Sampler.BorderColor.f[RCOMP] = CLAMP(params[0], 0.0F, 1.0F); + texObj->Sampler.BorderColor.f[GCOMP] = CLAMP(params[1], 0.0F, 1.0F); + texObj->Sampler.BorderColor.f[BCOMP] = CLAMP(params[2], 0.0F, 1.0F); + texObj->Sampler.BorderColor.f[ACOMP] = CLAMP(params[3], 0.0F, 1.0F); } return GL_TRUE; @@ -784,7 +784,7 @@ _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params) case GL_TEXTURE_BORDER_COLOR: FLUSH_VERTICES(ctx, _NEW_TEXTURE); /* set the integer-valued border color */ - COPY_4V(texObj->BorderColor.i, params); + COPY_4V(texObj->Sampler.BorderColor.i, params); break; default: _mesa_TexParameteriv(target, pname, params); @@ -814,7 +814,7 @@ _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params) case GL_TEXTURE_BORDER_COLOR: FLUSH_VERTICES(ctx, _NEW_TEXTURE); /* set the unsigned integer-valued border color */ - COPY_4V(texObj->BorderColor.ui, params); + COPY_4V(texObj->Sampler.BorderColor.ui, params); break; default: _mesa_TexParameteriv(target, pname, (const GLint *) params); @@ -1101,36 +1101,36 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params ) _mesa_lock_texture(ctx, obj); switch (pname) { case GL_TEXTURE_MAG_FILTER: - *params = ENUM_TO_FLOAT(obj->MagFilter); + *params = ENUM_TO_FLOAT(obj->Sampler.MagFilter); break; case GL_TEXTURE_MIN_FILTER: - *params = ENUM_TO_FLOAT(obj->MinFilter); + *params = ENUM_TO_FLOAT(obj->Sampler.MinFilter); break; case GL_TEXTURE_WRAP_S: - *params = ENUM_TO_FLOAT(obj->WrapS); + *params = ENUM_TO_FLOAT(obj->Sampler.WrapS); break; case GL_TEXTURE_WRAP_T: - *params = ENUM_TO_FLOAT(obj->WrapT); + *params = ENUM_TO_FLOAT(obj->Sampler.WrapT); break; case GL_TEXTURE_WRAP_R: - *params = ENUM_TO_FLOAT(obj->WrapR); + *params = ENUM_TO_FLOAT(obj->Sampler.WrapR); break; case GL_TEXTURE_BORDER_COLOR: if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP)) _mesa_update_state_locked(ctx); if(ctx->Color._ClampFragmentColor) { - params[0] = CLAMP(obj->BorderColor.f[0], 0.0F, 1.0F); - params[1] = CLAMP(obj->BorderColor.f[1], 0.0F, 1.0F); - params[2] = CLAMP(obj->BorderColor.f[2], 0.0F, 1.0F); - params[3] = CLAMP(obj->BorderColor.f[3], 0.0F, 1.0F); + params[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F); + params[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F); + params[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F); + params[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F); } else { - params[0] = obj->BorderColor.f[0]; - params[1] = obj->BorderColor.f[1]; - params[2] = obj->BorderColor.f[2]; - params[3] = obj->BorderColor.f[3]; + params[0] = obj->Sampler.BorderColor.f[0]; + params[1] = obj->Sampler.BorderColor.f[1]; + params[2] = obj->Sampler.BorderColor.f[2]; + params[3] = obj->Sampler.BorderColor.f[3]; } break; case GL_TEXTURE_RESIDENT: @@ -1147,10 +1147,10 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params ) *params = obj->Priority; break; case GL_TEXTURE_MIN_LOD: - *params = obj->MinLod; + *params = obj->Sampler.MinLod; break; case GL_TEXTURE_MAX_LOD: - *params = obj->MaxLod; + *params = obj->Sampler.MaxLod; break; case GL_TEXTURE_BASE_LEVEL: *params = (GLfloat) obj->BaseLevel; @@ -1160,14 +1160,14 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params ) break; case GL_TEXTURE_MAX_ANISOTROPY_EXT: if (ctx->Extensions.EXT_texture_filter_anisotropic) { - *params = obj->MaxAnisotropy; + *params = obj->Sampler.MaxAnisotropy; } else error = GL_TRUE; break; case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB: if (ctx->Extensions.ARB_shadow_ambient) { - *params = obj->CompareFailValue; + *params = obj->Sampler.CompareFailValue; } else error = GL_TRUE; @@ -1177,28 +1177,28 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params ) break; case GL_TEXTURE_COMPARE_MODE_ARB: if (ctx->Extensions.ARB_shadow) { - *params = (GLfloat) obj->CompareMode; + *params = (GLfloat) obj->Sampler.CompareMode; } else error = GL_TRUE; break; case GL_TEXTURE_COMPARE_FUNC_ARB: if (ctx->Extensions.ARB_shadow) { - *params = (GLfloat) obj->CompareFunc; + *params = (GLfloat) obj->Sampler.CompareFunc; } else error = GL_TRUE; break; case GL_DEPTH_TEXTURE_MODE_ARB: if (ctx->Extensions.ARB_depth_texture) { - *params = (GLfloat) obj->DepthMode; + *params = (GLfloat) obj->Sampler.DepthMode; } else error = GL_TRUE; break; case GL_TEXTURE_LOD_BIAS: if (ctx->Extensions.EXT_texture_lod_bias) { - *params = obj->LodBias; + *params = obj->Sampler.LodBias; } else error = GL_TRUE; @@ -1265,27 +1265,27 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) _mesa_lock_texture(ctx, obj); switch (pname) { case GL_TEXTURE_MAG_FILTER: - *params = (GLint) obj->MagFilter; + *params = (GLint) obj->Sampler.MagFilter; break;; case GL_TEXTURE_MIN_FILTER: - *params = (GLint) obj->MinFilter; + *params = (GLint) obj->Sampler.MinFilter; break;; case GL_TEXTURE_WRAP_S: - *params = (GLint) obj->WrapS; + *params = (GLint) obj->Sampler.WrapS; break;; case GL_TEXTURE_WRAP_T: - *params = (GLint) obj->WrapT; + *params = (GLint) obj->Sampler.WrapT; break;; case GL_TEXTURE_WRAP_R: - *params = (GLint) obj->WrapR; + *params = (GLint) obj->Sampler.WrapR; break;; case GL_TEXTURE_BORDER_COLOR: { GLfloat b[4]; - b[0] = CLAMP(obj->BorderColor.f[0], 0.0F, 1.0F); - b[1] = CLAMP(obj->BorderColor.f[1], 0.0F, 1.0F); - b[2] = CLAMP(obj->BorderColor.f[2], 0.0F, 1.0F); - b[3] = CLAMP(obj->BorderColor.f[3], 0.0F, 1.0F); + b[0] = CLAMP(obj->Sampler.BorderColor.f[0], 0.0F, 1.0F); + b[1] = CLAMP(obj->Sampler.BorderColor.f[1], 0.0F, 1.0F); + b[2] = CLAMP(obj->Sampler.BorderColor.f[2], 0.0F, 1.0F); + b[3] = CLAMP(obj->Sampler.BorderColor.f[3], 0.0F, 1.0F); params[0] = FLOAT_TO_INT(b[0]); params[1] = FLOAT_TO_INT(b[1]); params[2] = FLOAT_TO_INT(b[2]); @@ -1306,10 +1306,10 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) *params = FLOAT_TO_INT(obj->Priority); break;; case GL_TEXTURE_MIN_LOD: - *params = (GLint) obj->MinLod; + *params = (GLint) obj->Sampler.MinLod; break;; case GL_TEXTURE_MAX_LOD: - *params = (GLint) obj->MaxLod; + *params = (GLint) obj->Sampler.MaxLod; break;; case GL_TEXTURE_BASE_LEVEL: *params = obj->BaseLevel; @@ -1319,7 +1319,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) break;; case GL_TEXTURE_MAX_ANISOTROPY_EXT: if (ctx->Extensions.EXT_texture_filter_anisotropic) { - *params = (GLint) obj->MaxAnisotropy; + *params = (GLint) obj->Sampler.MaxAnisotropy; } else { error = GL_TRUE; @@ -1327,7 +1327,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) break; case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB: if (ctx->Extensions.ARB_shadow_ambient) { - *params = (GLint) FLOAT_TO_INT(obj->CompareFailValue); + *params = (GLint) FLOAT_TO_INT(obj->Sampler.CompareFailValue); } else { error = GL_TRUE; @@ -1338,7 +1338,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) break; case GL_TEXTURE_COMPARE_MODE_ARB: if (ctx->Extensions.ARB_shadow) { - *params = (GLint) obj->CompareMode; + *params = (GLint) obj->Sampler.CompareMode; } else { error = GL_TRUE; @@ -1346,7 +1346,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) break; case GL_TEXTURE_COMPARE_FUNC_ARB: if (ctx->Extensions.ARB_shadow) { - *params = (GLint) obj->CompareFunc; + *params = (GLint) obj->Sampler.CompareFunc; } else { error = GL_TRUE; @@ -1354,7 +1354,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) break; case GL_DEPTH_TEXTURE_MODE_ARB: if (ctx->Extensions.ARB_depth_texture) { - *params = (GLint) obj->DepthMode; + *params = (GLint) obj->Sampler.DepthMode; } else { error = GL_TRUE; @@ -1362,7 +1362,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params ) break; case GL_TEXTURE_LOD_BIAS: if (ctx->Extensions.EXT_texture_lod_bias) { - *params = (GLint) obj->LodBias; + *params = (GLint) obj->Sampler.LodBias; } else { error = GL_TRUE; @@ -1422,7 +1422,7 @@ _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params) switch (pname) { case GL_TEXTURE_BORDER_COLOR: - COPY_4V(params, texObj->BorderColor.i); + COPY_4V(params, texObj->Sampler.BorderColor.i); break; default: _mesa_GetTexParameteriv(target, pname, params); @@ -1442,7 +1442,7 @@ _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params) switch (pname) { case GL_TEXTURE_BORDER_COLOR: - COPY_4V(params, texObj->BorderColor.i); + COPY_4V(params, texObj->Sampler.BorderColor.i); break; default: { diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index 82e69ae11b5..1810b88b2bf 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -407,7 +407,7 @@ update_tex_combine(struct gl_context *ctx, struct gl_texture_unit *texUnit) } else if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL_EXT) { - format = texObj->DepthMode; + format = texObj->Sampler.DepthMode; } calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format); texUnit->_CurrentCombine = & texUnit->_EnvMode; @@ -827,6 +827,12 @@ _mesa_free_texture_data(struct gl_context *ctx) /* GL_ARB_texture_buffer_object */ _mesa_reference_buffer_object(ctx, &ctx->Texture.BufferObject, NULL); + +#if FEATURE_sampler_objects + for (u = 0; u < Elements(ctx->Texture.Unit); u++) { + _mesa_reference_sampler_object(ctx, &ctx->Texture.Unit[u].Sampler, NULL); + } +#endif } diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index 384aa2cb2c6..1fd26f44d56 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -582,7 +582,7 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[], value[0] = value[1] = value[2] = - value[3] = texObj->CompareFailValue; + value[3] = texObj->Sampler.CompareFailValue; } } return; diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 19d41e7061a..808aa73a083 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -38,6 +38,7 @@ #include "st_cb_texture.h" #include "st_format.h" #include "st_atom.h" +#include "st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -138,6 +139,7 @@ update_samplers(struct st_context *st) if (samplersUsed & (1 << su)) { struct gl_texture_object *texobj; struct gl_texture_image *teximg; + struct gl_sampler_object *msamp; GLuint texUnit; if (fprog->Base.SamplersUsed & (1 << su)) @@ -152,25 +154,27 @@ update_samplers(struct st_context *st) teximg = texobj->Image[0][texobj->BaseLevel]; - sampler->wrap_s = gl_wrap_xlate(texobj->WrapS); - sampler->wrap_t = gl_wrap_xlate(texobj->WrapT); - sampler->wrap_r = gl_wrap_xlate(texobj->WrapR); + msamp = st_get_mesa_sampler(st->ctx, texUnit); - sampler->min_img_filter = gl_filter_to_img_filter(texobj->MinFilter); - sampler->min_mip_filter = gl_filter_to_mip_filter(texobj->MinFilter); - sampler->mag_img_filter = gl_filter_to_img_filter(texobj->MagFilter); + sampler->wrap_s = gl_wrap_xlate(msamp->WrapS); + sampler->wrap_t = gl_wrap_xlate(msamp->WrapT); + sampler->wrap_r = gl_wrap_xlate(msamp->WrapR); + + sampler->min_img_filter = gl_filter_to_img_filter(msamp->MinFilter); + sampler->min_mip_filter = gl_filter_to_mip_filter(msamp->MinFilter); + sampler->mag_img_filter = gl_filter_to_img_filter(msamp->MagFilter); if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB) sampler->normalized_coords = 1; sampler->lod_bias = st->ctx->Texture.Unit[texUnit].LodBias + - texobj->LodBias; + msamp->LodBias; - sampler->min_lod = CLAMP(texobj->MinLod, + sampler->min_lod = CLAMP(msamp->MinLod, 0.0f, (GLfloat) texobj->MaxLevel - texobj->BaseLevel); sampler->max_lod = MIN2((GLfloat) texobj->MaxLevel - texobj->BaseLevel, - texobj->MaxLod); + msamp->MaxLod); if (sampler->max_lod < sampler->min_lod) { /* The GL spec doesn't seem to specify what to do in this case. * Swap the values. @@ -181,17 +185,18 @@ update_samplers(struct st_context *st) assert(sampler->min_lod <= sampler->max_lod); } - st_translate_color(texobj->BorderColor.f, + st_translate_color(msamp->BorderColor.f, teximg ? teximg->_BaseFormat : GL_RGBA, sampler->border_color); - sampler->max_anisotropy = (texobj->MaxAnisotropy == 1.0 ? 0 : (GLuint)texobj->MaxAnisotropy); + sampler->max_anisotropy = (msamp->MaxAnisotropy == 1.0 ? + 0 : (GLuint) msamp->MaxAnisotropy); /* only care about ARB_shadow, not SGI shadow */ - if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) { + if (msamp->CompareMode == GL_COMPARE_R_TO_TEXTURE) { sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; sampler->compare_func - = st_compare_func_to_pipe(texobj->CompareFunc); + = st_compare_func_to_pipe(msamp->CompareFunc); } st->state.num_samplers = su + 1; diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 6b9f969ac00..e5fb8f86878 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -138,12 +138,13 @@ check_sampler_swizzle(struct pipe_sampler_view *sv, static INLINE struct pipe_sampler_view * st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe, struct st_texture_object *stObj, + const struct gl_sampler_object *samp, enum pipe_format format) { struct pipe_sampler_view templ; GLuint swizzle = apply_depthmode(stObj->pt->format, stObj->base._Swizzle, - stObj->base.DepthMode); + samp->DepthMode); u_sampler_view_default_template(&templ, stObj->pt, @@ -164,6 +165,7 @@ st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe, static INLINE struct pipe_sampler_view * st_get_texture_sampler_view_from_stobj(struct st_texture_object *stObj, struct pipe_context *pipe, + const struct gl_sampler_object *samp, enum pipe_format format) { if (!stObj || !stObj->pt) { @@ -172,7 +174,7 @@ st_get_texture_sampler_view_from_stobj(struct st_texture_object *stObj, if (!stObj->sampler_view) { stObj->sampler_view = - st_create_texture_sampler_view_from_stobj(pipe, stObj, format); + st_create_texture_sampler_view_from_stobj(pipe, stObj, samp, format); } return stObj->sampler_view; @@ -200,16 +202,20 @@ update_textures(struct st_context *st) struct st_texture_object *stObj; GLboolean retval; GLuint texUnit; + const struct gl_sampler_object *samp; if (fprog->Base.SamplersUsed & (1 << su)) texUnit = fprog->Base.SamplerUnits[su]; else texUnit = vprog->Base.SamplerUnits[su]; + samp = st_get_mesa_sampler(st->ctx, texUnit); + texObj = st->ctx->Texture.Unit[texUnit]._Current; if (!texObj) { texObj = st_get_default_texture(st); + samp = &texObj->Sampler; } stObj = st_texture_object(texObj); @@ -228,7 +234,7 @@ update_textures(struct st_context *st) enum pipe_format firstImageFormat = st_mesa_format_to_pipe_format(texFormat); - if ((stObj->base.sRGBDecode == GL_SKIP_DECODE_EXT) && + if ((samp->sRGBDecode == GL_SKIP_DECODE_EXT) && (_mesa_get_format_color_encoding(texFormat) == GL_SRGB)) { /* don't do sRGB->RGB conversion. Interpret the texture * texture data as linear values. @@ -248,12 +254,14 @@ update_textures(struct st_context *st) if (stObj->sampler_view) if (check_sampler_swizzle(stObj->sampler_view, stObj->base._Swizzle, - stObj->base.DepthMode) || + samp->DepthMode) || (st_view_format != stObj->sampler_view->format) || stObj->base.BaseLevel != stObj->sampler_view->u.tex.first_level) pipe_sampler_view_reference(&stObj->sampler_view, NULL); - sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe, st_view_format); + sampler_view = st_get_texture_sampler_view_from_stobj(stObj, pipe, + samp, + st_view_format); } pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 302f2e1fa17..914c06b7023 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -362,8 +362,8 @@ guess_and_alloc_texture(struct st_context *st, * to re-allocating a texture buffer with space for more (or fewer) * mipmap levels later. */ - if ((stObj->base.MinFilter == GL_NEAREST || - stObj->base.MinFilter == GL_LINEAR || + if ((stObj->base.Sampler.MinFilter == GL_NEAREST || + stObj->base.Sampler.MinFilter == GL_LINEAR || stImage->base._BaseFormat == GL_DEPTH_COMPONENT || stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) && !stObj->base.GenerateMipmap && @@ -1742,8 +1742,8 @@ st_finalize_texture(struct gl_context *ctx, * incomplete. In that case, we'll have set stObj->lastLevel before * we get here. */ - if (stObj->base.MinFilter == GL_LINEAR || - stObj->base.MinFilter == GL_NEAREST) + if (stObj->base.Sampler.MinFilter == GL_LINEAR || + stObj->base.Sampler.MinFilter == GL_NEAREST) stObj->lastLevel = stObj->base.BaseLevel; else stObj->lastLevel = stObj->base._MaxLevel; @@ -1890,8 +1890,8 @@ st_get_default_texture(struct st_context *st) texObj, texImg, 0, 0); - texObj->MinFilter = GL_NEAREST; - texObj->MagFilter = GL_NEAREST; + texObj->Sampler.MinFilter = GL_NEAREST; + texObj->Sampler.MagFilter = GL_NEAREST; texObj->_Complete = GL_TRUE; st->default_texture = texObj; diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index d50c3c9af79..903e30df52f 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -163,6 +163,21 @@ st_get_texture_sampler_view(struct st_texture_object *stObj, } +/** + * Get pointer to the active sampler object for the given texture unit. + * This will either be a user-defined sampler object or the texture + * object's own sampler state. + */ +static INLINE struct gl_sampler_object * +st_get_mesa_sampler(const struct gl_context *ctx, GLuint unit) +{ + if (ctx->Texture.Unit[unit].Sampler) + return ctx->Texture.Unit[unit].Sampler; + else + return &ctx->Texture.Unit[unit]._Current->Sampler; +} + + extern struct pipe_resource * st_texture_create(struct st_context *st, enum pipe_texture_target target, diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index e391043f4d9..b6bfeaed4a9 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -71,7 +71,7 @@ fetch_texel_lod( struct gl_context *ctx, const GLfloat texcoord[4], GLfloat lamb SWcontext *swrast = SWRAST_CONTEXT(ctx); GLfloat rgba[4]; - lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); + lambda = CLAMP(lambda, texObj->Sampler.MinLod, texObj->Sampler.MaxLod); swrast->TextureSample[unit](ctx, texObj, 1, (const GLfloat (*)[4]) texcoord, @@ -115,9 +115,9 @@ fetch_texel_deriv( struct gl_context *ctx, const GLfloat texcoord[4], texcoord[0], texcoord[1], texcoord[3], 1.0F / texcoord[3]); - lambda += lodBias + texUnit->LodBias + texObj->LodBias; + lambda += lodBias + texUnit->LodBias + texObj->Sampler.LodBias; - lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); + lambda = CLAMP(lambda, texObj->Sampler.MinLod, texObj->Sampler.MaxLod); swrast->TextureSample[unit](ctx, texObj, 1, (const GLfloat (*)[4]) texcoord, diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index ef38a6b22b8..9cfecc9e3a4 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -490,7 +490,7 @@ interpolate_texcoords(struct gl_context *ctx, SWspan *span) if (obj) { const struct gl_texture_image *img = obj->Image[0][obj->BaseLevel]; - needLambda = (obj->MinFilter != obj->MagFilter) + needLambda = (obj->Sampler.MinFilter != obj->Sampler.MagFilter) || ctx->FragmentProgram._Current; texW = img->WidthScale; texH = img->HeightScale; diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c index 0c8cc9ff37b..7f49b6ffa50 100644 --- a/src/mesa/swrast/s_texcombine.c +++ b/src/mesa/swrast/s_texcombine.c @@ -631,9 +631,9 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) /* adjust texture lod (lambda) */ if (span->arrayMask & SPAN_LAMBDA) { - if (texUnit->LodBias + curObj->LodBias != 0.0F) { + if (texUnit->LodBias + curObj->Sampler.LodBias != 0.0F) { /* apply LOD bias, but don't clamp yet */ - const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias, + const GLfloat bias = CLAMP(texUnit->LodBias + curObj->Sampler.LodBias, -ctx->Const.MaxTextureLodBias, ctx->Const.MaxTextureLodBias); GLuint i; @@ -642,10 +642,11 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) } } - if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) { + if (curObj->Sampler.MinLod != -1000.0 || + curObj->Sampler.MaxLod != 1000.0) { /* apply LOD clamping to lambda */ - const GLfloat min = curObj->MinLod; - const GLfloat max = curObj->MaxLod; + const GLfloat min = curObj->Sampler.MinLod; + const GLfloat max = curObj->Sampler.MaxLod; GLuint i; for (i = 0; i < span->end; i++) { GLfloat l = lambda[i]; @@ -686,9 +687,9 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) /* adjust texture lod (lambda) */ if (span->arrayMask & SPAN_LAMBDA) { - if (texUnit->LodBias + curObj->LodBias != 0.0F) { + if (texUnit->LodBias + curObj->Sampler.LodBias != 0.0F) { /* apply LOD bias, but don't clamp yet */ - const GLfloat bias = CLAMP(texUnit->LodBias + curObj->LodBias, + const GLfloat bias = CLAMP(texUnit->LodBias + curObj->Sampler.LodBias, -ctx->Const.MaxTextureLodBias, ctx->Const.MaxTextureLodBias); GLuint i; @@ -697,10 +698,11 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span ) } } - if (curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) { + if (curObj->Sampler.MinLod != -1000.0 || + curObj->Sampler.MaxLod != 1000.0) { /* apply LOD clamping to lambda */ - const GLfloat min = curObj->MinLod; - const GLfloat max = curObj->MaxLod; + const GLfloat min = curObj->Sampler.MinLod; + const GLfloat max = curObj->Sampler.MaxLod; GLuint i; for (i = 0; i < span->end; i++) { GLfloat l = lambda[i]; diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c index 42785400c0e..106f8b75f9e 100644 --- a/src/mesa/swrast/s_texfilter.c +++ b/src/mesa/swrast/s_texfilter.c @@ -505,28 +505,28 @@ nearest_texcoord(const struct gl_texture_object *texObj, switch (texObj->Target) { case GL_TEXTURE_RECTANGLE_ARB: - *i = clamp_rect_coord_nearest(texObj->WrapS, texcoord[0], width); - *j = clamp_rect_coord_nearest(texObj->WrapT, texcoord[1], height); + *i = clamp_rect_coord_nearest(texObj->Sampler.WrapS, texcoord[0], width); + *j = clamp_rect_coord_nearest(texObj->Sampler.WrapT, texcoord[1], height); *k = 0; break; case GL_TEXTURE_1D: - *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); + *i = nearest_texel_location(texObj->Sampler.WrapS, img, width, texcoord[0]); *j = 0; *k = 0; break; case GL_TEXTURE_2D: - *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); - *j = nearest_texel_location(texObj->WrapT, img, height, texcoord[1]); + *i = nearest_texel_location(texObj->Sampler.WrapS, img, width, texcoord[0]); + *j = nearest_texel_location(texObj->Sampler.WrapT, img, height, texcoord[1]); *k = 0; break; case GL_TEXTURE_1D_ARRAY_EXT: - *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); + *i = nearest_texel_location(texObj->Sampler.WrapS, img, width, texcoord[0]); *j = tex_array_slice(texcoord[1], height); *k = 0; break; case GL_TEXTURE_2D_ARRAY_EXT: - *i = nearest_texel_location(texObj->WrapS, img, width, texcoord[0]); - *j = nearest_texel_location(texObj->WrapT, img, height, texcoord[1]); + *i = nearest_texel_location(texObj->Sampler.WrapS, img, width, texcoord[0]); + *j = nearest_texel_location(texObj->Sampler.WrapT, img, height, texcoord[1]); *k = tex_array_slice(texcoord[2], depth); break; default: @@ -553,24 +553,24 @@ linear_texcoord(const struct gl_texture_object *texObj, switch (texObj->Target) { case GL_TEXTURE_RECTANGLE_ARB: - clamp_rect_coord_linear(texObj->WrapS, texcoord[0], + clamp_rect_coord_linear(texObj->Sampler.WrapS, texcoord[0], width, i0, i1, wi); - clamp_rect_coord_linear(texObj->WrapT, texcoord[1], + clamp_rect_coord_linear(texObj->Sampler.WrapT, texcoord[1], height, j0, j1, wj); *slice = 0; break; case GL_TEXTURE_1D: case GL_TEXTURE_2D: - linear_texel_locations(texObj->WrapS, img, width, + linear_texel_locations(texObj->Sampler.WrapS, img, width, texcoord[0], i0, i1, wi); - linear_texel_locations(texObj->WrapT, img, height, + linear_texel_locations(texObj->Sampler.WrapT, img, height, texcoord[1], j0, j1, wj); *slice = 0; break; case GL_TEXTURE_1D_ARRAY_EXT: - linear_texel_locations(texObj->WrapS, img, width, + linear_texel_locations(texObj->Sampler.WrapS, img, width, texcoord[0], i0, i1, wi); *j0 = tex_array_slice(texcoord[1], height); *j1 = *j0; @@ -578,9 +578,9 @@ linear_texcoord(const struct gl_texture_object *texObj, break; case GL_TEXTURE_2D_ARRAY_EXT: - linear_texel_locations(texObj->WrapS, img, width, + linear_texel_locations(texObj->Sampler.WrapS, img, width, texcoord[0], i0, i1, wi); - linear_texel_locations(texObj->WrapT, img, height, + linear_texel_locations(texObj->Sampler.WrapT, img, height, texcoord[1], j0, j1, wj); *slice = tex_array_slice(texcoord[2], depth); break; @@ -656,12 +656,12 @@ compute_min_mag_ranges(const struct gl_texture_object *tObj, GLfloat minMagThresh; /* we shouldn't be here if minfilter == magfilter */ - ASSERT(tObj->MinFilter != tObj->MagFilter); + ASSERT(tObj->Sampler.MinFilter != tObj->Sampler.MagFilter); /* This bit comes from the OpenGL spec: */ - if (tObj->MagFilter == GL_LINEAR - && (tObj->MinFilter == GL_NEAREST_MIPMAP_NEAREST || - tObj->MinFilter == GL_NEAREST_MIPMAP_LINEAR)) { + if (tObj->Sampler.MagFilter == GL_LINEAR + && (tObj->Sampler.MinFilter == GL_NEAREST_MIPMAP_NEAREST || + tObj->Sampler.MinFilter == GL_NEAREST_MIPMAP_LINEAR)) { minMagThresh = 0.5F; } else { @@ -763,28 +763,28 @@ get_border_color(const struct gl_texture_object *tObj, { switch (img->_BaseFormat) { case GL_RGB: - rgba[0] = tObj->BorderColor.f[0]; - rgba[1] = tObj->BorderColor.f[1]; - rgba[2] = tObj->BorderColor.f[2]; + rgba[0] = tObj->Sampler.BorderColor.f[0]; + rgba[1] = tObj->Sampler.BorderColor.f[1]; + rgba[2] = tObj->Sampler.BorderColor.f[2]; rgba[3] = 1.0F; break; case GL_ALPHA: rgba[0] = rgba[1] = rgba[2] = 0.0; - rgba[3] = tObj->BorderColor.f[3]; + rgba[3] = tObj->Sampler.BorderColor.f[3]; break; case GL_LUMINANCE: - rgba[0] = rgba[1] = rgba[2] = tObj->BorderColor.f[0]; + rgba[0] = rgba[1] = rgba[2] = tObj->Sampler.BorderColor.f[0]; rgba[3] = 1.0; break; case GL_LUMINANCE_ALPHA: - rgba[0] = rgba[1] = rgba[2] = tObj->BorderColor.f[0]; - rgba[3] = tObj->BorderColor.f[3]; + rgba[0] = rgba[1] = rgba[2] = tObj->Sampler.BorderColor.f[0]; + rgba[3] = tObj->Sampler.BorderColor.f[3]; break; case GL_INTENSITY: - rgba[0] = rgba[1] = rgba[2] = rgba[3] = tObj->BorderColor.f[0]; + rgba[0] = rgba[1] = rgba[2] = rgba[3] = tObj->Sampler.BorderColor.f[0]; break; default: - COPY_4V(rgba, tObj->BorderColor.f); + COPY_4V(rgba, tObj->Sampler.BorderColor.f); } } @@ -804,7 +804,7 @@ sample_1d_nearest(struct gl_context *ctx, { const GLint width = img->Width2; /* without border, power of two */ GLint i; - i = nearest_texel_location(tObj->WrapS, img, width, texcoord[0]); + i = nearest_texel_location(tObj->Sampler.WrapS, img, width, texcoord[0]); /* skip over the border, if any */ i += img->Border; if (i < 0 || i >= (GLint) img->Width) { @@ -832,7 +832,7 @@ sample_1d_linear(struct gl_context *ctx, GLfloat a; GLfloat t0[4], t1[4]; /* texels */ - linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); + linear_texel_locations(tObj->Sampler.WrapS, img, width, texcoord[0], &i0, &i1, &a); if (img->Border) { i0 += img->Border; @@ -991,7 +991,7 @@ sample_lambda_1d( struct gl_context *ctx, if (minStart < minEnd) { /* do the minified texels */ const GLuint m = minEnd - minStart; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: for (i = minStart; i < minEnd; i++) sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -1026,7 +1026,7 @@ sample_lambda_1d( struct gl_context *ctx, if (magStart < magEnd) { /* do the magnified texels */ - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: for (i = magStart; i < magEnd; i++) sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -1065,8 +1065,8 @@ sample_2d_nearest(struct gl_context *ctx, GLint i, j; (void) ctx; - i = nearest_texel_location(tObj->WrapS, img, width, texcoord[0]); - j = nearest_texel_location(tObj->WrapT, img, height, texcoord[1]); + i = nearest_texel_location(tObj->Sampler.WrapS, img, width, texcoord[0]); + j = nearest_texel_location(tObj->Sampler.WrapT, img, height, texcoord[1]); /* skip over the border, if any */ i += img->Border; @@ -1100,8 +1100,8 @@ sample_2d_linear(struct gl_context *ctx, GLfloat a, b; GLfloat t00[4], t10[4], t01[4], t11[4]; /* sampled texel colors */ - linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); - linear_texel_locations(tObj->WrapT, img, height, texcoord[1], &j0, &j1, &b); + linear_texel_locations(tObj->Sampler.WrapS, img, width, texcoord[0], &i0, &i1, &a); + linear_texel_locations(tObj->Sampler.WrapT, img, height, texcoord[1], &j0, &j1, &b); if (img->Border) { i0 += img->Border; @@ -1165,8 +1165,8 @@ sample_2d_linear_repeat(struct gl_context *ctx, (void) ctx; - ASSERT(tObj->WrapS == GL_REPEAT); - ASSERT(tObj->WrapT == GL_REPEAT); + ASSERT(tObj->Sampler.WrapS == GL_REPEAT); + ASSERT(tObj->Sampler.WrapT == GL_REPEAT); ASSERT(img->Border == 0); ASSERT(img->_BaseFormat != GL_COLOR_INDEX); ASSERT(img->_IsPowerOfTwo); @@ -1270,8 +1270,8 @@ sample_2d_linear_mipmap_linear_repeat(struct gl_context *ctx, { GLuint i; ASSERT(lambda != NULL); - ASSERT(tObj->WrapS == GL_REPEAT); - ASSERT(tObj->WrapT == GL_REPEAT); + ASSERT(tObj->Sampler.WrapS == GL_REPEAT); + ASSERT(tObj->Sampler.WrapT == GL_REPEAT); for (i = 0; i < n; i++) { GLint level = linear_mipmap_level(tObj, lambda[i]); if (level >= tObj->_MaxLevel) { @@ -1317,8 +1317,8 @@ sample_linear_2d(struct gl_context *ctx, GLuint i; struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel]; (void) lambda; - if (tObj->WrapS == GL_REPEAT && - tObj->WrapT == GL_REPEAT && + if (tObj->Sampler.WrapS == GL_REPEAT && + tObj->Sampler.WrapT == GL_REPEAT && image->_IsPowerOfTwo && image->Border == 0) { for (i = 0; i < n; i++) { @@ -1356,8 +1356,8 @@ opt_sample_rgb_2d(struct gl_context *ctx, GLuint k; (void) ctx; (void) lambda; - ASSERT(tObj->WrapS==GL_REPEAT); - ASSERT(tObj->WrapT==GL_REPEAT); + ASSERT(tObj->Sampler.WrapS==GL_REPEAT); + ASSERT(tObj->Sampler.WrapT==GL_REPEAT); ASSERT(img->Border==0); ASSERT(img->TexFormat == MESA_FORMAT_RGB888); ASSERT(img->_IsPowerOfTwo); @@ -1398,8 +1398,8 @@ opt_sample_rgba_2d(struct gl_context *ctx, GLuint i; (void) ctx; (void) lambda; - ASSERT(tObj->WrapS==GL_REPEAT); - ASSERT(tObj->WrapT==GL_REPEAT); + ASSERT(tObj->Sampler.WrapS==GL_REPEAT); + ASSERT(tObj->Sampler.WrapT==GL_REPEAT); ASSERT(img->Border==0); ASSERT(img->TexFormat == MESA_FORMAT_RGBA8888); ASSERT(img->_IsPowerOfTwo); @@ -1428,8 +1428,8 @@ sample_lambda_2d(struct gl_context *ctx, GLuint minStart, minEnd; /* texels with minification */ GLuint magStart, magEnd; /* texels with magnification */ - const GLboolean repeatNoBorderPOT = (tObj->WrapS == GL_REPEAT) - && (tObj->WrapT == GL_REPEAT) + const GLboolean repeatNoBorderPOT = (tObj->Sampler.WrapS == GL_REPEAT) + && (tObj->Sampler.WrapT == GL_REPEAT) && (tImg->Border == 0 && (tImg->Width == tImg->RowStride)) && (tImg->_BaseFormat != GL_COLOR_INDEX) && tImg->_IsPowerOfTwo; @@ -1441,7 +1441,7 @@ sample_lambda_2d(struct gl_context *ctx, if (minStart < minEnd) { /* do the minified texels */ const GLuint m = minEnd - minStart; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: if (repeatNoBorderPOT) { switch (tImg->TexFormat) { @@ -1498,7 +1498,7 @@ sample_lambda_2d(struct gl_context *ctx, /* do the magnified texels */ const GLuint m = magEnd - magStart; - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: if (repeatNoBorderPOT) { switch (tImg->TexFormat) { @@ -1552,9 +1552,9 @@ sample_3d_nearest(struct gl_context *ctx, GLint i, j, k; (void) ctx; - i = nearest_texel_location(tObj->WrapS, img, width, texcoord[0]); - j = nearest_texel_location(tObj->WrapT, img, height, texcoord[1]); - k = nearest_texel_location(tObj->WrapR, img, depth, texcoord[2]); + i = nearest_texel_location(tObj->Sampler.WrapS, img, width, texcoord[0]); + j = nearest_texel_location(tObj->Sampler.WrapT, img, height, texcoord[1]); + k = nearest_texel_location(tObj->Sampler.WrapR, img, depth, texcoord[2]); if (i < 0 || i >= (GLint) img->Width || j < 0 || j >= (GLint) img->Height || @@ -1587,9 +1587,9 @@ sample_3d_linear(struct gl_context *ctx, GLfloat t000[4], t010[4], t001[4], t011[4]; GLfloat t100[4], t110[4], t101[4], t111[4]; - linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); - linear_texel_locations(tObj->WrapT, img, height, texcoord[1], &j0, &j1, &b); - linear_texel_locations(tObj->WrapR, img, depth, texcoord[2], &k0, &k1, &c); + linear_texel_locations(tObj->Sampler.WrapS, img, width, texcoord[0], &i0, &i1, &a); + linear_texel_locations(tObj->Sampler.WrapT, img, height, texcoord[1], &j0, &j1, &b); + linear_texel_locations(tObj->Sampler.WrapR, img, depth, texcoord[2], &k0, &k1, &c); if (img->Border) { i0 += img->Border; @@ -1794,7 +1794,7 @@ sample_lambda_3d(struct gl_context *ctx, if (minStart < minEnd) { /* do the minified texels */ GLuint m = minEnd - minStart; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: for (i = minStart; i < minEnd; i++) sample_3d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -1829,7 +1829,7 @@ sample_lambda_3d(struct gl_context *ctx, if (magStart < magEnd) { /* do the magnified texels */ - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: for (i = magStart; i < magEnd; i++) sample_3d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -2091,7 +2091,7 @@ sample_lambda_cube(struct gl_context *ctx, if (minStart < minEnd) { /* do the minified texels */ const GLuint m = minEnd - minStart; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: sample_nearest_cube(ctx, tObj, m, texcoords + minStart, lambda + minStart, rgba + minStart); @@ -2128,7 +2128,7 @@ sample_lambda_cube(struct gl_context *ctx, if (magStart < magEnd) { /* do the magnified texels */ const GLuint m = magEnd - magStart; - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: sample_nearest_cube(ctx, tObj, m, texcoords + magStart, lambda + magStart, rgba + magStart); @@ -2163,18 +2163,18 @@ sample_nearest_rect(struct gl_context *ctx, (void) ctx; (void) lambda; - ASSERT(tObj->WrapS == GL_CLAMP || - tObj->WrapS == GL_CLAMP_TO_EDGE || - tObj->WrapS == GL_CLAMP_TO_BORDER); - ASSERT(tObj->WrapT == GL_CLAMP || - tObj->WrapT == GL_CLAMP_TO_EDGE || - tObj->WrapT == GL_CLAMP_TO_BORDER); + ASSERT(tObj->Sampler.WrapS == GL_CLAMP || + tObj->Sampler.WrapS == GL_CLAMP_TO_EDGE || + tObj->Sampler.WrapS == GL_CLAMP_TO_BORDER); + ASSERT(tObj->Sampler.WrapT == GL_CLAMP || + tObj->Sampler.WrapT == GL_CLAMP_TO_EDGE || + tObj->Sampler.WrapT == GL_CLAMP_TO_BORDER); ASSERT(img->_BaseFormat != GL_COLOR_INDEX); for (i = 0; i < n; i++) { GLint row, col; - col = clamp_rect_coord_nearest(tObj->WrapS, texcoords[i][0], width); - row = clamp_rect_coord_nearest(tObj->WrapT, texcoords[i][1], height); + col = clamp_rect_coord_nearest(tObj->Sampler.WrapS, texcoords[i][0], width); + row = clamp_rect_coord_nearest(tObj->Sampler.WrapT, texcoords[i][1], height); if (col < 0 || col >= width || row < 0 || row >= height) get_border_color(tObj, img, rgba[i]); else @@ -2197,12 +2197,12 @@ sample_linear_rect(struct gl_context *ctx, (void) ctx; (void) lambda; - ASSERT(tObj->WrapS == GL_CLAMP || - tObj->WrapS == GL_CLAMP_TO_EDGE || - tObj->WrapS == GL_CLAMP_TO_BORDER); - ASSERT(tObj->WrapT == GL_CLAMP || - tObj->WrapT == GL_CLAMP_TO_EDGE || - tObj->WrapT == GL_CLAMP_TO_BORDER); + ASSERT(tObj->Sampler.WrapS == GL_CLAMP || + tObj->Sampler.WrapS == GL_CLAMP_TO_EDGE || + tObj->Sampler.WrapS == GL_CLAMP_TO_BORDER); + ASSERT(tObj->Sampler.WrapT == GL_CLAMP || + tObj->Sampler.WrapT == GL_CLAMP_TO_EDGE || + tObj->Sampler.WrapT == GL_CLAMP_TO_BORDER); ASSERT(img->_BaseFormat != GL_COLOR_INDEX); for (i = 0; i < n; i++) { @@ -2211,9 +2211,9 @@ sample_linear_rect(struct gl_context *ctx, GLfloat a, b; GLbitfield useBorderColor = 0x0; - clamp_rect_coord_linear(tObj->WrapS, texcoords[i][0], width, + clamp_rect_coord_linear(tObj->Sampler.WrapS, texcoords[i][0], width, &i0, &i1, &a); - clamp_rect_coord_linear(tObj->WrapT, texcoords[i][1], height, + clamp_rect_coord_linear(tObj->Sampler.WrapT, texcoords[i][1], height, &j0, &j1, &b); /* compute integer rows/columns */ @@ -2264,7 +2264,7 @@ sample_lambda_rect(struct gl_context *ctx, &minStart, &minEnd, &magStart, &magEnd); if (minStart < minEnd) { - if (tObj->MinFilter == GL_NEAREST) { + if (tObj->Sampler.MinFilter == GL_NEAREST) { sample_nearest_rect(ctx, tObj, minEnd - minStart, texcoords + minStart, NULL, rgba + minStart); } @@ -2274,7 +2274,7 @@ sample_lambda_rect(struct gl_context *ctx, } } if (magStart < magEnd) { - if (tObj->MagFilter == GL_NEAREST) { + if (tObj->Sampler.MagFilter == GL_NEAREST) { sample_nearest_rect(ctx, tObj, magEnd - magStart, texcoords + magStart, NULL, rgba + magStart); } @@ -2307,8 +2307,8 @@ sample_2d_array_nearest(struct gl_context *ctx, GLint array; (void) ctx; - i = nearest_texel_location(tObj->WrapS, img, width, texcoord[0]); - j = nearest_texel_location(tObj->WrapT, img, height, texcoord[1]); + i = nearest_texel_location(tObj->Sampler.WrapS, img, width, texcoord[0]); + j = nearest_texel_location(tObj->Sampler.WrapT, img, height, texcoord[1]); array = tex_array_slice(texcoord[2], depth); if (i < 0 || i >= (GLint) img->Width || @@ -2342,12 +2342,12 @@ sample_2d_array_linear(struct gl_context *ctx, GLfloat a, b; GLfloat t00[4], t01[4], t10[4], t11[4]; - linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); - linear_texel_locations(tObj->WrapT, img, height, texcoord[1], &j0, &j1, &b); + linear_texel_locations(tObj->Sampler.WrapS, img, width, texcoord[0], &i0, &i1, &a); + linear_texel_locations(tObj->Sampler.WrapT, img, height, texcoord[1], &j0, &j1, &b); array = tex_array_slice(texcoord[2], depth); if (array < 0 || array >= depth) { - COPY_4V(rgba, tObj->BorderColor.f); + COPY_4V(rgba, tObj->Sampler.BorderColor.f); } else { if (img->Border) { @@ -2532,7 +2532,7 @@ sample_lambda_2d_array(struct gl_context *ctx, if (minStart < minEnd) { /* do the minified texels */ GLuint m = minEnd - minStart; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: for (i = minStart; i < minEnd; i++) sample_2d_array_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -2575,7 +2575,7 @@ sample_lambda_2d_array(struct gl_context *ctx, if (magStart < magEnd) { /* do the magnified texels */ - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: for (i = magStart; i < magEnd; i++) sample_2d_array_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -2616,7 +2616,7 @@ sample_1d_array_nearest(struct gl_context *ctx, GLint array; (void) ctx; - i = nearest_texel_location(tObj->WrapS, img, width, texcoord[0]); + i = nearest_texel_location(tObj->Sampler.WrapS, img, width, texcoord[0]); array = tex_array_slice(texcoord[1], height); if (i < 0 || i >= (GLint) img->Width || @@ -2648,7 +2648,7 @@ sample_1d_array_linear(struct gl_context *ctx, GLfloat a; GLfloat t0[4], t1[4]; - linear_texel_locations(tObj->WrapS, img, width, texcoord[0], &i0, &i1, &a); + linear_texel_locations(tObj->Sampler.WrapS, img, width, texcoord[0], &i0, &i1, &a); array = tex_array_slice(texcoord[1], height); if (img->Border) { @@ -2813,7 +2813,7 @@ sample_lambda_1d_array(struct gl_context *ctx, if (minStart < minEnd) { /* do the minified texels */ GLuint m = minEnd - minStart; - switch (tObj->MinFilter) { + switch (tObj->Sampler.MinFilter) { case GL_NEAREST: for (i = minStart; i < minEnd; i++) sample_1d_array_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -2852,7 +2852,7 @@ sample_lambda_1d_array(struct gl_context *ctx, if (magStart < magEnd) { /* do the magnified texels */ - switch (tObj->MagFilter) { + switch (tObj->Sampler.MagFilter) { case GL_NEAREST: for (i = magStart; i < magEnd; i++) sample_1d_array_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel], @@ -2975,13 +2975,13 @@ choose_depth_texture_level(const struct gl_texture_object *tObj, GLfloat lambda) { GLint level; - if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) { + if (tObj->Sampler.MinFilter == GL_NEAREST || tObj->Sampler.MinFilter == GL_LINEAR) { /* no mipmapping - use base level */ level = tObj->BaseLevel; } else { /* choose mipmap level */ - lambda = CLAMP(lambda, tObj->MinLod, tObj->MaxLod); + lambda = CLAMP(lambda, tObj->Sampler.MinLod, tObj->Sampler.MaxLod); level = (GLint) lambda; level = CLAMP(level, tObj->BaseLevel, tObj->_MaxLevel); } @@ -3020,14 +3020,14 @@ sample_depth_texture( struct gl_context *ctx, tObj->Target == GL_TEXTURE_1D_ARRAY_EXT || tObj->Target == GL_TEXTURE_2D_ARRAY_EXT); - ambient = tObj->CompareFailValue; + ambient = tObj->Sampler.CompareFailValue; - /* XXXX if tObj->MinFilter != tObj->MagFilter, we're ignoring lambda */ + /* XXXX if tObj->Sampler.MinFilter != tObj->Sampler.MagFilter, we're ignoring lambda */ - function = (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) ? - tObj->CompareFunc : GL_NONE; + function = (tObj->Sampler.CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) ? + tObj->Sampler.CompareFunc : GL_NONE; - if (tObj->MagFilter == GL_NEAREST) { + if (tObj->Sampler.MagFilter == GL_NEAREST) { GLuint i; for (i = 0; i < n; i++) { GLfloat depthSample, depthRef; @@ -3040,14 +3040,14 @@ sample_depth_texture( struct gl_context *ctx, img->FetchTexelf(img, col, row, slice, &depthSample); } else { - depthSample = tObj->BorderColor.f[0]; + depthSample = tObj->Sampler.BorderColor.f[0]; } depthRef = CLAMP(texcoords[i][compare_coord], 0.0F, 1.0F); result = shadow_compare(function, depthRef, depthSample, ambient); - switch (tObj->DepthMode) { + switch (tObj->Sampler.DepthMode) { case GL_LUMINANCE: ASSIGN_4V(texel[i], result, result, result, 1.0F); break; @@ -3067,7 +3067,7 @@ sample_depth_texture( struct gl_context *ctx, } else { GLuint i; - ASSERT(tObj->MagFilter == GL_LINEAR); + ASSERT(tObj->Sampler.MagFilter == GL_LINEAR); for (i = 0; i < n; i++) { GLfloat depth00, depth01, depth10, depth11, depthRef; GLint i0, i1, j0, j1; @@ -3095,21 +3095,21 @@ sample_depth_texture( struct gl_context *ctx, } if (slice < 0 || slice >= (GLint) depth) { - depth00 = tObj->BorderColor.f[0]; - depth01 = tObj->BorderColor.f[0]; - depth10 = tObj->BorderColor.f[0]; - depth11 = tObj->BorderColor.f[0]; + depth00 = tObj->Sampler.BorderColor.f[0]; + depth01 = tObj->Sampler.BorderColor.f[0]; + depth10 = tObj->Sampler.BorderColor.f[0]; + depth11 = tObj->Sampler.BorderColor.f[0]; } else { /* get four depth samples from the texture */ if (useBorderTexel & (I0BIT | J0BIT)) { - depth00 = tObj->BorderColor.f[0]; + depth00 = tObj->Sampler.BorderColor.f[0]; } else { img->FetchTexelf(img, i0, j0, slice, &depth00); } if (useBorderTexel & (I1BIT | J0BIT)) { - depth10 = tObj->BorderColor.f[0]; + depth10 = tObj->Sampler.BorderColor.f[0]; } else { img->FetchTexelf(img, i1, j0, slice, &depth10); @@ -3117,13 +3117,13 @@ sample_depth_texture( struct gl_context *ctx, if (tObj->Target != GL_TEXTURE_1D_ARRAY_EXT) { if (useBorderTexel & (I0BIT | J1BIT)) { - depth01 = tObj->BorderColor.f[0]; + depth01 = tObj->Sampler.BorderColor.f[0]; } else { img->FetchTexelf(img, i0, j1, slice, &depth01); } if (useBorderTexel & (I1BIT | J1BIT)) { - depth11 = tObj->BorderColor.f[0]; + depth11 = tObj->Sampler.BorderColor.f[0]; } else { img->FetchTexelf(img, i1, j1, slice, &depth11); @@ -3141,7 +3141,7 @@ sample_depth_texture( struct gl_context *ctx, depth00, depth01, depth10, depth11, ambient, wi, wj); - switch (tObj->DepthMode) { + switch (tObj->Sampler.DepthMode) { case GL_LUMINANCE: ASSIGN_4V(texel[i], result, result, result, 1.0F); break; @@ -3197,7 +3197,8 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx, return &null_sample_func; } else { - const GLboolean needLambda = (GLboolean) (t->MinFilter != t->MagFilter); + const GLboolean needLambda = + (GLboolean) (t->Sampler.MinFilter != t->Sampler.MagFilter); const GLenum format = t->Image[0][t->BaseLevel]->_BaseFormat; switch (t->Target) { @@ -3208,11 +3209,11 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx, else if (needLambda) { return &sample_lambda_1d; } - else if (t->MinFilter == GL_LINEAR) { + else if (t->Sampler.MinFilter == GL_LINEAR) { return &sample_linear_1d; } else { - ASSERT(t->MinFilter == GL_NEAREST); + ASSERT(t->Sampler.MinFilter == GL_NEAREST); return &sample_nearest_1d; } case GL_TEXTURE_2D: @@ -3222,22 +3223,22 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx, else if (needLambda) { return &sample_lambda_2d; } - else if (t->MinFilter == GL_LINEAR) { + else if (t->Sampler.MinFilter == GL_LINEAR) { return &sample_linear_2d; } else { /* check for a few optimized cases */ const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; - ASSERT(t->MinFilter == GL_NEAREST); - if (t->WrapS == GL_REPEAT && - t->WrapT == GL_REPEAT && + ASSERT(t->Sampler.MinFilter == GL_NEAREST); + if (t->Sampler.WrapS == GL_REPEAT && + t->Sampler.WrapT == GL_REPEAT && img->_IsPowerOfTwo && img->Border == 0 && img->TexFormat == MESA_FORMAT_RGB888) { return &opt_sample_rgb_2d; } - else if (t->WrapS == GL_REPEAT && - t->WrapT == GL_REPEAT && + else if (t->Sampler.WrapS == GL_REPEAT && + t->Sampler.WrapT == GL_REPEAT && img->_IsPowerOfTwo && img->Border == 0 && img->TexFormat == MESA_FORMAT_RGBA8888) { @@ -3251,22 +3252,22 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx, if (needLambda) { return &sample_lambda_3d; } - else if (t->MinFilter == GL_LINEAR) { + else if (t->Sampler.MinFilter == GL_LINEAR) { return &sample_linear_3d; } else { - ASSERT(t->MinFilter == GL_NEAREST); + ASSERT(t->Sampler.MinFilter == GL_NEAREST); return &sample_nearest_3d; } case GL_TEXTURE_CUBE_MAP: if (needLambda) { return &sample_lambda_cube; } - else if (t->MinFilter == GL_LINEAR) { + else if (t->Sampler.MinFilter == GL_LINEAR) { return &sample_linear_cube; } else { - ASSERT(t->MinFilter == GL_NEAREST); + ASSERT(t->Sampler.MinFilter == GL_NEAREST); return &sample_nearest_cube; } case GL_TEXTURE_RECTANGLE_NV: @@ -3276,33 +3277,33 @@ _swrast_choose_texture_sample_func( struct gl_context *ctx, else if (needLambda) { return &sample_lambda_rect; } - else if (t->MinFilter == GL_LINEAR) { + else if (t->Sampler.MinFilter == GL_LINEAR) { return &sample_linear_rect; } else { - ASSERT(t->MinFilter == GL_NEAREST); + ASSERT(t->Sampler.MinFilter == GL_NEAREST); return &sample_nearest_rect; } case GL_TEXTURE_1D_ARRAY_EXT: if (needLambda) { return &sample_lambda_1d_array; } - else if (t->MinFilter == GL_LINEAR) { + else if (t->Sampler.MinFilter == GL_LINEAR) { return &sample_linear_1d_array; } else { - ASSERT(t->MinFilter == GL_NEAREST); + ASSERT(t->Sampler.MinFilter == GL_NEAREST); return &sample_nearest_1d_array; } case GL_TEXTURE_2D_ARRAY_EXT: if (needLambda) { return &sample_lambda_2d_array; } - else if (t->MinFilter == GL_LINEAR) { + else if (t->Sampler.MinFilter == GL_LINEAR) { return &sample_linear_2d_array; } else { - ASSERT(t->MinFilter == GL_NEAREST); + ASSERT(t->Sampler.MinFilter == GL_NEAREST); return &sample_nearest_2d_array; } default: diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index d07a4ef7513..8a9671aa08a 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -540,7 +540,7 @@ affine_span(struct gl_context *ctx, SWspan *span, info.smask = texImg->Width - 1; \ info.tmask = texImg->Height - 1; \ info.format = texImg->TexFormat; \ - info.filter = obj->MinFilter; \ + info.filter = obj->Sampler.MinFilter; \ info.envmode = unit->EnvMode; \ info.er = 0; \ info.eg = 0; \ @@ -805,7 +805,7 @@ fast_persp_span(struct gl_context *ctx, SWspan *span, info.smask = texImg->Width - 1; \ info.tmask = texImg->Height - 1; \ info.format = texImg->TexFormat; \ - info.filter = obj->MinFilter; \ + info.filter = obj->Sampler.MinFilter; \ info.envmode = unit->EnvMode; \ info.er = 0; \ info.eg = 0; \ @@ -1044,8 +1044,8 @@ _swrast_choose_triangle( struct gl_context *ctx ) texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL; format = texImg ? texImg->TexFormat : MESA_FORMAT_NONE; - minFilter = texObj2D ? texObj2D->MinFilter : GL_NONE; - magFilter = texObj2D ? texObj2D->MagFilter : GL_NONE; + minFilter = texObj2D ? texObj2D->Sampler.MinFilter : GL_NONE; + magFilter = texObj2D ? texObj2D->Sampler.MagFilter : GL_NONE; envMode = ctx->Texture.Unit[0].EnvMode; /* First see if we can use an optimized 2-D texture function */ @@ -1054,8 +1054,8 @@ _swrast_choose_triangle( struct gl_context *ctx ) && !ctx->ATIFragmentShader._Enabled && ctx->Texture._EnabledUnits == 0x1 && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT - && texObj2D->WrapS == GL_REPEAT - && texObj2D->WrapT == GL_REPEAT + && texObj2D->Sampler.WrapS == GL_REPEAT + && texObj2D->Sampler.WrapT == GL_REPEAT && texObj2D->_Swizzle == SWIZZLE_NOOP && texImg->_IsPowerOfTwo && texImg->Border == 0 -- cgit v1.2.3 From 847f991a87b9549eb89a521edb7cd149005006bb Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 11 Apr 2011 21:29:06 -0600 Subject: ir_to_mesa: silence signed/unsigned comparison warnings --- src/mesa/program/ir_to_mesa.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 107bfc7957e..3c9b9733832 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -757,7 +757,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) * of the type. However, this had better match the number of state * elements that we're going to copy into the new temporary. */ - assert(ir->num_state_slots == type_size(ir->type)); + assert((int) ir->num_state_slots == type_size(ir->type)); storage = new(mem_ctx) variable_storage(ir, PROGRAM_TEMPORARY, this->next_temp); @@ -788,7 +788,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir) } if (storage->file == PROGRAM_TEMPORARY && - dst.index != storage->index + ir->num_state_slots) { + dst.index != storage->index + (int) ir->num_state_slots) { fail_link(this->shader_program, "failed to load builtin uniform `%s' (%d/%d regs loaded)\n", ir->name, dst.index - storage->index, -- cgit v1.2.3 From 28cec9e832b716b84c11ddabfcee74e0daf6ec49 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 13 Apr 2011 11:09:55 -0700 Subject: mesa: Add support for the ARB_fragment_program part of ARB_draw_buffers. Fixes fbo-drawbuffers-arbfp. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=34321 Reviewed-by: Brian Paul Reviewed-by: Ian Romanick --- src/mesa/program/program_parse.y | 29 +++++++++++++++++++++++++++++ src/mesa/program/program_parser.h | 1 + 2 files changed, 30 insertions(+) (limited to 'src/mesa/program') diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y index 19aa8ccdb53..b35bc5a7cae 100644 --- a/src/mesa/program/program_parse.y +++ b/src/mesa/program/program_parse.y @@ -2064,6 +2064,34 @@ optResultFaceType: ? VERT_RESULT_COL0 : FRAG_RESULT_COLOR; } + | '[' INTEGER ']' + { + if (state->mode == ARB_vertex) { + yyerror(& @1, state, "invalid program result name"); + YYERROR; + } else { + if (!state->option.DrawBuffers) { + /* From the ARB_draw_buffers spec (same text exists + * for ATI_draw_buffers): + * + * If this option is not specified, a fragment + * program that attempts to bind + * "result.color[n]" will fail to load, and only + * "result.color" will be allowed. + */ + yyerror(& @1, state, + "result.color[] used without " + "`OPTION ARB_draw_buffers' or " + "`OPTION ATI_draw_buffers'"); + YYERROR; + } else if ($2 >= state->MaxDrawBuffers) { + yyerror(& @1, state, + "result.color[] exceeds MAX_DRAW_BUFFERS_ARB"); + YYERROR; + } + $$ = FRAG_RESULT_DATA0 + $2; + } + } | FRONT { if (state->mode == ARB_vertex) { @@ -2681,6 +2709,7 @@ _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *st state->MaxClipPlanes = ctx->Const.MaxClipPlanes; state->MaxLights = ctx->Const.MaxLights; state->MaxProgramMatrices = ctx->Const.MaxProgramMatrices; + state->MaxDrawBuffers = ctx->Const.MaxDrawBuffers; state->state_param_enum = (target == GL_VERTEX_PROGRAM_ARB) ? STATE_VERTEX_PROGRAM : STATE_FRAGMENT_PROGRAM; diff --git a/src/mesa/program/program_parser.h b/src/mesa/program/program_parser.h index d689eef7958..8e5aaee95e5 100644 --- a/src/mesa/program/program_parser.h +++ b/src/mesa/program/program_parser.h @@ -173,6 +173,7 @@ struct asm_parser_state { unsigned MaxClipPlanes; unsigned MaxLights; unsigned MaxProgramMatrices; + unsigned MaxDrawBuffers; /*@}*/ /** -- cgit v1.2.3 From fb6e39737a24f9652b6cdc10067736b8915c61f9 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 13 Apr 2011 12:07:31 -0700 Subject: mesa: Add support for OPTION ATI_draw_buffers to ARB_fp. Tested by piglit ati_draw_buffers-arbfp. Reviewed-by: Brian Paul Reviewed-by: Ian Romanick --- src/mesa/program/program_parse_extra.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/mesa/program') diff --git a/src/mesa/program/program_parse_extra.c b/src/mesa/program/program_parse_extra.c index ae98b782b70..4d928483e16 100644 --- a/src/mesa/program/program_parse_extra.c +++ b/src/mesa/program/program_parse_extra.c @@ -229,6 +229,16 @@ _mesa_ARBfp_parse_option(struct asm_parser_state *state, const char *option) } } } + } else if (strncmp(option, "ATI_", 4) == 0) { + option += 4; + + if (strcmp(option, "draw_buffers") == 0) { + /* Don't need to check extension availability because all Mesa-based + * drivers support GL_ATI_draw_buffers. + */ + state->option.DrawBuffers = 1; + return 1; + } } else if (strncmp(option, "NV_fragment_program", 19) == 0) { option += 19; -- cgit v1.2.3 From 257cc48de2f4e472eb651a4c70042e5cb6b9fe0e Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 5 Apr 2011 22:38:26 -0700 Subject: prog_optimize: get_src_arg_mask() respect writemask for more opcodes Reviewed-by: Eric Anholt --- src/mesa/program/prog_optimize.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/mesa/program') diff --git a/src/mesa/program/prog_optimize.c b/src/mesa/program/prog_optimize.c index 164297a3474..acf0f60eae8 100644 --- a/src/mesa/program/prog_optimize.c +++ b/src/mesa/program/prog_optimize.c @@ -74,6 +74,17 @@ get_src_arg_mask(const struct prog_instruction *inst, case OPCODE_MAD: case OPCODE_MUL: case OPCODE_SUB: + case OPCODE_CMP: + case OPCODE_FLR: + case OPCODE_FRC: + case OPCODE_LRP: + case OPCODE_SEQ: + case OPCODE_SGE: + case OPCODE_SGT: + case OPCODE_SLE: + case OPCODE_SLT: + case OPCODE_SNE: + case OPCODE_SSG: channel_mask = inst->DstReg.WriteMask & dst_mask; break; case OPCODE_RCP: -- cgit v1.2.3 From 97535699ee610a2f66732609f966102150847d3c Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Mon, 4 Apr 2011 22:07:55 -0700 Subject: prog_optimize: Add simplify CMP optimization pass This pass coverts CMP T0, T1 T2 T0 -> MOV T0, T2 when the CMP instruction is the first instruction to write to register T0. This pass is useful for hardware that requires a lot of lowering passes that generate many CMP instructions. --- src/mesa/program/prog_optimize.c | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'src/mesa/program') diff --git a/src/mesa/program/prog_optimize.c b/src/mesa/program/prog_optimize.c index acf0f60eae8..11debc485eb 100644 --- a/src/mesa/program/prog_optimize.c +++ b/src/mesa/program/prog_optimize.c @@ -1246,6 +1246,83 @@ print_it(struct gl_context *ctx, struct gl_program *program, const char *txt) { } #endif +/** + * This pass replaces CMP T0, T1 T2 T0 with MOV T0, T2 when the CMP + * instruction is the first instruction to write to register T0. The are + * several lowering passes done in GLSL IR (e.g. branches and + * relative addressing) that create a large number of conditional assignments + * that ir_to_mesa converts to CMP instructions like the one mentioned above. + * + * Here is why this conversion is safe: + * CMP T0, T1 T2 T0 can be expanded to: + * if (T1 < 0.0) + * MOV T0, T2; + * else + * MOV T0, T0; + * + * If (T1 < 0.0) evaluates to true then our replacement MOV T0, T2 is the same + * as the original program. If (T1 < 0.0) evaluates to false, executing + * MOV T0, T0 will store a garbage value in T0 since T0 is uninitialized. + * Therefore, it doesn't matter that we are replacing MOV T0, T0 with MOV T0, T2 + * because any instruction that was going to read from T0 after this was going + * to read a garbage value anyway. + */ +static void +_mesa_simplify_cmp(struct gl_program * program) +{ + GLuint tempWrites[REG_ALLOCATE_MAX_PROGRAM_TEMPS]; + GLuint outputWrites[MAX_PROGRAM_OUTPUTS]; + GLuint i; + + if (dbg) { + printf("Optimize: Begin reads without writes\n"); + _mesa_print_program(program); + } + + for (i = 0; i < REG_ALLOCATE_MAX_PROGRAM_TEMPS; i++) { + tempWrites[i] = 0; + } + + for (i = 0; i < MAX_PROGRAM_OUTPUTS; i++) { + outputWrites[i] = 0; + } + + for (i = 0; i < program->NumInstructions; i++) { + struct prog_instruction *inst = program->Instructions + i; + GLuint prevWriteMask; + + /* Give up if we encounter relative addressing or flow control. */ + if (_mesa_is_flow_control_opcode(inst->Opcode) || inst->DstReg.RelAddr) { + return; + } + + if (inst->DstReg.File == PROGRAM_OUTPUT) { + assert(inst->DstReg.Index < MAX_PROGRAM_OUTPUTS); + prevWriteMask = outputWrites[inst->DstReg.Index]; + outputWrites[inst->DstReg.Index] |= inst->DstReg.WriteMask; + } else if (inst->DstReg.File == PROGRAM_TEMPORARY) { + assert(inst->DstReg.Index < REG_ALLOCATE_MAX_PROGRAM_TEMPS); + prevWriteMask = tempWrites[inst->DstReg.Index]; + tempWrites[inst->DstReg.Index] |= inst->DstReg.WriteMask; + } + + /* For a CMP to be considered a conditional write, the destination + * register and source register two must be the same. */ + if (inst->Opcode == OPCODE_CMP + && !(inst->DstReg.WriteMask & prevWriteMask) + && inst->SrcReg[2].File == inst->DstReg.File + && inst->SrcReg[2].Index == inst->DstReg.Index + && inst->DstReg.WriteMask == get_src_arg_mask(inst, 2, NO_MASK)) { + + inst->Opcode = OPCODE_MOV; + inst->SrcReg[0] = inst->SrcReg[1]; + } + } + if (dbg) { + printf("Optimize: End reads without writes\n"); + _mesa_print_program(program); + } +} /** * Apply optimizations to the given program to eliminate unnecessary @@ -1256,6 +1333,7 @@ _mesa_optimize_program(struct gl_context *ctx, struct gl_program *program) { GLboolean any_change; + _mesa_simplify_cmp(program); /* Stop when no modifications were output */ do { any_change = GL_FALSE; -- cgit v1.2.3 From 4d203a01e20dedcfaab09c18922e8ed9dcb39729 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 15 Apr 2011 19:04:57 -0700 Subject: mesa: Kill gl_fragment_program::FogOption with fire All drivers expect this to always be GL_NONE. Don't let there be any opportunity for a bad value to leak out and infect some unsuspecting driver. If any driver for hardware that had fixed-function per-fragment fog (i915 and perhaps some r300-ish) was ever going to add support, it would have done it by now. Reviewed-by: Eric Anholt Acked-by: Corbin Simpson Acked-by: Alex Deucher --- .../drivers/dri/r300/compiler/r300_fragprog_emit.c | 2 -- src/mesa/main/ff_fragment_shader.cpp | 9 +----- src/mesa/main/mtypes.h | 1 - src/mesa/program/arbprogparse.c | 18 ++++-------- src/mesa/program/program.c | 1 - src/mesa/program/programopt.c | 33 ++++++++++++++-------- src/mesa/program/programopt.h | 4 ++- 7 files changed, 31 insertions(+), 37 deletions(-) (limited to 'src/mesa/program') diff --git a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c index 646a415ca51..8b73409136f 100644 --- a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c +++ b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c @@ -34,8 +34,6 @@ * \author Ben Skeggs * * \author Jerome Glisse - * - * \todo FogOption */ #include "r300_fragprog.h" diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp index b799b292664..0b53c28f7ae 100644 --- a/src/mesa/main/ff_fragment_shader.cpp +++ b/src/mesa/main/ff_fragment_shader.cpp @@ -1549,14 +1549,7 @@ create_new_program(struct gl_context *ctx, struct state_key *key, * the limits becuase it will potentially add some instructions. */ if (key->fog_enabled) { - /* Pull fog mode from struct gl_context, the value in the state key is - * a reduced value and not what is expected in FogOption - */ - p.program->FogOption = ctx->Fog.Mode; - p.program->Base.InputsRead |= FRAG_BIT_FOGC; - - _mesa_append_fog_code(ctx, p.program, GL_FALSE); - p.program->FogOption = GL_NONE; + _mesa_append_fog_code(ctx, p.program, ctx->Fog.Mode, GL_FALSE); } if (p.program->Base.NumTexIndirections > ctx->Const.FragmentProgram.MaxTexIndirections) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 5a25d649a13..160ae9d2622 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1923,7 +1923,6 @@ struct gl_geometry_program struct gl_fragment_program { struct gl_program Base; /**< base class */ - GLenum FogOption; GLboolean UsesKill; /**< shader uses KIL instruction */ GLboolean OriginUpperLeft; GLboolean PixelCenterInteger; diff --git a/src/mesa/program/arbprogparse.c b/src/mesa/program/arbprogparse.c index 7f778c3c381..dffc8abf735 100644 --- a/src/mesa/program/arbprogparse.c +++ b/src/mesa/program/arbprogparse.c @@ -116,20 +116,11 @@ _mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target, program->Base.SamplersUsed |= (1 << i); } program->Base.ShadowSamplers = prog.ShadowSamplers; - switch (state.option.Fog) { - case OPTION_FOG_EXP: program->FogOption = GL_EXP; break; - case OPTION_FOG_EXP2: program->FogOption = GL_EXP2; break; - case OPTION_FOG_LINEAR: program->FogOption = GL_LINEAR; break; - default: program->FogOption = GL_NONE; break; - } program->OriginUpperLeft = state.option.OriginUpperLeft; program->PixelCenterInteger = state.option.PixelCenterInteger; program->UsesKill = state.fragment.UsesKill; - if (program->FogOption) - program->Base.InputsRead |= FRAG_BIT_FOGC; - if (program->Base.Instructions) free(program->Base.Instructions); program->Base.Instructions = prog.Instructions; @@ -143,12 +134,15 @@ _mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target, * there's no hardware that wants to do fog in a discrete stage separate * from the fragment shader. */ - if (program->FogOption != GL_NONE) { + if (state.option.Fog != OPTION_NONE) { + static const GLenum fog_modes[4] = { + GL_NONE, GL_EXP, GL_EXP2, GL_LINEAR + }; + /* XXX: we should somehow recompile this to remove clamping if disabled * On the ATI driver, this is unclampled if fragment clamping is disabled */ - _mesa_append_fog_code(ctx, program, GL_TRUE); - program->FogOption = GL_NONE; + _mesa_append_fog_code(ctx, program, fog_modes[state.option.Fog], GL_TRUE); } #if DEBUG_FP diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c index 5b014872ed4..78efca9f122 100644 --- a/src/mesa/program/program.c +++ b/src/mesa/program/program.c @@ -557,7 +557,6 @@ _mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog) const struct gl_fragment_program *fp = (const struct gl_fragment_program *) prog; struct gl_fragment_program *fpc = (struct gl_fragment_program *) clone; - fpc->FogOption = fp->FogOption; fpc->UsesKill = fp->UsesKill; fpc->OriginUpperLeft = fp->OriginUpperLeft; fpc->PixelCenterInteger = fp->PixelCenterInteger; diff --git a/src/mesa/program/programopt.c b/src/mesa/program/programopt.c index 5ad9571f757..a239da2c609 100644 --- a/src/mesa/program/programopt.c +++ b/src/mesa/program/programopt.c @@ -230,15 +230,25 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog) /** - * Append extra instructions onto the given fragment program to implement - * the fog mode specified by fprog->FogOption. - * The fragment.fogcoord input is used to compute the fog blend factor. + * Append instructions to implement fog * - * XXX with a little work, this function could be adapted to add fog code + * The \c fragment.fogcoord input is used to compute the fog blend factor. + * + * \param ctx The GL context + * \param fprog Fragment program that fog instructions will be appended to. + * \param fog_mode Fog mode. One of \c GL_EXP, \c GL_EXP2, or \c GL_LINEAR. + * \param saturate True if writes to color outputs should be clamped to [0, 1] + * + * \note + * This function sets \c FRAG_BIT_FOGC in \c fprog->Base.InputsRead. + * + * \todo With a little work, this function could be adapted to add fog code * to vertex programs too. */ void -_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLboolean saturate) +_mesa_append_fog_code(struct gl_context *ctx, + struct gl_fragment_program *fprog, GLenum fog_mode, + GLboolean saturate) { static const gl_state_index fogPStateOpt[STATE_LENGTH] = { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 }; @@ -251,9 +261,9 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLint fogPRefOpt, fogColorRef; /* state references */ GLuint colorTemp, fogFactorTemp; /* temporary registerss */ - if (fprog->FogOption == GL_NONE) { + if (fog_mode == GL_NONE) { _mesa_problem(ctx, "_mesa_append_fog_code() called for fragment program" - " with FogOption == GL_NONE"); + " with fog_mode == GL_NONE"); return; } @@ -301,7 +311,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, /* emit instructions to compute fog blending factor */ /* this is always clamped to [0, 1] regardless of fragment clamping */ - if (fprog->FogOption == GL_LINEAR) { + if (fog_mode == GL_LINEAR) { /* MAD fogFactorTemp.x, fragment.fogcoord.x, fogPRefOpt.x, fogPRefOpt.y; */ inst->Opcode = OPCODE_MAD; inst->DstReg.File = PROGRAM_TEMPORARY; @@ -320,7 +330,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, inst++; } else { - ASSERT(fprog->FogOption == GL_EXP || fprog->FogOption == GL_EXP2); + ASSERT(fog_mode == GL_EXP || fog_mode == GL_EXP2); /* fogPRefOpt.z = d/ln(2), fogPRefOpt.w = d/sqrt(ln(2) */ /* EXP: MUL fogFactorTemp.x, fogPRefOpt.z, fragment.fogcoord.x; */ /* EXP2: MUL fogFactorTemp.x, fogPRefOpt.w, fragment.fogcoord.x; */ @@ -331,12 +341,12 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, inst->SrcReg[0].File = PROGRAM_STATE_VAR; inst->SrcReg[0].Index = fogPRefOpt; inst->SrcReg[0].Swizzle - = (fprog->FogOption == GL_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW; + = (fog_mode == GL_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW; inst->SrcReg[1].File = PROGRAM_INPUT; inst->SrcReg[1].Index = FRAG_ATTRIB_FOGC; inst->SrcReg[1].Swizzle = SWIZZLE_XXXX; inst++; - if (fprog->FogOption == GL_EXP2) { + if (fog_mode == GL_EXP2) { /* MUL fogFactorTemp.x, fogFactorTemp.x, fogFactorTemp.x; */ inst->Opcode = OPCODE_MUL; inst->DstReg.File = PROGRAM_TEMPORARY; @@ -397,7 +407,6 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, fprog->Base.Instructions = newInst; fprog->Base.NumInstructions = inst - newInst; fprog->Base.InputsRead |= FRAG_BIT_FOGC; - /* XXX do this? fprog->FogOption = GL_NONE; */ } diff --git a/src/mesa/program/programopt.h b/src/mesa/program/programopt.h index 79631aa5843..b9205823c29 100644 --- a/src/mesa/program/programopt.h +++ b/src/mesa/program/programopt.h @@ -32,7 +32,9 @@ extern void _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog); extern void -_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLboolean saturate); +_mesa_append_fog_code(struct gl_context *ctx, + struct gl_fragment_program *fprog, GLenum fog_mode, + GLboolean saturate); extern void _mesa_count_texture_indirections(struct gl_program *prog); -- cgit v1.2.3