glsl: add helper for calculating offsets for struct members
V2: update comments Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
This commit is contained in:
parent
12af915e27
commit
0ad44ce373
|
@ -1039,6 +1039,32 @@ glsl_type::component_slots() const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned
|
||||||
|
glsl_type::record_location_offset(unsigned length) const
|
||||||
|
{
|
||||||
|
unsigned offset = 0;
|
||||||
|
const glsl_type *t = this->without_array();
|
||||||
|
if (t->is_record()) {
|
||||||
|
assert(length <= t->length);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < length; i++) {
|
||||||
|
const glsl_type *st = t->fields.structure[i].type;
|
||||||
|
const glsl_type *wa = st->without_array();
|
||||||
|
if (wa->is_record()) {
|
||||||
|
unsigned r_offset = wa->record_location_offset(wa->length);
|
||||||
|
offset += st->is_array() ? st->length * r_offset : r_offset;
|
||||||
|
} else {
|
||||||
|
/* We dont worry about arrays here because unless the array
|
||||||
|
* contains a structure or another array it only takes up a single
|
||||||
|
* uniform slot.
|
||||||
|
*/
|
||||||
|
offset += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
glsl_type::uniform_locations() const
|
glsl_type::uniform_locations() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -291,6 +291,14 @@ struct glsl_type {
|
||||||
*/
|
*/
|
||||||
unsigned component_slots() const;
|
unsigned component_slots() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate offset between the base location of the struct in
|
||||||
|
* uniform storage and a struct member.
|
||||||
|
* For the initial call, length is the index of the member to find the
|
||||||
|
* offset for.
|
||||||
|
*/
|
||||||
|
unsigned record_location_offset(unsigned length) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the number of unique values from glGetUniformLocation for the
|
* Calculate the number of unique values from glGetUniformLocation for the
|
||||||
* elements of the type.
|
* elements of the type.
|
||||||
|
|
Loading…
Reference in New Issue