mesa: Branch 'glsl-compiler-1' - 3 commits
Brian Paul
brianp at kemper.freedesktop.org
Wed Jan 17 00:49:09 UTC 2007
progs/glsl/bump.c | 71 ++++++++++++++++++-
src/mesa/shader/slang/slang_codegen.c | 122 ++++++++++++++++++++++++++++------
src/mesa/shader/slang/slang_emit.c | 3
3 files changed, 172 insertions(+), 24 deletions(-)
New commits:
diff-tree 552a65e4546bd543d60ffe87dc298a41d8a318be (from 3596903068fb989dceefe60ea44f6e98f691c277)
Author: Brian <brian at yutani.localnet.net>
Date: Tue Jan 16 17:38:39 2007 -0700
Implement codegen for the selection operator ( b ? x : y )
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 4213e1c..0189b75 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1478,6 +1478,96 @@ _slang_gen_if(slang_assemble_ctx * A, co
/**
+ * Generate IR node for storage of a temporary of given size.
+ */
+static slang_ir_node *
+_slang_gen_temporary(GLint size)
+{
+ slang_ir_storage *store;
+ slang_ir_node *n;
+
+ store = _slang_new_ir_storage(PROGRAM_TEMPORARY, -1, size);
+ if (store) {
+ n = new_node(IR_VAR_DECL, NULL, NULL);
+ if (n) {
+ n->Store = store;
+ }
+ else {
+ free(store);
+ }
+ }
+ return n;
+}
+
+
+/**
+ * Generate code for a selection expression: b ? x : y
+ */
+static slang_ir_node *
+_slang_gen_select(slang_assemble_ctx *A, slang_operation *oper)
+{
+ slang_atom altAtom = slang_atom_pool_gen(A->atoms, "__selectAlt");
+ slang_atom endAtom = slang_atom_pool_gen(A->atoms, "__selectEnd");
+ slang_ir_node *altLab, *endLab;
+ slang_ir_node *tree, *tmpDecl, *tmpVar, *cond, *cjump, *jump;
+ slang_ir_node *bodx, *body, *assignx, *assigny;
+ slang_assembly_typeinfo type;
+ int size;
+
+ /* size of x or y's type */
+ slang_assembly_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 = _slang_gen_cond(cond);
+ tree = new_seq(tmpDecl, cond);
+
+ /* jump if true to "alt" label */
+ cjump = new_cjump(altAtom);
+ tree = new_seq(tree, cjump);
+
+ /* evaluate child 2 (y) and assign to tmp */
+ tmpVar = new_node(IR_VAR, NULL, NULL);
+ tmpVar->Store = tmpDecl->Store;
+ body = _slang_gen_operation(A, &oper->children[2]);
+ assigny = new_node(IR_MOVE, tmpVar, body);
+ tree = new_seq(tree, assigny);
+
+ /* jump to "end" label */
+ jump = new_jump(endAtom);
+ tree = new_seq(tree, jump);
+
+ /* "alt" label */
+ altLab = new_label(altAtom);
+ tree = new_seq(tree, altLab);
+
+ /* evaluate child 1 (x) and assign to tmp */
+ tmpVar = new_node(IR_VAR, NULL, NULL);
+ tmpVar->Store = tmpDecl->Store;
+ bodx = _slang_gen_operation(A, &oper->children[1]);
+ assignx = new_node(IR_MOVE, tmpVar, bodx);
+ tree = new_seq(tree, assignx);
+
+ /* "end" label */
+ endLab = new_label(endAtom);
+ tree = new_seq(tree, endLab);
+
+ /* tmp var value */
+ tmpVar = new_node(IR_VAR, NULL, NULL);
+ tmpVar->Store = tmpDecl->Store;
+ tree = new_seq(tree, tmpVar);
+
+ return tree;
+}
+
+
+/**
* Generate IR tree for a return statement.
*/
static slang_ir_node *
@@ -1643,24 +1733,6 @@ _slang_gen_variable(slang_assemble_ctx *
}
-#if 0
-static slang_ir_node *
-_slang_gen_logical_and(slang_assemble_ctx * A, slang_operation *oper)
-{
- /*
- * bool b;
- * b = test(child[0]);
- * if !b goto endLab;
- * b = test(child[1]);
- * endLab:
- * (b)
- */
- slang_ir_node *temp;
-
-}
-#endif
-
-
/**
* Generate IR tree for an assignment (=).
*/
@@ -1671,6 +1743,10 @@ _slang_gen_assignment(slang_assemble_ctx
oper->children[1].type == slang_oper_call) {
/* Special case of: x = f(a, b)
* Replace with f(a, b, x) (where x == hidden __retVal out param)
+ *
+ * XXX this could be even more effective if we could accomodate
+ * cases such as "v.x = f();" - would help with typical vertex
+ * transformation.
*/
slang_ir_node *n;
n = _slang_gen_function_call_name(A,
@@ -2023,6 +2099,14 @@ _slang_gen_operation(slang_assemble_ctx
return n;
}
+ case slang_oper_select: /* b ? x : y */
+ {
+ slang_ir_node *n;
+ assert(oper->num_children == 3);
+ n = _slang_gen_select(A, oper );
+ return n;
+ }
+
case slang_oper_asm:
return _slang_gen_asm(A, oper, NULL);
case slang_oper_call:
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index e58256c..1142bc6 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -617,7 +617,8 @@ emit(slang_var_table *vt, slang_ir_node
assert(n->Store);
assert(n->Store->File != PROGRAM_UNDEFINED);
assert(n->Store->Size > 0);
- if (n->Var->isTemp)
+ assert(n->Store->Index < 0);
+ if (!n->Var || n->Var->isTemp)
n->Store->Index = _slang_alloc_temp(vt, n->Store->Size);
else
n->Store->Index = _slang_alloc_var(vt, n->Store->Size);
diff-tree 3596903068fb989dceefe60ea44f6e98f691c277 (from 271d504ed72548a44a2a6e3712a10c17f62e243c)
Author: Brian <brian at yutani.localnet.net>
Date: Tue Jan 16 16:53:41 2007 -0700
fix typo
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 666f36b..4213e1c 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1669,7 +1669,7 @@ _slang_gen_assignment(slang_assemble_ctx
{
if (oper->children[0].type == slang_oper_identifier &&
oper->children[1].type == slang_oper_call) {
- /* Sspecial case of: x = f(a, b)
+ /* Special case of: x = f(a, b)
* Replace with f(a, b, x) (where x == hidden __retVal out param)
*/
slang_ir_node *n;
diff-tree 271d504ed72548a44a2a6e3712a10c17f62e243c (from 9d0ae967d42f968b4b41d6847e4d678930ebe8bf)
Author: Brian <brian at yutani.localnet.net>
Date: Tue Jan 16 15:27:11 2007 -0700
draw a box, press 'a' to animate
diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c
index b71c3af..a6846ac 100644
--- a/progs/glsl/bump.c
+++ b/progs/glsl/bump.c
@@ -34,18 +34,20 @@ struct uniform_info {
static struct uniform_info Uniforms[] = {
{ "LightPosition", 3, -1, { 0.57737, 0.57735, 0.57735, 0.0 } },
{ "SurfaceColor", 3, -1, { 0.8, 0.8, 0.2, 0 } },
- { "BumpDensity", 1, -1, { 16.0, 0, 0, 0 } },
- { "BumpSize", 1, -1, { 0.15, 0, 0, 0 } },
+ { "BumpDensity", 1, -1, { 10.0, 0, 0, 0 } },
+ { "BumpSize", 1, -1, { 0.125, 0, 0, 0 } },
{ "SpecularFactor", 1, -1, { 0.5, 0, 0, 0 } },
{ NULL, 0, 0, { 0, 0, 0, 0 } }
};
static GLint win = 0;
-static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
+static GLfloat xRot = 20.0f, yRot = 0.0f, zRot = 0.0f;
static GLuint tangentAttrib;
+static GLboolean Anim = GL_FALSE;
+
static void
CheckError(int line)
@@ -75,6 +77,63 @@ Square(GLfloat size)
static void
+Cube(GLfloat size)
+{
+ /* +X */
+ glPushMatrix();
+ glRotatef(90, 0, 1, 0);
+ glTranslatef(0, 0, size);
+ Square(size);
+ glPopMatrix();
+
+ /* -X */
+ glPushMatrix();
+ glRotatef(-90, 0, 1, 0);
+ glTranslatef(0, 0, size);
+ Square(size);
+ glPopMatrix();
+
+ /* +Y */
+ glPushMatrix();
+ glRotatef(90, 1, 0, 0);
+ glTranslatef(0, 0, size);
+ Square(size);
+ glPopMatrix();
+
+ /* -Y */
+ glPushMatrix();
+ glRotatef(-90, 1, 0, 0);
+ glTranslatef(0, 0, size);
+ Square(size);
+ glPopMatrix();
+
+
+ /* +Z */
+ glPushMatrix();
+ glTranslatef(0, 0, size);
+ Square(size);
+ glPopMatrix();
+
+ /* -Z */
+ glPushMatrix();
+ glRotatef(180, 0, 1, 0);
+ glTranslatef(0, 0, size);
+ Square(size);
+ glPopMatrix();
+
+}
+
+
+static void
+Idle(void)
+{
+ GLint t = glutGet(GLUT_ELAPSED_TIME);
+ yRot = t * 0.05;
+ glutPostRedisplay();
+}
+
+
+static void
Redisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -84,7 +143,7 @@ Redisplay(void)
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glRotatef(zRot, 0.0f, 0.0f, 1.0f);
- Square(2.0);
+ Cube(1.5);
glPopMatrix();
@@ -128,6 +187,10 @@ Key(unsigned char key, int x, int y)
(void) y;
switch(key) {
+ case 'a':
+ Anim = !Anim;
+ glutIdleFunc(Anim ? Idle : NULL);
+ break;
case 'z':
zRot += step;
break;
More information about the mesa-commit
mailing list