summaryrefslogtreecommitdiffstats
path: root/src/glsl/link_uniforms.cpp
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2012-05-01 15:10:14 -0700
committerEric Anholt <[email protected]>2012-07-20 10:44:04 -0700
commit8ab5842a6d992956ee365c0e0232c6e6b907863e (patch)
treeefdf5b2d19a5efa149904969cb9338f2f9a01b72 /src/glsl/link_uniforms.cpp
parent9feb403b0eb5365889cb01ca456a19247aaad502 (diff)
glsl: Assign locations for uniforms in UBOs using the std140 rules.
Fixes piglit layout-std140. Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl/link_uniforms.cpp')
-rw-r--r--src/glsl/link_uniforms.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index 4cc97cead80..d7ef5d4d281 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -29,6 +29,12 @@
#include "program/hash_table.h"
#include "program.h"
+static inline unsigned int
+align(unsigned int a, unsigned int align)
+{
+ return (a + align - 1) / align * align;
+}
+
/**
* \file link_uniforms.cpp
* Assign locations for GLSL uniforms.
@@ -317,9 +323,11 @@ private:
if (this->ubo_var) {
this->uniforms[id].block_index = this->ubo_block_index;
- /* FINISHME: Actual std140 offset assignment. */
+ unsigned alignment = type->std140_base_alignment(ubo_var->RowMajor);
+ this->ubo_byte_offset = align(this->ubo_byte_offset, alignment);
this->uniforms[id].offset = this->ubo_byte_offset;
- this->ubo_byte_offset += 4 * type->components();
+ this->ubo_byte_offset += type->std140_size(ubo_var->RowMajor);
+
this->uniforms[id].array_stride = 0;
this->uniforms[id].matrix_stride = 0;
this->uniforms[id].row_major = base_type->is_matrix() &&
@@ -454,6 +462,28 @@ link_update_uniform_buffer_variables(struct gl_shader *shader)
}
void
+link_assign_uniform_block_offsets(struct gl_shader *shader)
+{
+ for (unsigned b = 0; b < shader->NumUniformBlocks; b++) {
+ struct gl_uniform_block *block = &shader->UniformBlocks[b];
+
+ unsigned offset = 0;
+ for (unsigned int i = 0; i < block->NumUniforms; i++) {
+ struct gl_uniform_buffer_variable *ubo_var = &block->Uniforms[i];
+ const struct glsl_type *type = ubo_var->Type;
+
+ unsigned alignment = type->std140_base_alignment(ubo_var->RowMajor);
+ unsigned size = type->std140_size(ubo_var->RowMajor);
+
+ offset = align(offset, alignment);
+ ubo_var->Offset = offset;
+ offset += size;
+ }
+ block->UniformBufferSize = offset;
+ }
+}
+
+void
link_assign_uniform_locations(struct gl_shader_program *prog)
{
ralloc_free(prog->UniformStorage);