summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2008-07-21 13:58:50 -0600
committerBrian Paul <brian.paul@tungstengraphics.com>2008-07-21 13:58:50 -0600
commitfbf26e109b1e96aa4eeca018198ff0b5a71e557b (patch)
tree620c8b88f5ac24896447c4fcbfd8f98f17aa2bbc /src/mesa/shader/slang
parentd8cbac5330cfcdf66c9448ee339975869097a262 (diff)
mesa: assorted glsl uniform/attribute fixes
Fix incorrect uniform/attribute size query results. Add missing error checking for glUniform, glUniformMatrix params Fix an array size/allocation error.
Diffstat (limited to 'src/mesa/shader/slang')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c21
-rw-r--r--src/mesa/shader/slang/slang_link.c5
2 files changed, 22 insertions, 4 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index b8e130555d..8f5c95c06a 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -3059,6 +3059,23 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper)
}
+/**
+ * Compute total size of array give size of element, number of elements.
+ */
+static GLint
+array_size(GLint baseSize, GLint arrayLen)
+{
+ GLint total;
+ if (arrayLen > 1) {
+ /* round up base type to multiple of 4 */
+ total = ((baseSize + 3) & ~0x3) * MAX2(arrayLen, 1);
+ }
+ else {
+ total = baseSize;
+ }
+ return total;
+}
+
/**
* Called by compiler when a global variable has been parsed/compiled.
@@ -3098,7 +3115,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
}
else if (var->type.qualifier == SLANG_QUAL_UNIFORM) {
/* Uniform variable */
- const GLint totalSize = size * MAX2(var->array_len, 1);
+ const GLint totalSize = array_size(size, var->array_len);
const GLuint swizzle = _slang_var_swizzle(totalSize, 0);
if (prog) {
/* user-defined uniform */
@@ -3182,7 +3199,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
/* user-defined vertex attribute */
const GLint attr = -1; /* unknown */
GLint index = _mesa_add_attribute(prog->Attributes, varName,
- size, attr);
+ size, datatype, attr);
assert(index >= 0);
store = _slang_new_ir_storage(PROGRAM_INPUT,
VERT_ATTRIB_GENERIC0 + index, size);
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index f08b53e8b7..e9b9bbc43f 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -211,7 +211,6 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
{
GLuint i, j;
GLbitfield usedAttributes;
- GLint size = 4; /* XXX fix */
assert(prog->Target == GL_VERTEX_PROGRAM_ARB);
@@ -253,6 +252,8 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
* Start at 1 since generic attribute 0 always aliases
* glVertex/position.
*/
+ GLint size = prog->Attributes->Parameters[k].Size;
+ GLenum datatype = prog->Attributes->Parameters[k].DataType;
for (attr = 1; attr < MAX_VERTEX_ATTRIBS; attr++) {
if (((1 << attr) & usedAttributes) == 0)
break;
@@ -261,7 +262,7 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
/* too many! XXX record error log */
return GL_FALSE;
}
- _mesa_add_attribute(shProg->Attributes, name, size, attr);
+ _mesa_add_attribute(shProg->Attributes, name, size, datatype,attr);
/* set the attribute as used */
usedAttributes |= 1<<attr;