mesa, glsl_to_tgsi: Add new gl_context::NativeIntegers flag.

Previously, native integer support was based on whether the driver
advertised GLSL 1.30 or not.  However, drivers that natively support
integers may wish to do so for older GLSL versions as well.  Adding this
new opt-in flag allows them to do so.

Currently disabled by default on all drivers, which was the existing
behavior (no drivers currently implement GLSL 1.30).

Fixes piglit tests on i965 with INTEL_GLSL_VERSION=130 set:
- spec/glsl-1.10/fs-uniform-int-110.shader_test
- spec/glsl-1.30/fs-uniform-int-130.shader_test
(it was doubly converting the data)

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Kenneth Graunke 2011-08-15 14:18:16 -07:00
parent 07e9b9049f
commit 01d81dedc7
3 changed files with 37 additions and 27 deletions

View File

@ -2717,6 +2717,12 @@ struct gl_constants
GLuint GLSLVersion; /**< GLSL version supported (ex: 120 = 1.20) */ GLuint GLSLVersion; /**< GLSL version supported (ex: 120 = 1.20) */
/**
* Does the driver support real 32-bit integers? (Otherwise, integers are
* simulated via floats.)
*/
GLboolean NativeIntegers;
/** Which texture units support GL_ATI_envmap_bumpmap as targets */ /** Which texture units support GL_ATI_envmap_bumpmap as targets */
GLbitfield SupportedBumpUnits; GLbitfield SupportedBumpUnits;

View File

