From 6d1a59d15b31a0d03b8e741784dfc8b433435ba8 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 27 Apr 2016 13:20:45 +1000 Subject: [PATCH] glsl: move uniform block validation to link_uniform_blocks.cpp Reviewed-by: Eduardo Lima Mitev --- src/compiler/glsl/link_uniform_blocks.cpp | 53 +++++++++++++++++++++++ src/compiler/glsl/link_uniforms.cpp | 53 ----------------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp index 58f22fd61c5..ac415b54f03 100644 --- a/src/compiler/glsl/link_uniform_blocks.cpp +++ b/src/compiler/glsl/link_uniform_blocks.cpp @@ -500,3 +500,56 @@ link_uniform_blocks_are_compatible(const gl_uniform_block *a, return true; } + +/** + * Merges a uniform block into an array of uniform blocks that may or + * may not already contain a copy of it. + * + * Returns the index of the new block in the array. + */ +int +link_cross_validate_uniform_block(void *mem_ctx, + struct gl_uniform_block **linked_blocks, + unsigned int *num_linked_blocks, + struct gl_uniform_block *new_block) +{ + for (unsigned int i = 0; i < *num_linked_blocks; i++) { + struct gl_uniform_block *old_block = &(*linked_blocks)[i]; + + if (strcmp(old_block->Name, new_block->Name) == 0) + return link_uniform_blocks_are_compatible(old_block, new_block) + ? i : -1; + } + + *linked_blocks = reralloc(mem_ctx, *linked_blocks, + struct gl_uniform_block, + *num_linked_blocks + 1); + int linked_block_index = (*num_linked_blocks)++; + struct gl_uniform_block *linked_block = &(*linked_blocks)[linked_block_index]; + + memcpy(linked_block, new_block, sizeof(*new_block)); + linked_block->Uniforms = ralloc_array(*linked_blocks, + struct gl_uniform_buffer_variable, + linked_block->NumUniforms); + + memcpy(linked_block->Uniforms, + new_block->Uniforms, + sizeof(*linked_block->Uniforms) * linked_block->NumUniforms); + + linked_block->Name = ralloc_strdup(*linked_blocks, linked_block->Name); + + for (unsigned int i = 0; i < linked_block->NumUniforms; i++) { + struct gl_uniform_buffer_variable *ubo_var = + &linked_block->Uniforms[i]; + + if (ubo_var->Name == ubo_var->IndexName) { + ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name); + ubo_var->IndexName = ubo_var->Name; + } else { + ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name); + ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName); + } + } + + return linked_block_index; +} diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index 8db60a36f16..92f10958490 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -874,59 +874,6 @@ public: unsigned shader_shadow_samplers; }; -/** - * Merges a uniform block into an array of uniform blocks that may or - * may not already contain a copy of it. - * - * Returns the index of the new block in the array. - */ -int -link_cross_validate_uniform_block(void *mem_ctx, - struct gl_uniform_block **linked_blocks, - unsigned int *num_linked_blocks, - struct gl_uniform_block *new_block) -{ - for (unsigned int i = 0; i < *num_linked_blocks; i++) { - struct gl_uniform_block *old_block = &(*linked_blocks)[i]; - - if (strcmp(old_block->Name, new_block->Name) == 0) - return link_uniform_blocks_are_compatible(old_block, new_block) - ? i : -1; - } - - *linked_blocks = reralloc(mem_ctx, *linked_blocks, - struct gl_uniform_block, - *num_linked_blocks + 1); - int linked_block_index = (*num_linked_blocks)++; - struct gl_uniform_block *linked_block = &(*linked_blocks)[linked_block_index]; - - memcpy(linked_block, new_block, sizeof(*new_block)); - linked_block->Uniforms = ralloc_array(*linked_blocks, - struct gl_uniform_buffer_variable, - linked_block->NumUniforms); - - memcpy(linked_block->Uniforms, - new_block->Uniforms, - sizeof(*linked_block->Uniforms) * linked_block->NumUniforms); - - linked_block->Name = ralloc_strdup(*linked_blocks, linked_block->Name); - - for (unsigned int i = 0; i < linked_block->NumUniforms; i++) { - struct gl_uniform_buffer_variable *ubo_var = - &linked_block->Uniforms[i]; - - if (ubo_var->Name == ubo_var->IndexName) { - ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name); - ubo_var->IndexName = ubo_var->Name; - } else { - ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name); - ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName); - } - } - - return linked_block_index; -} - /** * Walks the IR and update the references to uniform blocks in the * ir_variables to point at linked shader's list (previously, they -- 2.30.2