Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 15 commits
  • 35 files changed
  • 2 commit comments
  • 1 contributor
Commits on Apr 26, 2011
@Plombo Plombo st/mesa: Add a GLSL IR to TGSI translator.
It is still a work in progress at this point, but it produces working and reasonably well-optimized code.

Originally based on ir_to_mesa and st_mesa_to_tgsi, but does not directly use Mesa IR instructions in TGSI generation, instead generating TGSI from the intermediate class glsl_to_tgsi_instruction.  It also has new optimization passes to replace _mesa_optimize_program.
809a11c
Commits on Apr 30, 2011
@Plombo Plombo mesa: fix segfault when no Mesa IR is generated b044467
@Plombo Plombo st/mesa: stop generating Mesa IR in st_glsl_to_tgsi
Before, it was still generating unused Mesa IR as a remnant of ir_to_mesa, and depended on some of the information from it.
3a04413
@Plombo Plombo st/mesa: remove reads to output registers in st_glsl_to_tgsi
Fixes a regression in 0 A.D. introduced by 809a11c.
f259e14
@Plombo Plombo st/mesa: remove a bad assertion
It was triggered by Alien Arena.
97c533d
Commits on May 01, 2011
@Plombo Plombo st/mesa: define the sampler objects used in st_glsl_to_tgsi
Fixes the Nexuiz title screen and the water in 0 A.D.
a14d109
@Plombo Plombo st/mesa: lower noise opcodes when converting from GLSL IR, not when g…
…enerating TGSI
078a9cc
@Plombo Plombo st/mesa: support DDY (ir_unop_dFdy) in GLSL to TGSI translator a5b8db0
Commits on May 02, 2011
@Plombo Plombo st/mesa: use TGSI opcodes when converting from GLSL IR
Before, the translator used Mesa IR opcodes (a holdover from ir_to_mesa) and converted them to TGSI opcodes during TGSI emission.
d5da618
Commits on May 03, 2011
@Plombo Plombo st/mesa: fix shaders with indirect addressing of temps
Fixes several Piglit tests, although it's a step backwards for optimization.
254a9ed
Commits on May 06, 2011
@Plombo Plombo gallium: add PIPE_SHADER_CAP_INTEGERS 4fe806f
Commits on May 17, 2011
@Plombo Plombo mesa: support boolean and integer-based parameters in prog_parameter
The functionality is not used by anything yet, and the glUniform functions will need to be reworked before this can reach its full usefulness.  It is nonetheless a step towards integer support in the state tracker and classic drivers.
6ce44db
Commits on May 22, 2011
@Plombo Plombo WIP: integer support 0328db1
Commits on Jun 08, 2011
@Plombo Plombo WIP 2: use a better hack for enabling GLSL 1.30 6f7b638
Commits on Jun 13, 2011
@Plombo Plombo WIP 3: restore path for targets without integer support 8fe3941
Showing with 4,929 additions and 267 deletions.
  1. +12 −1 src/gallium/auxiliary/tgsi/tgsi_exec.c
  2. +2 −0  src/gallium/auxiliary/tgsi/tgsi_exec.h
  3. +2 −0  src/gallium/drivers/i915/i915_screen.c
  4. +2 −0  src/gallium/drivers/i965/brw_screen.c
  5. +2 −0  src/gallium/drivers/nv50/nv50_screen.c
  6. +2 −0  src/gallium/drivers/nvc0/nvc0_screen.c
  7. +2 −0  src/gallium/drivers/nvfx/nvfx_screen.c
  8. +2 −0  src/gallium/drivers/r300/r300_screen.c
  9. +2 −0  src/gallium/drivers/r600/r600_pipe.c
  10. +2 −0  src/gallium/drivers/svga/svga_screen.c
  11. +1 −0  src/gallium/include/pipe/p_defines.h
  12. +1 −1  src/glsl/glsl_lexer.ll
  13. +15 −0 src/glsl/glsl_types.h
  14. +10 −1 src/glsl/lower_instructions.cpp
  15. +2 −1  src/mesa/main/ff_fragment_shader.cpp
  16. +5 −5 src/mesa/main/ffvertex_prog.c
  17. +30 −16 src/mesa/main/uniforms.c
  18. +4 −4 src/mesa/program/ir_to_mesa.cpp
  19. +15 −8 src/mesa/program/nvfragparse.c
  20. +1 −1  src/mesa/program/prog_execute.c
  21. +51 −27 src/mesa/program/prog_parameter.c
  22. +22 −8 src/mesa/program/prog_parameter.h
  23. +1 −1  src/mesa/program/prog_parameter_layout.c
  24. +1 −1  src/mesa/program/prog_print.c
  25. +5 −3 src/mesa/program/program.c
  26. +1 −1  src/mesa/program/sampler.cpp
  27. +2 −1  src/mesa/sources.mak
  28. +14 −0 src/mesa/state_tracker/st_cb_program.c
  29. +1 −1  src/mesa/state_tracker/st_extensions.c
  30. +4,388 −0 src/mesa/state_tracker/st_glsl_to_tgsi.cpp
  31. +66 −0 src/mesa/state_tracker/st_glsl_to_tgsi.h
  32. +2 −2 src/mesa/state_tracker/st_mesa_to_tgsi.c
  33. +6 −0 src/mesa/state_tracker/st_mesa_to_tgsi.h
  34. +228 −184 src/mesa/state_tracker/st_program.c
  35. +27 −0 src/mesa/state_tracker/st_program.h