@ -454,9 +454,9 @@ get_uniform(struct gl_context *ctx, GLuint program, GLint location,
for (i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
const int base = paramPos + offset + i; const int base = paramPos + offset + i;
for (j = 0; j < cols; j++ ) { for (j = 0; j < cols; j++ ) {
params[k++] = ctx->Const.GLSLVersion <= 120 ? params[k++] = ctx->Const.NativeIntegers ?
(GLint) prog->Parameters->ParameterValues[base][j].f : prog->Parameters->ParameterValues[base][j].i :
prog->Parameters->ParameterValues[base][j].i; (GLint) prog->Parameters->ParameterValues[base][j].f;
} }
} }
} }
@ -468,9 +468,9 @@ get_uniform(struct gl_context *ctx, GLuint program, GLint location,
for (i = 0; i < rows; i++) { for (i = 0; i < rows; i++) {
const int base = paramPos + offset + i; const int base = paramPos + offset + i;
for (j = 0; j < cols; j++ ) { for (j = 0; j < cols; j++ ) {
params[k++] = ctx->Const.GLSLVersion <= 120 ? params[k++] = ctx->Const.NativeIntegers ?
(GLuint) prog->Parameters->ParameterValues[base][j].f : prog->Parameters->ParameterValues[base][j].u :
prog->Parameters->ParameterValues[base][j].u; (GLuint) prog->Parameters->ParameterValues[base][j].f;
} }
} }
} }
@ -750,7 +750,7 @@ set_program_uniform(struct gl_context *ctx, struct gl_program *program,
if (basicType == GL_INT) { if (basicType == GL_INT) {
const GLint *iValues = ((const GLint *) values) + k * elems; const GLint *iValues = ((const GLint *) values) + k * elems;
for (i = 0; i < elems; i++) { for (i = 0; i < elems; i++) {
if (ctx->Const.GLSLVersion <= 120) if (!ctx->Const.NativeIntegers)
uniformVal[i].f = (GLfloat) iValues[i]; uniformVal[i].f = (GLfloat) iValues[i];
else else
uniformVal[i].i = iValues[i]; uniformVal[i].i = iValues[i];
@ -759,7 +759,7 @@ set_program_uniform(struct gl_context *ctx, struct gl_program *program,
else if (basicType == GL_UNSIGNED_INT) { else if (basicType == GL_UNSIGNED_INT) {
const GLuint *iValues = ((const GLuint *) values) + k * elems; const GLuint *iValues = ((const GLuint *) values) + k * elems;
for (i = 0; i < elems; i++) { for (i = 0; i < elems; i++) {
if (ctx->Const.GLSLVersion <= 120) if (!ctx->Const.NativeIntegers)
uniformVal[i].f = (GLfloat)(GLuint) iValues[i]; uniformVal[i].f = (GLfloat)(GLuint) iValues[i];
else else
uniformVal[i].u = iValues[i]; uniformVal[i].u = iValues[i];
@ -781,7 +781,7 @@ set_program_uniform(struct gl_context *ctx, struct gl_program *program,
else else
uniformVal[i].b = uniformVal[i].u ? 1 : 0; uniformVal[i].b = uniformVal[i].u ? 1 : 0;
if (ctx->Const.GLSLVersion <= 120) if (!ctx->Const.NativeIntegers)
uniformVal[i].f = uniformVal[i].b ? 1.0f : 0.0f; uniformVal[i].f = uniformVal[i].b ? 1.0f : 0.0f;
} }
} }

View File

@ -295,6 +295,7 @@ public:
bool indirect_addr_consts; bool indirect_addr_consts;
int glsl_version; int glsl_version;
bool native_integers;
variable_storage *find_variable_storage(ir_variable *var); variable_storage *find_variable_storage(ir_variable *var);
@ -600,7 +601,7 @@ glsl_to_tgsi_visitor::get_opcode(ir_instruction *ir, unsigned op,
if (src0.type == GLSL_TYPE_FLOAT || src1.type == GLSL_TYPE_FLOAT) if (src0.type == GLSL_TYPE_FLOAT || src1.type == GLSL_TYPE_FLOAT)
type = GLSL_TYPE_FLOAT; type = GLSL_TYPE_FLOAT;
else if (glsl_version >= 130) else if (native_integers)
type = src0.type; type = src0.type;
#define case4(c, f, i, u) \ #define case4(c, f, i, u) \
@ -881,7 +882,7 @@ glsl_to_tgsi_visitor::st_src_reg_for_int(int val)
st_src_reg src(PROGRAM_IMMEDIATE, -1, GLSL_TYPE_INT); st_src_reg src(PROGRAM_IMMEDIATE, -1, GLSL_TYPE_INT);
union gl_constant_value uval; union gl_constant_value uval;
assert(glsl_version >= 130); assert(native_integers);
uval.i = val; uval.i = val;
src.index = add_constant(src.file, &uval, 1, GL_INT, &src.swizzle); src.index = add_constant(src.file, &uval, 1, GL_INT, &src.swizzle);
@ -892,7 +893,7 @@ glsl_to_tgsi_visitor::st_src_reg_for_int(int val)
struct st_src_reg struct st_src_reg
glsl_to_tgsi_visitor::st_src_reg_for_type(int type, int val) glsl_to_tgsi_visitor::st_src_reg_for_type(int type, int val)
{ {
if (glsl_version >= 130) if (native_integers)
return type == GLSL_TYPE_FLOAT ? st_src_reg_for_float(val) : return type == GLSL_TYPE_FLOAT ? st_src_reg_for_float(val) :
st_src_reg_for_int(val); st_src_reg_for_int(val);
else else
@ -950,7 +951,7 @@ glsl_to_tgsi_visitor::get_temp(const glsl_type *type)
{ {
st_src_reg src; st_src_reg src;
src.type = glsl_version >= 130 ? type->base_type : GLSL_TYPE_FLOAT; src.type = native_integers ? type->base_type : GLSL_TYPE_FLOAT;
src.file = PROGRAM_TEMPORARY; src.file = PROGRAM_TEMPORARY;
src.index = next_temp; src.index = next_temp;
src.reladdr = NULL; src.reladdr = NULL;
@ -1053,7 +1054,7 @@ glsl_to_tgsi_visitor::visit(ir_variable *ir)
this->next_temp += type_size(ir->type); this->next_temp += type_size(ir->type);
dst = st_dst_reg(st_src_reg(PROGRAM_TEMPORARY, storage->index, dst = st_dst_reg(st_src_reg(PROGRAM_TEMPORARY, storage->index,
glsl_version >= 130 ? ir->type->base_type : GLSL_TYPE_FLOAT)); native_integers ? ir->type->base_type : GLSL_TYPE_FLOAT));
} }
@ -1069,7 +1070,7 @@ glsl_to_tgsi_visitor::visit(ir_variable *ir)
} }
} else { } else {
st_src_reg src(PROGRAM_STATE_VAR, index, st_src_reg src(PROGRAM_STATE_VAR, index,
glsl_version >= 130 ? ir->type->base_type : GLSL_TYPE_FLOAT); native_integers ? ir->type->base_type : GLSL_TYPE_FLOAT);
src.swizzle = slots[i].swizzle; src.swizzle = slots[i].swizzle;
emit(ir, TGSI_OPCODE_MOV, dst, src); emit(ir, TGSI_OPCODE_MOV, dst, src);
/* even a float takes up a whole vec4 reg in a struct/array. */ /* even a float takes up a whole vec4 reg in a struct/array. */
@ -1444,7 +1445,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
/* "==" operator producing a scalar boolean. */ /* "==" operator producing a scalar boolean. */
if (ir->operands[0]->type->is_vector() || if (ir->operands[0]->type->is_vector() ||
ir->operands[1]->type->is_vector()) { ir->operands[1]->type->is_vector()) {
st_src_reg temp = get_temp(glsl_version >= 130 ? st_src_reg temp = get_temp(native_integers ?
glsl_type::get_instance(ir->operands[0]->type->base_type, 4, 1) : glsl_type::get_instance(ir->operands[0]->type->base_type, 4, 1) :
glsl_type::vec4_type); glsl_type::vec4_type);
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
@ -1459,7 +1460,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
/* "!=" operator producing a scalar boolean. */ /* "!=" operator producing a scalar boolean. */
if (ir->operands[0]->type->is_vector() || if (ir->operands[0]->type->is_vector() ||
ir->operands[1]->type->is_vector()) { ir->operands[1]->type->is_vector()) {
st_src_reg temp = get_temp(glsl_version >= 130 ? st_src_reg temp = get_temp(native_integers ?
glsl_type::get_instance(ir->operands[0]->type->base_type, 4, 1) : glsl_type::get_instance(ir->operands[0]->type->base_type, 4, 1) :
glsl_type::vec4_type); glsl_type::vec4_type);
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
@ -1514,7 +1515,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
break; break;
case ir_unop_i2f: case ir_unop_i2f:
case ir_unop_b2f: case ir_unop_b2f:
if (glsl_version >= 130) { if (native_integers) {
emit(ir, TGSI_OPCODE_I2F, result_dst, op[0]); emit(ir, TGSI_OPCODE_I2F, result_dst, op[0]);
break; break;
} }
@ -1526,7 +1527,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
result_src = op[0]; result_src = op[0];
break; break;
case ir_unop_f2i: case ir_unop_f2i:
if (glsl_version >= 130) if (native_integers)
emit(ir, TGSI_OPCODE_F2I, result_dst, op[0]); emit(ir, TGSI_OPCODE_F2I, result_dst, op[0]);
else else
emit(ir, TGSI_OPCODE_TRUNC, result_dst, op[0]); emit(ir, TGSI_OPCODE_TRUNC, result_dst, op[0]);
@ -1567,7 +1568,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
break; break;
} }
case ir_unop_u2f: case ir_unop_u2f:
if (glsl_version >= 130) { if (native_integers) {
emit(ir, TGSI_OPCODE_U2F, result_dst, op[0]); emit(ir, TGSI_OPCODE_U2F, result_dst, op[0]);
break; break;
} }
@ -1719,7 +1720,7 @@ glsl_to_tgsi_visitor::visit(ir_dereference_variable *ir)
} }
this->result = st_src_reg(entry->file, entry->index, var->type); this->result = st_src_reg(entry->file, entry->index, var->type);
if (glsl_version <= 120) if (!native_integers)
this->result.type = GLSL_TYPE_FLOAT; this->result.type = GLSL_TYPE_FLOAT;
} }
@ -2109,27 +2110,27 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
} }
break; break;
case GLSL_TYPE_UINT: case GLSL_TYPE_UINT:
gl_type = glsl_version >= 130 ? GL_UNSIGNED_INT : GL_FLOAT; gl_type = native_integers ? GL_UNSIGNED_INT : GL_FLOAT;
for (i = 0; i < ir->type->vector_elements; i++) { for (i = 0; i < ir->type->vector_elements; i++) {
if (glsl_version >= 130) if (native_integers)
values[i].u = ir->value.u[i]; values[i].u = ir->value.u[i];
else else
values[i].f = ir->value.u[i]; values[i].f = ir->value.u[i];
} }
break; break;
case GLSL_TYPE_INT: case GLSL_TYPE_INT:
gl_type = glsl_version >= 130 ? GL_INT : GL_FLOAT; gl_type = native_integers ? GL_INT : GL_FLOAT;
for (i = 0; i < ir->type->vector_elements; i++) { for (i = 0; i < ir->type->vector_elements; i++) {
if (glsl_version >= 130) if (native_integers)
values[i].i = ir->value.i[i]; values[i].i = ir->value.i[i];
else else
values[i].f = ir->value.i[i]; values[i].f = ir->value.i[i];
} }
break; break;
case GLSL_TYPE_BOOL: case GLSL_TYPE_BOOL:
gl_type = glsl_version >= 130 ? GL_BOOL : GL_FLOAT; gl_type = native_integers ? GL_BOOL : GL_FLOAT;
for (i = 0; i < ir->type->vector_elements; i++) { for (i = 0; i < ir->type->vector_elements; i++) {
if (glsl_version >= 130) if (native_integers)
values[i].b = ir->value.b[i]; values[i].b = ir->value.b[i];
else else
values[i].f = ir->value.b[i]; values[i].f = ir->value.b[i];
@ -3611,6 +3612,7 @@ get_pixel_transfer_visitor(struct st_fragment_program *fp,
v->ctx = original->ctx; v->ctx = original->ctx;
v->prog = prog; v->prog = prog;
v->glsl_version = original->glsl_version; v->glsl_version = original->glsl_version;
v->native_integers = original->native_integers;
v->options = original->options; v->options = original->options;
v->next_temp = original->next_temp; v->next_temp = original->next_temp;
v->num_address_regs = original->num_address_regs; v->num_address_regs = original->num_address_regs;
@ -3739,6 +3741,7 @@ get_bitmap_visitor(struct st_fragment_program *fp,
v->ctx = original->ctx; v->ctx = original->ctx;
v->prog = prog; v->prog = prog;
v->glsl_version = original->glsl_version; v->glsl_version = original->glsl_version;
v->native_integers = original->native_integers;
v->options = original->options; v->options = original->options;
v->next_temp = original->next_temp; v->next_temp = original->next_temp;
v->num_address_regs = original->num_address_regs; v->num_address_regs = original->num_address_regs;
@ -4674,6 +4677,7 @@ get_mesa_program(struct gl_context *ctx,
v->shader_program = shader_program; v->shader_program = shader_program;
v->options = options; v->options = options;
v->glsl_version = ctx->Const.GLSLVersion; v->glsl_version = ctx->Const.GLSLVersion;
v->native_integers = ctx->Const.NativeIntegers;
add_uniforms_to_parameters_list(shader_program, shader, prog); add_uniforms_to_parameters_list(shader_program, shader, prog);