]> git.tdb.fi Git - libs/gl.git/commitdiff
Disallow certain types from appearing on variables
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 Apr 2021 21:17:02 +0000 (00:17 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 6 Apr 2021 21:21:44 +0000 (00:21 +0300)
source/glsl/validate.cpp
tests/glsl/conditional_multiple_emitvertex.glsl
tests/glsl/disallowed_types.glsl [new file with mode: 0644]

index 6ce2ee51400df1668f769c2bc4a086cf61c376f3..67d456a8a2a1d6abb3bc8253bab72a9ab2cac2ab 100644 (file)
@@ -251,8 +251,12 @@ void DeclarationValidator::visit(VariableDeclaration &var)
        }
 
        TypeDeclaration *type = var.type_declaration;
+       BasicTypeDeclaration::Kind kind = BasicTypeDeclaration::ALIAS;
        while(BasicTypeDeclaration *basic = dynamic_cast<BasicTypeDeclaration *>(type))
+       {
+               kind = basic->kind;
                type = basic->base_type;
+       }
        if(dynamic_cast<ImageTypeDeclaration *>(type))
        {
                if(scope!=GLOBAL && scope!=FUNCTION_PARAM)
@@ -260,6 +264,10 @@ void DeclarationValidator::visit(VariableDeclaration &var)
                else if(scope==GLOBAL && var.interface!="uniform")
                        error(var, format("Type '%s' only allowed with uniform interface", type->name));
        }
+       else if(kind==BasicTypeDeclaration::VOID)
+               error(var, "Type 'void' not allowed on variable");
+       else if(kind==BasicTypeDeclaration::BOOL && !var.interface.empty() && var.source!=BUILTIN_SOURCE)
+               error(var, "Type 'bool' not allowed on interface variable");
 
        if(var.init_expression)
        {
index 2e4f32b1ab601593104a6f76efb62e5b86c940c7..2d0cb5a5a031b1776926266d4fd7930b6b04ddb1 100644 (file)
@@ -1,4 +1,4 @@
-uniform bool flag;
+uniform int flag;
 uniform sampler2D tex;
 
 #pragma MSP stage(vertex)
@@ -15,13 +15,13 @@ layout(triangle_strip, max_vertices=3) out;
 void main()
 {
        passthrough[0];
-       if(flag)
+       if(flag!=0)
                EmitVertex();
        passthrough[1];
-       if(flag)
+       if(flag!=0)
                EmitVertex();
        passthrough[2];
-       if(flag)
+       if(flag!=0)
                EmitVertex();
 }
 
@@ -43,7 +43,7 @@ void main()
 */
 
 /* Expected output: geometry
-layout(location=0) uniform bool flag;
+layout(location=0) uniform int flag;
 layout(triangles) in;
 layout(triangle_strip, max_vertices=3) out;
 layout(location=0) in vec2 texcoord[];
@@ -52,15 +52,15 @@ void main()
 {
        gl_Position = gl_in[0].gl_Position;
        _gs_out_texcoord = texcoord[0];
-       if(flag)
+       if(flag!=0)
                EmitVertex();
        gl_Position = gl_in[1].gl_Position;
        _gs_out_texcoord = texcoord[1];
-       if(flag)
+       if(flag!=0)
                EmitVertex();
        gl_Position = gl_in[2].gl_Position;
        _gs_out_texcoord = texcoord[2];
-       if(flag)
+       if(flag!=0)
                EmitVertex();
 }
 */
diff --git a/tests/glsl/disallowed_types.glsl b/tests/glsl/disallowed_types.glsl
new file mode 100644 (file)
index 0000000..6835dbb
--- /dev/null
@@ -0,0 +1,14 @@
+uniform bool u_bool;
+
+#pragma MSP stage(vertex)
+void void_var;
+layout(location=0) in vec4 position;
+void main()
+{
+       gl_Position = position;
+}
+
+/* Expected error:
+<test>:1: Type 'bool' not allowed on interface variable
+<test>:4: Type 'void' not allowed on variable
+*/