View
13 src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -2978,6 +2978,17 @@ micro_xor(union tgsi_exec_channel *dst,
}
static void
+micro_mod(union tgsi_exec_channel *dst,
+ const union tgsi_exec_channel *src0,
+ const union tgsi_exec_channel *src1)
+{
+ dst->i[0] = src0->i[0] % src1->i[0];
+ dst->i[1] = src0->i[1] % src1->i[1];
+ dst->i[2] = src0->i[2] % src1->i[2];
+ dst->i[3] = src0->i[3] % src1->i[3];
+}
+
+static void
micro_f2i(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src)
{
@@ -3680,7 +3691,7 @@ exec_instruction(
break;
case TGSI_OPCODE_MOD:
- assert (0);
+ exec_vector_binary(mach, inst, micro_mod, TGSI_EXEC_DATA_INT, TGSI_EXEC_DATA_INT);
break;
case TGSI_OPCODE_XOR:
View
2  src/gallium/auxiliary/tgsi/tgsi_exec.h
@@ -400,6 +400,8 @@ tgsi_exec_get_shader_param(enum pipe_shader_cap param)
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 1;
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 1;
default:
return 0;
}
View
2  src/gallium/drivers/i915/i915_screen.c
@@ -216,6 +216,8 @@ i915_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_sha
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 0;
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
debug_printf("%s: Unkown cap %u.\n", __FUNCTION__, cap);
return 0;
View
2  src/gallium/drivers/i965/brw_screen.c
@@ -243,6 +243,8 @@ brw_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shad
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 1;
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
assert(0);
return 0;
View
2  src/gallium/drivers/nv50/nv50_screen.c
@@ -176,6 +176,8 @@ nv50_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 0; /* please inline, or provide function declarations */
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
NOUVEAU_ERR("unknown PIPE_SHADER_CAP %d\n", param);
return 0;
View
2  src/gallium/drivers/nvc0/nvc0_screen.c
@@ -164,6 +164,8 @@ nvc0_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 0; /* please inline, or provide function declarations */
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
NOUVEAU_ERR("unknown PIPE_SHADER_CAP %d\n", param);
return 0;
View
2  src/gallium/drivers/nvfx/nvfx_screen.c
@@ -168,6 +168,8 @@ nvfx_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader, enum
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 1;
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
break;
}
View
2  src/gallium/drivers/r300/r300_screen.c
@@ -256,6 +256,8 @@ static int r300_get_shader_param(struct pipe_screen *pscreen, unsigned shader, e
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 0;
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
break;
}
View
2  src/gallium/drivers/r600/r600_pipe.c
@@ -506,6 +506,8 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, unsigned shader, e
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 0;
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
return 0;
}
View
2  src/gallium/drivers/svga/svga_screen.c
@@ -286,6 +286,8 @@ static int svga_get_shader_param(struct pipe_screen *screen, unsigned shader, en
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 0;
+ case PIPE_SHADER_CAP_INTEGERS:
+ return 0;
default:
break;
}
View
1  src/gallium/include/pipe/p_defines.h
@@ -488,6 +488,7 @@ enum pipe_shader_cap
PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR = 14,
PIPE_SHADER_CAP_INDIRECT_CONST_ADDR = 15,
PIPE_SHADER_CAP_SUBROUTINES = 16, /* BGNSUB, ENDSUB, CAL, RET */
+ PIPE_SHADER_CAP_INTEGERS = 17,
};
View
2  src/glsl/glsl_lexer.ll
@@ -283,7 +283,7 @@ layout {
\*= return MUL_ASSIGN;
\/= return DIV_ASSIGN;
\+= return ADD_ASSIGN;
-\%= return MOD_ASSIGN;
+"%=" return MOD_ASSIGN;
\<\<= return LEFT_ASSIGN;
>>= return RIGHT_ASSIGN;
&= return AND_ASSIGN;
View
15 src/glsl/glsl_types.h
@@ -165,6 +165,21 @@ struct glsl_type {
static const glsl_type *const mat4x3_type;
static const glsl_type *const mat4_type;
/*@}*/
+
+ /**
+ * Get the built-in instance of the vec4 type for a specific base type
+ */
+ static const glsl_type *get_vec4_type(glsl_base_type base_type)
+ {
+ if (base_type == GLSL_TYPE_FLOAT)
+ return vec4_type;
+ else if (base_type == GLSL_TYPE_INT)
+ return ivec4_type;
+ else if (base_type == GLSL_TYPE_UINT)
+ return uvec4_type;
+ else
+ return NULL;
+ }
/**
View
11 src/glsl/lower_instructions.cpp
@@ -138,7 +138,9 @@ lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir)
/* op0 / op1 -> op0 * (1.0 / op1) */
ir->operation = ir_binop_mul;
ir->operands[1] = expr;
- } else {
+ }
+#if 0
+ else {
/* Be careful with integer division -- we need to do it as a
* float and re-truncate, since rcp(n > 1) of an integer would
* just be 0.
@@ -172,6 +174,7 @@ lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir)
ir->operands[0] = op0;
ir->operands[1] = NULL;
}
+#endif
this->progress = true;
}
@@ -214,6 +217,12 @@ lower_instructions_visitor::log_to_log2(ir_expression *ir)
void
lower_instructions_visitor::mod_to_fract(ir_expression *ir)
{
+ /* Don't lower integer modulus instructions, since the logical assumption of
+ * this pass (a % b == b * frac(a / b)) is only true for floats.
+ */
+ if (ir->type->is_integer())
+ return;
+
ir_variable *temp = new(ir) ir_variable(ir->operands[1]->type, "mod_b",
ir_var_temporary);
this->base_ir->insert_before(temp);
View
3  src/mesa/main/ff_fragment_shader.cpp
@@ -875,7 +875,8 @@ static struct ureg register_const4f( struct texenv_fragment_program *p,
values[1] = s1;
values[2] = s2;
values[3] = s3;
- idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values, 4,
+ idx = _mesa_add_unnamed_constant( p->program->Base.Parameters,
+ (gl_constant_value *) values, 4,
&swizzle );
r = make_ureg(PROGRAM_CONSTANT, idx);
r.swz = swizzle;
View
10 src/mesa/main/ffvertex_prog.c
@@ -455,13 +455,13 @@ static struct ureg register_const4f( struct tnl_program *p,
GLfloat s2,
GLfloat s3)
{
- GLfloat values[4];
+ gl_constant_value values[4];
GLint idx;
GLuint swizzle;
- values[0] = s0;
- values[1] = s1;
- values[2] = s2;
- values[3] = s3;
+ values[0].f = s0;
+ values[1].f = s1;
+ values[2].f = s2;
+ values[3].f = s3;
idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values, 4,
&swizzle );
ASSERT(swizzle == SWIZZLE_NOOP);
View
46 src/mesa/main/uniforms.c
@@ -434,7 +434,7 @@ _mesa_get_uniformfv(struct gl_context *ctx, GLuint program, GLint location,
const int base = paramPos + offset + i;
for (j = 0; j < cols; j++ ) {
- params[k++] = prog->Parameters->ParameterValues[base][j];
+ params[k++] = prog->Parameters->ParameterValues[base][j].f;
}
}
}
@@ -443,7 +443,7 @@ _mesa_get_uniformfv(struct gl_context *ctx, GLuint program, GLint location,
/**
* Called via glGetUniformiv().
- * \sa _mesa_get_uniformfv, only difference is a cast.
+ * \sa _mesa_get_uniformfv, only difference is the type.
*/
static void
_mesa_get_uniformiv(struct gl_context *ctx, GLuint program, GLint location,
@@ -469,7 +469,9 @@ _mesa_get_uniformiv(struct gl_context *ctx, GLuint program, GLint location,
const int base = paramPos + offset + i;
for (j = 0; j < cols; j++ ) {
- params[k++] = (GLint) prog->Parameters->ParameterValues[base][j];
+ params[k++] = ctx->Const.GLSLVersion <= 120 ?
+ (GLint) prog->Parameters->ParameterValues[base][j].f :
+ prog->Parameters->ParameterValues[base][j].i;
}
}
}
@@ -479,7 +481,7 @@ _mesa_get_uniformiv(struct gl_context *ctx, GLuint program, GLint location,
/**
* Called via glGetUniformuiv().
* New in GL_EXT_gpu_shader4, OpenGL 3.0
- * \sa _mesa_get_uniformfv, only difference is a cast.
+ * \sa _mesa_get_uniformfv, only difference is the type.
*/
static void
_mesa_get_uniformuiv(struct gl_context *ctx, GLuint program, GLint location,
@@ -505,7 +507,9 @@ _mesa_get_uniformuiv(struct gl_context *ctx, GLuint program, GLint location,
const int base = paramPos + offset + i;
for (j = 0; j < cols; j++ ) {
- params[k++] = (GLuint) prog->Parameters->ParameterValues[base][j];
+ params[k++] = ctx->Const.GLSLVersion <= 120 ?
+ (GLuint) prog->Parameters->ParameterValues[base][j].f :
+ prog->Parameters->ParameterValues[base][j].u;
}
}
}
@@ -701,7 +705,7 @@ set_program_uniform(struct gl_context *ctx, struct gl_program *program,
/* loop over number of samplers to change */
for (i = 0; i < count; i++) {
GLuint sampler =
- (GLuint) program->Parameters->ParameterValues[index + offset + i][0];
+ (GLuint)program->Parameters->ParameterValues[index+offset + i][0].f;
GLuint texUnit = ((GLuint *) values)[i];
/* check that the sampler (tex unit index) is legal */
@@ -764,42 +768,52 @@ set_program_uniform(struct gl_context *ctx, struct gl_program *program,
/* loop over number of array elements */
for (k = 0; k < count; k++) {
- GLfloat *uniformVal;
+ gl_constant_value *uniformVal;
if (offset + k >= slots) {
/* Extra array data is ignored */
break;
}
- /* uniformVal (the destination) is always float[4] */
+ /* uniformVal (the destination) is always gl_constant_value[4] */
uniformVal = program->Parameters->ParameterValues[index + offset + k];
if (basicType == GL_INT) {
- /* convert user's ints to floats */
const GLint *iValues = ((const GLint *) values) + k * elems;
for (i = 0; i < elems; i++) {
- uniformVal[i] = (GLfloat) iValues[i];
+ if (ctx->Const.GLSLVersion <= 120)
+ uniformVal[i].f = (GLfloat) iValues[i];
+ else
+ uniformVal[i].i = iValues[i];
}
}
else if (basicType == GL_UNSIGNED_INT) {
- /* convert user's uints to floats */
const GLuint *iValues = ((const GLuint *) values) + k * elems;
for (i = 0; i < elems; i++) {
- uniformVal[i] = (GLfloat) iValues[i];
+ if (ctx->Const.GLSLVersion <= 120)
+ uniformVal[i].f = (GLfloat)(GLuint) iValues[i];
+ else
+ uniformVal[i].u = iValues[i];
}
}
else {
const GLfloat *fValues = ((const GLfloat *) values) + k * elems;
assert(basicType == GL_FLOAT);
for (i = 0; i < elems; i++) {
- uniformVal[i] = fValues[i];
+ uniformVal[i].f = fValues[i];
}
}
- /* if the uniform is bool-valued, convert to 1.0 or 0.0 */
+ /* if the uniform is bool-valued, convert to 1 or 0 */
if (isUniformBool) {
for (i = 0; i < elems; i++) {
- uniformVal[i] = uniformVal[i] ? 1.0f : 0.0f;
+ if (basicType == GL_FLOAT)
+ uniformVal[i].b = uniformVal[i].f != 0.0f ? 1 : 0;
+ else
+ uniformVal[i].b = uniformVal[i].u ? 1 : 0;
+
+ if (ctx->Const.GLSLVersion <= 120)
+ uniformVal[i].f = uniformVal[i].b ? 1.0f : 0.0f;
}
}
}
@@ -960,7 +974,7 @@ set_program_uniform_matrix(struct gl_context *ctx, struct gl_program *program,
/* Ignore writes beyond the end of (the used part of) an array */
return;
}
- v = program->Parameters->ParameterValues[index + offset];
+ v = (GLfloat *) program->Parameters->ParameterValues[index + offset];
for (row = 0; row < rows; row++) {
if (transpose) {
v[row] = values[src + row * cols + col];
View
8 src/mesa/program/ir_to_mesa.cpp
@@ -599,7 +599,7 @@ ir_to_mesa_visitor::src_reg_for_float(float val)
src_reg src(PROGRAM_CONSTANT, -1, NULL);
src.index = _mesa_add_unnamed_constant(this->prog->Parameters,
- &val, 1, &src.swizzle);
+ (const gl_constant_value *)&val, 1, &src.swizzle);
return src;
}
@@ -1799,7 +1799,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir)
src = src_reg(PROGRAM_CONSTANT, -1, NULL);
src.index = _mesa_add_unnamed_constant(this->prog->Parameters,
- values,
+ (gl_constant_value *) values,
ir->type->vector_elements,
&src.swizzle);
emit(ir, OPCODE_MOV, mat_column, src);
@@ -1837,7 +1837,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir)
this->result = src_reg(PROGRAM_CONSTANT, -1, ir->type);
this->result.index = _mesa_add_unnamed_constant(this->prog->Parameters,
- values,
+ (gl_constant_value *) values,
ir->type->vector_elements,
&this->result.swizzle);
}
@@ -2525,7 +2525,7 @@ add_uniforms_to_parameters_list(struct gl_shader_program *shader_program,
*/
if (file == PROGRAM_SAMPLER) {
for (unsigned int j = 0; j < size / 4; j++)
- prog->Parameters->ParameterValues[index + j][0] = next_sampler++;
+ prog->Parameters->ParameterValues[index + j][0].f = next_sampler++;
}
/* The location chosen in the Parameters list here (returned
View
23 src/mesa/program/nvfragparse.c
@@ -472,8 +472,9 @@ Parse_ScalarConstant(struct parse_state *parseState, GLfloat *number)
const GLfloat *constant;
if (!Parse_Identifier(parseState, ident))
RETURN_ERROR1("Expected an identifier");
- constant = _mesa_lookup_parameter_value(parseState->parameters,
- -1, (const char *) ident);
+ constant = (GLfloat *)_mesa_lookup_parameter_value(parseState->parameters,
+ -1,
+ (const char *) ident);
/* XXX Check that it's a constant and not a parameter */
if (!constant) {
RETURN_ERROR1("Undefined symbol");
@@ -1039,7 +1040,8 @@ Parse_VectorSrc(struct parse_state *parseState,
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, NULL);
+ (gl_constant_value *) values,
+ 4, NULL);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
@@ -1051,7 +1053,8 @@ Parse_VectorSrc(struct parse_state *parseState,
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, NULL);
+ (gl_constant_value *) values,
+ 4, NULL);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
@@ -1145,7 +1148,8 @@ Parse_ScalarSrcReg(struct parse_state *parseState,
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, NULL);
+ (gl_constant_value *) values,
+ 4, NULL);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
@@ -1170,7 +1174,8 @@ Parse_ScalarSrcReg(struct parse_state *parseState,
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, NULL);
+ (gl_constant_value *) values,
+ 4, NULL);
srcReg->Index = paramIndex;
srcReg->File = PROGRAM_NAMED_PARAM;
needSuffix = GL_FALSE;
@@ -1296,7 +1301,8 @@ Parse_InstructionSequence(struct parse_state *parseState,
RETURN_ERROR2(id, "already defined");
}
_mesa_add_named_parameter(parseState->parameters,
- (const char *) id, value);
+ (const char *) id,
+ (gl_constant_value *) value);
}
else if (Parse_String(parseState, "DECLARE")) {
GLubyte id[100];
@@ -1315,7 +1321,8 @@ Parse_InstructionSequence(struct parse_state *parseState,
RETURN_ERROR2(id, "already declared");
}
_mesa_add_named_parameter(parseState->parameters,
- (const char *) id, value);
+ (const char *) id,
+ (gl_constant_value *) value);
}
else if (Parse_String(parseState, "END")) {
inst->Opcode = OPCODE_END;
View
2  src/mesa/program/prog_execute.c
@@ -157,7 +157,7 @@ get_src_register_pointer(const struct prog_src_register *source,
case PROGRAM_NAMED_PARAM:
if (reg >= (GLint) prog->Parameters->NumParameters)
return ZeroVec;
- return prog->Parameters->ParameterValues[reg];
+ return (GLfloat *) prog->Parameters->ParameterValues[reg];
case PROGRAM_SYSTEM_VALUE:
assert(reg < Elements(machine->SystemValues));
View
78 src/mesa/program/prog_parameter.c
@@ -56,8 +56,8 @@ _mesa_new_parameter_list_sized(unsigned size)
p->Parameters = (struct gl_program_parameter *)
calloc(1, size * sizeof(struct gl_program_parameter));
- p->ParameterValues = (GLfloat (*)[4])
- _mesa_align_malloc(size * 4 *sizeof(GLfloat), 16);
+ p->ParameterValues = (gl_constant_value (*)[4])
+ _mesa_align_malloc(size * 4 *sizeof(gl_constant_value), 16);
if ((p->Parameters == NULL) || (p->ParameterValues == NULL)) {
@@ -101,14 +101,15 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList)
* \param name the parameter name, will be duplicated/copied!
* \param size number of elements in 'values' vector (1..4, or more)
* \param datatype GL_FLOAT, GL_FLOAT_VECx, GL_INT, GL_INT_VECx or GL_NONE.
- * \param values initial parameter value, up to 4 GLfloats, or NULL
+ * \param values initial parameter value, up to 4 gl_constant_values, or NULL
* \param state state indexes, or NULL
* \return index of new parameter in the list, or -1 if error (out of mem)
*/
GLint
_mesa_add_parameter(struct gl_program_parameter_list *paramList,
gl_register_file type, const char *name,
- GLuint size, GLenum datatype, const GLfloat *values,
+ GLuint size, GLenum datatype,
+ const gl_constant_value *values,
const gl_state_index state[STATE_LENGTH],
GLbitfield flags)
{
@@ -127,10 +128,10 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
oldNum * sizeof(struct gl_program_parameter),
paramList->Size * sizeof(struct gl_program_parameter));
- paramList->ParameterValues = (GLfloat (*)[4])
+ paramList->ParameterValues = (gl_constant_value (*)[4])
_mesa_align_realloc(paramList->ParameterValues, /* old buf */
- oldNum * 4 * sizeof(GLfloat), /* old size */
- paramList->Size * 4 *sizeof(GLfloat), /* new sz */
+ oldNum * 4 * sizeof(gl_constant_value),/* old sz */
+ paramList->Size*4*sizeof(gl_constant_value),/*new*/
16);
}
@@ -142,7 +143,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
return -1;
}
else {
- GLuint i;
+ GLuint i, j;
paramList->NumParameters = oldNum + sz4;
@@ -163,7 +164,8 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
}
else {
/* silence valgrind */
- ASSIGN_4V(paramList->ParameterValues[oldNum + i], 0, 0, 0, 0);
+ for (j = 0; j < 4; j++)
+ paramList->ParameterValues[oldNum + i][j].f = 0;
}
size -= 4;
}
@@ -184,7 +186,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
*/
GLint
_mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat values[4])
+ const char *name, const gl_constant_value values[4])
{
return _mesa_add_parameter(paramList, PROGRAM_NAMED_PARAM, name,
4, GL_NONE, values, NULL, 0x0);
@@ -204,17 +206,17 @@ _mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
*/
GLint
_mesa_add_named_constant(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat values[4],
+ const char *name, const gl_constant_value values[4],
GLuint size)
{
/* first check if this is a duplicate constant */
GLint pos;
for (pos = 0; pos < (GLint)paramList->NumParameters; pos++) {
- const GLfloat *pvals = paramList->ParameterValues[pos];
- if (pvals[0] == values[0] &&
- pvals[1] == values[1] &&
- pvals[2] == values[2] &&
- pvals[3] == values[3] &&
+ const gl_constant_value *pvals = paramList->ParameterValues[pos];
+ if (pvals[0].u == values[0].u &&
+ pvals[1].u == values[1].u &&
+ pvals[2].u == values[2].u &&
+ pvals[3].u == values[3].u &&
strcmp(paramList->Parameters[pos].Name, name) == 0) {
/* Same name and value is already in the param list - reuse it */
return pos;
@@ -239,9 +241,9 @@ _mesa_add_named_constant(struct gl_program_parameter_list *paramList,
* \return index/position of the new parameter in the parameter list.
*/
GLint
-_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
- const GLfloat values[4], GLuint size,
- GLuint *swizzleOut)
+_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
+ const gl_constant_value values[4], GLuint size,
+ GLenum datatype, GLuint *swizzleOut)
{
GLint pos;
ASSERT(size >= 1);
@@ -262,7 +264,7 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
struct gl_program_parameter *p = paramList->Parameters + pos;
if (p->Type == PROGRAM_CONSTANT && p->Size + size <= 4) {
/* ok, found room */
- GLfloat *pVal = paramList->ParameterValues[pos];
+ gl_constant_value *pVal = paramList->ParameterValues[pos];
GLuint swz = p->Size; /* 1, 2 or 3 for Y, Z, W */
pVal[p->Size] = values[0];
p->Size++;
@@ -274,7 +276,7 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
/* add a new parameter to store this constant */
pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
- size, GL_NONE, values, NULL, 0x0);
+ size, datatype, values, NULL, 0x0);
if (pos >= 0 && swizzleOut) {
if (size == 1)
*swizzleOut = SWIZZLE_XXXX;
@@ -285,6 +287,28 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
}
/**
+ * Add a new unnamed constant to the parameter list. This will be used
+ * when a fragment/vertex program contains something like this:
+ * MOV r, { 0, 1, 2, 3 };
+ * If swizzleOut is non-null we'll search the parameter list for an
+ * existing instance of the constant which matches with a swizzle.
+ *
+ * \param paramList the parameter list
+ * \param values four float values
+ * \param swizzleOut returns swizzle mask for accessing the constant
+ * \return index/position of the new parameter in the parameter list.
+ * \sa _mesa_add_typed_unnamed_constant
+ */
+GLint
+_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
+ const gl_constant_value values[4], GLuint size,
+ GLuint *swizzleOut)
+{
+ return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE,
+ swizzleOut);
+}
+
+/**
* Add parameter representing a varying variable.
*/
GLint
@@ -401,7 +425,7 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
* Lookup a parameter value by name in the given parameter list.
* \return pointer to the float[4] values.
*/
-GLfloat *
+gl_constant_value *
_mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
GLsizei nameLen, const char *name)
{
@@ -465,7 +489,7 @@ _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
*/
GLboolean
_mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
- const GLfloat v[], GLuint vSize,
+ const gl_constant_value v[], GLuint vSize,
GLint *posOut, GLuint *swizzleOut)
{
GLuint i;
@@ -484,7 +508,7 @@ _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
/* swizzle not allowed */
GLuint j, match = 0;
for (j = 0; j < vSize; j++) {
- if (v[j] == list->ParameterValues[i][j])
+ if (v[j].u == list->ParameterValues[i][j].u)
match++;
}
if (match == vSize) {
@@ -498,7 +522,7 @@ _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
/* look for v[0] anywhere within float[4] value */
GLuint j;
for (j = 0; j < list->Parameters[i].Size; j++) {
- if (list->ParameterValues[i][j] == v[0]) {
+ if (list->ParameterValues[i][j].u == v[0].u) {
/* found it */
*posOut = i;
*swizzleOut = MAKE_SWIZZLE4(j, j, j, j);
@@ -511,13 +535,13 @@ _mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
GLuint swz[4];
GLuint match = 0, j, k;
for (j = 0; j < vSize; j++) {
- if (v[j] == list->ParameterValues[i][j]) {
+ if (v[j].u == list->ParameterValues[i][j].u) {
swz[j] = j;
match++;
}
else {
for (k = 0; k < list->Parameters[i].Size; k++) {
- if (v[j] == list->ParameterValues[i][k]) {
+ if (v[j].u == list->ParameterValues[i][k].u) {
swz[j] = k;
match++;
break;
View
30 src/mesa/program/prog_parameter.h
@@ -46,7 +46,15 @@
#define PROG_PARAM_BIT_CYL_WRAP 0x10 /**< XXX gallium debug */
/*@}*/
-
+/**
+ * Actual data for constant values of parameters.
+ */
+typedef union gl_constant_value {
+ GLfloat f;
+ GLboolean b;
+ GLint i;
+ GLuint u;
+} gl_constant_value;
/**
* Program parameter.
@@ -81,7 +89,7 @@ struct gl_program_parameter_list
GLuint Size; /**< allocated size of Parameters, ParameterValues */
GLuint NumParameters; /**< number of parameters in arrays */
struct gl_program_parameter *Parameters; /**< Array [Size] */
- GLfloat (*ParameterValues)[4]; /**< Array [Size] of GLfloat[4] */
+ gl_constant_value (*ParameterValues)[4]; /**< Array [Size] of constant[4] */
GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
might invalidate ParameterValues[] */
};
@@ -112,22 +120,28 @@ _mesa_num_parameters(const struct gl_program_parameter_list *list)
extern GLint
_mesa_add_parameter(struct gl_program_parameter_list *paramList,
gl_register_file type, const char *name,
- GLuint size, GLenum datatype, const GLfloat *values,
+ GLuint size, GLenum datatype,
+ const gl_constant_value *values,
const gl_state_index state[STATE_LENGTH],
GLbitfield flags);
extern GLint
_mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat values[4]);
+ const char *name, const gl_constant_value values[4]);
extern GLint
_mesa_add_named_constant(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat values[4],
+ const char *name, const gl_constant_value values[4],
GLuint size);
extern GLint
+_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
+ const gl_constant_value values[4], GLuint size,
+ GLenum datatype, GLuint *swizzleOut);
+
+extern GLint
_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
- const GLfloat values[4], GLuint size,
+ const gl_constant_value values[4], GLuint size,
GLuint *swizzleOut);
extern GLint
@@ -143,7 +157,7 @@ extern GLint
_mesa_add_state_reference(struct gl_program_parameter_list *paramList,
const gl_state_index stateTokens[STATE_LENGTH]);
-extern GLfloat *
+extern gl_constant_value *
_mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
GLsizei nameLen, const char *name);
@@ -153,7 +167,7 @@ _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
extern GLboolean
_mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
- const GLfloat v[], GLuint vSize,
+ const gl_constant_value v[], GLuint vSize,
GLint *posOut, GLuint *swizzleOut);
extern GLuint
View
2  src/mesa/program/prog_parameter_layout.c
@@ -182,7 +182,7 @@ _mesa_layout_parameters(struct asm_parser_state *state)
switch (p->Type) {
case PROGRAM_CONSTANT: {
- const float *const v =
+ const gl_constant_value *const v =
state->prog->Parameters->ParameterValues[idx];
inst->Base.SrcReg[i].Index =
View
2  src/mesa/program/prog_print.c
@@ -978,7 +978,7 @@ _mesa_fprint_parameter_list(FILE *f,
fprintf(f, "dirty state flags: 0x%x\n", list->StateFlags);
for (i = 0; i < list->NumParameters; i++){
struct gl_program_parameter *param = list->Parameters + i;
- const GLfloat *v = list->ParameterValues[i];
+ const GLfloat *v = (GLfloat *) list->ParameterValues[i];
fprintf(f, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
i, param->Size,
_mesa_register_file_name(list->Parameters[i].Type),
View
8 src/mesa/program/program.c
@@ -388,8 +388,9 @@ _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog)
if (prog->String)
free(prog->String);
- _mesa_free_instructions(prog->Instructions, prog->NumInstructions);
-
+ if (prog->Instructions) {
+ _mesa_free_instructions(prog->Instructions, prog->NumInstructions);
+ }
if (prog->Parameters) {
_mesa_free_parameter_list(prog->Parameters);
}
@@ -1029,7 +1030,8 @@ _mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog)
GLuint i;
GLuint whiteSwizzle;
GLint whiteIndex = _mesa_add_unnamed_constant(prog->Parameters,
- white, 4, &whiteSwizzle);
+ (gl_constant_value *) white,
+ 4, &whiteSwizzle);
(void) whiteIndex;
View
2  src/mesa/program/sampler.cpp
@@ -132,6 +132,6 @@ _mesa_get_sampler_uniform_value(class ir_dereference *sampler,
index += getname.offset;
- return prog->Parameters->ParameterValues[index][0];
+ return prog->Parameters->ParameterValues[index][0].f;
}
}
View
3  src/mesa/sources.mak
@@ -336,7 +336,8 @@ MESA_GALLIUM_SOURCES = \
MESA_GALLIUM_CXX_SOURCES = \
$(MAIN_CXX_SOURCES) \
- $(SHADER_CXX_SOURCES)
+ $(SHADER_CXX_SOURCES) \
+ state_tracker/st_glsl_to_tgsi.cpp
# All the core C sources, for dependency checking
ALL_SOURCES = \
View
14 src/mesa/state_tracker/st_cb_program.c
@@ -44,6 +44,7 @@
#include "st_program.h"
#include "st_mesa_to_tgsi.h"
#include "st_cb_program.h"
+#include "st_glsl_to_tgsi.h"
@@ -129,6 +130,9 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
{
struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
st_release_vp_variants( st, stvp );
+
+ if (stvp->glsl_to_tgsi)
+ free_glsl_to_tgsi_visitor(stvp->glsl_to_tgsi);
}
break;
case MESA_GEOMETRY_PROGRAM:
@@ -137,6 +141,9 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
(struct st_geometry_program *) prog;
st_release_gp_variants(st, stgp);
+
+ if (stgp->glsl_to_tgsi)
+ free_glsl_to_tgsi_visitor(stgp->glsl_to_tgsi);
if (stgp->tgsi.tokens) {
st_free_tokens((void *) stgp->tgsi.tokens);
@@ -151,6 +158,9 @@ st_delete_program(struct gl_context *ctx, struct gl_program *prog)
st_release_fp_variants(st, stfp);
+ if (stfp->glsl_to_tgsi)
+ free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
+
if (stfp->tgsi.tokens) {
st_free_tokens(stfp->tgsi.tokens);
stfp->tgsi.tokens = NULL;
@@ -242,4 +252,8 @@ st_init_program_functions(struct dd_function_table *functions)
functions->DeleteProgram = st_delete_program;
functions->IsProgramNative = st_is_program_native;
functions->ProgramStringNotify = st_program_string_notify;
+
+ functions->NewShader = st_new_shader;
+ functions->NewShaderProgram = st_new_shader_program;
+ functions->LinkShader = st_link_shader;
}
View
2  src/mesa/state_tracker/st_extensions.c
@@ -201,7 +201,7 @@ void st_init_limits(struct st_context *st)
/* XXX we'll need a better query here someday */
if (screen->get_param(screen, PIPE_CAP_GLSL)) {
- c->GLSLVersion = 120;
+ c->GLSLVersion = 130;
}
}
View
4,388 src/mesa/state_tracker/st_glsl_to_tgsi.cpp
4,388 additions, 0 deletions not shown
View
66 src/mesa/state_tracker/st_glsl_to_tgsi.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ * Copyright © 2011 Bryan Cain
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "main/glheader.h"
+#include "tgsi/tgsi_ureg.h"
+
+struct gl_context;
+struct gl_shader;
+struct gl_shader_program;
+struct glsl_to_tgsi_visitor;
+
+enum pipe_error st_translate_program(
+ struct gl_context *ctx,
+ uint procType,
+ struct ureg_program *ureg,
+ struct glsl_to_tgsi_visitor *program,
+ const struct gl_program *proginfo,
+ GLuint numInputs,
+ const GLuint inputMapping[],
+ const ubyte inputSemanticName[],
+ const ubyte inputSemanticIndex[],
+ const GLuint interpMode[],
+ GLuint numOutputs,
+ const GLuint outputMapping[],
+ const ubyte outputSemanticName[],
+ const ubyte outputSemanticIndex[],
+ boolean passthrough_edgeflags);
+
+void free_glsl_to_tgsi_visitor(struct glsl_to_tgsi_visitor *v);
+
+struct gl_shader *st_new_shader(struct gl_context *ctx, GLuint name, GLuint type);
+
+struct gl_shader_program *
+st_new_shader_program(struct gl_context *ctx, GLuint name);
+
+void st_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);
+GLboolean st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);
+
+#ifdef __cplusplus
+}
+#endif
View
4 src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -267,7 +267,7 @@ src_register( struct st_translate *t,
/**
* Map mesa texture target to TGSI texture target.
*/
-static unsigned
+unsigned
translate_texture_target( GLuint textarget,
GLboolean shadow )
{
@@ -511,7 +511,7 @@ static void emit_ddy( struct st_translate *t,
-static unsigned
+unsigned
translate_opcode( unsigned op )
{
switch( op ) {
View
6 src/mesa/state_tracker/st_mesa_to_tgsi.h
@@ -64,6 +64,12 @@ st_translate_mesa_program(
void
st_free_tokens(const struct tgsi_token *tokens);
+unsigned
+translate_opcode(unsigned op);
+
+unsigned
+translate_texture_target(GLuint textarget, GLboolean shadow);
+
#if defined __cplusplus
} /* extern "C" */
View
412 src/mesa/state_tracker/st_program.c
@@ -174,8 +174,8 @@ st_release_gp_variants(struct st_context *st, struct st_geometry_program *stgp)
* \param tokensOut destination for TGSI tokens
* \return pointer to cached pipe_shader object.
*/
-static void
-st_prepare_vertex_program(struct st_context *st,
+void
+st_prepare_vertex_program(struct gl_context *ctx,
struct st_vertex_program *stvp)
{
GLuint attr;
@@ -184,9 +184,10 @@ st_prepare_vertex_program(struct st_context *st,
stvp->num_outputs = 0;
if (stvp->Base.IsPositionInvariant)
- _mesa_insert_mvp_code(st->ctx, &stvp->Base);
+ _mesa_insert_mvp_code(ctx, &stvp->Base);
- assert(stvp->Base.Base.NumInstructions > 1);
+ if (!stvp->glsl_to_tgsi)
+ assert(stvp->Base.Base.NumInstructions > 1);
/*
* Determine number of inputs, the mappings between VERT_ATTRIB_x
@@ -292,10 +293,13 @@ st_translate_vertex_program(struct st_context *st,
enum pipe_error error;
unsigned num_outputs;
- st_prepare_vertex_program( st, stvp );
+ st_prepare_vertex_program(st->ctx, stvp);
- _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_OUTPUT);
- _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_VARYING);
+ if (!stvp->glsl_to_tgsi)
+ {
+ _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_OUTPUT);
+ _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_VARYING);
+ }
ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
if (ureg == NULL) {
@@ -318,22 +322,41 @@ st_translate_vertex_program(struct st_context *st,
debug_printf("\n");
}
- error = st_translate_mesa_program(st->ctx,
- TGSI_PROCESSOR_VERTEX,
- ureg,
- &stvp->Base.Base,
- /* inputs */
- vpv->num_inputs,
- stvp->input_to_index,
- NULL, /* input semantic name */
- NULL, /* input semantic index */
- NULL,
- /* outputs */
- num_outputs,
- stvp->result_to_output,
- stvp->output_semantic_name,
- stvp->output_semantic_index,
- key->passthrough_edgeflags );
+ if (stvp->glsl_to_tgsi)
+ error = st_translate_program(st->ctx,
+ TGSI_PROCESSOR_VERTEX,
+ ureg,
+ stvp->glsl_to_tgsi,
+ &stvp->Base.Base,
+ /* inputs */
+ stvp->num_inputs,
+ stvp->input_to_index,
+ NULL, /* input semantic name */
+ NULL, /* input semantic index */
+ NULL, /* interp mode */
+ /* outputs */
+ stvp->num_outputs,
+ stvp->result_to_output,
+ stvp->output_semantic_name,
+ stvp->output_semantic_index,
+ key->passthrough_edgeflags );
+ else
+ error = st_translate_mesa_program(st->ctx,
+ TGSI_PROCESSOR_VERTEX,
+ ureg,
+ &stvp->Base.Base,
+ /* inputs */
+ vpv->num_inputs,
+ stvp->input_to_index,
+ NULL, /* input semantic name */
+ NULL, /* input semantic index */
+ NULL,
+ /* outputs */
+ num_outputs,
+ stvp->result_to_output,
+ stvp->output_semantic_name,
+ stvp->output_semantic_index,
+ key->passthrough_edgeflags );
if (error)
goto fail;
@@ -393,6 +416,151 @@ st_get_vp_variant(struct st_context *st,
return vpv;
}
+/**
+ * Translate Mesa fragment shader attributes to TGSI attributes.
+ * \return GL_TRUE if color output should be written to all render targets,
+ * GL_FALSE if not
+ */
+GLboolean
+st_prepare_fragment_program(struct gl_context *ctx,
+ struct st_fragment_program *stfp)
+{
+ GLuint attr;
+ const GLbitfield inputsRead = stfp->Base.Base.InputsRead;
+ GLboolean write_all = GL_FALSE;
+
+ /*
+ * Convert Mesa program inputs to TGSI input register semantics.
+ */
+ for (attr = 0; attr < FRAG_ATTRIB_MAX; attr++) {
+ if (inputsRead & (1 << attr)) {
+ const GLuint slot = stfp->num_inputs++;
+
+ stfp->input_to_index[attr] = slot;
+
+ switch (attr) {
+ case FRAG_ATTRIB_WPOS:
+ stfp->input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
+ stfp->input_semantic_index[slot] = 0;
+ stfp->interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ case FRAG_ATTRIB_COL0:
+ stfp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ stfp->input_semantic_index[slot] = 0;
+ stfp->interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ case FRAG_ATTRIB_COL1:
+ stfp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
+ stfp->input_semantic_index[slot] = 1;
+ stfp->interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
+ break;
+ case FRAG_ATTRIB_FOGC:
+ stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+ stfp->input_semantic_index[slot] = 0;
+ stfp->interp_mode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ break;
+ case FRAG_ATTRIB_FACE:
+ stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
+ stfp->input_semantic_index[slot] = 0;
+ stfp->interp_mode[slot] = TGSI_INTERPOLATE_CONSTANT;
+ break;
+ /* In most cases, there is nothing special about these
+ * inputs, so adopt a convention to use the generic
+ * semantic name and the mesa FRAG_ATTRIB_ number as the
+ * index.
+ *
+ * All that is required is that the vertex shader labels
+ * its own outputs similarly, and that the vertex shader
+ * generates at least every output required by the
+ * fragment shader plus fixed-function hardware (such as
+ * BFC).
+ *
+ * There is no requirement that semantic indexes start at
+ * zero or be restricted to a particular range -- nobody
+ * should be building tables based on semantic index.
+ */
+ case FRAG_ATTRIB_PNTC:
+ case FRAG_ATTRIB_TEX0:
+ case FRAG_ATTRIB_TEX1:
+ case FRAG_ATTRIB_TEX2:
+ case FRAG_ATTRIB_TEX3:
+ case FRAG_ATTRIB_TEX4:
+ case FRAG_ATTRIB_TEX5:
+ case FRAG_ATTRIB_TEX6:
+ case FRAG_ATTRIB_TEX7:
+ case FRAG_ATTRIB_VAR0:
+ default:
+ /* Actually, let's try and zero-base this just for
+ * readability of the generated TGSI.
+ */
+ assert(attr >= FRAG_ATTRIB_TEX0);
+ stfp->input_semantic_index[slot] = (attr - FRAG_ATTRIB_TEX0);
+ stfp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+ if (attr == FRAG_ATTRIB_PNTC)
+ stfp->interp_mode[slot] = TGSI_INTERPOLATE_LINEAR;
+ else
+ stfp->interp_mode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+ break;
+ }
+ }
+ else {
+ stfp->input_to_index[attr] = -1;
+ }
+ }
+
+ /*
+ * Semantics and mapping for outputs
+ */
+ {
+ uint numColors = 0;
+ GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten;
+
+ /* if z is written, emit that first */
+ if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
+ stfp->output_semantic_name[stfp->num_outputs] = TGSI_SEMANTIC_POSITION;
+ stfp->output_semantic_index[stfp->num_outputs] = 0;
+ stfp->result_to_output[FRAG_RESULT_DEPTH] = stfp->num_outputs;
+ stfp->num_outputs++;
+ outputsWritten &= ~(1 << FRAG_RESULT_DEPTH);
+ }
+
+ if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_STENCIL)) {
+ stfp->output_semantic_name[stfp->num_outputs] = TGSI_SEMANTIC_STENCIL;
+ stfp->output_semantic_index[stfp->num_outputs] = 0;
+ stfp->result_to_output[FRAG_RESULT_STENCIL] = stfp->num_outputs;
+ stfp->num_outputs++;
+ outputsWritten &= ~(1 << FRAG_RESULT_STENCIL);
+ }
+
+ /* handle remaning outputs (color) */
+ for (attr = 0; attr < FRAG_RESULT_MAX; attr++) {
+ if (outputsWritten & BITFIELD64_BIT(attr)) {
+ switch (attr) {
+ case FRAG_RESULT_DEPTH:
+ case FRAG_RESULT_STENCIL:
+ /* handled above */
+ assert(0);
+ break;
+ case FRAG_RESULT_COLOR:
+ write_all = GL_TRUE; /* fallthrough */
+ default:
+ assert(attr == FRAG_RESULT_COLOR ||
+ (FRAG_RESULT_DATA0 <= attr && attr < FRAG_RESULT_MAX));
+ stfp->output_semantic_name[stfp->num_outputs] = TGSI_SEMANTIC_COLOR;
+ stfp->output_semantic_index[stfp->num_outputs] = numColors;
+ stfp->result_to_output[attr] = stfp->num_outputs;
+ numColors++;
+ break;
+ }
+
+ stfp->num_outputs++;
+ }
+ }
+ }
+
+ return write_all;
+}
+
/**
* Translate a Mesa fragment shader into a TGSI shader using extra info in
@@ -445,154 +613,12 @@ st_translate_fragment_program(struct st_context *st,
if (!stfp->tgsi.tokens) {
/* need to translate Mesa instructions to TGSI now */
- GLuint outputMapping[FRAG_RESULT_MAX];
- GLuint inputMapping[FRAG_ATTRIB_MAX];
- GLuint interpMode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */
- GLuint attr;
enum pipe_error error;
- const GLbitfield inputsRead = stfp->Base.Base.InputsRead;
struct ureg_program *ureg;
- GLboolean write_all = GL_FALSE;
-
- ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
- ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
- uint fs_num_inputs = 0;
-
- ubyte fs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
- ubyte fs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
- uint fs_num_outputs = 0;
-
-
- _mesa_remove_output_reads(&stfp->Base.Base, PROGRAM_OUTPUT);
-
- /*
- * Convert Mesa program inputs to TGSI input register semantics.
- */
- for (attr = 0; attr < FRAG_ATTRIB_MAX; attr++) {
- if (inputsRead & (1 << attr)) {
- const GLuint slot = fs_num_inputs++;
-
- inputMapping[attr] = slot;
-
- switch (attr) {
- case FRAG_ATTRIB_WPOS:
- input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- break;
- case FRAG_ATTRIB_COL0:
- input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- break;
- case FRAG_ATTRIB_COL1:
- input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
- input_semantic_index[slot] = 1;
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- break;
- case FRAG_ATTRIB_FOGC:
- input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
- break;
- case FRAG_ATTRIB_FACE:
- input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
- input_semantic_index[slot] = 0;
- interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
- break;
- /* In most cases, there is nothing special about these
- * inputs, so adopt a convention to use the generic
- * semantic name and the mesa FRAG_ATTRIB_ number as the
- * index.
- *
- * All that is required is that the vertex shader labels
- * its own outputs similarly, and that the vertex shader
- * generates at least every output required by the
- * fragment shader plus fixed-function hardware (such as
- * BFC).
- *
- * There is no requirement that semantic indexes start at
- * zero or be restricted to a particular range -- nobody
- * should be building tables based on semantic index.
- */
- case FRAG_ATTRIB_PNTC:
- case FRAG_ATTRIB_TEX0:
- case FRAG_ATTRIB_TEX1:
- case FRAG_ATTRIB_TEX2:
- case FRAG_ATTRIB_TEX3:
- case FRAG_ATTRIB_TEX4:
- case FRAG_ATTRIB_TEX5:
- case FRAG_ATTRIB_TEX6:
- case FRAG_ATTRIB_TEX7:
- case FRAG_ATTRIB_VAR0:
- default:
- /* Actually, let's try and zero-base this just for
- * readability of the generated TGSI.
- */
- assert(attr >= FRAG_ATTRIB_TEX0);
- input_semantic_index[slot] = (attr - FRAG_ATTRIB_TEX0);
- input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
- if (attr == FRAG_ATTRIB_PNTC)
- interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
- else
- interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
- break;
- }
- }
- else {
- inputMapping[attr] = -1;
- }
- }
-
- /*
- * Semantics and mapping for outputs
- */
- {
- uint numColors = 0;
- GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten;
-
- /* if z is written, emit that first */
- if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
- fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_POSITION;
- fs_output_semantic_index[fs_num_outputs] = 0;
- outputMapping[FRAG_RESULT_DEPTH] = fs_num_outputs;
- fs_num_outputs++;
- outputsWritten &= ~(1 << FRAG_RESULT_DEPTH);
- }
-
- if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_STENCIL)) {
- fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_STENCIL;
- fs_output_semantic_index[fs_num_outputs] = 0;
- outputMapping[FRAG_RESULT_STENCIL] = fs_num_outputs;
- fs_num_outputs++;
- outputsWritten &= ~(1 << FRAG_RESULT_STENCIL);
- }
-
- /* handle remaning outputs (color) */
- for (attr = 0; attr < FRAG_RESULT_MAX; attr++) {
- if (outputsWritten & BITFIELD64_BIT(attr)) {
- switch (attr) {
- case FRAG_RESULT_DEPTH:
- case FRAG_RESULT_STENCIL:
- /* handled above */
- assert(0);
- break;
- case FRAG_RESULT_COLOR:
- write_all = GL_TRUE; /* fallthrough */
- default:
- assert(attr == FRAG_RESULT_COLOR ||
- (FRAG_RESULT_DATA0 <= attr && attr < FRAG_RESULT_MAX));
- fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_COLOR;
- fs_output_semantic_index[fs_num_outputs] = numColors;
- outputMapping[attr] = fs_num_outputs;
- numColors++;
- break;
- }
-
- fs_num_outputs++;
- }
- }
- }
+ GLboolean write_all = st_prepare_fragment_program(st->ctx, stfp);
+
+ if (!stfp->glsl_to_tgsi)
+ _mesa_remove_output_reads(&stfp->Base.Base, PROGRAM_OUTPUT);
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
@@ -606,21 +632,39 @@ st_translate_fragment_program(struct st_context *st,
if (write_all == GL_TRUE)
ureg_property_fs_color0_writes_all_cbufs(ureg, 1);
- error = st_translate_mesa_program(st->ctx,
- TGSI_PROCESSOR_FRAGMENT,
- ureg,
- &stfp->Base.Base,
- /* inputs */
- fs_num_inputs,
- inputMapping,
- input_semantic_name,
- input_semantic_index,
- interpMode,
- /* outputs */
- fs_num_outputs,
- outputMapping,
- fs_output_semantic_name,
- fs_output_semantic_index, FALSE );
+ if (stfp->glsl_to_tgsi)
+ error = st_translate_program(st->ctx,
+ TGSI_PROCESSOR_FRAGMENT,
+ ureg,
+ stfp->glsl_to_tgsi,
+ &stfp->Base.Base,
+ /* inputs */
+ stfp->num_inputs,
+ stfp->input_to_index,
+ stfp->input_semantic_name,
+ stfp->input_semantic_index,
+ stfp->interp_mode,
+ /* outputs */
+ stfp->num_outputs,
+ stfp->result_to_output,
+ stfp->output_semantic_name,
+ stfp->output_semantic_index, FALSE );
+ else
+ error = st_translate_mesa_program(st->ctx,
+ TGSI_PROCESSOR_FRAGMENT,
+ ureg,
+ &stfp->Base.Base,
+ /* inputs */
+ stfp->num_inputs,
+ stfp->input_to_index,
+ stfp->input_semantic_name,
+ stfp->input_semantic_index,
+ stfp->interp_mode,
+ /* outputs */
+ stfp->num_outputs,
+ stfp->result_to_output,
+ stfp->output_semantic_name,
+ stfp->output_semantic_index, FALSE );
stfp->tgsi.tokens = ureg_get_tokens( ureg, NULL );
ureg_destroy( ureg );
View
27 src/mesa/state_tracker/st_program.h
@@ -38,6 +38,7 @@
#include "program/program.h"
#include "pipe/p_state.h"
#include "st_context.h"
+#include "st_glsl_to_tgsi.h"
/** Fragment program variant key */
@@ -83,6 +84,22 @@ struct st_fp_variant
struct st_fragment_program
{
struct gl_fragment_program Base;
+ struct glsl_to_tgsi_visitor* glsl_to_tgsi;
+
+ /** maps a Mesa FRAG_ATTRIB_x to a packed TGSI input index */
+ GLuint input_to_index[FRAG_ATTRIB_MAX];
+ /** maps a TGSI input index back to a Mesa FRAG_ATTRIB_x */
+ GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
+ ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
+ ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
+ GLuint num_inputs;
+ GLuint interp_mode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */
+
+ /** Maps FRAG_RESULT_x to slot */
+ GLuint result_to_output[FRAG_RESULT_MAX];
+ ubyte output_semantic_name[FRAG_RESULT_MAX];
+ ubyte output_semantic_index[FRAG_RESULT_MAX];
+ GLuint num_outputs;
struct pipe_shader_state tgsi;
@@ -136,6 +153,7 @@ struct st_vp_variant
struct st_vertex_program
{
struct gl_vertex_program Base; /**< The Mesa vertex program */
+ struct glsl_to_tgsi_visitor* glsl_to_tgsi;
/** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
GLuint input_to_index[VERT_ATTRIB_MAX];
@@ -184,6 +202,7 @@ struct st_gp_variant
struct st_geometry_program
{
struct gl_geometry_program Base; /**< The Mesa geometry program */
+ struct glsl_to_tgsi_visitor* glsl_to_tgsi;
/** map GP input back to VP output */
GLuint input_map[PIPE_MAX_SHADER_INPUTS];
@@ -276,6 +295,14 @@ st_get_gp_variant(struct st_context *st,
const struct st_gp_variant_key *key);
+extern void
+st_prepare_vertex_program(struct gl_context *ctx,
+ struct st_vertex_program *stvp);
+
+extern GLboolean
+st_prepare_fragment_program(struct gl_context *ctx,
+ struct st_fragment_program *stfp);
+
extern void
st_release_vp_variants( struct st_context *st,

Showing you all comments on commits in this comparison.

@chrisbmr

I'd like to note that it would be useful to keep an eye on the possibility of putting temporary arrays into TGSI_FILE_TEMPORARY_ARRAY (with a separate declaration for each array) instead of TGSI_FILE_TEMPORARY, this would help a lot with optimization of indirect array access in the backends.

@Plombo

Sure, I'll be sure to keep an eye on it.

Something went wrong with that request. Please try again.