mesa: Branch 'glsl-compiler-1' - 4 commits
Brian Paul
brianp at kemper.freedesktop.org
Thu Mar 22 15:15:47 UTC 2007
src/mesa/shader/nvfragparse.c | 11 ++--
src/mesa/shader/nvvertparse.c | 3 -
src/mesa/shader/prog_parameter.c | 92 ++++++++++++++++++++++---------------
src/mesa/shader/prog_print.c | 6 ++
src/mesa/shader/program.c | 4 -
src/mesa/shader/programopt.c | 3 -
src/mesa/shader/slang/slang_emit.c | 37 +++++++++++---
src/mesa/shader/slang/slang_link.c | 4 -
8 files changed, 100 insertions(+), 60 deletions(-)
New commits:
diff-tree 0aad9e262784b0f2ac85afdce88414c986dae2f7 (from 12229f119d754715e0315846fdd8d6e9213e8edf)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 22 09:15:39 2007 -0600
First pass at implementing structure compares.
Need to improve this. There may be holes in a structure so we can't
just blindly compare the full 4-float registers.
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index e578c82..bc08104 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -778,25 +778,48 @@ static struct prog_instruction *
emit_compare(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct prog_instruction *inst;
+ gl_inst_opcode opcode;
assert(n->Opcode == IR_SEQUAL || n->Opcode == IR_SNEQUAL);
+ opcode = n->Opcode == IR_SEQUAL ? OPCODE_SEQ : OPCODE_SNE;
+
/* gen code for children */
emit(emitInfo, n->Children[0]);
emit(emitInfo, n->Children[1]);
assert(n->Children[0]->Store->Size == n->Children[1]->Store->Size);
- /* gen this instruction and src registers */
- inst = new_instruction(emitInfo,
- (n->Opcode == IR_SEQUAL) ? OPCODE_SEQ : OPCODE_SNE);
+ if (!n->Store) {
+ if (!alloc_temp_storage(emitInfo, n, 1)) /* 1 bool */
+ return NULL;
+ }
+
if (n->Children[0]->Store->Size > 4) {
/* struct compare */
- _mesa_problem(NULL, "struct compare not implemented!");
- return NULL;
+ GLint i, num = (n->Children[0]->Store->Size + 3) / 4;
+
+ /*printf("BEGIN COMPARE size %d\n", num);*/
+ for (i = 0; i < num; i++) {
+ inst = new_instruction(emitInfo, opcode);
+ inst->SrcReg[0].File = n->Children[0]->Store->File;
+ inst->SrcReg[0].Index = n->Children[0]->Store->Index + i;
+ inst->SrcReg[1].File = n->Children[1]->Store->File;
+ inst->SrcReg[1].Index = n->Children[1]->Store->Index + i;
+ inst->DstReg.File = n->Store->File;
+ inst->DstReg.Index = n->Store->Index;
+ if (i == 0) {
+ inst->CondUpdate = 1; /* update cond code */
+ }
+ else {
+ inst->DstReg.CondMask = COND_NE; /* update if !=0 */
+ }
+ /*_mesa_print_instruction(inst);*/
+ }
}
else {
/* small/simple types */
+ inst = new_instruction(emitInfo, opcode);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
storage_to_src_reg(&inst->SrcReg[1], n->Children[1]->Store);
}
@@ -806,10 +829,6 @@ emit_compare(slang_emit_info *emitInfo,
free_temp_storage(emitInfo->vt, n->Children[1]);
/* result storage */
- if (!n->Store) {
- if (!alloc_temp_storage(emitInfo, n, 1)) /* 1 bool */
- return NULL;
- }
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
return inst;
diff-tree 12229f119d754715e0315846fdd8d6e9213e8edf (from 1bf81e3c5d65b636658d11072f4f027f5c499396)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 22 09:11:26 2007 -0600
use _mesa_copy_instructions()
diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c
index c46d8aa..ffa7ba4 100644
--- a/src/mesa/shader/nvfragparse.c
+++ b/src/mesa/shader/nvfragparse.c
@@ -1545,8 +1545,7 @@ _mesa_parse_nv_fragment_program(GLcontex
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
return; /* out of memory */
}
- _mesa_memcpy(newInst, instBuffer,
- parseState.numInst * sizeof(struct prog_instruction));
+ _mesa_copy_instructions(newInst, instBuffer, parseState.numInst);
/* install the program */
program->Base.Target = target;
diff --git a/src/mesa/shader/nvvertparse.c b/src/mesa/shader/nvvertparse.c
index 0bc0c05..ac96d4a 100644
--- a/src/mesa/shader/nvvertparse.c
+++ b/src/mesa/shader/nvvertparse.c
@@ -1378,8 +1378,7 @@ _mesa_parse_nv_vertex_program(GLcontext
_mesa_free(programString);
return; /* out of memory */
}
- _mesa_memcpy(newInst, instBuffer,
- parseState.numInst * sizeof(struct prog_instruction));
+ _mesa_copy_instructions(newInst, instBuffer, parseState.numInst);
/* install the program */
program->Base.Target = target;
diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index ae26c3c..c1606ac 100644
--- a/src/mesa/shader/program.c
+++ b/src/mesa/shader/program.c
@@ -342,8 +342,8 @@ _mesa_clone_program(GLcontext *ctx, cons
_mesa_delete_program(ctx, clone);
return NULL;
}
- memcpy(clone->Instructions, prog->Instructions,
- prog->NumInstructions * sizeof(struct prog_instruction));
+ _mesa_copy_instructions(clone->Instructions, prog->Instructions,
+ prog->NumInstructions);
clone->InputsRead = prog->InputsRead;
clone->OutputsWritten = prog->OutputsWritten;
memcpy(clone->TexturesUsed, prog->TexturesUsed, sizeof(prog->TexturesUsed));
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index d427ee3..f1d8ce3 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -150,8 +150,7 @@ _mesa_append_fog_code(GLcontext *ctx, st
}
/* Copy orig instructions into new instruction buffer */
- _mesa_memcpy(newInst, fprog->Base.Instructions,
- origLen * sizeof(struct prog_instruction));
+ _mesa_copy_instructions(newInst, fprog->Base.Instructions, origLen);
/* PARAM fogParamsRefOpt = internal optimized fog params; */
fogPRefOpt
diff-tree 1bf81e3c5d65b636658d11072f4f027f5c499396 (from 1936b25ebd580c5ef9e8cb471a986da39ef46ca5)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 22 09:07:27 2007 -0600
In _mesa_add_unnamed_constant() and _mesa_lookup_parameter_constant() allow swizzleOut==NULL.
There are times when we don't want to allow swizzling when searching for or
adding vector constants. Passing NULL for swizzleOut disables swizzling.
This fixes a constant/swizzle bug in link_uniform_vars().
diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c
index b4e19ce..c46d8aa 100644
--- a/src/mesa/shader/nvfragparse.c
+++ b/src/mesa/shader/nvfragparse.c
@@ -1040,7 +1040,7 @@ Parse_VectorSrc(struct parse_state *pars
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, &swizzle);
+ values, 4, NULL);
ASSERT(swizzle == SWIZZLE_NOOP);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
@@ -1053,7 +1053,7 @@ Parse_VectorSrc(struct parse_state *pars
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, &swizzle);
+ values, 4, NULL);
ASSERT(swizzle == SWIZZLE_NOOP);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
@@ -1145,7 +1145,7 @@ Parse_ScalarSrcReg(struct parse_state *p
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, &swizzle);
+ values, 4, NULL);
ASSERT(swizzle == SWIZZLE_NOOP);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
@@ -1171,7 +1171,7 @@ Parse_ScalarSrcReg(struct parse_state *p
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
paramIndex = _mesa_add_unnamed_constant(parseState->parameters,
- values, 4, &swizzle);
+ values, 4, NULL);
ASSERT(swizzle == SWIZZLE_NOOP);
srcReg->Index = paramIndex;
srcReg->File = PROGRAM_NAMED_PARAM;
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index 4633015..adffafd 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -192,9 +192,12 @@ _mesa_add_named_constant(struct gl_progr
/**
- * Add a new unnamed constant to the parameter list.
- * This will be used when the program contains something like this:
+ * 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 };
+ * We'll search the parameter list for an existing instance of the
+ * constant. If swizzleOut is non-null, we'll try swizzling when
+ * looking for a match.
*
* \param paramList the parameter list
* \param values four float values
@@ -219,7 +222,7 @@ _mesa_add_unnamed_constant(struct gl_pro
* to add this constant. This will only work for single-element
* constants because we rely on smearing (i.e. .yyyy or .zzzz).
*/
- if (size == 1) {
+ if (size == 1 && swizzleOut) {
for (pos = 0; pos < (GLint) paramList->NumParameters; pos++) {
struct gl_program_parameter *p = paramList->Parameters + pos;
if (p->Type == PROGRAM_CONSTANT && p->Size + size <= 4) {
@@ -237,10 +240,9 @@ _mesa_add_unnamed_constant(struct gl_pro
/* add a new parameter to store this constant */
pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
size, values, NULL);
- if (pos >= 0) {
+ if (pos >= 0 && swizzleOut) {
if (size == 1)
- *swizzleOut = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X,
- SWIZZLE_X, SWIZZLE_X);
+ *swizzleOut = SWIZZLE_XXXX;
else
*swizzleOut = SWIZZLE_NOOP;
}
@@ -460,13 +462,14 @@ _mesa_lookup_parameter_index(const struc
/**
* Look for a float vector in the given parameter list. The float vector
- * may be of length 1, 2, 3 or 4.
+ * may be of length 1, 2, 3 or 4. If swizzleOut is non-null, we'll try
+ * swizzling to find a match.
* \param list the parameter list to search
* \param v the float vector to search for
* \param size number of element in v
* \param posOut returns the position of the constant, if found
* \param swizzleOut returns a swizzle mask describing location of the
- * vector elements if found
+ * vector elements if found.
* \return GL_TRUE if found, GL_FALSE if not found
*/
GLboolean
@@ -484,43 +487,58 @@ _mesa_lookup_parameter_constant(const st
for (i = 0; i < list->NumParameters; i++) {
if (list->Parameters[i].Type == PROGRAM_CONSTANT) {
- if (vSize == 1) {
- /* look for v[0] anywhere within float[4] value */
- GLuint j;
- for (j = 0; j < 4; j++) {
- if (list->ParameterValues[i][j] == v[0]) {
- /* found it */
- *posOut = i;
- *swizzleOut = MAKE_SWIZZLE4(j, j, j, j);
- return GL_TRUE;
- }
- }
- }
- else if (vSize <= list->Parameters[i].Size) {
- /* see if we can match this constant (with a swizzle) */
- GLuint swz[4];
- GLuint match = 0, j, k;
+ if (!swizzleOut) {
+ /* swizzle not allowed */
+ GLuint j, match = 0;
for (j = 0; j < vSize; j++) {
- if (v[j] == list->ParameterValues[i][j]) {
- swz[j] = j;
+ if (v[j] == list->ParameterValues[i][j])
match++;
- }
- else {
- for (k = 0; k < list->Parameters[i].Size; k++) {
- if (v[j] == list->ParameterValues[i][k]) {
- swz[j] = k;
- match++;
- break;
- }
- }
- }
}
if (match == vSize) {
*posOut = i;
- *swizzleOut = MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]);
return GL_TRUE;
}
}
+ else {
+ /* try matching w/ swizzle */
+ if (vSize == 1) {
+ /* look for v[0] anywhere within float[4] value */
+ GLuint j;
+ for (j = 0; j < 4; j++) {
+ if (list->ParameterValues[i][j] == v[0]) {
+ /* found it */
+ *posOut = i;
+ *swizzleOut = MAKE_SWIZZLE4(j, j, j, j);
+ return GL_TRUE;
+ }
+ }
+ }
+ else if (vSize <= list->Parameters[i].Size) {
+ /* see if we can match this constant (with a swizzle) */
+ GLuint swz[4];
+ GLuint match = 0, j, k;
+ for (j = 0; j < vSize; j++) {
+ if (v[j] == list->ParameterValues[i][j]) {
+ swz[j] = j;
+ match++;
+ }
+ else {
+ for (k = 0; k < list->Parameters[i].Size; k++) {
+ if (v[j] == list->ParameterValues[i][k]) {
+ swz[j] = k;
+ match++;
+ break;
+ }
+ }
+ }
+ }
+ if (match == vSize) {
+ *posOut = i;
+ *swizzleOut = MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]);
+ return GL_TRUE;
+ }
+ }
+ }
}
}
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index a3cc233..bcd54d6 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -172,10 +172,10 @@ link_uniform_vars(struct gl_shader_progr
j = _mesa_lookup_parameter_index(shProg->Uniforms, -1, p->Name);
}
else {
- GLuint swizzle;
+ /*GLuint swizzle;*/
ASSERT(p->Type == PROGRAM_CONSTANT);
if (_mesa_lookup_parameter_constant(shProg->Uniforms, pVals,
- p->Size, &j, &swizzle)) {
+ p->Size, &j, NULL)) {
assert(j >= 0);
}
else {
diff-tree 1936b25ebd580c5ef9e8cb471a986da39ef46ca5 (from 629ec2b06be40a32fa820a105e40e7b894acc84e)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 22 09:04:18 2007 -0600
print conditional writemask, if enabled
diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c
index 4519f0c..d290ce0 100644
--- a/src/mesa/shader/prog_print.c
+++ b/src/mesa/shader/prog_print.c
@@ -388,6 +388,12 @@ print_dst_reg(const struct prog_dst_regi
dstReg->Index, mode, prog),
writemask_string(dstReg->WriteMask));
+ if (dstReg->CondMask != COND_TR) {
+ _mesa_printf(" (%s.%s)",
+ condcode_string(dstReg->CondMask),
+ _mesa_swizzle_string(dstReg->CondSwizzle, GL_FALSE, GL_FALSE));
+ }
+
#if 0
_mesa_printf("%s[%d]%s",
file_string((enum register_file) dstReg->File, mode),
More information about the mesa-commit
mailing list