From: Mikko Rasa Date: Tue, 6 Apr 2021 23:02:40 +0000 (+0300) Subject: Compare array sizes in TypeComparer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3ffa465364a36477b81b1b644ae8d19ee3bac8c2;p=libs%2Fgl.git Compare array sizes in TypeComparer --- diff --git a/source/glsl/reflect.cpp b/source/glsl/reflect.cpp index 93d64e5f..e6355316 100644 --- a/source/glsl/reflect.cpp +++ b/source/glsl/reflect.cpp @@ -51,6 +51,36 @@ T *TypeComparer::multi_visit(T &node) return 0; } +void TypeComparer::visit(Literal &literal) +{ + if(Literal *lit1 = multi_visit(literal)) + { + if(!lit1->type || !literal.type) + r_result = false; + else + { + compare(*lit1->type, *literal.type); + if(r_result) + r_result = (literal.value.check_type() && lit1->value.value()==literal.value.value()); + } + } +} + +void TypeComparer::visit(VariableReference &var) +{ + if(VariableReference *var1 = multi_visit(var)) + { + if(!var1->declaration || !var.declaration) + r_result = false; + else if(!var1->declaration->constant || !var.declaration->constant) + r_result = false; + else if(!var1->declaration->init_expression || !var.declaration->init_expression) + r_result = false; + else + compare(*var1->declaration->init_expression, *var.declaration->init_expression); + } +} + void TypeComparer::visit(BasicTypeDeclaration &basic) { if(BasicTypeDeclaration *basic1 = multi_visit(basic)) @@ -106,8 +136,13 @@ void TypeComparer::visit(VariableDeclaration &var) r_result = false; else { - // TODO Compare array sizes - if(var1->type_declaration!=var.type_declaration) + if(var1->array) + { + r_result = false; + if(var1->array_size && var.array_size) + compare(*var1->array_size, *var.array_size); + } + if(r_result && var1->type_declaration!=var.type_declaration) compare(*var1->type_declaration, *var.type_declaration); // TODO Compare layout qualifiers for interface block members } diff --git a/source/glsl/reflect.h b/source/glsl/reflect.h index 9520feb6..56ead82c 100644 --- a/source/glsl/reflect.h +++ b/source/glsl/reflect.h @@ -27,6 +27,8 @@ private: void compare(Node &, Node &); template T *multi_visit(T &); + virtual void visit(Literal &); + virtual void visit(VariableReference &); virtual void visit(BasicTypeDeclaration &); virtual void visit(ImageTypeDeclaration &); virtual void visit(StructDeclaration &); diff --git a/tests/glsl/array_in_uniform_block.glsl b/tests/glsl/array_in_uniform_block.glsl new file mode 100644 index 00000000..3d53b3de --- /dev/null +++ b/tests/glsl/array_in_uniform_block.glsl @@ -0,0 +1,86 @@ +const int n_lights = 2; +struct LightParams +{ + vec3 direction; + vec3 color; +}; +uniform Lighting +{ + LightParams lights[n_lights]; +}; +uniform vec3 ambient; +uniform mat4 model_matrix; +uniform mat4 view_matrix; +uniform mat4 proj_matrix; + +#pragma MSP stage(vertex) +layout(location=0) in vec4 position; +layout(location=1) in vec3 normal; +out vec3 eye_light_dir[n_lights]; +void main() +{ + for(int i=0; i