From 8af48fc4d62798dbcc00bcfbbd8bc8f3b47982c7 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 14 Mar 2006 11:23:16 +0000 Subject: More GLSL code: - add texture sampling support; - fix assembly codegen bugs; --- src/mesa/shader/slang/slang_assemble.c | 69 +++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 14 deletions(-) (limited to 'src/mesa/shader/slang/slang_assemble.c') diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c index b24d3183841..faa13b33e69 100644 --- a/src/mesa/shader/slang/slang_assemble.c +++ b/src/mesa/shader/slang/slang_assemble.c @@ -644,7 +644,12 @@ static const struct { "float_noise3", slang_asm_float_noise3, slang_asm_float_copy }, { "float_noise4", slang_asm_float_noise4, slang_asm_float_copy }, { "int_to_float", slang_asm_int_to_float, slang_asm_float_copy }, + { "vec4_tex1d", slang_asm_vec4_tex1d, slang_asm_none }, { "vec4_tex2d", slang_asm_vec4_tex2d, slang_asm_none }, + { "vec4_tex3d", slang_asm_vec4_tex3d, slang_asm_none }, + { "vec4_texcube", slang_asm_vec4_texcube, slang_asm_none }, + { "vec4_shad1d", slang_asm_vec4_shad1d, slang_asm_none }, + { "vec4_shad2d", slang_asm_vec4_shad2d, slang_asm_none }, /* mesa-specific extensions */ { "float_print", slang_asm_float_deref, slang_asm_float_print }, { "int_print", slang_asm_int_deref, slang_asm_int_print }, @@ -930,7 +935,9 @@ static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *t else { GLuint i, struct_size = 0, field_offset = 0, field_size = 0; + GLboolean relocate, shrink; + /* calculate struct size, field offset and field size */ for (i = 0; i < tib->spec._struct->fields->num_variables; i++) { slang_variable *field; @@ -960,28 +967,56 @@ static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *t field_offset += size; } - if (!PLAB (A->file, slang_asm_addr_push, field_offset)) - return GL_FALSE; + /* + * OPTIMIZATION: If selecting the last field, no relocation is needed. + */ + relocate = field_offset != struct_size - field_size; - if (ref == slang_ref_force) + /* + * OPTIMIZATION: If field and struct sizes are equal, no partial free is needed. + */ + shrink = field_size != struct_size; + + if (relocate) { - if (!PUSH (A->file, slang_asm_addr_add)) + if (!PLAB (A->file, slang_asm_addr_push, field_offset)) return GL_FALSE; } + + if (ref == slang_ref_force) + { + if (relocate) + { + if (!PUSH (A->file, slang_asm_addr_add)) + return GL_FALSE; + } + } else { - GLuint i; + GLuint free_b = 0; - /* move the selected element to the beginning of the master expression */ - for (i = 0; i < field_size; i += 4) - if (!PLAB2 (A->file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4)) - return GL_FALSE; - if (!PLAB (A->file, slang_asm_local_free, 4)) - return GL_FALSE; + if (relocate) + { + GLuint i; - /* free the rest of the master expression */ - if (!PLAB (A->file, slang_asm_local_free, struct_size - field_size)) - return GL_FALSE; + /* move the selected element to the beginning of the master expression */ + for (i = 0; i < field_size; i += 4) + if (!PLAB2 (A->file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4)) + return GL_FALSE; + free_b += 4; + } + + if (shrink) + { + /* free the rest of the master expression */ + free_b += struct_size - field_size; + } + + if (free_b) + { + if (!PLAB (A->file, slang_asm_local_free, free_b)) + return GL_FALSE; + } } } @@ -1173,14 +1208,17 @@ GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, case slang_oper_addassign: if (!_slang_assemble_assign (A, op, "+=", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_subassign: if (!_slang_assemble_assign (A, op, "-=", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_mulassign: if (!_slang_assemble_assign (A, op, "*=", ref)) return GL_FALSE; + A->ref = ref; break; /*case slang_oper_modassign:*/ /*case slang_oper_lshassign:*/ @@ -1191,6 +1229,7 @@ GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, case slang_oper_divassign: if (!_slang_assemble_assign (A, op, "/=", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_select: if (!_slang_assemble_select (A, op)) @@ -1279,10 +1318,12 @@ GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, case slang_oper_preincrement: if (!_slang_assemble_assign (A, op, "++", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_predecrement: if (!_slang_assemble_assign (A, op, "--", ref)) return GL_FALSE; + A->ref = ref; break; case slang_oper_plus: if (!_slang_dereference (A, op)) -- cgit v1.2.3