#! Contains the tests of how the bindings lay out what they hold, each size and #! member's place as C's own on 64-bit Windows and Linux, which lay them out #! alike, and of the constants they give. import std::testing; import malunal::vulkan; # How far into what holds it a member is, in bytes, of their addresses. def apart(whole: u64, part: u64): u64 { return part - whole; } @test def lays_structs_out_as_c_does(t: &mut tester): void { t.expects(size_of::() == 8 && size_of::() == 12 && size_of::() == 16); t.expects(size_of::() == 48 && size_of::() == 64); t.expects(size_of::() == 824 && size_of::() == 504); t.expects(size_of::() == 220 && size_of::() == 520); t.expects(size_of::() == 208 && size_of::() == 80); t.expects(size_of::() == 144 && size_of::() == 64); t.expects(size_of::() == 96 && size_of::() == 72); t.expects(size_of::() == 104 && size_of::() == 96); t.expects(size_of::() == 48 && size_of::() == 24); t.expects(size_of::() == 24 && size_of::() == 16); } @test def lays_unions_out_as_c_does(t: &mut tester): void { t.expects(size_of::() == 16 && size_of::() == 16); val floats: f32[4] = [1, 0.5, 0.25, 1]; val color := clear_color_value{ float32 = floats }; t.expects(color.uint32[0] == 0x3F800000 && color.uint32[1] == 0x3F000000); } @test def places_members_as_c_does(t: &mut tester): void { var properties := physical_device_properties{}; val at := address(&properties) as u64; t.expects(apart(at, address(&properties.limits) as u64) == 296); t.expects(apart(at, address(&properties.limits.timestamp_period) as u64) == 296 + 424); t.expects(apart(at, address(&properties.sparse_properties) as u64) == 800); # Vulkan 1.0's features, each a word, in their order, and 1.2's after a type # and a chain. var features := physical_device_features{}; val start := address(&features) as u64; t.expects(apart(start, address(&features.image_cube_array) as u64) == 2 * 4); t.expects(apart(start, address(&features.sampler_anisotropy) as u64) == 19 * 4); t.expects(apart(start, address(&features.shader_float64) as u64) == 39 * 4); var twelve := physical_device_vulkan_1_2_features{}; val begun := address(&twelve) as u64; t.expects(apart(begun, address(&twelve.draw_indirect_count) as u64) == 16 + 1 * 4); t.expects(apart(begun, address(&twelve.runtime_descriptor_array) as u64) == 16 + 29 * 4); # A union of words after words, aligned as C aligns it, by 4, and the struct # holding it by 8, as its handles are. var attachment := rendering_attachment_info{}; t.expects(apart(address(&attachment) as u64, address(&attachment.clear_value) as u64) == 52); } @test def gives_each_struct_its_own_type(t: &mut tester): void { val info := instance_create_info{}; val twelve := physical_device_vulkan_1_2_features{}; val swapchain := swapchain_create_info_khr{}; t.expects(info.s_type == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO && VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO == 1); t.expects(twelve.s_type == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES && twelve.s_type == 51); t.expects(swapchain.s_type == VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR && swapchain.s_type == 1000001000); } @test def writes_constants_as_vulkan_does(t: &mut tester): void { t.expects(VK_API_VERSION_1_3 == VK_MAKE_API_VERSION(0, 1, 3, 0) && VK_API_VERSION_1_3 == 4206592); t.expects(VK_API_VERSION_MAJOR(VK_API_VERSION_1_3) == 1 && VK_API_VERSION_MINOR(VK_API_VERSION_1_3) == 3); t.expects(VK_WHOLE_SIZE == 0xFFFFFFFFFFFFFFFF && VK_QUEUE_FAMILY_IGNORED == 0xFFFFFFFF && VK_LOD_CLAMP_NONE == 1000f); t.expects(VK_ERROR_OUT_OF_DATE_KHR == -1000001004 && VK_FORMAT_B8G8R8A8_SRGB == 50); t.expects(VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT == 0x800 && VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT == 0x400000000); t.expects(VK_KHR_SWAPCHAIN_EXTENSION_NAME == "VK_KHR_swapchain" && VK_EXT_DEBUG_UTILS_EXTENSION_NAME == "VK_EXT_debug_utils"); }