mesa: Branch 'glsl-compiler-1' - 7 commits
Brian Paul
brianp at kemper.freedesktop.org
Thu Mar 8 18:29:46 UTC 2007
src/mesa/shader/slang/slang_codegen.c | 80 +++++++++++-----------------------
src/mesa/shader/slang/slang_emit.c | 36 ---------------
src/mesa/shader/slang/slang_ir.h | 2
3 files changed, 29 insertions(+), 89 deletions(-)
New commits:
diff-tree ec89aba7c6de29e1dc24b04740b0716e18028b12 (from cce4e505690f3d5aef630bd4c4c4a455f08519a1)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 8 11:29:22 2007 -0700
remove unused new_cjump()
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 570a946..de78c2b 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -455,20 +455,6 @@ new_float_literal(const float v[4])
}
/**
- * Conditional jump.
- * \param zeroOrOne indicates if the jump is to be taken on zero, or non-zero
- * condition code state.
- */
-static slang_ir_node *
-new_cjump(slang_label *dest, GLuint zeroOrOne)
-{
- slang_ir_node *n = new_node0(zeroOrOne ? IR_CJUMP1 : IR_CJUMP0);
- if (n)
- n->Label = dest;
- return n;
-}
-
-/**
* Unconditional jump.
*/
static slang_ir_node *
diff-tree cce4e505690f3d5aef630bd4c4c4a455f08519a1 (from 63772e2a2c0d67a88816bfb52a250b86ecd97f20)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 8 11:16:13 2007 -0700
IR_CJUMP0/1 no longer used/needed
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 1d18929..f07ad66 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -122,8 +122,6 @@ static const slang_ir_info IrInfo[] = {
{ IR_SCOPE, "IR_SCOPE", OPCODE_NOP, 0, 0 },
{ IR_LABEL, "IR_LABEL", OPCODE_NOP, 0, 0 },
{ IR_JUMP, "IR_JUMP", OPCODE_NOP, 0, 0 },
- { IR_CJUMP0, "IR_CJUMP0", OPCODE_NOP, 0, 0 },
- { IR_CJUMP1, "IR_CJUMP1", OPCODE_NOP, 0, 0 },
{ IR_IF, "IR_IF", OPCODE_NOP, 0, 0 },
{ IR_KILL, "IR_KILL", OPCODE_NOP, 0, 0 },
{ IR_COND, "IR_COND", OPCODE_NOP, 0, 0 },
@@ -303,14 +301,6 @@ slang_print_ir(const slang_ir_node *n, i
case IR_JUMP:
printf("JUMP %s\n", n->Label->Name);
break;
- case IR_CJUMP0:
- printf("CJUMP0 %s\n", n->Label->Name);
- slang_print_ir(n->Children[0], indent+3);
- break;
- case IR_CJUMP1:
- printf("CJUMP1 %s\n", n->Label->Name);
- slang_print_ir(n->Children[0], indent+3);
- break;
case IR_IF:
printf("IF \n");
@@ -877,25 +867,6 @@ emit_label(slang_emit_info *emitInfo, co
static struct prog_instruction *
-emit_cjump(slang_emit_info *emitInfo, slang_ir_node *n, GLuint zeroOrOne)
-{
- struct prog_instruction *inst;
- assert(n->Opcode == IR_CJUMP0 || n->Opcode == IR_CJUMP1);
- inst = new_instruction(emitInfo, OPCODE_BRA);
- if (zeroOrOne)
- inst->DstReg.CondMask = COND_NE; /* branch if non-zero */
- else
- inst->DstReg.CondMask = COND_EQ; /* branch if equal to zero */
- inst->DstReg.CondSwizzle = SWIZZLE_X;
- inst->BranchTarget = _slang_label_get_location(n->Label);
- if (inst->BranchTarget < 0) {
- _slang_label_add_reference(n->Label, emitInfo->prog->NumInstructions - 1);
- }
- return inst;
-}
-
-
-static struct prog_instruction *
emit_jump(slang_emit_info *emitInfo, slang_ir_node *n)
{
struct prog_instruction *inst;
@@ -1039,7 +1010,7 @@ emit_cond(slang_emit_info *emitInfo, sla
{
/* Conditional expression (in if/while/for stmts).
* Need to update condition code register.
- * Next instruction is typically an IR_CJUMP0/1.
+ * Next instruction is typically an IR_IF.
*/
/* last child expr instruction: */
struct prog_instruction *inst = emit(emitInfo, n->Children[0]);
@@ -1560,10 +1531,6 @@ emit(slang_emit_info *emitInfo, slang_ir
assert(n);
assert(n->Label);
return emit_jump(emitInfo, n);
- case IR_CJUMP0:
- return emit_cjump(emitInfo, n, 0);
- case IR_CJUMP1:
- return emit_cjump(emitInfo, n, 1);
case IR_KILL:
return emit_kill(emitInfo);
diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
index cd1f606..d2985ea 100644
--- a/src/mesa/shader/slang/slang_ir.h
+++ b/src/mesa/shader/slang/slang_ir.h
@@ -50,8 +50,6 @@ typedef enum
IR_LABEL, /* target of a jump or cjump */
IR_JUMP, /* unconditional jump */
- IR_CJUMP0, /* conditional jump if zero */
- IR_CJUMP1, /* conditional jump if one (or non-zero) */
IR_COND, /* conditional expression/predicate */
IR_IF, /* high-level IF/then/else */
diff-tree 63772e2a2c0d67a88816bfb52a250b86ecd97f20 (from b3dd49429b6cbd87b67a0277127c24fb534c69a6)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 8 11:07:52 2007 -0700
rewrite _slang_gen_select() to use IF node
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index f05c8eb..570a946 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1559,81 +1559,13 @@ _slang_gen_var_decl(slang_assemble_ctx *
/**
* Generate code for a selection expression: b ? x : y
- * XXX in some cases we could implement a selection expression
+ * XXX In some cases we could implement a selection expression
* with an LRP instruction (use the boolean as the interpolant).
+ * Otherwise, we use an IF/ELSE/ENDIF construct.
*/
static slang_ir_node *
_slang_gen_select(slang_assemble_ctx *A, slang_operation *oper)
{
- slang_label *altLabel, *endLabel;
- slang_ir_node *altLab, *endLab;
- slang_ir_node *tree, *tmpDecl, *tmpVar, *cond, *cjump, *jump;
- slang_ir_node *bodx, *body, *assignx, *assigny;
- slang_typeinfo type;
- int size;
-
- assert(oper->type == SLANG_OPER_SELECT);
- assert(oper->num_children == 3);
-
- altLabel = _slang_label_new("selectAlt");
- endLabel = _slang_label_new("selectEnd");
-
- /* size of x or y's type */
- slang_typeinfo_construct(&type);
- _slang_typeof_operation(A, &oper->children[1], &type);
- size = _slang_sizeof_type_specifier(&type.spec);
- assert(size > 0);
-
- /* temporary var */
- tmpDecl = _slang_gen_temporary(size);
-
- /* eval condition */
- cond = _slang_gen_operation(A, &oper->children[0]);
- cond = new_cond(cond);
- tree = new_seq(tmpDecl, cond);
-
- /* jump if false to "alt" label */
- cjump = new_cjump(altLabel, 0);
- tree = new_seq(tree, cjump);
-
- /* evaluate child 1 (x) and assign to tmp */
- tmpVar = new_node0(IR_VAR);
- tmpVar->Store = tmpDecl->Store;
- body = _slang_gen_operation(A, &oper->children[1]);
- assigny = new_node2(IR_MOVE, tmpVar, body);
- tree = new_seq(tree, assigny);
-
- /* jump to "end" label */
- jump = new_jump(endLabel);
- tree = new_seq(tree, jump);
-
- /* "alt" label */
- altLab = new_label(altLabel);
- tree = new_seq(tree, altLab);
-
- /* evaluate child 2 (y) and assign to tmp */
- tmpVar = new_node0(IR_VAR);
- tmpVar->Store = tmpDecl->Store;
- bodx = _slang_gen_operation(A, &oper->children[2]);
- assignx = new_node2(IR_MOVE, tmpVar, bodx);
- tree = new_seq(tree, assignx);
-
- /* "end" label */
- endLab = new_label(endLabel);
- tree = new_seq(tree, endLab);
-
- /* tmp var value */
- tmpVar = new_node0(IR_VAR);
- tmpVar->Store = tmpDecl->Store;
- tree = new_seq(tree, tmpVar);
-
- return tree;
-}
-
-
-static slang_ir_node *
-_slang_gen_hl_select(slang_assemble_ctx *A, slang_operation *oper)
-{
slang_ir_node *cond, *ifNode, *trueExpr, *falseExpr, *trueNode, *falseNode;
slang_ir_node *tmpDecl, *tmpVar, *tree;
slang_typeinfo type;
@@ -1675,6 +1607,8 @@ _slang_gen_hl_select(slang_assemble_ctx
tree = new_seq(ifNode, tmpVar);
tree = new_seq(tmpDecl, tree);
+
+ slang_print_ir(tree, 10);
return tree;
}
@@ -2056,7 +1990,9 @@ _slang_gen_assignment(slang_assemble_ctx
slang_ir_node *n, *lhs, *rhs;
lhs = _slang_gen_operation(A, &oper->children[0]);
if (lhs->Store->File != PROGRAM_OUTPUT &&
- lhs->Store->File != PROGRAM_TEMPORARY) {
+ lhs->Store->File != PROGRAM_TEMPORARY &&
+ lhs->Store->File != PROGRAM_VARYING &&
+ lhs->Store->File != PROGRAM_UNDEFINED) {
slang_info_log_error(A->log, "Assignment to read-only variable");
return NULL;
}
@@ -2492,7 +2428,7 @@ _slang_gen_operation(slang_assemble_ctx
{
slang_ir_node *n;
assert(oper->num_children == 3);
- n = _slang_gen_hl_select(A, oper);
+ n = _slang_gen_select(A, oper);
return n;
}
diff-tree b3dd49429b6cbd87b67a0277127c24fb534c69a6 (from 609306de17583a0780cb7db314429371706915fb)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 8 10:53:50 2007 -0700
s/_slang_gen_hl_if/_slang_gen_if/
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index cbe86fa..f05c8eb 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1631,6 +1631,54 @@ _slang_gen_select(slang_assemble_ctx *A,
}
+static slang_ir_node *
+_slang_gen_hl_select(slang_assemble_ctx *A, slang_operation *oper)
+{
+ slang_ir_node *cond, *ifNode, *trueExpr, *falseExpr, *trueNode, *falseNode;
+ slang_ir_node *tmpDecl, *tmpVar, *tree;
+ slang_typeinfo type;
+ int size;
+
+ assert(oper->type == SLANG_OPER_SELECT);
+ assert(oper->num_children == 3);
+
+ /* size of x or y's type */
+ slang_typeinfo_construct(&type);
+ _slang_typeof_operation(A, &oper->children[1], &type);
+ size = _slang_sizeof_type_specifier(&type.spec);
+ assert(size > 0);
+
+ /* temporary var */
+ tmpDecl = _slang_gen_temporary(size);
+
+ /* the condition (child 0) */
+ cond = _slang_gen_operation(A, &oper->children[0]);
+ cond = new_cond(cond);
+
+ /* if-true body (child 1) */
+ tmpVar = new_node0(IR_VAR);
+ tmpVar->Store = tmpDecl->Store;
+ trueExpr = _slang_gen_operation(A, &oper->children[1]);
+ trueNode = new_node2(IR_MOVE, tmpVar, trueExpr);
+
+ /* if-false body (child 2) */
+ tmpVar = new_node0(IR_VAR);
+ tmpVar->Store = tmpDecl->Store;
+ falseExpr = _slang_gen_operation(A, &oper->children[2]);
+ falseNode = new_node2(IR_MOVE, tmpVar, falseExpr);
+
+ ifNode = new_if(cond, trueNode, falseNode);
+
+ /* tmp var value */
+ tmpVar = new_node0(IR_VAR);
+ tmpVar->Store = tmpDecl->Store;
+
+ tree = new_seq(ifNode, tmpVar);
+ tree = new_seq(tmpDecl, tree);
+ return tree;
+}
+
+
/**
* Generate code for &&.
*/
@@ -2444,7 +2492,7 @@ _slang_gen_operation(slang_assemble_ctx
{
slang_ir_node *n;
assert(oper->num_children == 3);
- n = _slang_gen_select(A, oper);
+ n = _slang_gen_hl_select(A, oper);
return n;
}
diff-tree 609306de17583a0780cb7db314429371706915fb (from c9f486c38f80a71b89152bde78be628b531101ef)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 8 10:43:57 2007 -0700
s/_slang_gen_hl_if/_slang_gen_if/
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index b1b4616..cbe86fa 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1461,7 +1461,7 @@ is_operation_type(const const slang_oper
* IR_IF instruction.
*/
static slang_ir_node *
-_slang_gen_hl_if(slang_assemble_ctx * A, const slang_operation *oper)
+_slang_gen_if(slang_assemble_ctx * A, const slang_operation *oper)
{
/*
* eval expr (child[0]), updating condcodes
@@ -2462,7 +2462,7 @@ _slang_gen_operation(slang_assemble_ctx
case SLANG_OPER_IDENTIFIER:
return _slang_gen_variable(A, oper);
case SLANG_OPER_IF:
- return _slang_gen_hl_if(A, oper);
+ return _slang_gen_if(A, oper);
case SLANG_OPER_FIELD:
return _slang_gen_field(A, oper);
case SLANG_OPER_SUBSCRIPT:
diff-tree c9f486c38f80a71b89152bde78be628b531101ef (from bf86ddaa2018d58c894da27d7a7a7b5449d1338e)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 8 10:40:37 2007 -0700
remove old assertion
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index df53c01..1d18929 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1021,7 +1021,6 @@ emit_move(slang_emit_info *emitInfo, sla
char *srcAnnot, *dstAnnot;
inst = new_instruction(emitInfo, OPCODE_MOV);
assert(n->Children[0]->Store->Index >= 0);
- assert(n->Children[0]->Store->Index < 16);
storage_to_dst_reg(&inst->DstReg, n->Children[0]->Store, n->Writemask);
storage_to_src_reg(&inst->SrcReg[0], n->Children[1]->Store);
dstAnnot = storage_annotation(n->Children[0], emitInfo->prog);
diff-tree bf86ddaa2018d58c894da27d7a7a7b5449d1338e (from de8172673e23bad1186553b91a7c22e65d93692a)
Author: Brian <brian at yutani.localnet.net>
Date: Thu Mar 8 10:40:25 2007 -0700
check for attempted writes to read-only vars
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 1c037d4..b1b4616 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -2007,6 +2007,12 @@ _slang_gen_assignment(slang_assemble_ctx
else {
slang_ir_node *n, *lhs, *rhs;
lhs = _slang_gen_operation(A, &oper->children[0]);
+ if (lhs->Store->File != PROGRAM_OUTPUT &&
+ lhs->Store->File != PROGRAM_TEMPORARY) {
+ slang_info_log_error(A->log, "Assignment to read-only variable");
+ return NULL;
+ }
+
rhs = _slang_gen_operation(A, &oper->children[1]);
if (lhs && rhs) {
/* convert lhs swizzle into writemask */
More information about the mesa-commit
mailing list