diff options
author | Brian <[email protected]> | 2007-01-20 09:22:13 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2007-01-20 09:22:13 -0700 |
commit | a3e938b8da07e656775e88bb4b078429723689a2 (patch) | |
tree | 8b27fbcf45e6a9580bb8f428ffdad229385d3e1d /src | |
parent | 9f07ed00e4d4bca95189720dd44bf57a228baf02 (diff) |
Reimplement && and || to do short-circuit evaluation.
Improved shader error handling.
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/shader/slang/library/slang_core.gc | 19 | ||||
-rw-r--r-- | src/mesa/shader/slang/library/slang_core_gc.h | 90 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 158 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_emit.c | 9 |
4 files changed, 159 insertions, 117 deletions
diff --git a/src/mesa/shader/slang/library/slang_core.gc b/src/mesa/shader/slang/library/slang_core.gc index 407c613ab50..811568c7bad 100644 --- a/src/mesa/shader/slang/library/slang_core.gc +++ b/src/mesa/shader/slang/library/slang_core.gc @@ -2470,11 +2470,6 @@ bool __operator <= (const int a, const int b) { } -//bool __operator ^^ (const bool a, const bool b) { -// return a != b; -//} - - bool __logicalNot(const bool a) { @@ -2483,20 +2478,6 @@ bool __logicalNot(const bool a) return true; } -bool __logicalAnd(const bool a, const bool b) -{ - if (a) - return b; - return false; -} - -bool __logicalOr(const bool a, const bool b) -{ - if (a) - return true; - return b; -} - bool __logicalXor(const bool a, const bool b) { // XXX return a != b; diff --git a/src/mesa/shader/slang/library/slang_core_gc.h b/src/mesa/shader/slang/library/slang_core_gc.h index b1869c5d894..b34cbb89cef 100644 --- a/src/mesa/shader/slang/library/slang_core_gc.h +++ b/src/mesa/shader/slang/library/slang_core_gc.h @@ -805,50 +805,50 @@ 1,0,1,2,17,1,1,0,5,97,0,0,1,1,0,5,98,0,0,0,1,8,58,102,108,111,97,116,0,18,97,0,0,0,58,102,108,111, 97,116,0,18,98,0,0,0,42,0,0,1,0,1,0,95,95,108,111,103,105,99,97,108,78,111,116,0,1,1,0,1,97,0,0,0, 1,10,18,97,0,0,8,15,2,48,0,0,9,14,0,8,15,2,49,0,0,0,1,0,1,0,95,95,108,111,103,105,99,97,108,65,110, -100,0,1,1,0,1,97,0,0,1,1,0,1,98,0,0,0,1,10,18,97,0,0,8,18,98,0,0,9,14,0,8,15,2,48,0,0,0,1,0,1,0,95, -95,108,111,103,105,99,97,108,79,114,0,1,1,0,1,97,0,0,1,1,0,1,98,0,0,0,1,10,18,97,0,0,8,15,2,49,0,0, -9,14,0,8,18,98,0,0,0,1,0,1,0,95,95,108,111,103,105,99,97,108,88,111,114,0,1,1,0,1,97,0,0,1,1,0,1, -98,0,0,0,1,10,18,97,0,0,8,58,95,95,108,111,103,105,99,97,108,78,111,116,0,18,98,0,0,0,0,9,14,0,8, -18,98,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,9,102,0,0,0,1,4,102,108,111,97,116,95, -112,114,105,110,116,0,18,102,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,5,105,0,0,0,1, -4,105,110,116,95,112,114,105,110,116,0,18,105,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1, -1,0,1,98,0,0,0,1,4,98,111,111,108,95,112,114,105,110,116,0,18,98,0,0,0,0,1,0,0,0,112,114,105,110, -116,77,69,83,65,0,1,1,0,10,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0, -0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,0,1,0,0,0,112,114,105,110,116, -77,69,83,65,0,1,1,0,11,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0, -9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,9,58,112,114,105,110,116,77,69,83, -65,0,18,118,0,59,122,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,12,118,0,0,0,1,9,58, -112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0, -18,118,0,59,121,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,122,0,0,0,0,9,58,112, -114,105,110,116,77,69,83,65,0,18,118,0,59,119,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0, -1,1,0,6,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114, -105,110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1, -0,7,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105, -110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59, -122,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,8,118,0,0,0,1,9,58,112,114,105,110, -116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0, -0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,122,0,0,0,0,9,58,112,114,105,110,116,77, -69,83,65,0,18,118,0,59,119,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,2,118,0,0,0,1, -9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83, -65,0,18,118,0,59,121,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,3,118,0,0,0,1,9,58, -112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0, -18,118,0,59,121,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,122,0,0,0,0,0,1,0,0,0, -112,114,105,110,116,77,69,83,65,0,1,1,0,4,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18, +100,0,1,1,0,1,97,0,0,1,1,0,1,98,0,0,0,1,10,18,97,0,0,9,18,95,95,114,101,116,86,97,108,0,18,98,0,20, +0,9,18,95,95,114,101,116,86,97,108,0,15,2,48,0,20,0,0,1,0,1,0,95,95,108,111,103,105,99,97,108,79, +114,0,1,1,0,1,97,0,0,1,1,0,1,98,0,0,0,1,10,18,97,0,0,8,15,2,49,0,0,9,14,0,8,18,98,0,0,0,1,0,1,0,95, +95,108,111,103,105,99,97,108,88,111,114,0,1,1,0,1,97,0,0,1,1,0,1,98,0,0,0,1,10,18,97,0,0,8,58,95, +95,108,111,103,105,99,97,108,78,111,116,0,18,98,0,0,0,0,9,14,0,8,18,98,0,0,0,1,0,0,0,112,114,105, +110,116,77,69,83,65,0,1,1,0,9,102,0,0,0,1,4,102,108,111,97,116,95,112,114,105,110,116,0,18,102,0,0, +0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,5,105,0,0,0,1,4,105,110,116,95,112,114,105,110, +116,0,18,105,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,1,98,0,0,0,1,4,98,111,111,108, +95,112,114,105,110,116,0,18,98,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,10,118,0,0, +0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69, +83,65,0,18,118,0,59,121,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,11,118,0,0,0,1,9, +58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65, +0,18,118,0,59,121,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,122,0,0,0,0,0,1,0,0,0, +112,114,105,110,116,77,69,83,65,0,1,1,0,12,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18, 118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,9,58,112,114, 105,110,116,77,69,83,65,0,18,118,0,59,122,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0, -59,119,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,13,109,0,0,0,1,9,58,112,114,105, -110,116,77,69,83,65,0,18,109,0,16,8,48,0,57,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0, -16,10,49,0,57,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,14,109,0,0,0,1,9,58,112,114, -105,110,116,77,69,83,65,0,18,109,0,16,8,48,0,57,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18, -109,0,16,10,49,0,57,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,10,50,0,57,0,0,0,0,1, -0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,15,109,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65, -0,18,109,0,16,8,48,0,57,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,10,49,0,57,0,0,0, -9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,10,50,0,57,0,0,0,9,58,112,114,105,110,116,77,69, -83,65,0,18,109,0,16,10,51,0,57,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,16,101,0,0, -0,1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65, -0,1,1,0,17,101,0,0,0,1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,1,0,0,0,112,114,105, -110,116,77,69,83,65,0,1,1,0,18,101,0,0,0,1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,1, -0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,19,101,0,0,0,1,4,105,110,116,95,112,114,105,110,116, -0,18,101,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,20,101,0,0,0,1,4,105,110,116,95, -112,114,105,110,116,0,18,101,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,21,101,0,0,0, -1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,0 +59,119,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,6,118,0,0,0,1,9,58,112,114,105, +110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59, +121,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,7,118,0,0,0,1,9,58,112,114,105,110, +116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0, +0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,122,0,0,0,0,0,1,0,0,0,112,114,105,110,116, +77,69,83,65,0,1,1,0,8,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9, +58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65, +0,18,118,0,59,122,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,119,0,0,0,0,0,1,0,0,0, +112,114,105,110,116,77,69,83,65,0,1,1,0,2,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18, +118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,0,1,0,0,0,112, +114,105,110,116,77,69,83,65,0,1,1,0,3,118,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0, +59,120,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,121,0,0,0,0,9,58,112,114,105,110, +116,77,69,83,65,0,18,118,0,59,122,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,4,118, +0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,120,0,0,0,0,9,58,112,114,105,110,116,77, +69,83,65,0,18,118,0,59,121,0,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,122,0,0,0,0, +9,58,112,114,105,110,116,77,69,83,65,0,18,118,0,59,119,0,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69, +83,65,0,1,1,0,13,109,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,8,48,0,57,0,0,0,9, +58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,10,49,0,57,0,0,0,0,1,0,0,0,112,114,105,110,116,77, +69,83,65,0,1,1,0,14,109,0,0,0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,8,48,0,57,0,0,0, +9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,10,49,0,57,0,0,0,9,58,112,114,105,110,116,77,69, +83,65,0,18,109,0,16,10,50,0,57,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,15,109,0,0, +0,1,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,8,48,0,57,0,0,0,9,58,112,114,105,110,116,77, +69,83,65,0,18,109,0,16,10,49,0,57,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,10,50,0, +57,0,0,0,9,58,112,114,105,110,116,77,69,83,65,0,18,109,0,16,10,51,0,57,0,0,0,0,1,0,0,0,112,114,105, +110,116,77,69,83,65,0,1,1,0,16,101,0,0,0,1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,1, +0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,17,101,0,0,0,1,4,105,110,116,95,112,114,105,110,116, +0,18,101,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,18,101,0,0,0,1,4,105,110,116,95, +112,114,105,110,116,0,18,101,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0,1,1,0,19,101,0,0,0, +1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,1,0,0,0,112,114,105,110,116,77,69,83,65,0, +1,1,0,20,101,0,0,0,1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,1,0,0,0,112,114,105,110, +116,77,69,83,65,0,1,1,0,21,101,0,0,0,1,4,105,110,116,95,112,114,105,110,116,0,18,101,0,0,0,0,0 diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 60bf57035f0..6923c00562a 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -544,18 +544,11 @@ new_label(slang_atom labName) } static slang_ir_node * -new_float_literal(float x, float y, float z, float w) +new_float_literal(const float v[4]) { - GLuint size; + const GLuint size = (v[0] == v[1] && v[0] == v[2] && v[0] == v[3]) ? 1 : 4; slang_ir_node *n = new_node(IR_FLOAT, NULL, NULL); - if (x == y && x == z && x == w) - size = 1; - else - size = 4; - n->Value[0] = x; - n->Value[1] = y; - n->Value[2] = z; - n->Value[3] = w; + COPY_4V(n->Value, v); /* allocate a storage object, but compute actual location (Index) later */ n->Store = _slang_new_ir_storage(PROGRAM_CONSTANT, -1, size); return n; @@ -598,10 +591,8 @@ new_var(slang_assemble_ctx *A, slang_operation *oper, slang_atom name) { slang_variable *v = _slang_locate_variable(oper->locals, name, GL_TRUE); slang_ir_node *n = new_node(IR_VAR, NULL, NULL); - if (!v) { - printf("VAR NOT FOUND %s\n", (char *) name); - assert(v); - } + if (!v) + return NULL; assert(!oper->var || oper->var == v); v->used = GL_TRUE; n->Var = v; @@ -1626,9 +1617,12 @@ _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper) 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; + slang_assembly_typeinfo type; int size; + assert(oper->type == slang_oper_select); + assert(oper->num_children == 3); + /* size of x or y's type */ slang_assembly_typeinfo_construct(&type); _slang_typeof_operation(A, &oper->children[1], &type); @@ -1647,10 +1641,10 @@ _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper) cjump = new_cjump(altAtom, 0); tree = new_seq(tree, cjump); - /* evaluate child 2 (y) and assign to tmp */ + /* evaluate child 1 (x) and assign to tmp */ tmpVar = new_node(IR_VAR, NULL, NULL); tmpVar->Store = tmpDecl->Store; - body = _slang_gen_operation(A, &oper->children[2]); + body = _slang_gen_operation(A, &oper->children[1]); assigny = new_node(IR_MOVE, tmpVar, body); tree = new_seq(tree, assigny); @@ -1662,10 +1656,10 @@ _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper) altLab = new_label(altAtom); tree = new_seq(tree, altLab); - /* evaluate child 1 (x) and assign to tmp */ + /* evaluate child 2 (y) and assign to tmp */ tmpVar = new_node(IR_VAR, NULL, NULL); tmpVar->Store = tmpDecl->Store; - bodx = _slang_gen_operation(A, &oper->children[1]); + bodx = _slang_gen_operation(A, &oper->children[2]); assignx = new_node(IR_MOVE, tmpVar, bodx); tree = new_seq(tree, assignx); @@ -1683,6 +1677,67 @@ _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper) /** + * Generate code for &&. + */ +static slang_ir_node * +_slang_gen_logical_and(slang_assemble_ctx *A, slang_operation *oper) +{ + /* rewrite "a && b" as "a ? b : false" */ + slang_operation *select; + slang_ir_node *n; + + select = slang_operation_new(1); + select->type = slang_oper_select; + select->num_children = 3; + select->children = slang_operation_new(3); + + slang_operation_copy(&select->children[0], &oper->children[0]); + slang_operation_copy(&select->children[1], &oper->children[1]); + select->children[2].type = slang_oper_literal_bool; + ASSIGN_4V(select->children[2].literal, 0, 0, 0, 0); + + n = _slang_gen_select(A, select); + + /* xxx wrong */ + free(select->children); + free(select); + + return n; +} + + +/** + * Generate code for ||. + */ +static slang_ir_node * +_slang_gen_logical_or(slang_assemble_ctx *A, slang_operation *oper) +{ + /* rewrite "a || b" as "a ? true : b" */ + slang_operation *select; + slang_ir_node *n; + + select = slang_operation_new(1); + select->type = slang_oper_select; + select->num_children = 3; + select->children = slang_operation_new(3); + + slang_operation_copy(&select->children[0], &oper->children[0]); + select->children[1].type = slang_oper_literal_bool; + ASSIGN_4V(select->children[2].literal, 1, 1, 1, 1); + slang_operation_copy(&select->children[2], &oper->children[1]); + + n = _slang_gen_select(A, select); + + /* xxx wrong */ + free(select->children); + free(select); + + return n; +} + + + +/** * Generate IR tree for a return statement. */ static slang_ir_node * @@ -1779,6 +1834,7 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) slang_ir_node *n; slang_ir_node *varDecl; slang_variable *v; + const char *varName = (char *) oper->a_id; assert(oper->num_children == 0 || oper->num_children == 1); @@ -1792,10 +1848,10 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) slang_ir_node *var, *init, *rhs; assert(oper->num_children == 1); var = new_var(A, oper, oper->a_id); + if (!var) { + RETURN_ERROR2("Undefined variable:", varName, 0); + } /* XXX make copy of this initializer? */ - /* - printf("\n*** ASSEMBLE INITIALIZER %p\n", (void*) v->initializer); - */ rhs = _slang_gen_operation(A, &oper->children[0]); assert(rhs); init = new_node(IR_MOVE, var, rhs); @@ -1805,10 +1861,10 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper) else if (v->initializer) { slang_ir_node *var, *init, *rhs; var = new_var(A, oper, oper->a_id); + if (!var) { + RETURN_ERROR2("Undefined variable:", varName, 0); + } /* XXX make copy of this initializer? */ - /* - printf("\n*** ASSEMBLE INITIALIZER %p\n", (void*) v->initializer); - */ rhs = _slang_gen_operation(A, v->initializer); assert(rhs); init = new_node(IR_MOVE, var, rhs); @@ -1835,9 +1891,9 @@ _slang_gen_variable(slang_assemble_ctx * A, slang_operation *oper) */ slang_atom aVar = oper->var ? oper->var->a_name : oper->a_id; slang_ir_node *n = new_var(A, oper, aVar); - /* - assert(oper->var); - */ + if (!n) { + RETURN_ERROR2("Undefined variable:", (char *) aVar, 0); + } return n; } @@ -1876,18 +1932,19 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper) } c0 = _slang_gen_operation(A, lhs); c1 = _slang_gen_operation(A, &oper->children[1]); - - assert(c1); - n = new_node(IR_MOVE, c0, c1); - /* - assert(c1->Opcode != IR_SEQ); - */ - if (c0->Writemask != WRITEMASK_XYZW) - /* XXX this is a hack! */ - n->Writemask = c0->Writemask; - else - n->Writemask = mask; - return n; + if (c0 && c1) { + n = new_node(IR_MOVE, c0, c1); + /*assert(c1->Opcode != IR_SEQ);*/ + if (c0->Writemask != WRITEMASK_XYZW) + /* XXX this is a hack! */ + n->Writemask = c0->Writemask; + else + n->Writemask = mask; + return n; + } + else { + return NULL; + } } } @@ -2206,25 +2263,25 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) n = _slang_gen_function_call_name(A, "/=", oper, &oper->children[0]); return n; } - case slang_oper_logicalor: + case slang_oper_logicaland: { slang_ir_node *n; assert(oper->num_children == 2); - n = _slang_gen_function_call_name(A, "__logicalOr", oper, NULL); + n = _slang_gen_logical_and(A, oper); return n; } - case slang_oper_logicalxor: + case slang_oper_logicalor: { slang_ir_node *n; assert(oper->num_children == 2); - n = _slang_gen_function_call_name(A, "__logicalXor", oper, NULL); + n = _slang_gen_logical_or(A, oper); return n; } - case slang_oper_logicaland: + case slang_oper_logicalxor: { slang_ir_node *n; assert(oper->num_children == 2); - n = _slang_gen_function_call_name(A, "__logicalAnd", oper, NULL); + n = _slang_gen_function_call_name(A, "__logicalXor", oper, NULL); return n; } case slang_oper_not: @@ -2239,7 +2296,7 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) { slang_ir_node *n; assert(oper->num_children == 3); - n = _slang_gen_select(A, oper ); + n = _slang_gen_select(A, oper); return n; } @@ -2263,12 +2320,11 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) case slang_oper_subscript: return _slang_gen_subscript(A, oper); case slang_oper_literal_float: - return new_float_literal(oper->literal[0], oper->literal[1], - oper->literal[2], oper->literal[3]); + /* fall-through */ case slang_oper_literal_int: - return new_float_literal(oper->literal[0], 0, 0, 0); + /* fall-through */ case slang_oper_literal_bool: - return new_float_literal(oper->literal[0], 0, 0, 0); + return new_float_literal(oper->literal); case slang_oper_postincrement: /* var++ */ { diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 9dda28d842e..6c31bfc677f 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -432,6 +432,10 @@ emit_binop(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) assert(info->InstOpcode != OPCODE_NOP); + /* XXX check if Opcode == OPCODE_ADD, then check if either child is a MUL, + * replace with MAD instruction. + */ + /* gen code for children */ emit(vt, n->Children[0], prog); emit(vt, n->Children[1], prog); @@ -629,7 +633,7 @@ emit_move(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) #endif { if (n->Children[0]->Store->Size > 4) { - /* move matrix/struct etc */ + /* move matrix/struct etc (block of registers) */ slang_ir_storage dstStore = *n->Children[0]->Store; slang_ir_storage srcStore = *n->Children[1]->Store; GLint size = srcStore.Size; @@ -649,6 +653,7 @@ emit_move(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) } } else { + /* single register move */ inst = new_instruction(prog, OPCODE_MOV); assert(n->Children[0]->Store->Index >= 0); assert(n->Children[0]->Store->Index < 16); @@ -833,7 +838,7 @@ emit(slang_var_table *vt, slang_ir_node *n, struct gl_program *prog) case IR_FLOAT: /* find storage location for this float constant */ n->Store->Index = _mesa_add_unnamed_constant(prog->Parameters, n->Value, - n->Store->Size/*4*/, + n->Store->Size, &n->Store->Swizzle); if (n->Store->Index < 0) { RETURN_ERROR("Ran out of space for constants.", 0); |