예제 #1
0
파일: shader.py 프로젝트: cryptolukas/lava
    def test_detection_type_arrays(self):
        rng = np.random.RandomState(321)
        variables = [
            Scalar.uint(),
            Scalar.int(),
            Scalar.float(),
            Scalar.double()
        ]
        variables += [
            Vector(n, dtype)
            for n, dtype in itertools.product(range(2, 5), DataType.ALL)
        ]

        for definition, layout, _ in itertools.product(
                variables, [Layout.STD140, Layout.STD430], range(3)):
            container = Struct(
                [Array(definition, Random.shape(rng, 3, 5), layout)], layout)

            glsl = self.build_glsl_program(
                ((container, 0, BufferUsage.STORAGE_BUFFER), ))
            shader = self.shader_from_txt(glsl, verbose=False)
            shader.inspect()

            detected_definition, _ = shader.get_block(0)
            self.assertTrue(container.compare(detected_definition, quiet=True))

            if isinstance(definition, Vector):
                if definition.length(
                ) < 3 and definition.dtype != DataType.DOUBLE:
                    self.assertEqual(detected_definition.layout, layout)
예제 #2
0
파일: transfer_in.py 프로젝트: osanj/lava
    def test_nested_with_arrays_of_structs(self):
        rng = np.random.RandomState(123)

        simple = [Scalar.uint(), Scalar.int(), Scalar.float(), Scalar.double()]
        simple += [
            Vector(n, dtype)
            for n, dtype in itertools.product(range(2, 5), DataType.ALL)
        ]

        for layout, _ in itertools.product([Layout.STD140, Layout.STD430],
                                           range(10)):
            matrices = [
                Matrix(n, m, dtype, layout)
                for n, m, dtype in itertools.product(range(2, 5), range(
                    2, 5), [DataType.FLOAT, DataType.DOUBLE])
            ]
            simple_and_matrices = simple + matrices

            struct = Struct(rng.choice(simple_and_matrices,
                                       size=4,
                                       replace=False),
                            layout,
                            type_name="SomeStruct")
            structs = [struct]
            arrays = [Array(struct, Random.shape(rng, 2, 3), layout)]

            for _ in range(2):
                members = [arrays[-1]] + rng.choice(
                    simple_and_matrices, size=3, replace=False).tolist()
                structs.append(
                    Struct(rng.permutation(members),
                           layout,
                           type_name="SomeStruct{}".format(len(structs))))
                arrays.append(
                    Array(structs[-1], Random.shape(rng, 2, 3), layout))

            container = structs[-1]
            structs = structs[:-1]

            self.run_test(container, structs, BufferUsage.STORAGE_BUFFER)
            if layout == Layout.STD140:
                self.run_test(container, structs, BufferUsage.UNIFORM_BUFFER)
예제 #3
0
    def test_array_of_matrices(self):
        # skipping ROW_MAJOR order for now since the glsl generation does not support it
        rng = np.random.RandomState(123)
        matrix_combinations = itertools.product(range(2, 5), range(
            2, 5), [DataType.FLOAT, DataType.DOUBLE])

        for (n, m, dtype), layout, _ in itertools.product(
                matrix_combinations, [Layout.STD140, Layout.STD430], range(3)):
            matrix = Matrix(n, m, dtype, layout)
            container = Struct(
                [Array(matrix, Random.shape(rng, 3, 5), layout)], layout)

            self.run_test(container, [], BufferUsage.STORAGE_BUFFER)
예제 #4
0
    def test_detection_type_arrays_of_matrices(self):
        rng = np.random.RandomState(321)
        matrix_attributes = itertools.product(range(2, 5), range(2, 5), [DataType.FLOAT, DataType.DOUBLE])

        for (n, m, dtype), layout, _ in itertools.product(matrix_attributes, [Layout.STD140, Layout.STD430], range(3)):
            matrix = Matrix(n, m, dtype, layout)
            container = Struct([Array(matrix, Random.shape(rng, 3, 5), layout)], layout)

            glsl = self.build_glsl_program(((container, 0, BufferUsage.STORAGE_BUFFER),))
            shader = self.shader_from_txt(glsl, verbose=False)
            shader.inspect()

            detected_definition, _ = shader.code.get_block(0)
            self.assertTrue(container.compare(detected_definition, quiet=True))
예제 #5
0
파일: transfer_in.py 프로젝트: osanj/lava
    def test_array_of_vectors(self):
        rng = np.random.RandomState(123)
        vector_types = [
            Vector(n, dtype)
            for n, dtype in itertools.product(range(2, 5), DataType.ALL)
        ]

        for definition, layout, _ in itertools.product(
                vector_types, [Layout.STD140, Layout.STD430], range(5)):
            container = Struct(
                [Array(definition, Random.shape(rng, 3, 5), layout)], layout)

            self.run_test(container, [], BufferUsage.STORAGE_BUFFER)
            if layout == Layout.STD140:
                self.run_test(container, [], BufferUsage.UNIFORM_BUFFER)
예제 #6
0
파일: transfer_in.py 프로젝트: osanj/lava
    def test_array_of_scalars(self):
        rng = np.random.RandomState(123)
        scalar_types = [
            Scalar.uint(),
            Scalar.int(),
            Scalar.float(),
            Scalar.double()
        ]

        for definition, layout, _ in itertools.product(
                scalar_types, [Layout.STD140, Layout.STD430], range(5)):
            container = Struct(
                [Array(definition, Random.shape(rng, 5, 7), layout)], layout)

            self.run_test(container, [], BufferUsage.STORAGE_BUFFER)
            if layout == Layout.STD140:
                self.run_test(container, [], BufferUsage.UNIFORM_BUFFER)
예제 #7
0
파일: transfer_in.py 프로젝트: osanj/lava
    def test_array_of_structs(self):
        rng = np.random.RandomState(123)
        simple = [Scalar.uint(), Scalar.int(), Scalar.float(), Scalar.double()]
        simple += [
            Vector(n, dtype)
            for n, dtype in itertools.product(range(2, 5), DataType.ALL)
        ]

        for layout, _ in itertools.product([Layout.STD140, Layout.STD430],
                                           range(5)):
            struct = Struct(rng.choice(simple, size=3, replace=False),
                            layout,
                            type_name="SomeStruct")
            array = Array(struct, Random.shape(rng, 3, 5), layout)
            container = Struct([array], layout)

            self.run_test(container, [struct], BufferUsage.STORAGE_BUFFER)
            if layout == Layout.STD140:
                self.run_test(container, [struct], BufferUsage.UNIFORM_BUFFER)