GL_ARB_uniform_buffer_object spec defines standard layout rules to define how data are packed in a uniform buffer object, using offset and stride. A single ir_variable::location is not enough to hold every possible case and thus we defined a new type whose structure mirror the one of associated glsl_type of stored variable. --- src/glsl/linker.cpp | 23 +++++++++++++++++++++++ src/mesa/main/mtypes.h | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index 289a398..5ae928d 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -1173,6 +1173,29 @@ update_array_sizes(struct gl_shader_program *prog) } } +#if FEATURE_ARB_uniform_buffer_object +/** + * Create gl_variable_storage tree that mirror type. + */ +static union gl_variable_storage * +create_storage_type(const struct glsl_type *const type, void *ctx=NULL) +{ + union gl_variable_storage *storage_tree = (union gl_variable_storage *) ralloc_size(ctx,sizeof(union gl_variable_storage)); + if ( type->is_record() ) { + storage_tree->AsRecord.Fields = (union gl_variable_storage **) ralloc_array_size(storage_tree, sizeof(union gl_variable_storage *), type->length); + for (unsigned i = 0; i < type->length; i++) { + storage_tree->AsRecord.Fields[i] = create_storage_type(type->fields.structure[i].type, storage_tree); + } + } + if (type->is_array()) { + storage_tree->AsArray.FirstElement = create_storage_type(type->fields.array, storage_tree); + } + return storage_tree; +} + +#endif + + /** * Find a contiguous set of available bits in a bitmask. * diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index c4b5e28..865b6dc 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2128,6 +2128,29 @@ struct gl_sl_pragmas }; /** + * Holds storage information (offset and stride) about complex data type + */ +union gl_variable_storage +{ + struct { + GLuint Offset; /** Offset in bytes from start of buffer */ + } AsLeaf; /** Associated type is scalar or vector not in an array */ + struct { + GLuint Offset; /** Offset in bytes from start of buffer */ + GLuint RowStride; /** Stride to access next element in a row */ + GLuint ColumnStride; /** Stride to access next element in a column */ + } AsMatrix; /** Associated type is a matrix */ + struct { + union gl_variable_storage **Fields; /** Ralloced array of gl_variable_storage* associated to each fields */ + } AsRecord; /** Associated type is record */ + struct { + GLuint Stride; /** Stride in bytes between elements */ + union gl_variable_storage *FirstElement; /** Ralloced gl_variable_storage that holds storage info for + the first element of the array ; info about others element are deducable using this and Stride */ + } AsArray; +}; + +/** * Uniform Buffer Object variable informations. * This come in 2 flavors : * As layout informations (Size,Offset,...) are defined per program and not per shader, @@ -2140,6 +2163,8 @@ struct gl_shader_ubo_variable { char* Name; const struct glsl_type* Type; + const union gl_variable_storage *Storage; +}; }; -- 1.7.7 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev