summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang
diff options
context:
space:
mode:
authorKeith Whitwell <keithw@vmware.com>2009-01-19 10:15:04 +0000
committerKeith Whitwell <keithw@vmware.com>2009-01-19 10:15:04 +0000
commitb5db6b039c34117be4e441a2b95abbf97df928c3 (patch)
tree8efb8698304b70f67cc408e8d12b93ae01a13015 /src/mesa/shader/slang
parent8f3fac6107460b6d9b011b5c76246468bb16004b (diff)
parent76753e30781e88912c0465642616ab16bbc1b4f3 (diff)
Merge commit 'origin/gallium-0.2' into gallium-xlib-rework
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r--src/mesa/shader/slang/library/slang_pp_directives.syn20
-rw-r--r--src/mesa/shader/slang/library/slang_pp_directives_syn.h11
-rw-r--r--src/mesa/shader/slang/library/slang_shader.syn13
-rw-r--r--src/mesa/shader/slang/library/slang_shader_syn.h4
-rw-r--r--src/mesa/shader/slang/slang_codegen.c57
-rw-r--r--src/mesa/shader/slang/slang_codegen.h1
-rw-r--r--src/mesa/shader/slang/slang_compile.c54
-rw-r--r--src/mesa/shader/slang/slang_emit.c46
-rw-r--r--src/mesa/shader/slang/slang_emit.h4
-rw-r--r--src/mesa/shader/slang/slang_ir.c22
-rw-r--r--src/mesa/shader/slang/slang_ir.h13
-rw-r--r--src/mesa/shader/slang/slang_link.c14
-rw-r--r--src/mesa/shader/slang/slang_preprocess.c89
-rw-r--r--src/mesa/shader/slang/slang_preprocess.h7
-rw-r--r--src/mesa/shader/slang/slang_typeinfo.c2
15 files changed, 279 insertions, 78 deletions
diff --git a/src/mesa/shader/slang/library/slang_pp_directives.syn b/src/mesa/shader/slang/library/slang_pp_directives.syn
index d4a321034d..b51d168cc0 100644
--- a/src/mesa/shader/slang/library/slang_pp_directives.syn
+++ b/src/mesa/shader/slang/library/slang_pp_directives.syn
@@ -79,6 +79,12 @@
.emtcode BEHAVIOR_WARN 3
.emtcode BEHAVIOR_DISABLE 4
+/*
+ * The PRAGMA_* symbols follow TOKEN_PRAGMA
+ */
+.emtcode PRAGMA_NO_PARAM 0
+.emtcode PRAGMA_PARAM 1
+
source
optional_directive .and .loop source_element .and '\0' .emit ESCAPE_TOKEN .emit TOKEN_END;
@@ -153,6 +159,7 @@ directive
dir_elif .emit TOKEN_ELIF .or
dir_endif .emit TOKEN_ENDIF .or
dir_ext .emit TOKEN_EXTENSION .or
+ dir_pragma .emit TOKEN_PRAGMA .or
dir_line .emit TOKEN_LINE;
dir_define
@@ -187,6 +194,19 @@ dir_ext
dir_line
optional_space .and '#' .and optional_space .and "line" .and expression;
+dir_pragma
+ optional_space .and '#' .and optional_space .and "pragma" .and symbol .and opt_pragma_param;
+
+
+opt_pragma_param
+ pragma_param .or .true .emit PRAGMA_NO_PARAM;
+
+pragma_param
+ optional_space .and '(' .emit PRAGMA_PARAM .and optional_space .and symbol_no_space .and optional_space .and ')';
+
+symbol_no_space
+ symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\0';
+
symbol
space .and symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\0';
diff --git a/src/mesa/shader/slang/library/slang_pp_directives_syn.h b/src/mesa/shader/slang/library/slang_pp_directives_syn.h
index 35e7bc2761..430f8d8217 100644
--- a/src/mesa/shader/slang/library/slang_pp_directives_syn.h
+++ b/src/mesa/shader/slang/library/slang_pp_directives_syn.h
@@ -20,6 +20,8 @@
".emtcode BEHAVIOR_ENABLE 2\n"
".emtcode BEHAVIOR_WARN 3\n"
".emtcode BEHAVIOR_DISABLE 4\n"
+".emtcode PRAGMA_NO_PARAM 0\n"
+".emtcode PRAGMA_PARAM 1\n"
"source\n"
" optional_directive .and .loop source_element .and '\\0' .emit ESCAPE_TOKEN .emit TOKEN_END;\n"
"source_element\n"
@@ -76,6 +78,7 @@
" dir_elif .emit TOKEN_ELIF .or\n"
" dir_endif .emit TOKEN_ENDIF .or\n"
" dir_ext .emit TOKEN_EXTENSION .or\n"
+" dir_pragma .emit TOKEN_PRAGMA .or\n"
" dir_line .emit TOKEN_LINE;\n"
"dir_define\n"
" optional_space .and '#' .and optional_space .and \"define\" .and symbol .and opt_parameters .and\n"
@@ -99,6 +102,14 @@
" optional_space .and ':' .and optional_space .and extension_behavior;\n"
"dir_line\n"
" optional_space .and '#' .and optional_space .and \"line\" .and expression;\n"
+"dir_pragma\n"
+" optional_space .and '#' .and optional_space .and \"pragma\" .and symbol .and opt_pragma_param;\n"
+"opt_pragma_param\n"
+" pragma_param .or .true .emit PRAGMA_NO_PARAM;\n"
+"pragma_param\n"
+" optional_space .and '(' .emit PRAGMA_PARAM .and optional_space .and symbol_no_space .and optional_space .and ')';\n"
+"symbol_no_space\n"
+" symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\\0';\n"
"symbol\n"
" space .and symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\\0';\n"
"opt_parameters\n"
diff --git a/src/mesa/shader/slang/library/slang_shader.syn b/src/mesa/shader/slang/library/slang_shader.syn
index 0ad4a1cba6..cc5c70a02f 100644
--- a/src/mesa/shader/slang/library/slang_shader.syn
+++ b/src/mesa/shader/slang/library/slang_shader.syn
@@ -1162,13 +1162,6 @@ compound_statement_3
lbrace .and statement_list .and rbrace;
/*
- * <statement_no_new_scope> ::= <compound_statement_no_new_scope>
- * | <simple_statement>
- */
-statement_no_new_scope
- compound_statement_no_new_scope .or simple_statement;
-
-/*
* <compound_statement_no_new_scope> ::= "{" "}"
* | "{" <statement_list> "}"
*/
@@ -1181,6 +1174,7 @@ compound_statement_no_new_scope_2
compound_statement_no_new_scope_3
lbrace .and statement_list .and rbrace;
+
/*
* <statement_list> ::= <statement>
* | <statement_list> <statement>
@@ -1242,8 +1236,7 @@ condition_3
/*
* <iteration_statement> ::= "while" "(" <condition> ")" <statement>
* | "do" <statement> "while" "(" <expression> ")" ";"
- * | "for" "(" <for_init_statement> <for_rest_statement> ")"
- * <statement_no_new_scope>
+ * | "for" "(" <for_init_statement> <for_rest_statement> ")" <statement>
*/
iteration_statement
iteration_statement_1 .or iteration_statement_2 .or iteration_statement_3;
@@ -1255,7 +1248,7 @@ iteration_statement_2
expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;
iteration_statement_3
"for" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and
- for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;
+ for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement;
/*
* <for_init_statement> ::= <expression_statement>
diff --git a/src/mesa/shader/slang/library/slang_shader_syn.h b/src/mesa/shader/slang/library/slang_shader_syn.h
index e1705dfe19..6a382970e1 100644
--- a/src/mesa/shader/slang/library/slang_shader_syn.h
+++ b/src/mesa/shader/slang/library/slang_shader_syn.h
@@ -566,8 +566,6 @@
" lbrace .and rbrace;\n"
"compound_statement_3\n"
" lbrace .and statement_list .and rbrace;\n"
-"statement_no_new_scope\n"
-" compound_statement_no_new_scope .or simple_statement;\n"
"compound_statement_no_new_scope\n"
" compound_statement_no_new_scope_1 .emit OP_BLOCK_BEGIN_NO_NEW_SCOPE .and .true .emit OP_END;\n"
"compound_statement_no_new_scope_1\n"
@@ -617,7 +615,7 @@
" expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;\n"
"iteration_statement_3\n"
" \"for\" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and\n"
-" for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;\n"
+" for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement;\n"
"for_init_statement\n"
" expression_statement .emit OP_EXPRESSION .or declaration_statement .emit OP_DECLARE;\n"
"conditionopt\n"
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index ba1c955a1a..11340d26e2 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -228,7 +228,14 @@ _slang_sizeof_type_specifier(const slang_type_specifier *spec)
break;
case SLANG_SPEC_STRUCT:
sz = _slang_field_offset(spec, 0); /* special use */
- if (sz > 4) {
+ if (sz == 1) {
+ /* 1-float structs are actually troublesome to deal with since they
+ * might get placed at R.x, R.y, R.z or R.z. Return size=2 to
+ * ensure the object is placed at R.x
+ */
+ sz = 2;
+ }
+ else if (sz > 4) {
sz = (sz + 3) & ~0x3; /* round up to multiple of four */
}
break;
@@ -4232,6 +4239,21 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper)
/**
+ * Check if the given type specifier is a rectangular texture sampler.
+ */
+static GLboolean
+is_rect_sampler_spec(const slang_type_specifier *spec)
+{
+ while (spec->_array) {
+ spec = spec->_array;
+ }
+ return spec->type == SLANG_SPEC_SAMPLER2DRECT ||
+ spec->type == SLANG_SPEC_SAMPLER2DRECTSHADOW;
+}
+
+
+
+/**
* Called by compiler when a global variable has been parsed/compiled.
* Here we examine the variable's type to determine what kind of register
* storage will be used.
@@ -4254,10 +4276,14 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
slang_ir_storage *store = NULL;
int dbg = 0;
const GLenum datatype = _slang_gltype_from_specifier(&var->type.specifier);
- const GLint texIndex = sampler_to_texture_index(var->type.specifier.type);
const GLint size = _slang_sizeof_type_specifier(&var->type.specifier);
const GLint arrayLen = _slang_array_length(var);
const GLint totalSize = _slang_array_size(size, arrayLen);
+ GLint texIndex = sampler_to_texture_index(var->type.specifier.type);
+
+ /* check for sampler2D arrays */
+ if (texIndex == -1 && var->type.specifier._array)
+ texIndex = sampler_to_texture_index(var->type.specifier._array->type);
if (texIndex != -1) {
/* This is a texture sampler variable...
@@ -4271,15 +4297,32 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
}
#if FEATURE_es2_glsl /* XXX should use FEATURE_texture_rect */
/* disallow rect samplers */
- if (var->type.specifier.type == SLANG_SPEC_SAMPLER2DRECT ||
- var->type.specifier.type == SLANG_SPEC_SAMPLER2DRECTSHADOW) {
+ if (is_rect_sampler_spec(&var->type.specifier)) {
slang_info_log_error(A->log, "invalid sampler type for '%s'", varName);
return GL_FALSE;
}
+#else
+ (void) is_rect_sampler_spec; /* silence warning */
#endif
{
GLint sampNum = _mesa_add_sampler(prog->Parameters, varName, datatype);
- store = _slang_new_ir_storage(PROGRAM_SAMPLER, sampNum, texIndex);
+ store = _slang_new_ir_storage_sampler(sampNum, texIndex, totalSize);
+
+ /* If we have a sampler array, then we need to allocate the
+ * additional samplers to ensure we don't allocate them elsewhere.
+ * We can't directly use _mesa_add_sampler() as that checks the
+ * varName and gets a match, so we call _mesa_add_parameter()
+ * directly and use the last sampler number from the call above.
+ */
+ if (arrayLen > 0) {
+ GLint a = arrayLen - 1;
+ GLint i;
+ for (i = 0; i < a; i++) {
+ GLfloat value = (GLfloat)(i + sampNum + 1);
+ (void) _mesa_add_parameter(prog->Parameters, PROGRAM_SAMPLER,
+ varName, 1, datatype, &value, NULL, 0x0);
+ }
+ }
}
if (dbg) printf("SAMPLER ");
}
@@ -4463,7 +4506,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
n = _slang_gen_var_decl(A, var, var->initializer);
/* emit GPU instructions */
- success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE, A->log);
+ success = _slang_emit_code(n, A->vartable, A->program, A->pragmas, GL_FALSE, A->log);
_slang_free_ir_tree(n);
}
@@ -4573,7 +4616,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun)
#endif
/* Emit program instructions */
- success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE, A->log);
+ success = _slang_emit_code(n, A->vartable, A->program, A->pragmas, GL_TRUE, A->log);
_slang_free_ir_tree(n);
/* free codegen context */
diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h
index 9489033d7b..f2daa034e4 100644
--- a/src/mesa/shader/slang/slang_codegen.h
+++ b/src/mesa/shader/slang/slang_codegen.h
@@ -36,6 +36,7 @@ typedef struct slang_assemble_ctx_
slang_atom_pool *atoms;
slang_name_space space;
struct gl_program *program;
+ struct gl_sl_pragmas *pragmas;
slang_var_table *vartable;
slang_info_log *log;
struct slang_label_ *curFuncEndLabel;
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index 0a527f3220..818b90b7a8 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -144,6 +144,7 @@ typedef struct slang_output_ctx_
slang_function_scope *funs;
slang_struct_scope *structs;
struct gl_program *program;
+ struct gl_sl_pragmas *pragmas;
slang_var_table *vartable;
GLuint default_precision[TYPE_SPECIFIER_COUNT];
GLboolean allow_precision;
@@ -1005,7 +1006,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
/* parse child statements, do not create new variable scope */
oper->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE;
while (*C->I != OP_END)
- if (!parse_child_operation(C, O, oper, 1))
+ if (!parse_child_operation(C, O, oper, GL_TRUE))
RETURN0;
C->I++;
break;
@@ -1017,7 +1018,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
oper->type = SLANG_OPER_BLOCK_NEW_SCOPE;
o.vars = oper->locals;
while (*C->I != OP_END)
- if (!parse_child_operation(C, &o, oper, 1))
+ if (!parse_child_operation(C, &o, oper, GL_TRUE))
RETURN0;
C->I++;
}
@@ -1074,7 +1075,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
if (oper->a_id == SLANG_ATOM_NULL)
RETURN0;
while (*C->I != OP_END) {
- if (!parse_child_operation(C, O, oper, 0))
+ if (!parse_child_operation(C, O, oper, GL_FALSE))
RETURN0;
}
C->I++;
@@ -1090,21 +1091,21 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
break;
case OP_RETURN:
oper->type = SLANG_OPER_RETURN;
- if (!parse_child_operation(C, O, oper, 0))
+ if (!parse_child_operation(C, O, oper, GL_FALSE))
RETURN0;
break;
case OP_EXPRESSION:
oper->type = SLANG_OPER_EXPRESSION;
- if (!parse_child_operation(C, O, oper, 0))
+ if (!parse_child_operation(C, O, oper, GL_FALSE))
RETURN0;
break;
case OP_IF:
oper->type = SLANG_OPER_IF;
- if (!parse_child_operation(C, O, oper, 0))
+ if (!parse_child_operation(C, O, oper, GL_FALSE))
RETURN0;
- if (!parse_child_operation(C, O, oper, 1))
+ if (!parse_child_operation(C, O, oper, GL_TRUE))
RETURN0;
- if (!parse_child_operation(C, O, oper, 1))
+ if (!parse_child_operation(C, O, oper, GL_TRUE))
RETURN0;
break;
case OP_WHILE:
@@ -1113,17 +1114,17 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
oper->type = SLANG_OPER_WHILE;
o.vars = oper->locals;
- if (!parse_child_operation(C, &o, oper, 1))
+ if (!parse_child_operation(C, &o, oper, GL_TRUE))
RETURN0;
- if (!parse_child_operation(C, &o, oper, 1))
+ if (!parse_child_operation(C, &o, oper, GL_TRUE))
RETURN0;
}
break;
case OP_DO:
oper->type = SLANG_OPER_DO;
- if (!parse_child_operation(C, O, oper, 1))
+ if (!parse_child_operation(C, O, oper, GL_TRUE))
RETURN0;
- if (!parse_child_operation(C, O, oper, 0))
+ if (!parse_child_operation(C, O, oper, GL_FALSE))
RETURN0;
break;
case OP_FOR:
@@ -1132,13 +1133,13 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
oper->type = SLANG_OPER_FOR;
o.vars = oper->locals;
- if (!parse_child_operation(C, &o, oper, 1))
+ if (!parse_child_operation(C, &o, oper, GL_TRUE))
RETURN0;
- if (!parse_child_operation(C, &o, oper, 1))
+ if (!parse_child_operation(C, &o, oper, GL_TRUE))
RETURN0;
- if (!parse_child_operation(C, &o, oper, 0))
+ if (!parse_child_operation(C, &o, oper, GL_FALSE))
RETURN0;
- if (!parse_child_operation(C, &o, oper, 1))
+ if (!parse_child_operation(C, &o, oper, GL_TRUE))
RETURN0;
}
break;
@@ -1429,7 +1430,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O,
C->I++;
while (*C->I != OP_END)
- if (!parse_child_operation(C, O, op, 0))
+ if (!parse_child_operation(C, O, op, GL_FALSE))
RETURN0;
C->I++;
#if 0
@@ -1470,9 +1471,9 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O,
RETURN0;
}
else {
+ /* parse the array constructor size */
slang_operation array_size;
array_constructor = GL_TRUE;
- /* parse the array constructor size */
slang_operation_construct(&array_size);
if (!parse_expression(C, O, &array_size)) {
slang_operation_destruct(&array_size);
@@ -1494,7 +1495,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O,
RETURN0;
}
while (*C->I != OP_END)
- if (!parse_child_operation(C, O, op, 0))
+ if (!parse_child_operation(C, O, op, GL_FALSE))
RETURN0;
C->I++;
@@ -2059,6 +2060,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O,
A.space.structs = O->structs;
A.space.vars = O->vars;
A.program = O->program;
+ A.pragmas = O->pragmas;
A.vartable = O->vartable;
A.log = C->L;
A.curFuncEndLabel = NULL;
@@ -2349,6 +2351,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
o.structs = &unit->structs;
o.vars = &unit->vars;
o.program = shader ? shader->Program : NULL;
+ o.pragmas = shader ? &shader->Pragmas : NULL;
o.vartable = _slang_new_var_table(maxRegs);
_slang_push_var_table(o.vartable);
@@ -2417,6 +2420,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
A.space.structs = o.structs;
A.space.vars = o.vars;
A.program = o.program;
+ A.pragmas = &shader->Pragmas;
A.vartable = o.vartable;
A.log = C->L;
@@ -2475,7 +2479,8 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit,
slang_unit_type type, slang_info_log * infolog,
slang_code_unit * builtin,
struct gl_shader *shader,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
byte *prod;
GLuint size, start, version;
@@ -2504,7 +2509,7 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit,
/* Now preprocess the source string. */
slang_string_init(&preprocessed);
if (!_slang_preprocess_directives(&preprocessed, &source[start],
- infolog, extensions)) {
+ infolog, extensions, pragmas)) {
slang_string_free(&preprocessed);
slang_info_log_error(infolog, "failed to preprocess the source.");
return GL_FALSE;
@@ -2578,7 +2583,8 @@ static GLboolean
compile_object(grammar * id, const char *source, slang_code_object * object,
slang_unit_type type, slang_info_log * infolog,
struct gl_shader *shader,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
slang_code_unit *builtins = NULL;
GLuint base_version = 110;
@@ -2677,7 +2683,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object,
/* compile the actual shader - pass-in built-in library for external shader */
return compile_with_grammar(*id, source, &object->unit, type, infolog,
- builtins, shader, extensions);
+ builtins, shader, extensions, pragmas);
}
@@ -2701,7 +2707,7 @@ compile_shader(GLcontext *ctx, slang_code_object * object,
_slang_code_object_ctr(object);
success = compile_object(&id, shader->Source, object, type, infolog, shader,
- &ctx->Extensions);
+ &ctx->Extensions, &shader->Pragmas);
if (id != 0)
grammar_destroy(id);
if (!success)
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index d3b4e64b78..ea446fa5d4 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1271,6 +1271,20 @@ emit_tex(slang_emit_info *emitInfo, slang_ir_node *n)
opcode = OPCODE_TXP;
}
+ if (n->Children[0]->Opcode == IR_ELEMENT) {
+ /* array is the sampler (a uniform which'll indicate the texture unit) */
+ assert(n->Children[0]->Children[0]->Store);
+ assert(n->Children[0]->Children[0]->Store->File == PROGRAM_SAMPLER);
+
+ emit(emitInfo, n->Children[0]);
+
+ n->Children[0]->Var = n->Children[0]->Children[0]->Var;
+ } else {
+ /* this is the sampler (a uniform which'll indicate the texture unit) */
+ assert(n->Children[0]->Store);
+ assert(n->Children[0]->Store->File == PROGRAM_SAMPLER);
+ }
+
/* emit code for the texcoord operand */
(void) emit(emitInfo, n->Children[1]);
@@ -1286,17 +1300,10 @@ emit_tex(slang_emit_info *emitInfo, slang_ir_node *n)
NULL,
NULL);
- /* Child[0] is the sampler (a uniform which'll indicate the texture unit) */
- assert(n->Children[0]->Store);
- assert(n->Children[0]->Store->File == PROGRAM_SAMPLER);
- /* Store->Index is the sampler index */
+ /* Store->Index is the uniform/sampler index */
assert(n->Children[0]->Store->Index >= 0);
- /* Store->Size is the texture target */
- assert(n->Children[0]->Store->Size >= TEXTURE_1D_INDEX);
- assert(n->Children[0]->Store->Size <= TEXTURE_RECT_INDEX);
-
- inst->TexSrcTarget = n->Children[0]->Store->Size;
- inst->TexSrcUnit = n->Children[0]->Store->Index; /* i.e. uniform's index */
+ inst->TexSrcUnit = n->Children[0]->Store->Index;
+ inst->TexSrcTarget = n->Children[0]->Store->TexTarget;
/* mark the sampler as being used */
_mesa_use_uniform(emitInfo->prog->Parameters,
@@ -1342,9 +1349,10 @@ emit_copy(slang_emit_info *emitInfo, slang_ir_node *n)
if (n->Store->File == PROGRAM_SAMPLER) {
/* no code generated for sampler assignments,
- * just copy the sampler index at compile time.
+ * just copy the sampler index/target at compile time.
*/
n->Store->Index = n->Children[1]->Store->Index;
+ n->Store->TexTarget = n->Children[1]->Store->TexTarget;
return NULL;
}
@@ -2370,10 +2378,20 @@ _slang_resolve_subroutines(slang_emit_info *emitInfo)
-
+/**
+ * Convert the IR tree into GPU instructions.
+ * \param n root of IR tree
+ * \param vt variable table
+ * \param prog program to put GPU instructions into
+ * \param pragmas controls codegen options
+ * \param withEnd if true, emit END opcode at end
+ * \param log log for emitting errors/warnings/info
+ */
GLboolean
_slang_emit_code(slang_ir_node *n, slang_var_table *vt,
- struct gl_program *prog, GLboolean withEnd,
+ struct gl_program *prog,
+ const struct gl_sl_pragmas *pragmas,
+ GLboolean withEnd,
slang_info_log *log)
{
GET_CURRENT_CONTEXT(ctx);
@@ -2390,7 +2408,7 @@ _slang_emit_code(slang_ir_node *n, slang_var_table *vt,
emitInfo.EmitHighLevelInstructions = ctx->Shader.EmitHighLevelInstructions;
emitInfo.EmitCondCodes = ctx->Shader.EmitCondCodes;
- emitInfo.EmitComments = ctx->Shader.EmitComments;
+ emitInfo.EmitComments = ctx->Shader.EmitComments || pragmas->Debug;
emitInfo.EmitBeginEndSub = GL_TRUE;
if (!emitInfo.EmitCondCodes) {
diff --git a/src/mesa/shader/slang/slang_emit.h b/src/mesa/shader/slang/slang_emit.h
index 59fb2fa890..8ff52bf605 100644
--- a/src/mesa/shader/slang/slang_emit.h
+++ b/src/mesa/shader/slang/slang_emit.h
@@ -46,7 +46,9 @@ _slang_var_swizzle(GLint size, GLint comp);
extern GLboolean
_slang_emit_code(slang_ir_node *n, slang_var_table *vartable,
- struct gl_program *prog, GLboolean withEnd,
+ struct gl_program *prog,
+ const struct gl_sl_pragmas *pragmas,
+ GLboolean withEnd,
slang_info_log *log);
diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c
index c33c80da99..e4c6e0ea51 100644
--- a/src/mesa/shader/slang/slang_ir.c
+++ b/src/mesa/shader/slang/slang_ir.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 7.1
*
* Copyright (C) 2005-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -216,6 +216,26 @@ _slang_new_ir_storage_indirect(enum register_file file,
}
+/**
+ * Allocate IR storage for a texture sampler.
+ * \param sampNum the sampler number/index
+ * \param texTarget one of TEXTURE_x_INDEX values
+ * \param size number of samplers (in case of sampler array)
+ */
+slang_ir_storage *
+_slang_new_ir_storage_sampler(GLint sampNum, GLuint texTarget, GLint size)
+{
+ slang_ir_storage *st;
+ assert(texTarget < NUM_TEXTURE_TARGETS);
+ st = _slang_new_ir_storage(PROGRAM_SAMPLER, sampNum, size);
+ if (st) {
+ st->TexTarget = texTarget;
+ }
+ return st;
+}
+
+
+
/* XXX temporary function */
void
_slang_copy_ir_storage(slang_ir_storage *dst, const slang_ir_storage *src)
diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
index a258e92e06..644269d491 100644
--- a/src/mesa/shader/slang/slang_ir.h
+++ b/src/mesa/shader/slang/slang_ir.h
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.3
*
- * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
+ * Copyright (C) 2005-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -168,8 +168,8 @@ typedef enum
struct slang_ir_storage_
{
enum register_file File; /**< PROGRAM_TEMPORARY, PROGRAM_INPUT, etc */
- GLint Index; /**< -1 means unallocated */
- GLint Size; /**< number of floats */
+ GLint Index; /**< -1 means unallocated */
+ GLint Size; /**< number of floats or ints */
GLuint Swizzle; /**< Swizzle AND writemask info */
GLint RefCount; /**< Used during IR tree delete */
@@ -179,6 +179,7 @@ struct slang_ir_storage_
enum register_file IndirectFile;
GLint IndirectIndex;
GLuint IndirectSwizzle;
+ GLuint TexTarget; /**< If File==PROGRAM_SAMPLER, one of TEXTURE_x_INDEX */
/** If Parent is non-null, Index is relative to parent.
* The other fields are ignored.
@@ -254,6 +255,10 @@ _slang_new_ir_storage_indirect(enum register_file file,
GLint indirectIndex,
GLuint indirectSwizzle);
+extern slang_ir_storage *
+_slang_new_ir_storage_sampler(GLint sampNum, GLuint texTarget, GLint size);
+
+
extern void
_slang_copy_ir_storage(slang_ir_storage *dst, const slang_ir_storage *src);
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index a68cafc086..b5862bda82 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -260,8 +260,8 @@ link_uniform_vars(GLcontext *ctx,
GLuint newSampNum = *numSamplers;
if (newSampNum >= ctx->Const.MaxTextureImageUnits) {
char s[100];
- sprintf(s, "Too many texture samplers (%u, max is %u)",
- newSampNum, ctx->Const.MaxTextureImageUnits);
+ _mesa_sprintf(s, "Too many texture samplers (%u, max is %u)",
+ newSampNum, ctx->Const.MaxTextureImageUnits);
link_error(shProg, s);
return GL_FALSE;
}
@@ -282,12 +282,14 @@ link_uniform_vars(GLcontext *ctx,
for (i = 0; i < prog->NumInstructions; i++) {
struct prog_instruction *inst = prog->Instructions + i;
if (_mesa_is_tex_instruction(inst->Opcode)) {
- /*
+ const GLint oldSampNum = inst->TexSrcUnit;
+
+#if 0
printf("====== remap sampler from %d to %d\n",
- inst->Sampler, map[ inst->Sampler ]);
- */
+ inst->TexSrcUnit, samplerMap[ inst->TexSrcUnit ]);
+#endif
+
/* here, texUnit is really samplerUnit */
- const GLint oldSampNum = inst->TexSrcUnit;
if (oldSampNum < Elements(samplerMap)) {
const GLuint newSampNum = samplerMap[oldSampNum];
inst->TexSrcUnit = newSampNum;
diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c
index 76e757cb38..cd79c8b94a 100644
--- a/src/mesa/shader/slang/slang_preprocess.c
+++ b/src/mesa/shader/slang/slang_preprocess.c
@@ -51,6 +51,9 @@ grammar_error_to_log (slang_info_log *log)
GLint pos;
grammar_get_last_error ((byte *) (buf), sizeof (buf), &pos);
+ if (buf[0] == 0) {
+ _mesa_snprintf(buf, sizeof(buf), "Preprocessor error");
+ }
slang_info_log_error (log, buf);
}
@@ -528,6 +531,56 @@ pp_ext_set(pp_ext *self, const char *name, GLboolean enable)
}
+static void
+pp_pragmas_init(struct gl_sl_pragmas *pragmas)
+{
+ pragmas->Optimize = GL_TRUE;
+ pragmas->Debug = GL_FALSE;
+}
+
+
+/**
+ * Called in response to #pragma. For example, "#pragma debug(on)" would
+ * call this function as pp_pragma("debug", "on").
+ * \return GL_TRUE if pragma is valid, GL_FALSE if invalid
+ */
+static GLboolean
+pp_pragma(struct gl_sl_pragmas *pragmas, const char *pragma, const char *param)
+{
+#if 0
+ printf("#pragma %s %s\n", pragma, param);
+#endif
+ if (_mesa_strcmp(pragma, "optimize") == 0) {
+ if (!param)
+ return GL_FALSE; /* missing required param */
+ if (_mesa_strcmp(param, "on") == 0) {
+ pragmas->Optimize = GL_TRUE;
+ }
+ else if (_mesa_strcmp(param, "off") == 0) {
+ pragmas->Optimize = GL_FALSE;
+ }
+ else {
+ return GL_FALSE; /* invalid param */
+ }
+ }
+ else if (_mesa_strcmp(pragma, "debug") == 0) {
+ if (!param)
+ return GL_FALSE; /* missing required param */
+ if (_mesa_strcmp(param, "on") == 0) {
+ pragmas->Debug = GL_TRUE;
+ }
+ else if (_mesa_strcmp(param, "off") == 0) {
+ pragmas->Debug = GL_FALSE;
+ }
+ else {
+ return GL_FALSE; /* invalid param */
+ }
+ }
+ /* all other pragmas are silently ignored */
+ return GL_TRUE;
+}
+
+
/**
* The state of preprocessor: current line, file and version number, list
* of all defined macros and the #if/#endif context.
@@ -862,11 +915,16 @@ parse_if (slang_string *output, const byte *prod, GLuint *pi, GLint *result, pp_
#define BEHAVIOR_WARN 3
#define BEHAVIOR_DISABLE 4
+#define PRAGMA_NO_PARAM 0
+#define PRAGMA_PARAM 1
+
+
static GLboolean
preprocess_source (slang_string *output, const char *source,
grammar pid, grammar eid,
slang_info_log *elog,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
static const char *predefined[] = {
"__FILE__",
@@ -888,6 +946,7 @@ preprocess_source (slang_string *output, const char *source,
}
pp_state_init (&state, elog, extensions);
+ pp_pragmas_init (pragmas);
/* add the predefined symbols to the symbol table */
for (i = 0; predefined[i]; i++) {
@@ -940,9 +999,11 @@ preprocess_source (slang_string *output, const char *source,
else {
const char *id;
GLuint idlen;
+ GLubyte token;
i++;
- switch (prod[i++]) {
+ token = prod[i++];
+ switch (token) {
case TOKEN_END:
/* End of source string.
@@ -1159,6 +1220,25 @@ preprocess_source (slang_string *output, const char *source,
}
break;
+ case TOKEN_PRAGMA:
+ {
+ GLint have_param;
+ const char *pragma, *param;
+
+ pragma = (const char *) (&prod[i]);
+ i += _mesa_strlen(pragma) + 1;
+ have_param = (prod[i++] == PRAGMA_PARAM);
+ if (have_param) {
+ param = (const char *) (&prod[i]);
+ i += _mesa_strlen(param) + 1;
+ }
+ else {
+ param = NULL;
+ }
+ pp_pragma(pragmas, pragma, param);
+ }
+ break;
+
case TOKEN_LINE:
id = (const char *) (&prod[i]);
i += _mesa_strlen (id) + 1;
@@ -1223,7 +1303,8 @@ GLboolean
_slang_preprocess_directives(slang_string *output,
const char *input,
slang_info_log *elog,
- const struct gl_extensions *extensions)
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas)
{
grammar pid, eid;
GLboolean success;
@@ -1239,7 +1320,7 @@ _slang_preprocess_directives(slang_string *output,
grammar_destroy (pid);
return GL_FALSE;
}
- success = preprocess_source (output, input, pid, eid, elog, extensions);
+ success = preprocess_source (output, input, pid, eid, elog, extensions, pragmas);
grammar_destroy (eid);
grammar_destroy (pid);
return success;
diff --git a/src/mesa/shader/slang/slang_preprocess.h b/src/mesa/shader/slang/slang_preprocess.h
index dd996a6314..f344820dae 100644
--- a/src/mesa/shader/slang/slang_preprocess.h
+++ b/src/mesa/shader/slang/slang_preprocess.h
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.3
*
- * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
+ * Copyright (C) 2005-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -35,6 +35,7 @@ _slang_preprocess_version (const char *, GLuint *, GLuint *, slang_info_log *);
extern GLboolean
_slang_preprocess_directives(slang_string *output, const char *input,
slang_info_log *,
- const struct gl_extensions *extensions);
+ const struct gl_extensions *extensions,
+ struct gl_sl_pragmas *pragmas);
#endif /* SLANG_PREPROCESS_H */
diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c
index a5bcde404f..1ef43f58c0 100644
--- a/src/mesa/shader/slang/slang_typeinfo.c
+++ b/src/mesa/shader/slang/slang_typeinfo.c
@@ -23,7 +23,7 @@
*/
/**
- * \file slang_assemble_typeinfo.c
+ * \file slang_typeinfo.c
* slang type info
* \author Michal Krol
*/