def test_detection_type_bools(self): glsl = """ #version 450 #extension GL_ARB_separate_shader_objects : enable layout({layout}, binding = 0) buffer Buffer {{ bool var1; bool[720][1280] var2; bvec2 var3; bvec3 var4; bvec4 var5; bvec3[5] var6; }}; void main() {{}} """ for layout in (Layout.STD140, Layout.STD430): # the vulkan spir-v compiler turns bools into uints expected_definition = Struct([ Scalar.uint(), Array(Scalar.uint(), (720, 1280), layout), Vector.uvec2(), Vector.uvec3(), Vector.uvec4(), Array(Vector.uvec3(), 5, layout) ], layout) shader = self.shader_from_txt(glsl.format(layout=layout), verbose=False) shader.inspect() detected_definition, _ = shader.code.get_block(0) equal = expected_definition.compare(detected_definition, quiet=True) self.assertTrue(equal)
def test_arb_example_std140(self): layout = Layout.STD430 struct_a = Struct( [ Scalar.int(), Vector.uvec2() # actually bvec2 ], layout, type_name="structA") struct_b = Struct([ Vector.uvec3(), Vector.vec2(), Array(Scalar.float(), 2, layout), Vector.vec2(), Array(Matrix(3, 3, DataType.FLOAT, layout), 2, layout) ], layout, type_name="structB") container = Struct([ Scalar.float(), Vector.vec2(), Vector.vec3(), struct_a, Scalar.float(), Array(Scalar.float(), 2, layout), Matrix(2, 3, DataType.FLOAT, layout), Array(struct_b, 2, layout) ], layout) self.run_test(container, [struct_a, struct_b], BufferUsage.STORAGE_BUFFER)
def test_struct_shared_between_different_layouts(self): glsl = """ #version 450 #extension GL_ARB_separate_shader_objects : enable struct Shared { int var1; double var2; }; layout(std140, binding = 0) buffer BufferA { uvec2 varA1; Shared varA2; // expected offset 16 }; layout(std430, binding = 1) buffer BufferB { uvec2 varB1; Shared varB2; // expected offset 8 }; void main() {} """ shared_std140 = Struct([Scalar.int(), Scalar.double()], Layout.STD140) shared_std430 = Struct([Scalar.int(), Scalar.double()], Layout.STD430) container_std140 = Struct([Vector.uvec2(), shared_std140], Layout.STD140) container_std430 = Struct([Vector.uvec2(), shared_std430], Layout.STD430) shader = self.shader_from_txt(glsl, verbose=False) shader.inspect() definition0, _ = shader.get_block(0) definition1, _ = shader.get_block(1) self.assertTrue(container_std140.compare(definition0, quiet=True)) self.assertFalse(container_std140.compare(definition1, quiet=True)) self.assertFalse(container_std430.compare(definition0, quiet=True)) self.assertTrue(container_std430.compare(definition1, quiet=True))