def test_manual(self): buffer_usage = BufferUsage.STORAGE_BUFFER buffer_layout = Layout.STD140 buffer_order = Order.ROW_MAJOR structA = Struct([Vector.ivec2(), Scalar.double()], buffer_layout, member_names=["a", "b"], type_name="structA") structB = Struct([Scalar.uint(), Scalar.double()], buffer_layout, type_name="structB") structC = Struct([structB, Vector.ivec2()], buffer_layout, type_name="structC") structs = [structA, structB, structC] variables = [ Vector.vec3(), Vector.ivec4(), Array(structC, 2, buffer_layout), Vector.ivec4(), Scalar.uint(), Array(Scalar.double(), (5, 2), buffer_layout), Scalar.int(), Array(Vector.vec4(), (2, 3, 4), buffer_layout), Vector.dvec2(), structA ] container = Struct(variables, buffer_layout, type_name="block") print(container) glsl = self.build_glsl_program(container, structs, buffer_usage) # print(glsl) values, array_expected = self.build_values(container.definitions) array_expected = np.array(array_expected, dtype=np.float32) bytez_input = container.to_bytes(values) bytez_output = self.run_program(glsl, bytez_input, array_expected.nbytes, usage_input=buffer_usage) array = np.frombuffer(bytez_output, dtype=array_expected.dtype) print(array_expected) print(array) print("equal", ((array_expected - array) == 0).all())
def test_manually(self): # byte cache test buffer_usage = BufferUsage.STORAGE_BUFFER buffer_layout = Layout.STD430 buffer_order = Order.ROW_MAJOR struct1 = Struct([Vector.vec3(), Vector.ivec2()], buffer_layout, member_names=["a", "b"], type_name="structB") struct2 = Struct( [Scalar.double(), Scalar.double(), struct1], buffer_layout, type_name="structC") structs = [struct1, struct2] variables = [ Scalar.uint(), Array(Vector.vec2(), (5, 2, 3), buffer_layout), Array(Scalar.float(), 5, buffer_layout), struct2, # this struct needs padding at the end Scalar.uint(), Array(struct1, (2, 3), buffer_layout) ] container = Struct(variables, buffer_layout, type_name="block") cache = ByteCache(container) print("") print("") pprint.pprint(cache.values) print(cache[-1][0][0]["a"]) print("") print("") pprint.pprint(cache) print(cache[-1][0][0]) print("") print("") pprint.pprint(cache.get_as_dict())
def test_manually(self): buffer_usage = BufferUsage.STORAGE_BUFFER buffer_layout = Layout.STD140 buffer_order = Order.ROW_MAJOR structA = Struct([Vector.ivec2(), Scalar.double()], buffer_layout, member_names=["a", "b"], type_name="structA") structB = Struct([Scalar.uint(), Scalar.double()], buffer_layout, type_name="structB") structC = Struct([structB, Vector.ivec2()], buffer_layout, type_name="structC") structs = [structA, structB, structC] variables = [ Vector.vec3(), Vector.ivec4(), Array(structC, 2, buffer_layout), Vector.ivec4(), Scalar.uint(), Array(Scalar.double(), (5, 2), buffer_layout), Scalar.int(), Array(Vector.vec4(), (2, 3, 4), buffer_layout), Vector.dvec2(), structA ] container = Struct(variables, buffer_layout, type_name="block") print(container) glsl = self.build_glsl_program(container, structs, buffer_usage) # print(glsl) values_expected, array = self.build_values(container.definitions) array = np.array(array, dtype=np.float32) bytez_in = array.tobytes() # std430 bytez_out = self.run_program(glsl, bytez_in, container.size()) values = container.from_bytes(bytez_out) register = {} steps = {Scalar: 0, Vector: 0, Array: 0, Struct: 0} for struct in structs + [container]: self.build_register(register, struct, steps) values_ftd = self.format_values(container, values, register) values_expected_ftd = self.format_values(container, values_expected, register) print("") self.print_formatted_values(values_ftd) print("") self.print_formatted_values(values_expected_ftd) print("") print("") print(values_ftd == values_expected_ftd)