|
|
@@ -141,6 +141,14 @@ compare_to_impl(const ShaderType &other) const {
|
|
|
- (_scalar_type < other_scalar._scalar_type);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Returns the alignment in bytes of this type in memory, if applicable.
|
|
|
+ */
|
|
|
+int ShaderType::Scalar::
|
|
|
+get_align_bytes() const {
|
|
|
+ return (_scalar_type == ST_double) ? 8 : 4;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns true if this type contains the given scalar type.
|
|
|
*/
|
|
|
@@ -185,6 +193,15 @@ compare_to_impl(const ShaderType &other) const {
|
|
|
- (_num_components < other_vector._num_components);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Returns the alignment in bytes of this type in memory, if applicable.
|
|
|
+ */
|
|
|
+int ShaderType::Vector::
|
|
|
+get_align_bytes() const {
|
|
|
+ int component_align = (_scalar_type == ST_double) ? 8 : 4;
|
|
|
+ return component_align * ((_num_components == 3) ? 4 : _num_components);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns true if this type contains the given scalar type.
|
|
|
*/
|
|
|
@@ -232,6 +249,16 @@ compare_to_impl(const ShaderType &other) const {
|
|
|
- (_num_columns < other_matrix._num_columns);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Returns the alignment in bytes of this type in memory, if applicable.
|
|
|
+ */
|
|
|
+int ShaderType::Matrix::
|
|
|
+get_align_bytes() const {
|
|
|
+ //TODO: needs to be checked
|
|
|
+ int row_align = (_scalar_type == ST_double) ? 32 : 16;
|
|
|
+ return row_align * _num_rows;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns the number of in/out locations taken up by in/out variables having
|
|
|
* this type.
|
|
|
@@ -241,6 +268,36 @@ get_num_interface_locations() const {
|
|
|
return _num_rows;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Adds a member to this struct.
|
|
|
+ */
|
|
|
+void ShaderType::Struct::
|
|
|
+add_member(const ShaderType *type, std::string name) {
|
|
|
+ Member member;
|
|
|
+ member.type = type;
|
|
|
+ member.name = std::move(name);
|
|
|
+ member.offset = _members.empty() ? 0 : _members.back().offset + _members.back().type->get_size_bytes();
|
|
|
+ int alignment = type->get_align_bytes();
|
|
|
+ member.offset += alignment - ((member.offset + (alignment - 1)) % alignment) - 1;
|
|
|
+ _members.push_back(std::move(member));
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Adds a member to this struct with a given offset.
|
|
|
+ */
|
|
|
+void ShaderType::Struct::
|
|
|
+add_member(const ShaderType *type, std::string name, uint32_t offset) {
|
|
|
+ pvector<Member>::iterator it = _members.begin();
|
|
|
+ while (it != _members.end() && it->offset < offset) {
|
|
|
+ ++it;
|
|
|
+ }
|
|
|
+ Member member;
|
|
|
+ member.type = type;
|
|
|
+ member.name = std::move(name);
|
|
|
+ member.offset = offset;
|
|
|
+ _members.insert(it, std::move(member));
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns true if this type contains the given scalar type.
|
|
|
*/
|
|
|
@@ -295,6 +352,18 @@ compare_to_impl(const ShaderType &other) const {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Returns the alignment in bytes of this type in memory, if applicable.
|
|
|
+ */
|
|
|
+int ShaderType::Struct::
|
|
|
+get_align_bytes() const {
|
|
|
+ int align = 16;
|
|
|
+ for (const Member &member : _members) {
|
|
|
+ align = std::max(align, member.type->get_align_bytes());
|
|
|
+ }
|
|
|
+ return align;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns the size in bytes of this type in memory, if applicable. Opaque
|
|
|
* types will return -1.
|
|
|
@@ -376,13 +445,30 @@ compare_to_impl(const ShaderType &other) const {
|
|
|
- (_num_elements < other_array._num_elements);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Returns the array stride in bytes.
|
|
|
+ */
|
|
|
+int ShaderType::Array::
|
|
|
+get_stride_bytes() const {
|
|
|
+ int element_size = _element_type->get_size_bytes();
|
|
|
+ return (element_size + 15) & ~15;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Returns the alignment in bytes of this type in memory, if applicable.
|
|
|
+ */
|
|
|
+int ShaderType::Array::
|
|
|
+get_align_bytes() const {
|
|
|
+ return get_stride_bytes();
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns the size in bytes of this type in memory, if applicable. Opaque
|
|
|
* types will return -1.
|
|
|
*/
|
|
|
int ShaderType::Array::
|
|
|
get_size_bytes() const {
|
|
|
- return _element_type->get_size_bytes() * _num_elements;
|
|
|
+ return get_stride_bytes() * _num_elements;
|
|
|
}
|
|
|
|
|
|
/**
|