Initial Commit
This commit is contained in:
20 files changed
+8665
No files matched your search
@@ -0,0 +1,327 @@
|
||||
#! Contains the tests of what `malunal.vulkan.bindings` writes, of a small
|
||||
#! registry of their own, written as `vk.xml` is: the names it gives, the types
|
||||
#! of members and parameters, constants' values, the functions the loader
|
||||
#! exports and the types of the rest, a platform's file, the versions and
|
||||
#! extensions bound, and what it refuses.
|
||||
|
||||
import std::containers;
|
||||
import std::testing;
|
||||
|
||||
# A registry of a few of each: Vulkan SC's parts, which are left out, among
|
||||
# them.
|
||||
const small_registry: strview = """
|
||||
<registry>
|
||||
<types>
|
||||
<type requires="vk_platform" name="void"/>
|
||||
<type requires="vk_platform" name="char"/>
|
||||
<type requires="vk_platform" name="float"/>
|
||||
<type requires="vk_platform" name="uint32_t"/>
|
||||
<type requires="vk_platform" name="uint64_t"/>
|
||||
<type requires="windows.h" name="HWND"/>
|
||||
<type api="vulkan" category="define">// Version of this file
|
||||
#define <name>VK_HEADER_VERSION</name> 7</type>
|
||||
<type api="vulkansc" category="define">// Version of this file
|
||||
#define <name>VK_HEADER_VERSION</name> 3</type>
|
||||
<type category="basetype">typedef <type>uint32_t</type> <name>VkFlags</name>;</type>
|
||||
<type category="basetype">typedef <type>uint64_t</type> <name>VkFlags64</name>;</type>
|
||||
<type category="basetype">typedef <type>uint32_t</type> <name>VkBool32</name>;</type>
|
||||
<type category="handle"><type>VK_DEFINE_HANDLE</type>(<name>VkInstance</name>)</type>
|
||||
<type category="handle"><type>VK_DEFINE_NON_DISPATCHABLE_HANDLE</type>(<name>VkThing</name>)</type>
|
||||
<type name="VkStructureType" category="enum"/>
|
||||
<type name="VkResult" category="enum"/>
|
||||
<type name="VkStageFlagBits2" category="enum"/>
|
||||
<type category="bitmask" bitvalues="VkStageFlagBits2">typedef <type>VkFlags64</type> <name>VkStageFlags2</name>;</type>
|
||||
<type category="funcpointer">typedef void (VKAPI_PTR *<name>PFN_vkVoidFunction</name>)(void);</type>
|
||||
<type category="funcpointer">typedef VkBool32 (VKAPI_PTR *<name>PFN_vkHeardCallback</name>)(
|
||||
<type>uint32_t</type> severity,
|
||||
const <type>char</type>* pMessage,
|
||||
<type>void</type>* pUserData);</type>
|
||||
<type category="struct" name="VkThingCreateInfo">
|
||||
<member values="VK_STRUCTURE_TYPE_THING_CREATE_INFO"><type>VkStructureType</type> <name>sType</name></member>
|
||||
<member optional="true">const <type>void</type>* <name>pNext</name></member>
|
||||
<member><type>uint32_t</type> <name>nameCount</name></member>
|
||||
<member len="nameCount">const <type>char</type>* const* <name>ppNames</name></member>
|
||||
<member><type>char</type> <name>label</name>[<enum>VK_MAX_LABEL_SIZE</enum>]</member>
|
||||
<member><type>uint64_t</type> <name>module</name><comment>Which module</comment></member>
|
||||
<member><type>VkStageFlags2</type> <name>stages</name></member>
|
||||
<member><type>float</type> <name>matrix</name>[3][4]</member>
|
||||
<member><type>PFN_vkHeardCallback</type> <name>pfnHeard</name></member>
|
||||
<member api="vulkansc"><type>uint32_t</type> <name>scOnly</name></member>
|
||||
</type>
|
||||
<type category="struct" name="VkExtent2D">
|
||||
<member><type>uint32_t</type> <name>width</name></member>
|
||||
<member><type>uint32_t</type> <name>height</name></member>
|
||||
</type>
|
||||
<type category="struct" name="VkPhysicalDeviceVulkan13Features">
|
||||
<member values="VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES"><type>VkStructureType</type> <name>sType</name></member>
|
||||
<member optional="true"><type>void</type>* <name>pNext</name></member>
|
||||
<member><type>VkBool32</type> <name>shaderFloat64</name></member>
|
||||
<member><type>uint32_t</type> <name>deviceUUID</name></member>
|
||||
<member><type>uint32_t</type> <name>maxImageDimension2D</name></member>
|
||||
</type>
|
||||
<type category="struct" name="VkPackedKHR">
|
||||
<member><type>uint32_t</type> <name>index</name>:24</member>
|
||||
<member><type>uint32_t</type> <name>mask</name>:8</member>
|
||||
</type>
|
||||
<type category="struct" name="VkWin32ThingCreateInfoKHR">
|
||||
<member values="VK_STRUCTURE_TYPE_WIN32_THING_CREATE_INFO_KHR"><type>VkStructureType</type> <name>sType</name></member>
|
||||
<member optional="true">const <type>void</type>* <name>pNext</name></member>
|
||||
<member><type>HWND</type> <name>hwnd</name></member>
|
||||
</type>
|
||||
<type category="struct" name="VkThingCreateInfoKHR" alias="VkThingCreateInfo"/>
|
||||
</types>
|
||||
<enums name="API Constants">
|
||||
<enum type="uint32_t" value="64" name="VK_MAX_LABEL_SIZE"/>
|
||||
<enum type="uint32_t" value="(~0U)" name="VK_REMAINING"/>
|
||||
<enum type="uint64_t" value="(~0ULL)" name="VK_WHOLE"/>
|
||||
<enum type="float" value="1000.0F" name="VK_CLAMP"/>
|
||||
</enums>
|
||||
<enums name="VkStructureType" type="enum">
|
||||
<enum value="0" name="VK_STRUCTURE_TYPE_THING_CREATE_INFO"/>
|
||||
</enums>
|
||||
<enums name="VkResult" type="enum">
|
||||
<enum value="0" name="VK_SUCCESS"/>
|
||||
<enum value="-1" name="VK_ERROR_OUT_OF_HOST_MEMORY"/>
|
||||
</enums>
|
||||
<enums name="VkStageFlagBits2" type="bitmask" bitwidth="64">
|
||||
<enum bitpos="0" name="VK_STAGE_2_FIRST_BIT"/>
|
||||
<enum bitpos="40" name="VK_STAGE_2_FAR_BIT"/>
|
||||
</enums>
|
||||
<commands>
|
||||
<command export="vulkan,vulkansc">
|
||||
<proto><type>VkResult</type> <name>vkCreateThing</name></proto>
|
||||
<param><type>VkInstance</type> <name>instance</name></param>
|
||||
<param>const <type>VkThingCreateInfo</type>* <name>pCreateInfo</name></param>
|
||||
<param optional="true">const <type>void</type>* <name>pAllocator</name></param>
|
||||
<param><type>VkThing</type>* <name>pThing</name></param>
|
||||
</command>
|
||||
<command export="vulkan">
|
||||
<proto><type>void</type> <name>vkListThings</name></proto>
|
||||
<param><type>VkInstance</type> <name>instance</name></param>
|
||||
<param optional="false,true"><type>uint32_t</type>* <name>pCount</name></param>
|
||||
<param optional="true" len="pCount"><type>VkExtent2D</type>* <name>pThings</name></param>
|
||||
<param>const <type>float</type> <name>blend</name>[4]</param>
|
||||
</command>
|
||||
<command export="vulkan">
|
||||
<proto><type>PFN_vkVoidFunction</type> <name>vkGetInstanceProcAddr</name></proto>
|
||||
<param><type>VkInstance</type> <name>instance</name></param>
|
||||
<param len="null-terminated">const <type>char</type>* <name>pName</name></param>
|
||||
</command>
|
||||
<command>
|
||||
<proto><type>void</type> <name>vkHearEXT</name></proto>
|
||||
<param><type>VkInstance</type> <name>instance</name></param>
|
||||
<param><type>VkPhysicalDeviceVulkan13Features</type>* <name>pFeatures</name></param>
|
||||
</command>
|
||||
<command>
|
||||
<proto><type>VkResult</type> <name>vkCreateWin32ThingKHR</name></proto>
|
||||
<param><type>VkInstance</type> <name>instance</name></param>
|
||||
<param>const <type>VkWin32ThingCreateInfoKHR</type>* <name>pCreateInfo</name></param>
|
||||
</command>
|
||||
<command name="vkCreateThingKHR" alias="vkCreateThing"/>
|
||||
</commands>
|
||||
<feature api="vulkan,vulkansc" name="VK_VERSION_1_0" number="1.0">
|
||||
<require>
|
||||
<type name="VkThingCreateInfo"/>
|
||||
<type name="VkResult"/>
|
||||
<enum name="VK_REMAINING"/>
|
||||
<enum name="VK_WHOLE"/>
|
||||
<enum name="VK_CLAMP"/>
|
||||
<command name="vkCreateThing"/>
|
||||
<command name="vkGetInstanceProcAddr"/>
|
||||
</require>
|
||||
</feature>
|
||||
<feature api="vulkan" name="VK_VERSION_1_1" number="1.1">
|
||||
<require>
|
||||
<type name="VkPhysicalDeviceVulkan13Features"/>
|
||||
<type name="VkPackedKHR"/>
|
||||
<enum offset="0" extnumber="12" extends="VkStructureType" name="VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES"/>
|
||||
<command name="vkListThings"/>
|
||||
</require>
|
||||
</feature>
|
||||
<feature api="vulkansc" name="VKSC_VERSION_1_0" number="1.0">
|
||||
<require>
|
||||
<command name="vkSafetyOnly"/>
|
||||
</require>
|
||||
</feature>
|
||||
<extensions>
|
||||
<extension name="VK_EXT_heard" number="3" supported="vulkan">
|
||||
<require>
|
||||
<enum value="2" name="VK_EXT_HEARD_SPEC_VERSION"/>
|
||||
<enum value=""VK_EXT_heard"" name="VK_EXT_HEARD_EXTENSION_NAME"/>
|
||||
<enum offset="1" extends="VkResult" dir="-" name="VK_ERROR_NOT_HEARD_EXT"/>
|
||||
<command name="vkHearEXT"/>
|
||||
</require>
|
||||
<require depends="VK_VERSION_1_1">
|
||||
<type name="VkThingCreateInfoKHR"/>
|
||||
<command name="vkCreateThingKHR"/>
|
||||
</require>
|
||||
</extension>
|
||||
<extension name="VK_KHR_win32_thing" number="10" supported="vulkan" platform="win32" depends="VK_EXT_heard">
|
||||
<require>
|
||||
<enum offset="0" extends="VkStructureType" name="VK_STRUCTURE_TYPE_WIN32_THING_CREATE_INFO_KHR"/>
|
||||
<type name="VkWin32ThingCreateInfoKHR"/>
|
||||
<command name="vkCreateWin32ThingKHR"/>
|
||||
</require>
|
||||
</extension>
|
||||
<extension name="VK_EXT_disabled" number="4" supported="disabled"/>
|
||||
<extension name="VK_MVK_moved" number="5" supported="vulkan" platform="macos"/>
|
||||
</extensions>
|
||||
</registry>
|
||||
""";
|
||||
|
||||
# What's wanted of the small registry: its newest version, and the extensions
|
||||
# named, the platform's exported.
|
||||
def wanting_of(major: u32, minor: u32, names: span<strview>): wanting {
|
||||
var made := wanting{ major = major, minor = minor, extensions = vector::<strview>::new(), exported = vector::<strview>::new() };
|
||||
for &each in names {
|
||||
made.extensions.append(each);
|
||||
}
|
||||
made.exported.append("VK_KHR_win32_thing");
|
||||
return made;
|
||||
}
|
||||
|
||||
# The text of a file written, or nothing where none of the name was.
|
||||
def text_of(files: &vector<made_file>, name: strview): strview {
|
||||
for &each in files {
|
||||
return each.text.span if each.name.span == name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
# Whether a file holds a line.
|
||||
def holds_line(text: strview, line: strview): bool {
|
||||
return text.find(line) is some(_);
|
||||
}
|
||||
|
||||
@test def names_types_and_members_as_sakura_does(t: &mut tester): void {
|
||||
val names: strview[2] = ["VK_EXT_heard", "VK_KHR_win32_thing"];
|
||||
val wanted := wanting_of(0, 0, names[:]);
|
||||
var files := vector::<made_file>::new();
|
||||
var problems := vector::<string>::new();
|
||||
t.expects(bindings_of(small_registry, &wanted, &mut files, &mut problems) && problems.length == 0);
|
||||
val types := text_of(&files, "types.sakura");
|
||||
t.expects(holds_line(types, "pub struct thing_create_info {\n"));
|
||||
t.expects(holds_line(types, " pub var s_type: u32 = VK_STRUCTURE_TYPE_THING_CREATE_INFO; #! VkStructureType\n"));
|
||||
t.expects(holds_line(types, " pub var next: *u8;\n"));
|
||||
t.expects(holds_line(types, " pub var name_count: u32;\n"));
|
||||
t.expects(holds_line(types, " pub var names: **u8;\n"));
|
||||
t.expects(holds_line(types, " pub var label: u8[64];\n"));
|
||||
t.expects(holds_line(types, " pub var module_: u64; #! Which module\n"));
|
||||
t.expects(holds_line(types, " pub var stages: u64; #! VkStageFlags2\n"));
|
||||
# C's 3 arrays of 4, as Sakura writes them: innermost first.
|
||||
t.expects(holds_line(types, " pub var matrix: f32[4][3];\n"));
|
||||
t.expects(holds_line(types, " pub var heard: PFN_vkHeardCallback;\n"));
|
||||
t.expects(!holds_line(types, "sc_only"));
|
||||
# By its `sType`, and in snake case.
|
||||
t.expects(holds_line(types, "pub struct physical_device_vulkan_1_3_features {\n"));
|
||||
t.expects(holds_line(types, " pub var next: *mut u8;\n"));
|
||||
t.expects(holds_line(types, " pub var shader_float64: u32; #! VkBool32\n"));
|
||||
t.expects(holds_line(types, " pub var device_uuid: u32;\n"));
|
||||
t.expects(holds_line(types, " pub var max_image_dimension_2d: u32;\n"));
|
||||
t.expects(holds_line(types, "pub struct extent_2d {\n"));
|
||||
# Bitfields as one word, an alias by its vendor's letters, and a callback.
|
||||
t.expects(holds_line(types, "pub struct packed_khr {\n pub var index_and_mask: u32; #! Bits, the lowest first: index, 24, mask, 8.\n"));
|
||||
t.expects(holds_line(types, "pub type thing_create_info_khr = thing_create_info;\n"));
|
||||
t.expects(holds_line(types, "pub type PFN_vkHeardCallback = cfn<def(u32, *u8, *mut u8): u32>;\n"));
|
||||
}
|
||||
|
||||
@test def gives_constants_their_values(t: &mut tester): void {
|
||||
val names: strview[1] = ["VK_EXT_heard"];
|
||||
val wanted := wanting_of(0, 0, names[:]);
|
||||
var files := vector::<made_file>::new();
|
||||
var problems := vector::<string>::new();
|
||||
t.expects(bindings_of(small_registry, &wanted, &mut files, &mut problems));
|
||||
val overview := text_of(&files, "vulkan.sakura");
|
||||
t.expects(holds_line(overview, "pub const VK_HEADER_VERSION: u32 = 7;\n"));
|
||||
t.expects(holds_line(overview, "pub const VK_API_VERSION_1_1: u32 = (1 << 22) | (1 << 12);\n"));
|
||||
val constants := text_of(&files, "constants.sakura");
|
||||
t.expects(holds_line(constants, "pub const VK_REMAINING: u32 = 0xFFFFFFFF;\n"));
|
||||
t.expects(holds_line(constants, "pub const VK_WHOLE: u64 = 0xFFFFFFFFFFFFFFFF;\n"));
|
||||
t.expects(holds_line(constants, "pub const VK_CLAMP: f32 = 1000.0;\n"));
|
||||
t.expects(holds_line(constants, "pub const VK_MAX_LABEL_SIZE: u32 = 64;\n"));
|
||||
t.expects(holds_line(constants, "pub const VK_ERROR_OUT_OF_HOST_MEMORY: i32 = -1;\n"));
|
||||
t.expects(holds_line(constants, "pub const VK_ERROR_NOT_HEARD_EXT: i32 = -1000002001;\n"));
|
||||
t.expects(holds_line(constants, "pub const VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES: u32 = 1000011000;\n"));
|
||||
t.expects(holds_line(constants, "pub const VK_STAGE_2_FAR_BIT: u64 = 0x10000000000;\n"));
|
||||
t.expects(holds_line(constants, "# VK_EXT_heard\npub const VK_EXT_HEARD_SPEC_VERSION: u32 = 2;\npub const VK_EXT_HEARD_EXTENSION_NAME: strview = \"VK_EXT_heard\";\n"));
|
||||
}
|
||||
|
||||
@test def declares_what_the_loader_exports_and_types_the_rest(t: &mut tester): void {
|
||||
val names: strview[1] = ["VK_EXT_heard"];
|
||||
val wanted := wanting_of(0, 0, names[:]);
|
||||
var files := vector::<made_file>::new();
|
||||
var problems := vector::<string>::new();
|
||||
t.expects(bindings_of(small_registry, &wanted, &mut files, &mut problems));
|
||||
val commands := text_of(&files, "commands.sakura");
|
||||
t.expects(holds_line(commands, "extern import \"vulkan-1.dll\" when os == windows;\n"));
|
||||
t.expects(holds_line(commands, "pub def vkCreateThing(instance: u64, create_info: &thing_create_info, allocator: *u8, thing: &mut u64): i32;\n"));
|
||||
t.expects(holds_line(commands, "pub def vkListThings(instance: u64, count: &mut u32, things: *mut extent_2d, blend: &f32[4]): void;\n"));
|
||||
t.expects(holds_line(commands, "pub def vkGetInstanceProcAddr(instance: u64, name: *u8): PFN_vkVoidFunction;\n"));
|
||||
t.expects(!holds_line(commands, "pub def vkHearEXT"));
|
||||
t.expects(holds_line(commands, "pub type PFN_vkHearEXT = cfn<def(u64, &mut physical_device_vulkan_1_3_features): void>;\n"));
|
||||
t.expects(holds_line(commands, "pub type PFN_vkCreateThingKHR = PFN_vkCreateThing;\n"));
|
||||
t.expects(!holds_line(commands, "vkSafetyOnly"));
|
||||
}
|
||||
|
||||
@test def writes_a_platforms_file_for_its_system(t: &mut tester): void {
|
||||
val names: strview[2] = ["VK_EXT_heard", "VK_KHR_win32_thing"];
|
||||
val wanted := wanting_of(0, 0, names[:]);
|
||||
var files := vector::<made_file>::new();
|
||||
var problems := vector::<string>::new();
|
||||
t.expects(bindings_of(small_registry, &wanted, &mut files, &mut problems));
|
||||
val win32 := text_of(&files, "win32.sakura");
|
||||
t.expects(holds_line(win32, "extern import \"vulkan-1.dll\" when os == windows;\n\nextern module malunal::vulkan when os == windows;\n"));
|
||||
t.expects(holds_line(win32, "pub const VK_STRUCTURE_TYPE_WIN32_THING_CREATE_INFO_KHR: u32 = 1000009000;\n"));
|
||||
t.expects(holds_line(win32, "pub struct win32_thing_create_info_khr {\n"));
|
||||
t.expects(holds_line(win32, " pub var hwnd: u64; #! HWND\n"));
|
||||
t.expects(holds_line(win32, "pub def vkCreateWin32ThingKHR(instance: u64, create_info: &win32_thing_create_info_khr): i32;\n"));
|
||||
t.expects(!holds_line(text_of(&files, "types.sakura"), "win32_thing"));
|
||||
t.expects(text_of(&files, "xlib.sakura").length == 0);
|
||||
}
|
||||
|
||||
@test def binds_an_older_version_without_whats_newer(t: &mut tester): void {
|
||||
val names: strview[1] = ["VK_EXT_heard"];
|
||||
val wanted := wanting_of(1, 0, names[:]);
|
||||
var files := vector::<made_file>::new();
|
||||
var problems := vector::<string>::new();
|
||||
t.expects(bindings_of(small_registry, &wanted, &mut files, &mut problems));
|
||||
t.expects(!holds_line(text_of(&files, "vulkan.sakura"), "VK_API_VERSION_1_1"));
|
||||
t.expects(holds_line(text_of(&files, "vulkan.sakura"), "Vulkan 1.1.7, to Vulkan 1.0"));
|
||||
t.expects(!holds_line(text_of(&files, "commands.sakura"), "vkListThings"));
|
||||
# What the extension needs only with 1.1.
|
||||
t.expects(!holds_line(text_of(&files, "commands.sakura"), "PFN_vkCreateThingKHR"));
|
||||
t.expects(!holds_line(text_of(&files, "types.sakura"), "thing_create_info_khr"));
|
||||
}
|
||||
|
||||
@test def refuses_what_cant_be_bound(t: &mut tester): void {
|
||||
val cases: strview[4] = ["VK_EXT_nothing", "VK_EXT_disabled", "VK_MVK_moved", "VK_KHR_win32_thing"];
|
||||
val said: strview[4] = [
|
||||
"The registry has no extension VK_EXT_nothing.",
|
||||
"VK_EXT_disabled isn't Vulkan's, or is disabled.",
|
||||
"VK_MVK_moved is of the platform macos",
|
||||
"VK_KHR_win32_thing needs VK_EXT_heard",
|
||||
];
|
||||
for i in 0..4u {
|
||||
val wanted := wanting_of(0, 0, cases[i:1]);
|
||||
var files := vector::<made_file>::new();
|
||||
var problems := vector::<string>::new();
|
||||
t.expects(!bindings_of(small_registry, &wanted, &mut files, &mut problems) && problems.length == 1);
|
||||
t.expects(problems.length == 1 && problems[0].span.starts_with(said[i]));
|
||||
}
|
||||
val heard: strview[1] = ["VK_EXT_heard"];
|
||||
val too_new := wanting_of(2, 0, heard[:]);
|
||||
var files := vector::<made_file>::new();
|
||||
var problems := vector::<string>::new();
|
||||
t.expects(!bindings_of(small_registry, &too_new, &mut files, &mut problems));
|
||||
t.expects(problems.length == 1 && problems[0].span == "The registry has no Vulkan 2.0.");
|
||||
}
|
||||
|
||||
@test def writes_c_names_in_snake_case(t: &mut tester): void {
|
||||
t.expects(snake_of("sType").span == "s_type" && snake_of("deviceUUID").span == "device_uuid");
|
||||
t.expects(snake_of("shaderFloat64").span == "shader_float64" && snake_of("maxImageDimension2D").span == "max_image_dimension_2d");
|
||||
t.expects(snake_of("Extent2D").span == "extent_2d" && snake_of("textureCompressionASTC_HDR").span == "texture_compression_astc_hdr");
|
||||
t.expects(snake_of("storageBuffer16BitAccess").span == "storage_buffer16_bit_access" && snake_of("image2DViewOf3D").span == "image_2d_view_of_3d");
|
||||
t.expects(snake_of("driverID").span == "driver_id" && snake_of("SurfaceFormatKHR").span == "surface_format_khr");
|
||||
t.expects(without_prefix("ppEnabledLayerNames") == "EnabledLayerNames" && without_prefix("pfnCallback") == "Callback");
|
||||
t.expects(without_prefix("plane") == "plane" && without_prefix("pNext") == "Next");
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#! 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::<extent_2d>() == 8 && size_of::<offset_3d>() == 12 && size_of::<rect_2d>() == 16);
|
||||
t.expects(size_of::<application_info>() == 48 && size_of::<instance_create_info>() == 64);
|
||||
t.expects(size_of::<physical_device_properties>() == 824 && size_of::<physical_device_limits>() == 504);
|
||||
t.expects(size_of::<physical_device_features>() == 220 && size_of::<physical_device_memory_properties>() == 520);
|
||||
t.expects(size_of::<physical_device_vulkan_1_2_features>() == 208 && size_of::<physical_device_vulkan_1_3_features>() == 80);
|
||||
t.expects(size_of::<graphics_pipeline_create_info>() == 144 && size_of::<write_descriptor_set>() == 64);
|
||||
t.expects(size_of::<image_memory_barrier_2>() == 96 && size_of::<rendering_attachment_info>() == 72);
|
||||
t.expects(size_of::<swapchain_create_info_khr>() == 104 && size_of::<debug_utils_messenger_callback_data_ext>() == 96);
|
||||
t.expects(size_of::<allocation_callbacks>() == 48 && size_of::<descriptor_set_layout_binding>() == 24);
|
||||
t.expects(size_of::<memory_requirements>() == 24 && size_of::<base_in_structure>() == 16);
|
||||
}
|
||||
|
||||
@test def lays_unions_out_as_c_does(t: &mut tester): void {
|
||||
t.expects(size_of::<clear_color_value>() == 16 && size_of::<clear_value>() == 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");
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#! Contains the tests of calls of the loader: the version it gives, an instance
|
||||
#! made and the devices it finds, what a device has, and a function found by
|
||||
#! its name and called through its type.
|
||||
|
||||
import std::testing;
|
||||
import malunal::vulkan;
|
||||
|
||||
@test def gives_the_version_it_has(t: &mut tester): void {
|
||||
var version: u32 = 0;
|
||||
t.expects(vkEnumerateInstanceVersion(&mut version) == VK_SUCCESS);
|
||||
t.expects(VK_API_VERSION_MAJOR(version) == 1 && VK_API_VERSION_MINOR(version) >= 1);
|
||||
}
|
||||
|
||||
@test def makes_an_instance_and_finds_its_devices(t: &mut tester): void {
|
||||
val app := application_info{ application_name = "malunal.vulkan.tests".data, api_version = VK_API_VERSION_1_3 };
|
||||
val info := instance_create_info{ application_info = address(&app) };
|
||||
var instance: u64 = 0;
|
||||
t.expects(vkCreateInstance(&info, null, &mut instance) == VK_SUCCESS && instance != VK_NULL_HANDLE);
|
||||
if instance == VK_NULL_HANDLE {
|
||||
return;
|
||||
}
|
||||
|
||||
var count: u32 = 0;
|
||||
t.expects(vkEnumeratePhysicalDevices(instance, &mut count, null) == VK_SUCCESS);
|
||||
var devices: u64[8];
|
||||
count = count < 8 ? count : 8;
|
||||
if count > 0 {
|
||||
_ = vkEnumeratePhysicalDevices(instance, &mut count, (&mut devices) as *mut u64);
|
||||
var properties := physical_device_properties{};
|
||||
vkGetPhysicalDeviceProperties(devices[0], &mut properties);
|
||||
t.expects(properties.device_name[0] != 0 && VK_API_VERSION_MAJOR(properties.api_version) == 1);
|
||||
t.expects(properties.limits.max_image_dimension_2d >= 4096 && properties.limits.timestamp_period > 0f);
|
||||
|
||||
# Vulkan 1.3's features, chained after 1.0's: a device of 1.3 has these.
|
||||
var thirteen := physical_device_vulkan_1_3_features{};
|
||||
var features := physical_device_features_2{ next = address(&mut thirteen) as *mut u8 };
|
||||
vkGetPhysicalDeviceFeatures2(devices[0], &mut features);
|
||||
if VK_API_VERSION_MINOR(properties.api_version) >= 3 {
|
||||
t.expects(thirteen.dynamic_rendering == VK_TRUE && thirteen.synchronization2 == VK_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
# A function found by name, and called through its type.
|
||||
val found := vkGetInstanceProcAddr(instance, "vkDestroyInstance".data) as u64;
|
||||
t.expects(found != 0);
|
||||
val destroy := found as PFN_vkDestroyInstance;
|
||||
destroy(instance, null);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#! Contains the `main` that runs vulkan's tests, each in a copy of the program
|
||||
#! of its own. `blossom test` runs them, and `--test TEXT` those whose name
|
||||
#! holds the text.
|
||||
|
||||
import system;
|
||||
import std::testing;
|
||||
|
||||
def main(args: span<strview>): void {
|
||||
exit(tester::run(args));
|
||||
}
|
||||
Reference in new issue
Block a user