Merge branch 'glsl-to-tgsi'
Conflicts: src/mesa/state_tracker/st_atom_pixeltransfer.c src/mesa/state_tracker/st_program.c
This commit is contained in:
@@ -2988,6 +2988,17 @@ micro_xor(union tgsi_exec_channel *dst,
|
||||
dst->u[3] = src0->u[3] ^ src1->u[3];
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -3691,7 +3702,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:
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -221,6 +221,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: Unknown cap %u.\n", __FUNCTION__, cap);
|
||||
return 0;
|
||||
|
@@ -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;
|
||||
|
@@ -183,6 +183,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;
|
||||
|
@@ -170,6 +170,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;
|
||||
|
@@ -179,6 +179,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;
|
||||
}
|
||||
|
@@ -258,6 +258,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;
|
||||
}
|
||||
|
@@ -468,6 +468,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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -495,6 +495,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,
|
||||
};
|
||||
|
||||
|
||||
|
@@ -617,7 +617,7 @@ fs_visitor::setup_paramvalues_refs()
|
||||
/* Set up the pointers to ParamValues now that that array is finalized. */
|
||||
for (unsigned int i = 0; i < c->prog_data.nr_params; i++) {
|
||||
c->prog_data.param[i] =
|
||||
fp->Base.Parameters->ParameterValues[this->param_index[i]] +
|
||||
(const float *)fp->Base.Parameters->ParameterValues[this->param_index[i]] +
|
||||
this->param_offset[i];
|
||||
}
|
||||
}
|
||||
|
@@ -1359,7 +1359,7 @@ get_src_reg( struct brw_vs_compile *c,
|
||||
|
||||
if (component >= 0) {
|
||||
params = c->vp->program.Base.Parameters;
|
||||
f = params->ParameterValues[src->Index][component];
|
||||
f = params->ParameterValues[src->Index][component].f;
|
||||
|
||||
if (src->Abs)
|
||||
f = fabs(f);
|
||||
|
@@ -126,10 +126,10 @@ static GLboolean r200VertexProgUpdateParams(struct gl_context *ctx, struct r200_
|
||||
case PROGRAM_NAMED_PARAM:
|
||||
//fprintf(stderr, "%s", vp->Parameters->Parameters[pi].Name);
|
||||
case PROGRAM_CONSTANT:
|
||||
*fcmd++ = paramList->ParameterValues[pi][0];
|
||||
*fcmd++ = paramList->ParameterValues[pi][1];
|
||||
*fcmd++ = paramList->ParameterValues[pi][2];
|
||||
*fcmd++ = paramList->ParameterValues[pi][3];
|
||||
*fcmd++ = paramList->ParameterValues[pi][0].f;
|
||||
*fcmd++ = paramList->ParameterValues[pi][1].f;
|
||||
*fcmd++ = paramList->ParameterValues[pi][2].f;
|
||||
*fcmd++ = paramList->ParameterValues[pi][3].f;
|
||||
break;
|
||||
default:
|
||||
_mesa_problem(NULL, "Bad param type in %s", __FUNCTION__);
|
||||
|
@@ -752,10 +752,10 @@ GLboolean evergreenSetupFPconstants(struct gl_context * ctx)
|
||||
unNumParamData = paramList->NumParameters;
|
||||
|
||||
for(ui=0; ui<unNumParamData; ui++) {
|
||||
evergreen->ps.consts[ui][0].f32All = paramList->ParameterValues[ui][0];
|
||||
evergreen->ps.consts[ui][1].f32All = paramList->ParameterValues[ui][1];
|
||||
evergreen->ps.consts[ui][2].f32All = paramList->ParameterValues[ui][2];
|
||||
evergreen->ps.consts[ui][3].f32All = paramList->ParameterValues[ui][3];
|
||||
evergreen->ps.consts[ui][0].f32All = paramList->ParameterValues[ui][0].f;
|
||||
evergreen->ps.consts[ui][1].f32All = paramList->ParameterValues[ui][1].f;
|
||||
evergreen->ps.consts[ui][2].f32All = paramList->ParameterValues[ui][2].f;
|
||||
evergreen->ps.consts[ui][3].f32All = paramList->ParameterValues[ui][3].f;
|
||||
}
|
||||
|
||||
/* alloc multiple of 16 constants */
|
||||
|
@@ -684,17 +684,17 @@ GLboolean evergreenSetupVPconstants(struct gl_context * ctx)
|
||||
for(ui=0; ui<unNumParamData; ui++) {
|
||||
if(paramList->Parameters[ui].Type == PROGRAM_UNIFORM)
|
||||
{
|
||||
evergreen->vs.consts[ui][0].f32All = paramListOrginal->ParameterValues[ui][0];
|
||||
evergreen->vs.consts[ui][1].f32All = paramListOrginal->ParameterValues[ui][1];
|
||||
evergreen->vs.consts[ui][2].f32All = paramListOrginal->ParameterValues[ui][2];
|
||||
evergreen->vs.consts[ui][3].f32All = paramListOrginal->ParameterValues[ui][3];
|
||||
evergreen->vs.consts[ui][0].f32All = paramListOrginal->ParameterValues[ui][0].f;
|
||||
evergreen->vs.consts[ui][1].f32All = paramListOrginal->ParameterValues[ui][1].f;
|
||||
evergreen->vs.consts[ui][2].f32All = paramListOrginal->ParameterValues[ui][2].f;
|
||||
evergreen->vs.consts[ui][3].f32All = paramListOrginal->ParameterValues[ui][3].f;
|
||||
}
|
||||
else
|
||||
{
|
||||
evergreen->vs.consts[ui][0].f32All = paramList->ParameterValues[ui][0];
|
||||
evergreen->vs.consts[ui][1].f32All = paramList->ParameterValues[ui][1];
|
||||
evergreen->vs.consts[ui][2].f32All = paramList->ParameterValues[ui][2];
|
||||
evergreen->vs.consts[ui][3].f32All = paramList->ParameterValues[ui][3];
|
||||
evergreen->vs.consts[ui][0].f32All = paramList->ParameterValues[ui][0].f;
|
||||
evergreen->vs.consts[ui][1].f32All = paramList->ParameterValues[ui][1].f;
|
||||
evergreen->vs.consts[ui][2].f32All = paramList->ParameterValues[ui][2].f;
|
||||
evergreen->vs.consts[ui][3].f32All = paramList->ParameterValues[ui][3].f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -778,10 +778,10 @@ GLboolean r700SetupFragmentProgram(struct gl_context * ctx)
|
||||
unNumParamData = paramList->NumParameters;
|
||||
|
||||
for(ui=0; ui<unNumParamData; ui++) {
|
||||
r700->ps.consts[ui][0].f32All = paramList->ParameterValues[ui][0];
|
||||
r700->ps.consts[ui][1].f32All = paramList->ParameterValues[ui][1];
|
||||
r700->ps.consts[ui][2].f32All = paramList->ParameterValues[ui][2];
|
||||
r700->ps.consts[ui][3].f32All = paramList->ParameterValues[ui][3];
|
||||
r700->ps.consts[ui][0].f32All = paramList->ParameterValues[ui][0].f;
|
||||
r700->ps.consts[ui][1].f32All = paramList->ParameterValues[ui][1].f;
|
||||
r700->ps.consts[ui][2].f32All = paramList->ParameterValues[ui][2].f;
|
||||
r700->ps.consts[ui][3].f32All = paramList->ParameterValues[ui][3].f;
|
||||
}
|
||||
|
||||
/* Load fp constants to gpu */
|
||||
|
@@ -720,17 +720,17 @@ GLboolean r700SetupVertexProgram(struct gl_context * ctx)
|
||||
for(ui=0; ui<unNumParamData; ui++) {
|
||||
if(paramList->Parameters[ui].Type == PROGRAM_UNIFORM)
|
||||
{
|
||||
r700->vs.consts[ui][0].f32All = paramListOrginal->ParameterValues[ui][0];
|
||||
r700->vs.consts[ui][1].f32All = paramListOrginal->ParameterValues[ui][1];
|
||||
r700->vs.consts[ui][2].f32All = paramListOrginal->ParameterValues[ui][2];
|
||||
r700->vs.consts[ui][3].f32All = paramListOrginal->ParameterValues[ui][3];
|
||||
r700->vs.consts[ui][0].f32All = paramListOrginal->ParameterValues[ui][0].f;
|
||||
r700->vs.consts[ui][1].f32All = paramListOrginal->ParameterValues[ui][1].f;
|
||||
r700->vs.consts[ui][2].f32All = paramListOrginal->ParameterValues[ui][2].f;
|
||||
r700->vs.consts[ui][3].f32All = paramListOrginal->ParameterValues[ui][3].f;
|
||||
}
|
||||
else
|
||||
{
|
||||
r700->vs.consts[ui][0].f32All = paramList->ParameterValues[ui][0];
|
||||
r700->vs.consts[ui][1].f32All = paramList->ParameterValues[ui][1];
|
||||
r700->vs.consts[ui][2].f32All = paramList->ParameterValues[ui][2];
|
||||
r700->vs.consts[ui][3].f32All = paramList->ParameterValues[ui][3];
|
||||
r700->vs.consts[ui][0].f32All = paramList->ParameterValues[ui][0].f;
|
||||
r700->vs.consts[ui][1].f32All = paramList->ParameterValues[ui][1].f;
|
||||
r700->vs.consts[ui][2].f32All = paramList->ParameterValues[ui][2].f;
|
||||
r700->vs.consts[ui][3].f32All = paramList->ParameterValues[ui][3].f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -874,7 +874,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;
|
||||
|
@@ -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);
|
||||
|
@@ -429,7 +429,7 @@ get_uniform(struct gl_context *ctx, GLuint program, GLint location,
|
||||
for (i = 0; i < rows; i++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -442,7 +442,7 @@ get_uniform(struct gl_context *ctx, GLuint program, GLint location,
|
||||
const int base = paramPos + offset + i;
|
||||
for (j = 0; j < cols; j++ ) {
|
||||
params[k++] = (GLdouble)
|
||||
prog->Parameters->ParameterValues[base][j];
|
||||
prog->Parameters->ParameterValues[base][j].f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -454,8 +454,9 @@ get_uniform(struct gl_context *ctx, GLuint program, GLint location,
|
||||
for (i = 0; i < rows; i++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -467,8 +468,9 @@ get_uniform(struct gl_context *ctx, GLuint program, GLint location,
|
||||
for (i = 0; i < rows; i++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -670,7 +672,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];
|
||||
program->Parameters->ParameterValues[index+offset + i][0].f;
|
||||
GLuint texUnit = ((GLuint *) values)[i];
|
||||
|
||||
/* check that the sampler (tex unit index) is legal */
|
||||
@@ -735,42 +737,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -936,7 +948,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];
|
||||
|
@@ -585,7 +585,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;
|
||||
}
|
||||
@@ -1795,7 +1795,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);
|
||||
@@ -1833,7 +1833,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);
|
||||
}
|
||||
@@ -2533,7 +2533,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
|
||||
|
@@ -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;
|
||||
|
@@ -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));
|
||||
|
@@ -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;
|
||||
@@ -284,6 +286,28 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -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;
|
||||
|
@@ -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
|
||||
|
@@ -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 =
|
||||
|
@@ -985,7 +985,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),
|
||||
|
@@ -388,8 +388,9 @@ _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog)
|
||||
if (prog->String)
|
||||
free(prog->String);
|
||||
|
||||
if (prog->Instructions) {
|
||||
_mesa_free_instructions(prog->Instructions, prog->NumInstructions);
|
||||
|
||||
}
|
||||
if (prog->Parameters) {
|
||||
_mesa_free_parameter_list(prog->Parameters);
|
||||
}
|
||||
@@ -1031,7 +1032,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;
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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 = \
|
||||
|
@@ -84,26 +84,6 @@ make_state_key(struct gl_context *ctx, struct state_key *key)
|
||||
}
|
||||
|
||||
|
||||
static struct pipe_resource *
|
||||
create_color_map_texture(struct gl_context *ctx)
|
||||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct pipe_context *pipe = st->pipe;
|
||||
struct pipe_resource *pt;
|
||||
enum pipe_format format;
|
||||
const uint texSize = 256; /* simple, and usually perfect */
|
||||
|
||||
/* find an RGBA texture format */
|
||||
format = st_choose_format(pipe->screen, GL_RGBA, GL_NONE, GL_NONE,
|
||||
PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
|
||||
|
||||
/* create texture for color map/table */
|
||||
pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
|
||||
texSize, texSize, 1, 1, PIPE_BIND_SAMPLER_VIEW);
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the pixelmap texture with the contents of the R/G/B/A pixel maps.
|
||||
*/
|
||||
@@ -219,7 +199,7 @@ get_pixel_transfer_program(struct gl_context *ctx, const struct state_key *key)
|
||||
|
||||
/* create the colormap/texture now if not already done */
|
||||
if (!st->pixel_xfer.pixelmap_texture) {
|
||||
st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx);
|
||||
st->pixel_xfer.pixelmap_texture = st_create_color_map_texture(ctx);
|
||||
st->pixel_xfer.pixelmap_sampler_view =
|
||||
st_create_texture_sampler_view(st->pipe,
|
||||
st->pixel_xfer.pixelmap_texture);
|
||||
|
@@ -172,6 +172,23 @@ make_bitmap_fragment_program(struct gl_context *ctx, GLuint samplerIndex)
|
||||
}
|
||||
|
||||
|
||||
static struct gl_program *
|
||||
make_bitmap_fragment_program_glsl(struct st_context *st,
|
||||
struct st_fragment_program *orig,
|
||||
GLuint samplerIndex)
|
||||
{
|
||||
struct gl_context *ctx = st->ctx;
|
||||
struct st_fragment_program *fp = (struct st_fragment_program *)
|
||||
ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
|
||||
|
||||
if (!fp)
|
||||
return NULL;
|
||||
|
||||
get_bitmap_visitor(fp, orig->glsl_to_tgsi, samplerIndex);
|
||||
return &fp->Base.Base;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
find_free_bit(uint bitfield)
|
||||
{
|
||||
@@ -199,6 +216,7 @@ st_make_bitmap_fragment_program(struct st_context *st,
|
||||
GLuint *bitmap_sampler)
|
||||
{
|
||||
struct st_fragment_program *bitmap_prog;
|
||||
struct st_fragment_program *stfpIn = (struct st_fragment_program *) fpIn;
|
||||
struct gl_program *newProg;
|
||||
uint sampler;
|
||||
|
||||
@@ -207,6 +225,10 @@ st_make_bitmap_fragment_program(struct st_context *st,
|
||||
* with the bitmap sampler/kill instructions.
|
||||
*/
|
||||
sampler = find_free_bit(fpIn->Base.SamplersUsed);
|
||||
|
||||
if (stfpIn->glsl_to_tgsi)
|
||||
newProg = make_bitmap_fragment_program_glsl(st, stfpIn, sampler);
|
||||
else {
|
||||
bitmap_prog = make_bitmap_fragment_program(st->ctx, sampler);
|
||||
|
||||
newProg = _mesa_combine_programs(st->ctx,
|
||||
@@ -214,6 +236,7 @@ st_make_bitmap_fragment_program(struct st_context *st,
|
||||
&fpIn->Base);
|
||||
/* done with this after combining */
|
||||
st_reference_fragprog(st, &bitmap_prog, NULL);
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
|
@@ -94,6 +94,46 @@ is_passthrough_program(const struct gl_fragment_program *prog)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a fragment program which implements the current pixel transfer ops.
|
||||
*/
|
||||
static struct gl_fragment_program *
|
||||
get_glsl_pixel_transfer_program(struct st_context *st,
|
||||
struct st_fragment_program *orig)
|
||||
{
|
||||
int pixelMaps = 0, scaleAndBias = 0;
|
||||
struct gl_context *ctx = st->ctx;
|
||||
struct st_fragment_program *fp = (struct st_fragment_program *)
|
||||
ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
|
||||
|
||||
if (!fp)
|
||||
return NULL;
|
||||
|
||||
if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 ||
|
||||
ctx->Pixel.GreenBias != 0.0 || ctx->Pixel.GreenScale != 1.0 ||
|
||||
ctx->Pixel.BlueBias != 0.0 || ctx->Pixel.BlueScale != 1.0 ||
|
||||
ctx->Pixel.AlphaBias != 0.0 || ctx->Pixel.AlphaScale != 1.0) {
|
||||
scaleAndBias = 1;
|
||||
}
|
||||
|
||||
pixelMaps = ctx->Pixel.MapColorFlag;
|
||||
|
||||
if (pixelMaps) {
|
||||
/* create the colormap/texture now if not already done */
|
||||
if (!st->pixel_xfer.pixelmap_texture) {
|
||||
st->pixel_xfer.pixelmap_texture = st_create_color_map_texture(ctx);
|
||||
st->pixel_xfer.pixelmap_sampler_view =
|
||||
st_create_texture_sampler_view(st->pipe,
|
||||
st->pixel_xfer.pixelmap_texture);
|
||||
}
|
||||
}
|
||||
|
||||
get_pixel_transfer_visitor(fp, orig->glsl_to_tgsi,
|
||||
scaleAndBias, pixelMaps);
|
||||
|
||||
return &fp->Base;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make fragment shader for glDraw/CopyPixels. This shader is made
|
||||
@@ -107,11 +147,15 @@ st_make_drawpix_fragment_program(struct st_context *st,
|
||||
struct gl_fragment_program **fpOut)
|
||||
{
|
||||
struct gl_program *newProg;
|
||||
struct st_fragment_program *stfp = (struct st_fragment_program *) fpIn;
|
||||
|
||||
if (is_passthrough_program(fpIn)) {
|
||||
newProg = (struct gl_program *) _mesa_clone_fragment_program(st->ctx,
|
||||
&st->pixel_xfer.program->Base);
|
||||
}
|
||||
else if (stfp->glsl_to_tgsi != NULL) {
|
||||
newProg = (struct gl_program *) get_glsl_pixel_transfer_program(st, stfp);
|
||||
}
|
||||
else {
|
||||
#if 0
|
||||
/* debug */
|
||||
|
@@ -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:
|
||||
@@ -138,6 +142,9 @@ st_delete_program(struct gl_context *ctx, struct gl_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);
|
||||
stgp->tgsi.tokens = NULL;
|
||||
@@ -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;
|
||||
}
|
||||
|
4962
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
Normal file
4962
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
72
src/mesa/state_tracker/st_glsl_to_tgsi.h
Normal file
72
src/mesa/state_tracker/st_glsl_to_tgsi.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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);
|
||||
void get_pixel_transfer_visitor(struct st_fragment_program *fp,
|
||||
struct glsl_to_tgsi_visitor *original,
|
||||
int scale_and_bias, int pixel_maps);
|
||||
void get_bitmap_visitor(struct st_fragment_program *fp,
|
||||
struct glsl_to_tgsi_visitor *original,
|
||||
int samplerIndex);
|
||||
|
||||
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
|
@@ -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 ) {
|
||||
@@ -1207,7 +1207,7 @@ st_translate_mesa_program(
|
||||
else
|
||||
t->constants[i] =
|
||||
ureg_DECL_immediate( ureg,
|
||||
program->Parameters->ParameterValues[i],
|
||||
(const float*) program->Parameters->ParameterValues[i],
|
||||
4 );
|
||||
break;
|
||||
default:
|
||||
|
@@ -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" */
|
||||
|
@@ -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,8 +184,9 @@ 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);
|
||||
|
||||
if (!stvp->glsl_to_tgsi)
|
||||
assert(stvp->Base.Base.NumInstructions > 1);
|
||||
|
||||
/*
|
||||
@@ -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);
|
||||
|
||||
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,6 +322,25 @@ st_translate_vertex_program(struct st_context *st,
|
||||
debug_printf("\n");
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -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;
|
||||
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;
|
||||
|
||||
GLboolean write_all = st_prepare_fragment_program(st->ctx, stfp);
|
||||
|
||||
if (!stfp->glsl_to_tgsi)
|
||||
_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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
|
||||
if (ureg == NULL)
|
||||
return NULL;
|
||||
@@ -605,21 +631,39 @@ st_translate_fragment_program(struct st_context *st,
|
||||
if (write_all == GL_TRUE)
|
||||
ureg_property_fs_color0_writes_all_cbufs(ureg, 1);
|
||||
|
||||
if (stfp->glsl_to_tgsi)
|
||||
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
|
||||
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,
|
||||
stfp->num_inputs,
|
||||
stfp->input_to_index,
|
||||
stfp->input_semantic_name,
|
||||
stfp->input_semantic_index,
|
||||
stfp->interp_mode,
|
||||
/* outputs */
|
||||
fs_num_outputs,
|
||||
outputMapping,
|
||||
fs_output_semantic_name,
|
||||
fs_output_semantic_index, FALSE );
|
||||
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 );
|
||||
|
@@ -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,
|
||||
|
@@ -396,3 +396,23 @@ st_texture_image_copy(struct pipe_context *pipe,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct pipe_resource *
|
||||
st_create_color_map_texture(struct gl_context *ctx)
|
||||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct pipe_context *pipe = st->pipe;
|
||||
struct pipe_resource *pt;
|
||||
enum pipe_format format;
|
||||
const uint texSize = 256; /* simple, and usually perfect */
|
||||
|
||||
/* find an RGBA texture format */
|
||||
format = st_choose_format(pipe->screen, GL_RGBA, GL_NONE, GL_NONE,
|
||||
PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW);
|
||||
|
||||
/* create texture for color map/table */
|
||||
pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0,
|
||||
texSize, texSize, 1, 1, PIPE_BIND_SAMPLER_VIEW);
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
@@ -232,4 +232,8 @@ st_texture_image_copy(struct pipe_context *pipe,
|
||||
struct pipe_resource *src, GLuint srcLevel,
|
||||
GLuint face);
|
||||
|
||||
|
||||
extern struct pipe_resource *
|
||||
st_create_color_map_texture(struct gl_context *ctx);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user