diff options
author | Ian Romanick <[email protected]> | 2011-01-25 10:41:20 -0800 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2011-03-29 13:21:08 -0700 |
commit | 89d81ab16c05818b290ed735c1343d3abde449bf (patch) | |
tree | 256104ebb7bdcc721ff0d70178047acb8c83ed21 /src/glsl/ir_variable.cpp | |
parent | 92e412e788931ad464125113a64eec8a8223cda3 (diff) |
glsl: Calcluate Mesa state slots in front-end instead of back-end
This should be the last bit of infrastructure changes before
generating GLSL IR for assembly shaders.
This commit leaves some odd code formatting in ir_to_mesa and brw_fs.
This was done to minimize whitespace changes / reindentation in some
loops. The following commit will restore formatting sanity.
Reviewed-by: Eric Anholt <[email protected]>
Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/glsl/ir_variable.cpp')
-rw-r--r-- | src/glsl/ir_variable.cpp | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp index c2715254a59..f3577175691 100644 --- a/src/glsl/ir_variable.cpp +++ b/src/glsl/ir_variable.cpp @@ -327,7 +327,43 @@ static ir_variable * add_uniform(exec_list *instructions, glsl_symbol_table *symtab, const char *name, const glsl_type *type) { - return add_variable(instructions, symtab, name, type, ir_var_uniform, -1); + ir_variable *const uni = + add_variable(instructions, symtab, name, type, ir_var_uniform, -1); + + unsigned i; + for (i = 0; _mesa_builtin_uniform_desc[i].name != NULL; i++) { + if (strcmp(_mesa_builtin_uniform_desc[i].name, name) == 0) { + break; + } + } + + assert(_mesa_builtin_uniform_desc[i].name != NULL); + const struct gl_builtin_uniform_desc* const statevar = + &_mesa_builtin_uniform_desc[i]; + + const unsigned array_count = type->is_array() ? type->length : 1; + uni->num_state_slots = array_count * statevar->num_elements; + + ir_state_slot *slots = + ralloc_array(uni, ir_state_slot, uni->num_state_slots); + + uni->state_slots = slots; + + for (unsigned a = 0; a < array_count; a++) { + for (unsigned j = 0; j < statevar->num_elements; j++) { + struct gl_builtin_uniform_element *element = &statevar->elements[j]; + + memcpy(slots->tokens, element->tokens, sizeof(element->tokens)); + if (type->is_array()) { + slots->tokens[1] = a; + } + + slots->swizzle = element->swizzle; + slots++; + } + } + + return uni; } static void @@ -341,8 +377,12 @@ add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab, assert(type != NULL); - add_variable(instructions, symtab, proto->name, type, proto->mode, - proto->slot); + if (proto->mode == ir_var_uniform) { + add_uniform(instructions, symtab, proto->name, type); + } else { + add_variable(instructions, symtab, proto->name, type, proto->mode, + proto->slot); + } } static void |