aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/shader/slang/slang_codegen.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
committermarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
commit29b86f9852b2b7ecc31cdfee56679537e40bc6e2 (patch)
tree1e6ec8ccf2dbf773260a1953b8e13c49f9b7c5f5 /mesalib/src/mesa/shader/slang/slang_codegen.c
parent529236591df7366479a6fac30b387667678fd1ba (diff)
downloadvcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.gz
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.bz2
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.zip
svn merge -r524:HEAD "^/branches/released" .
Diffstat (limited to 'mesalib/src/mesa/shader/slang/slang_codegen.c')
-rw-r--r--mesalib/src/mesa/shader/slang/slang_codegen.c117
1 files changed, 76 insertions, 41 deletions
diff --git a/mesalib/src/mesa/shader/slang/slang_codegen.c b/mesalib/src/mesa/shader/slang/slang_codegen.c
index ee5a50ca8..ecb2f6d5c 100644
--- a/mesalib/src/mesa/shader/slang/slang_codegen.c
+++ b/mesalib/src/mesa/shader/slang/slang_codegen.c
@@ -100,14 +100,18 @@ static GLboolean
is_sampler_type(const slang_fully_specified_type *t)
{
switch (t->specifier.type) {
- case SLANG_SPEC_SAMPLER1D:
- case SLANG_SPEC_SAMPLER2D:
- case SLANG_SPEC_SAMPLER3D:
- case SLANG_SPEC_SAMPLERCUBE:
- case SLANG_SPEC_SAMPLER1DSHADOW:
- case SLANG_SPEC_SAMPLER2DSHADOW:
- case SLANG_SPEC_SAMPLER2DRECT:
- case SLANG_SPEC_SAMPLER2DRECTSHADOW:
+ case SLANG_SPEC_SAMPLER_1D:
+ case SLANG_SPEC_SAMPLER_2D:
+ case SLANG_SPEC_SAMPLER_3D:
+ case SLANG_SPEC_SAMPLER_CUBE:
+ case SLANG_SPEC_SAMPLER_1D_SHADOW:
+ case SLANG_SPEC_SAMPLER_2D_SHADOW:
+ case SLANG_SPEC_SAMPLER_RECT:
+ case SLANG_SPEC_SAMPLER_RECT_SHADOW:
+ case SLANG_SPEC_SAMPLER_1D_ARRAY:
+ case SLANG_SPEC_SAMPLER_2D_ARRAY:
+ case SLANG_SPEC_SAMPLER_1D_ARRAY_SHADOW:
+ case SLANG_SPEC_SAMPLER_2D_ARRAY_SHADOW:
return GL_TRUE;
default:
return GL_FALSE;
@@ -222,14 +226,18 @@ _slang_sizeof_type_specifier(const slang_type_specifier *spec)
case SLANG_SPEC_MAT43:
sz = 4 * 4; /* 4 columns (regs) */
break;
- case SLANG_SPEC_SAMPLER1D:
- case SLANG_SPEC_SAMPLER2D:
- case SLANG_SPEC_SAMPLER3D:
- case SLANG_SPEC_SAMPLERCUBE:
- case SLANG_SPEC_SAMPLER1DSHADOW:
- case SLANG_SPEC_SAMPLER2DSHADOW:
- case SLANG_SPEC_SAMPLER2DRECT:
- case SLANG_SPEC_SAMPLER2DRECTSHADOW:
+ case SLANG_SPEC_SAMPLER_1D:
+ case SLANG_SPEC_SAMPLER_2D:
+ case SLANG_SPEC_SAMPLER_3D:
+ case SLANG_SPEC_SAMPLER_CUBE:
+ case SLANG_SPEC_SAMPLER_1D_SHADOW:
+ case SLANG_SPEC_SAMPLER_2D_SHADOW:
+ case SLANG_SPEC_SAMPLER_RECT:
+ case SLANG_SPEC_SAMPLER_RECT_SHADOW:
+ case SLANG_SPEC_SAMPLER_1D_ARRAY:
+ case SLANG_SPEC_SAMPLER_2D_ARRAY:
+ case SLANG_SPEC_SAMPLER_1D_ARRAY_SHADOW:
+ case SLANG_SPEC_SAMPLER_2D_ARRAY_SHADOW:
sz = 1; /* a sampler is basically just an integer index */
break;
case SLANG_SPEC_STRUCT:
@@ -310,22 +318,30 @@ static GLint
sampler_to_texture_index(const slang_type_specifier_type type)
{
switch (type) {
- case SLANG_SPEC_SAMPLER1D:
+ case SLANG_SPEC_SAMPLER_1D:
return TEXTURE_1D_INDEX;
- case SLANG_SPEC_SAMPLER2D:
+ case SLANG_SPEC_SAMPLER_2D:
return TEXTURE_2D_INDEX;
- case SLANG_SPEC_SAMPLER3D:
+ case SLANG_SPEC_SAMPLER_3D:
return TEXTURE_3D_INDEX;
- case SLANG_SPEC_SAMPLERCUBE:
+ case SLANG_SPEC_SAMPLER_CUBE:
return TEXTURE_CUBE_INDEX;
- case SLANG_SPEC_SAMPLER1DSHADOW:
+ case SLANG_SPEC_SAMPLER_1D_SHADOW:
return TEXTURE_1D_INDEX; /* XXX fix */
- case SLANG_SPEC_SAMPLER2DSHADOW:
+ case SLANG_SPEC_SAMPLER_2D_SHADOW:
return TEXTURE_2D_INDEX; /* XXX fix */
- case SLANG_SPEC_SAMPLER2DRECT:
+ case SLANG_SPEC_SAMPLER_RECT:
return TEXTURE_RECT_INDEX;
- case SLANG_SPEC_SAMPLER2DRECTSHADOW:
+ case SLANG_SPEC_SAMPLER_RECT_SHADOW:
return TEXTURE_RECT_INDEX; /* XXX fix */
+ case SLANG_SPEC_SAMPLER_1D_ARRAY:
+ return TEXTURE_1D_ARRAY_INDEX;
+ case SLANG_SPEC_SAMPLER_2D_ARRAY:
+ return TEXTURE_2D_ARRAY_INDEX;
+ case SLANG_SPEC_SAMPLER_1D_ARRAY_SHADOW:
+ return TEXTURE_1D_ARRAY_INDEX;
+ case SLANG_SPEC_SAMPLER_2D_ARRAY_SHADOW:
+ return TEXTURE_2D_ARRAY_INDEX;
default:
return -1;
}
@@ -453,6 +469,14 @@ static slang_asm_info AsmInfo[] = {
{ "vec4_tex_cube", IR_TEX, 1, 2 }, /* cubemap */
{ "vec4_tex_rect", IR_TEX, 1, 2 }, /* rectangle */
{ "vec4_tex_rect_bias", IR_TEX, 1, 2 }, /* rectangle w/ projection */
+ { "vec4_tex_1d_array", IR_TEX, 1, 2 },
+ { "vec4_tex_1d_array_bias", IR_TEXB, 1, 2 },
+ { "vec4_tex_1d_array_shadow", IR_TEX, 1, 2 },
+ { "vec4_tex_1d_array_bias_shadow", IR_TEXB, 1, 2 },
+ { "vec4_tex_2d_array", IR_TEX, 1, 2 },
+ { "vec4_tex_2d_array_bias", IR_TEXB, 1, 2 },
+ { "vec4_tex_2d_array_shadow", IR_TEX, 1, 2 },
+ { "vec4_tex_2d_array_bias_shadow", IR_TEXB, 1, 2 },
/* texture / sampler but with shadow comparison */
{ "vec4_tex_1d_shadow", IR_TEX_SH, 1, 2 },
@@ -1020,7 +1044,7 @@ slang_substitute(slang_assemble_ctx *A, slang_operation *oper,
GLuint i;
v = _slang_variable_locate(oper->locals, id, GL_TRUE);
if (!v) {
- if (_mesa_strcmp((char *) oper->a_id, "__notRetFlag"))
+ if (strcmp((char *) oper->a_id, "__notRetFlag"))
_mesa_problem(NULL, "var %s not found!\n", (char *) oper->a_id);
return;
}
@@ -1658,7 +1682,7 @@ slang_find_asm_info(const char *name)
{
GLuint i;
for (i = 0; AsmInfo[i].Name; i++) {
- if (_mesa_strcmp(AsmInfo[i].Name, name) == 0) {
+ if (strcmp(AsmInfo[i].Name, name) == 0) {
return AsmInfo + i;
}
}
@@ -1730,7 +1754,7 @@ swizzle_to_writemask(slang_assemble_ctx *A, GLuint swizzle,
/* end */
break;
}
- assert(swz >= 0 && swz <= 3);
+ assert(swz <= 3);
if (swizzle != SWIZZLE_XXXX &&
swizzle != SWIZZLE_YYYY &&
@@ -1870,6 +1894,7 @@ _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper,
_mesa_problem(NULL, "undefined __asm function %s\n",
(char *) oper->a_id);
assert(info);
+ return NULL;
}
assert(info->NumParams <= 3);
@@ -2317,7 +2342,7 @@ _slang_is_vec_mat_type(const char *name)
};
int i;
for (i = 0; vecmat_types[i]; i++)
- if (_mesa_strcmp(name, vecmat_types[i]) == 0)
+ if (strcmp(name, vecmat_types[i]) == 0)
return GL_TRUE;
return GL_FALSE;
}
@@ -3117,7 +3142,7 @@ _slang_can_unroll_for_loop(slang_assemble_ctx * A, const slang_operation *oper)
if (start >= end)
return GL_FALSE; /* degenerate case */
- if (end - start > MAX_FOR_LOOP_UNROLL_ITERATIONS) {
+ if ((GLuint)(end - start) > MAX_FOR_LOOP_UNROLL_ITERATIONS) {
slang_info_log_print(A->log,
"Note: 'for (%s=%d; %s<%d; ++%s)' is too"
" many iterations to unroll",
@@ -3160,6 +3185,7 @@ _slang_unroll_for_loop(slang_assemble_ctx * A, const slang_operation *oper)
varId = oper->children[0].children[0].a_id;
var = _slang_variable_locate(oper->children[0].children[0].locals,
varId, GL_TRUE);
+ assert(var);
start = (GLint) var->initializer->literal[0];
}
else {
@@ -3196,7 +3222,7 @@ _slang_unroll_for_loop(slang_assemble_ctx * A, const slang_operation *oper)
newOper = slang_operation_new(1);
newOper->type = SLANG_OPER_LITERAL_INT;
newOper->literal_size = 1;
- newOper->literal[0] = iter;
+ newOper->literal[0] = (GLfloat) iter;
/* replace instances of the loop variable with newOper */
slang_substitute(A, body, 1, &oldVar, &newOper, GL_FALSE);
@@ -3639,7 +3665,7 @@ make_constant_array(slang_assemble_ctx *A,
assert(initializer->type == SLANG_OPER_CALL);
assert(initializer->array_constructor);
- values = (GLfloat *) _mesa_malloc(numElements * 4 * sizeof(GLfloat));
+ values = (GLfloat *) malloc(numElements * 4 * sizeof(GLfloat));
/* convert constructor params into ordinary floats */
for (i = 0; i < numElements; i++) {
@@ -3670,7 +3696,7 @@ make_constant_array(slang_assemble_ctx *A,
}
assert(var->store->Size == size);
- _mesa_free(values);
+ free(values);
return GL_TRUE;
}
@@ -3763,6 +3789,14 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
#endif
}
+ if (var->type.qualifier == SLANG_QUAL_UNIFORM &&
+ !A->allow_uniform_initializers) {
+ slang_info_log_error(A->log,
+ "initializer for uniform %s not allowed",
+ varName);
+ return NULL;
+ }
+
/* IR for the variable we're initializing */
varRef = new_var(A, var);
if (!varRef) {
@@ -4174,7 +4208,7 @@ swizzle_size(GLuint swizzle)
GLuint size = 0, i;
for (i = 0; i < 4; i++) {
GLuint swz = GET_SWZ(swizzle, i);
- size += (swz >= 0 && swz <= 3);
+ size += (swz <= 3);
}
return size;
}
@@ -4190,6 +4224,7 @@ _slang_gen_swizzle(slang_ir_node *child, GLuint swizzle)
n->Store = _slang_new_ir_storage_relative(0,
swizzle_size(swizzle),
child->Store);
+ assert(n->Store);
n->Store->Swizzle = swizzle;
}
return n;
@@ -4241,14 +4276,15 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper)
if (oper->children[0].type == SLANG_OPER_IDENTIFIER) {
/* Check that var is writeable */
+ const char *varName = (char *) oper->children[0].a_id;
slang_variable *var
= _slang_variable_locate(oper->children[0].locals,
oper->children[0].a_id, GL_TRUE);
if (!var) {
- slang_info_log_error(A->log, "undefined variable '%s'",
- (char *) oper->children[0].a_id);
+ slang_info_log_error(A->log, "undefined variable '%s'", varName);
return NULL;
}
+
if (var->type.qualifier == SLANG_QUAL_CONST ||
var->type.qualifier == SLANG_QUAL_ATTRIBUTE ||
var->type.qualifier == SLANG_QUAL_UNIFORM ||
@@ -4256,7 +4292,7 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper)
A->program->Target == GL_FRAGMENT_PROGRAM_ARB)) {
slang_info_log_error(A->log,
"illegal assignment to read-only variable '%s'",
- (char *) oper->children[0].a_id);
+ varName);
return NULL;
}
@@ -4490,7 +4526,6 @@ _slang_gen_array_element(slang_assemble_ctx * A, slang_operation *oper)
SWIZZLE_NIL);
n = _slang_gen_swizzle(n, swizzle);
}
- assert(n->Store);
return n;
}
else {
@@ -4914,8 +4949,8 @@ 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;
+ return spec->type == SLANG_SPEC_SAMPLER_RECT ||
+ spec->type == SLANG_SPEC_SAMPLER_RECT_SHADOW;
}
@@ -5215,7 +5250,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun)
slang_ir_node *n;
GLboolean success = GL_TRUE;
- if (_mesa_strcmp((char *) fun->header.a_name, "main") != 0) {
+ if (strcmp((char *) fun->header.a_name, "main") != 0) {
/* we only really generate code for main, all other functions get
* inlined or codegen'd upon an actual call.
*/
@@ -5312,7 +5347,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun)
/* free codegen context */
/*
- _mesa_free(A->codegen);
+ free(A->codegen);
*/
return success;