gpu

source of vulkan::vk

1// The part of Vulkan the GPU package uses, written by hand from the2// Khronos headers (vulkan_core.h, Apache-2.0 or MIT): the structures it3// fills, in C's layout, the numbers it passes, and the functions, loaded4// through vkGetInstanceProcAddr and vkGetDeviceProcAddr. Dispatchable5// handles (instance, physical device, device, queue, command buffer) are6// pointers; the others are 64-bit numbers.78import std::ffi;9import std::option;10import std::string;1112pub const API_VERSION_1_1: u32 = (1 << 22) | (1 << 12);13pub const API_VERSION_1_2: u32 = (1 << 22) | (2 << 12);14pub const API_VERSION_1_3: u32 = (1 << 22) | (3 << 12);1516// results, of which a driver may give others17pub const SUCCESS: i32 = 0;18pub const INCOMPLETE: i32 = 5;19pub const SUBOPTIMAL: i32 = 1000001003;20pub const ERROR_OUT_OF_DATE: i32 = -1000001004;21pub const ERROR_OUT_OF_POOL_MEMORY: i32 = -1000069000;22pub const ERROR_FRAGMENTED_POOL: i32 = -12;2324pub const STAGE_2_ALL_COMMANDS: u64 = 0x10000;25pub const STAGE_2_HOST: u64 = 0x4000;26pub const ACCESS_2_HOST_READ: u64 = 0x2000;27pub const ACCESS_2_MEMORY_READ: u64 = 0x8000;28pub const ACCESS_2_MEMORY_WRITE: u64 = 0x10000;29pub const STAGE_COLOR_ATTACHMENT_OUTPUT: u32 = 0x400;3031pub const BUFFER_USAGE_TRANSFER_SOURCE: u32 = 1;32pub const BUFFER_USAGE_TRANSFER_DESTINATION: u32 = 2;33pub const BUFFER_USAGE_UNIFORM: u32 = 0x10;34pub const BUFFER_USAGE_STORAGE: u32 = 0x20;35pub const BUFFER_USAGE_INDEX: u32 = 0x40;36pub const BUFFER_USAGE_VERTEX: u32 = 0x80;3738pub const IMAGE_USAGE_TRANSFER_SOURCE: u32 = 1;39pub const IMAGE_USAGE_TRANSFER_DESTINATION: u32 = 2;40pub const IMAGE_USAGE_SAMPLED: u32 = 4;41pub const IMAGE_USAGE_COLOR_ATTACHMENT: u32 = 0x10;4243pub const MEMORY_DEVICE_LOCAL: u32 = 1;44pub const MEMORY_HOST_VISIBLE: u32 = 2;45pub const MEMORY_HOST_COHERENT: u32 = 4;46pub const MEMORY_HOST_CACHED: u32 = 8;4748pub const SHADER_STAGE_VERTEX: u32 = 1;49pub const SHADER_STAGE_FRAGMENT: u32 = 0x10;50pub const SHADER_STAGE_COMPUTE: u32 = 0x20;5152// physical device types, of which a driver may give others53pub const PHYSICAL_DEVICE_INTEGRATED: u32 = 1;54pub const PHYSICAL_DEVICE_DISCRETE: u32 = 2;5556pub const QUEUE_GRAPHICS: u32 = 1;57pub const QUEUE_COMPUTE: u32 = 2;58pub const QUEUE_FAMILY_IGNORED: u32 = 0xFFFFFFFF;59pub const COMMAND_POOL_RESET_BUFFER: u32 = 2;60pub const COMMAND_BUFFER_ONE_TIME_SUBMIT: u32 = 1;61pub const IMAGE_ASPECT_COLOR: u32 = 1;62pub const SAMPLE_COUNT_1: u32 = 1;63pub const COLOR_COMPONENTS_ALL: u32 = 0xF;64pub const STAGE_ALL_COMMANDS: u32 = 0x10000;65pub const COMPOSITE_ALPHA_OPAQUE: u32 = 1;66pub const DESCRIPTOR_POOL_FREE_SET: u32 = 1;6768// The `kind` each structure starts with.69pub type StructureType = enum : u32 {70    ApplicationInfo = 0,71    InstanceCreateInfo = 1,72    DeviceQueueCreateInfo = 2,73    DeviceCreateInfo = 3,74    SubmitInfo = 4,75    MemoryAllocateInfo = 5,76    FenceCreateInfo = 8,77    SemaphoreCreateInfo = 9,78    BufferCreateInfo = 12,79    ImageCreateInfo = 14,80    ImageViewCreateInfo = 15,81    ShaderModuleCreateInfo = 16,82    PipelineShaderStageCreateInfo = 18,83    PipelineVertexInputStateCreateInfo = 19,84    PipelineInputAssemblyStateCreateInfo = 20,85    PipelineViewportStateCreateInfo = 22,86    PipelineRasterizationStateCreateInfo = 23,87    PipelineMultisampleStateCreateInfo = 24,88    PipelineColorBlendStateCreateInfo = 26,89    PipelineDynamicStateCreateInfo = 27,90    GraphicsPipelineCreateInfo = 28,91    ComputePipelineCreateInfo = 29,92    PipelineLayoutCreateInfo = 30,93    SamplerCreateInfo = 31,94    DescriptorSetLayoutCreateInfo = 32,95    DescriptorPoolCreateInfo = 33,96    DescriptorSetAllocateInfo = 34,97    WriteDescriptorSet = 35,98    CommandPoolCreateInfo = 39,99    CommandBufferAllocateInfo = 40,100    CommandBufferBeginInfo = 42,101    PhysicalDeviceVulkan13Features = 53,102    PhysicalDeviceDynamicRenderingFeatures = 1000044003,103    PhysicalDeviceSynchronization2Features = 1000314007,104    RenderingInfo = 1000044000,105    RenderingAttachmentInfo = 1000044001,106    PipelineRenderingCreateInfo = 1000044002,107    DependencyInfo = 1000314003,108    ImageMemoryBarrier2 = 1000314002,109    MemoryBarrier2 = 1000314000,110    SwapchainCreateInfo = 1000001000,111    PresentInfo = 1000001001,112    WaylandSurfaceCreateInfo = 1000006000,113    Win32SurfaceCreateInfo = 1000009000,114};115116pub type Format = enum : u32 {117    Undefined = 0,118    R8Unorm = 9,119    R8G8B8A8Unorm = 37,120    B8G8R8A8Unorm = 44,121    R32Sfloat = 100,122    R32G32Sfloat = 103,123    R32G32B32Sfloat = 106,124    R32G32B32A32Sfloat = 109,125    R32Uint = 98,126    R32Sint = 99,127};128129pub type ImageLayout = enum : u32 {130    Undefined = 0,131    General = 1,132    ColorAttachment = 2,133    ShaderReadOnly = 5,134    TransferSource = 6,135    TransferDestination = 7,136    PresentSource = 1000001002,137};138139pub type DescriptorType = enum : u32 {140    Sampler = 0,141    SampledImage = 2,142    UniformBuffer = 6,143    StorageBuffer = 7,144};145146pub type CommandBufferLevel = enum : u32 {147    Primary = 0,148};149150pub type ImageType = enum : u32 {151    Type2D = 1,152};153154pub type ImageViewType = enum : u32 {155    Type2D = 1,156};157158pub type ImageTiling = enum : u32 {159    Optimal = 0,160};161162pub type Filter = enum : u32 {163    Nearest = 0,164    Linear = 1,165};166167pub type SamplerAddressMode = enum : u32 {168    Repeat = 0,169    ClampToEdge = 2,170};171172pub type VertexInputRate = enum : u32 {173    Vertex = 0,174    Instance = 1,175};176177pub type PrimitiveTopology = enum : u32 {178    TriangleList = 3,179    TriangleStrip = 4,180};181182pub type BlendFactor = enum : u32 {183    One = 1,184    SourceAlpha = 6,185    OneMinusSourceAlpha = 7,186};187188pub type DynamicState = enum : u32 {189    Viewport = 0,190    Scissor = 1,191};192193pub type AttachmentLoadOp = enum : u32 {194    Load = 0,195    Clear = 1,196};197198pub type AttachmentStoreOp = enum : u32 {199    Store = 0,200};201202pub type IndexType = enum : u32 {203    Uint16 = 0,204    Uint32 = 1,205};206207pub type PipelineBindPoint = enum : u32 {208    Graphics = 0,209    Compute = 1,210};211212pub type ColorSpace = enum : u32 {213    SrgbNonlinear = 0,214};215216pub type PresentMode = enum : u32 {217    Fifo = 2,218};219220/* --- Structures --- */221222pub type Offset2D = struct {223    pub x: i32,224    pub y: i32,225};226227pub type Extent2D = struct {228    pub width: u32,229    pub height: u32,230};231232pub type Offset3D = struct {233    pub x: i32,234    pub y: i32,235    pub z: i32,236};237238pub type Extent3D = struct {239    pub width: u32,240    pub height: u32,241    pub depth: u32,242};243244pub type ApplicationInfo = struct {245    pub kind: StructureType = StructureType::ApplicationInfo,246    pub next: c_pointer = 0,247    pub application_name: c_pointer,248    pub application_version: u32,249    pub engine_name: c_pointer,250    pub engine_version: u32,251    pub api_version: u32,252};253254pub type InstanceCreateInfo = struct {255    pub kind: StructureType = StructureType::InstanceCreateInfo,256    pub next: c_pointer = 0,257    pub flags: u32 = 0,258    pub application_info: c_pointer,259    pub layer_count: u32 = 0,260    pub layers: c_pointer = 0,261    pub extension_count: u32 = 0,262    pub extensions: c_pointer = 0,263};264265pub type DeviceQueueCreateInfo = struct {266    pub kind: StructureType = StructureType::DeviceQueueCreateInfo,267    pub next: c_pointer = 0,268    pub flags: u32 = 0,269    pub family: u32,270    pub count: u32,271    pub priorities: c_pointer,272};273274pub type DeviceCreateInfo = struct {275    pub kind: StructureType = StructureType::DeviceCreateInfo,276    pub next: c_pointer = 0,277    pub flags: u32 = 0,278    pub queue_info_count: u32,279    pub queue_infos: c_pointer,280    pub layer_count: u32 = 0,281    pub layers: c_pointer = 0,282    pub extension_count: u32,283    pub extensions: c_pointer,284    pub features: c_pointer = 0,285};286287pub type Vulkan13Features = struct {288    pub kind: StructureType = StructureType::PhysicalDeviceVulkan13Features,289    pub next: c_pointer = 0,290    pub robust_image_access: u32 = 0,291    pub inline_uniform_block: u32 = 0,292    pub inline_uniform_block_update_after_bind: u32 = 0,293    pub pipeline_creation_cache_control: u32 = 0,294    pub private_data: u32 = 0,295    pub demote_to_helper_invocation: u32 = 0,296    pub terminate_invocation: u32 = 0,297    pub subgroup_size_control: u32 = 0,298    pub compute_full_subgroups: u32 = 0,299    pub synchronization2: u32 = 0,300    pub texture_compression_astc_hdr: u32 = 0,301    pub zero_initialize_workgroup_memory: u32 = 0,302    pub dynamic_rendering: u32 = 0,303    pub integer_dot_product: u32 = 0,304    pub maintenance4: u32 = 0,305};306307// VkPhysicalDeviceDynamicRenderingFeatures, and the synchronization2 one,308// which have the same shape.309pub type FeatureFlag = struct {310    pub kind: StructureType,311    pub next: c_pointer = 0,312    pub enabled: u32,313};314315pub type MemoryAllocateInfo = struct {316    pub kind: StructureType = StructureType::MemoryAllocateInfo,317    pub next: c_pointer = 0,318    pub size: u64,319    pub memory_type: u32,320};321322pub type MemoryRequirements = struct {323    pub size: u64,324    pub alignment: u64,325    pub memory_types: u32,326};327328pub type BufferCreateInfo = struct {329    pub kind: StructureType = StructureType::BufferCreateInfo,330    pub next: c_pointer = 0,331    pub flags: u32 = 0,332    pub size: u64,333    pub usage: u32,334    pub sharing: u32 = 0,335    pub family_count: u32 = 0,336    pub families: c_pointer = 0,337};338339pub type ImageCreateInfo = struct {340    pub kind: StructureType = StructureType::ImageCreateInfo,341    pub next: c_pointer = 0,342    pub flags: u32 = 0,343    pub image_type: ImageType,344    pub format: Format,345    pub extent: Extent3D,346    pub mip_levels: u32,347    pub array_layers: u32,348    pub samples: u32,349    pub tiling: ImageTiling,350    pub usage: u32,351    pub sharing: u32 = 0,352    pub family_count: u32 = 0,353    pub families: c_pointer = 0,354    pub initial_layout: ImageLayout,355};356357pub type SubresourceRange = struct {358    pub aspect: u32,359    pub base_level: u32,360    pub level_count: u32,361    pub base_layer: u32,362    pub layer_count: u32,363};364365pub fn SubresourceRange::color() -> SubresourceRange {366    return SubresourceRange {367        .aspect = IMAGE_ASPECT_COLOR,368        .base_level = 0,369        .level_count = 1,370        .base_layer = 0,371        .layer_count = 1372    };373}374375pub type ImageViewCreateInfo = struct {376    pub kind: StructureType = StructureType::ImageViewCreateInfo,377    pub next: c_pointer = 0,378    pub flags: u32 = 0,379    pub image: u64,380    pub view_type: ImageViewType,381    pub format: Format,382    pub components: [u32 : 4],383    pub range: SubresourceRange,384};385386pub type SamplerCreateInfo = struct {387    pub kind: StructureType = StructureType::SamplerCreateInfo,388    pub next: c_pointer = 0,389    pub flags: u32 = 0,390    pub mag_filter: Filter,391    pub min_filter: Filter,392    pub mipmap_mode: u32 = 0,393    pub address_u: SamplerAddressMode,394    pub address_v: SamplerAddressMode,395    pub address_w: SamplerAddressMode,396    pub lod_bias: f32 = 0.0,397    pub anisotropy_enable: u32 = 0,398    pub max_anisotropy: f32,399    pub compare_enable: u32 = 0,400    pub compare: u32 = 0,401    pub min_lod: f32 = 0.0,402    pub max_lod: f32 = 0.0,403    pub border: u32 = 0,404    pub unnormalized: u32 = 0,405};406407pub type ShaderModuleCreateInfo = struct {408    pub kind: StructureType = StructureType::ShaderModuleCreateInfo,409    pub next: c_pointer = 0,410    pub flags: u32 = 0,411    pub size: c_size,412    pub code: c_pointer,413};414415pub type DescriptorSetLayoutBinding = struct {416    pub binding: u32,417    pub descriptor_type: DescriptorType,418    pub count: u32,419    pub stages: u32,420    pub immutable_samplers: c_pointer = 0,421};422423pub type DescriptorSetLayoutCreateInfo = struct {424    pub kind: StructureType = StructureType::DescriptorSetLayoutCreateInfo,425    pub next: c_pointer = 0,426    pub flags: u32 = 0,427    pub binding_count: u32,428    pub bindings: c_pointer,429};430431pub type PipelineLayoutCreateInfo = struct {432    pub kind: StructureType = StructureType::PipelineLayoutCreateInfo,433    pub next: c_pointer = 0,434    pub flags: u32 = 0,435    pub set_layout_count: u32,436    pub set_layouts: c_pointer,437    pub push_range_count: u32 = 0,438    pub push_ranges: c_pointer = 0,439};440441pub type DescriptorPoolSize = struct {442    pub descriptor_type: DescriptorType,443    pub count: u32,444};445446pub type DescriptorPoolCreateInfo = struct {447    pub kind: StructureType = StructureType::DescriptorPoolCreateInfo,448    pub next: c_pointer = 0,449    pub flags: u32 = 0,450    pub max_sets: u32,451    pub size_count: u32,452    pub sizes: c_pointer,453};454455pub type DescriptorSetAllocateInfo = struct {456    pub kind: StructureType = StructureType::DescriptorSetAllocateInfo,457    pub next: c_pointer = 0,458    pub pool: u64,459    pub count: u32,460    pub layouts: c_pointer,461};462463pub type DescriptorBufferInfo = struct {464    pub buffer: u64,465    pub offset: u64,466    pub range: u64,467};468469pub type DescriptorImageInfo = struct {470    pub sampler: u64,471    pub view: u64,472    pub layout: ImageLayout,473};474475pub type WriteDescriptorSet = struct {476    pub kind: StructureType = StructureType::WriteDescriptorSet,477    pub next: c_pointer = 0,478    pub set: u64,479    pub binding: u32,480    pub array_element: u32 = 0,481    pub count: u32,482    pub descriptor_type: DescriptorType,483    pub image_info: c_pointer = 0,484    pub buffer_info: c_pointer = 0,485    pub texel_buffer_view: c_pointer = 0,486};487488pub type PipelineShaderStageCreateInfo = struct {489    pub kind: StructureType = StructureType::PipelineShaderStageCreateInfo,490    pub next: c_pointer = 0,491    pub flags: u32 = 0,492    pub stage: u32,493    pub module: u64,494    pub name: c_pointer,495    pub specialization: c_pointer = 0,496};497498pub type VertexInputBinding = struct {499    pub binding: u32,500    pub stride: u32,501    pub rate: VertexInputRate,502};503504pub type VertexInputAttribute = struct {505    pub location: u32,506    pub binding: u32,507    pub format: Format,508    pub offset: u32,509};510511pub type PipelineVertexInputStateCreateInfo = struct {512    pub kind: StructureType = StructureType::PipelineVertexInputStateCreateInfo,513    pub next: c_pointer = 0,514    pub flags: u32 = 0,515    pub binding_count: u32,516    pub bindings: c_pointer,517    pub attribute_count: u32,518    pub attributes: c_pointer,519};520521pub type PipelineInputAssemblyStateCreateInfo = struct {522    pub kind: StructureType = StructureType::PipelineInputAssemblyStateCreateInfo,523    pub next: c_pointer = 0,524    pub flags: u32 = 0,525    pub topology: PrimitiveTopology,526    pub primitive_restart: u32 = 0,527};528529pub type PipelineViewportStateCreateInfo = struct {530    pub kind: StructureType = StructureType::PipelineViewportStateCreateInfo,531    pub next: c_pointer = 0,532    pub flags: u32 = 0,533    pub viewport_count: u32,534    pub viewports: c_pointer = 0,535    pub scissor_count: u32,536    pub scissors: c_pointer = 0,537};538539pub type PipelineRasterizationStateCreateInfo = struct {540    pub kind: StructureType = StructureType::PipelineRasterizationStateCreateInfo,541    pub next: c_pointer = 0,542    pub flags: u32 = 0,543    pub depth_clamp: u32 = 0,544    pub rasterizer_discard: u32 = 0,545    pub polygon_mode: u32 = 0,546    pub cull_mode: u32 = 0,547    pub front_face: u32 = 0,548    pub depth_bias: u32 = 0,549    pub depth_bias_constant: f32 = 0.0,550    pub depth_bias_clamp: f32 = 0.0,551    pub depth_bias_slope: f32 = 0.0,552    pub line_width: f32,553};554555pub type PipelineMultisampleStateCreateInfo = struct {556    pub kind: StructureType = StructureType::PipelineMultisampleStateCreateInfo,557    pub next: c_pointer = 0,558    pub flags: u32 = 0,559    pub samples: u32,560    pub sample_shading: u32 = 0,561    pub min_sample_shading: f32 = 0.0,562    pub sample_mask: c_pointer = 0,563    pub alpha_to_coverage: u32 = 0,564    pub alpha_to_one: u32 = 0,565};566567pub type ColorBlendAttachment = struct {568    pub enable: u32,569    pub source_color: BlendFactor,570    pub destination_color: BlendFactor,571    pub color_op: u32,572    pub source_alpha: BlendFactor,573    pub destination_alpha: BlendFactor,574    pub alpha_op: u32,575    pub write_mask: u32,576};577578pub type PipelineColorBlendStateCreateInfo = struct {579    pub kind: StructureType = StructureType::PipelineColorBlendStateCreateInfo,580    pub next: c_pointer = 0,581    pub flags: u32 = 0,582    pub logic_op_enable: u32 = 0,583    pub logic_op: u32 = 0,584    pub attachment_count: u32,585    pub attachments: c_pointer,586    pub constants: [f32 : 4] = [0.0 : 4],587};588589pub type PipelineDynamicStateCreateInfo = struct {590    pub kind: StructureType = StructureType::PipelineDynamicStateCreateInfo,591    pub next: c_pointer = 0,592    pub flags: u32 = 0,593    pub count: u32,594    pub states: c_pointer,595};596597pub type PipelineRenderingCreateInfo = struct {598    pub kind: StructureType = StructureType::PipelineRenderingCreateInfo,599    pub next: c_pointer = 0,600    pub view_mask: u32 = 0,601    pub color_count: u32,602    pub color_formats: c_pointer,603    pub depth_format: Format = Format::Undefined,604    pub stencil_format: Format = Format::Undefined,605};606607pub type GraphicsPipelineCreateInfo = struct {608    pub kind: StructureType = StructureType::GraphicsPipelineCreateInfo,609    pub next: c_pointer = 0,610    pub flags: u32 = 0,611    pub stage_count: u32,612    pub stages: c_pointer,613    pub vertex_input: c_pointer,614    pub input_assembly: c_pointer,615    pub tessellation: c_pointer = 0,616    pub viewport: c_pointer,617    pub rasterization: c_pointer,618    pub multisample: c_pointer,619    pub depth_stencil: c_pointer = 0,620    pub color_blend: c_pointer,621    pub dynamic: c_pointer,622    pub layout: u64,623    pub render_pass: u64 = 0,624    pub subpass: u32 = 0,625    pub base_pipeline: u64 = 0,626    pub base_index: i32 = -1,627};628629pub type ComputePipelineCreateInfo = struct {630    pub kind: StructureType = StructureType::ComputePipelineCreateInfo,631    pub next: c_pointer = 0,632    pub flags: u32 = 0,633    pub stage: PipelineShaderStageCreateInfo,634    pub layout: u64,635    pub base_pipeline: u64 = 0,636    pub base_index: i32 = -1,637};638639pub type Rect2D = struct {640    pub offset: Offset2D,641    pub extent: Extent2D,642};643644pub type Viewport = struct {645    pub x: f32,646    pub y: f32,647    pub width: f32,648    pub height: f32,649    pub min_depth: f32,650    pub max_depth: f32,651};652653pub type RenderingAttachmentInfo = struct {654    pub kind: StructureType = StructureType::RenderingAttachmentInfo,655    pub next: c_pointer = 0,656    pub view: u64,657    pub layout: ImageLayout,658    pub resolve_mode: u32 = 0,659    pub resolve_view: u64 = 0,660    pub resolve_layout: ImageLayout = ImageLayout::Undefined,661    pub load: AttachmentLoadOp,662    pub store: AttachmentStoreOp,663    pub clear: [f32 : 4],664};665666pub type RenderingInfo = struct {667    pub kind: StructureType = StructureType::RenderingInfo,668    pub next: c_pointer = 0,669    pub flags: u32 = 0,670    pub area: Rect2D,671    pub layer_count: u32,672    pub view_mask: u32 = 0,673    pub color_count: u32,674    pub colors: c_pointer,675    pub depth: c_pointer = 0,676    pub stencil: c_pointer = 0,677};678679pub type CommandPoolCreateInfo = struct {680    pub kind: StructureType = StructureType::CommandPoolCreateInfo,681    pub next: c_pointer = 0,682    pub flags: u32 = 0,683    pub family: u32,684};685686pub type CommandBufferAllocateInfo = struct {687    pub kind: StructureType = StructureType::CommandBufferAllocateInfo,688    pub next: c_pointer = 0,689    pub pool: u64,690    pub level: CommandBufferLevel,691    pub count: u32,692};693694pub type CommandBufferBeginInfo = struct {695    pub kind: StructureType = StructureType::CommandBufferBeginInfo,696    pub next: c_pointer = 0,697    pub flags: u32 = 0,698    pub inheritance: c_pointer = 0,699};700701pub type SubmitInfo = struct {702    pub kind: StructureType = StructureType::SubmitInfo,703    pub next: c_pointer = 0,704    pub wait_count: u32 = 0,705    pub waits: c_pointer = 0,706    pub wait_stages: c_pointer = 0,707    pub buffer_count: u32,708    pub buffers: c_pointer,709    pub signal_count: u32 = 0,710    pub signals: c_pointer = 0,711};712713pub type SemaphoreCreateInfo = struct {714    pub kind: StructureType = StructureType::SemaphoreCreateInfo,715    pub next: c_pointer = 0,716    pub flags: u32 = 0,717};718719pub type FenceCreateInfo = struct {720    pub kind: StructureType = StructureType::FenceCreateInfo,721    pub next: c_pointer = 0,722    pub flags: u32 = 0,723};724725pub type MemoryBarrier2 = struct {726    pub kind: StructureType = StructureType::MemoryBarrier2,727    pub next: c_pointer = 0,728    pub source_stages: u64,729    pub source_access: u64,730    pub destination_stages: u64,731    pub destination_access: u64,732};733734pub type ImageMemoryBarrier2 = struct {735    pub kind: StructureType = StructureType::ImageMemoryBarrier2,736    pub next: c_pointer = 0,737    pub source_stages: u64,738    pub source_access: u64,739    pub destination_stages: u64,740    pub destination_access: u64,741    pub old_layout: ImageLayout,742    pub new_layout: ImageLayout,743    pub source_family: u32,744    pub destination_family: u32,745    pub image: u64,746    pub range: SubresourceRange,747};748749pub type DependencyInfo = struct {750    pub kind: StructureType = StructureType::DependencyInfo,751    pub next: c_pointer = 0,752    pub flags: u32 = 0,753    pub memory_count: u32 = 0,754    pub memory: c_pointer = 0,755    pub buffer_count: u32 = 0,756    pub buffers: c_pointer = 0,757    pub image_count: u32 = 0,758    pub images: c_pointer = 0,759};760761pub type BufferCopy = struct {762    pub source_offset: u64,763    pub destination_offset: u64,764    pub size: u64,765};766767pub type SubresourceLayers = struct {768    pub aspect: u32,769    pub level: u32,770    pub base_layer: u32,771    pub layer_count: u32,772};773774pub fn SubresourceLayers::color() -> SubresourceLayers {775    return SubresourceLayers {776        .aspect = IMAGE_ASPECT_COLOR,777        .level = 0,778        .base_layer = 0,779        .layer_count = 1780    };781}782783pub type ImageCopy = struct {784    pub source_subresource: SubresourceLayers,785    pub source_offset: Offset3D,786    pub destination_subresource: SubresourceLayers,787    pub destination_offset: Offset3D,788    pub extent: Extent3D,789};790791pub type BufferImageCopy = struct {792    pub buffer_offset: u64,793    pub row_length: u32,794    pub image_height: u32,795    pub subresource: SubresourceLayers,796    pub offset: Offset3D,797    pub extent: Extent3D,798};799800pub type SwapchainCreateInfo = struct {801    pub kind: StructureType = StructureType::SwapchainCreateInfo,802    pub next: c_pointer = 0,803    pub flags: u32 = 0,804    pub surface: u64,805    pub min_images: u32,806    pub format: Format,807    pub color_space: ColorSpace,808    pub extent: Extent2D,809    pub array_layers: u32,810    pub usage: u32,811    pub sharing: u32 = 0,812    pub family_count: u32 = 0,813    pub families: c_pointer = 0,814    pub transform: u32,815    pub composite_alpha: u32,816    pub present_mode: PresentMode,817    pub clipped: u32,818    pub old_swapchain: u64,819};820821pub type PresentInfo = struct {822    pub kind: StructureType = StructureType::PresentInfo,823    pub next: c_pointer = 0,824    pub wait_count: u32,825    pub waits: c_pointer,826    pub swapchain_count: u32,827    pub swapchains: c_pointer,828    pub indices: c_pointer,829    pub results: c_pointer = 0,830};831832pub type SurfaceCapabilities = struct {833    pub min_images: u32,834    pub max_images: u32,835    pub current_extent: Extent2D,836    pub min_extent: Extent2D,837    pub max_extent: Extent2D,838    pub max_layers: u32,839    pub supported_transforms: u32,840    pub current_transform: u32,841    pub supported_alpha: u32,842    pub supported_usage: u32,843};844845pub type SurfaceFormat = struct {846    pub format: u32,847    pub color_space: u32,848};849850pub type WaylandSurfaceCreateInfo = struct {851    pub kind: StructureType = StructureType::WaylandSurfaceCreateInfo,852    pub next: c_pointer = 0,853    pub flags: u32 = 0,854    pub display: c_pointer,855    pub surface: c_pointer,856};857858pub type Win32SurfaceCreateInfo = struct {859    pub kind: StructureType = StructureType::Win32SurfaceCreateInfo,860    pub next: c_pointer = 0,861    pub flags: u32 = 0,862    pub instance: c_pointer,863    pub hwnd: c_pointer,864};865866/* --- Functions --- */867868pub type GetProcAddr = extern (c_pointer, c_pointer) -> c_pointer;869870// The function of that name, from vkGetInstanceProcAddr or871// vkGetDeviceProcAddr; None when the implementation lacks it.872pub fn find<F: CFunction>(get: GetProcAddr, owner: c_pointer, name: &[u8]) -> Option<F> {873    var text = String::from(&name);874    text.push(0);875    const address = get(owner, c_pointer::of(&text.view()));876    if (address == 0) {877        return ::None;878    }879    return ::Some(copy address as F);880}881882// The function of that name, or of the second: the core name of a883// function and its extension's.884pub fn function<F: CFunction>(get: GetProcAddr, owner: c_pointer, name: &[u8], other: &[u8]) -> F {885    if (find<F>(get, owner, &name) is ::Some |move f|) {886        return move f;887    }888    if (other.length() > 0 && find<F>(get, owner, &other) is ::Some |move f|) {889        return move f;890    }891    const message = f"pkg::alloy::gpu: the Vulkan implementation lacks {name}";892    panic message.view();893}894895pub type InstanceFunctions = struct {896    pub destroy_instance: extern (c_pointer, c_pointer),897    pub enumerate_physical_devices: extern (c_pointer, c_pointer, c_pointer) -> i32,898    pub get_properties: extern (c_pointer, c_pointer),899    pub get_queue_families: extern (c_pointer, c_pointer, c_pointer),900    pub get_memory_properties: extern (c_pointer, c_pointer),901    pub enumerate_device_extensions: extern (c_pointer, c_pointer, c_pointer, c_pointer) -> i32,902    pub create_device: extern (c_pointer, c_pointer, c_pointer, c_pointer) -> i32,903    pub get_device_proc_addr: GetProcAddr,904};905906pub fn InstanceFunctions::load(get: GetProcAddr, instance: c_pointer) -> InstanceFunctions {907    return InstanceFunctions {908        .destroy_instance = function(get, instance, &"vkDestroyInstance", &""),909        .enumerate_physical_devices = function(get, instance, &"vkEnumeratePhysicalDevices", &""),910        .get_properties = function(get, instance, &"vkGetPhysicalDeviceProperties", &""),911        .get_queue_families = function(912            get,913            instance,914            &"vkGetPhysicalDeviceQueueFamilyProperties",915            &""916        ),917        .get_memory_properties = function(918            get,919            instance,920            &"vkGetPhysicalDeviceMemoryProperties",921            &""922        ),923        .enumerate_device_extensions = function(924            get,925            instance,926            &"vkEnumerateDeviceExtensionProperties",927            &""928        ),929        .create_device = function(get, instance, &"vkCreateDevice", &""),930        .get_device_proc_addr = function(get, instance, &"vkGetDeviceProcAddr", &"")931    };932}933934// Functions taking a device: (device, create info, allocator, made).935pub type Create = extern (c_pointer, c_pointer, c_pointer, c_pointer) -> i32;936// Functions destroying an object: (device, object, allocator).937pub type Destroy = extern (c_pointer, u64, c_pointer);938939pub type DeviceFunctions = struct {940    pub get_queue: extern (c_pointer, u32, u32, c_pointer),941    pub wait_idle: extern (c_pointer) -> i32,942    pub create_buffer: Create,943    pub destroy_buffer: Destroy,944    pub buffer_requirements: extern (c_pointer, u64, c_pointer),945    pub allocate_memory: Create,946    pub free_memory: Destroy,947    pub bind_buffer_memory: extern (c_pointer, u64, u64, u64) -> i32,948    pub map_memory: extern (c_pointer, u64, u64, u64, u32, c_pointer) -> i32,949    pub create_image: Create,950    pub destroy_image: Destroy,951    pub image_requirements: extern (c_pointer, u64, c_pointer),952    pub bind_image_memory: extern (c_pointer, u64, u64, u64) -> i32,953    pub create_image_view: Create,954    pub destroy_image_view: Destroy,955    pub create_sampler: Create,956    pub destroy_sampler: Destroy,957    pub create_shader_module: Create,958    pub destroy_shader_module: Destroy,959    pub create_set_layout: Create,960    pub create_pipeline_layout: Create,961    pub create_graphics_pipelines: extern (962        c_pointer,963        u64,964        u32,965        c_pointer,966        c_pointer,967        c_pointer968    ) -> i32,969    pub create_compute_pipelines: extern (970        c_pointer,971        u64,972        u32,973        c_pointer,974        c_pointer,975        c_pointer976    ) -> i32,977    pub create_descriptor_pool: Create,978    pub destroy_pipeline: Destroy,979    pub allocate_sets: extern (c_pointer, c_pointer, c_pointer) -> i32,980    pub free_sets: extern (c_pointer, u64, u32, c_pointer) -> i32,981    pub update_sets: extern (c_pointer, u32, c_pointer, u32, c_pointer),982    pub create_command_pool: Create,983    pub allocate_command_buffers: extern (c_pointer, c_pointer, c_pointer) -> i32,984    pub begin_command_buffer: extern (c_pointer, c_pointer) -> i32,985    pub end_command_buffer: extern (c_pointer) -> i32,986    pub create_fence: Create,987    pub wait_for_fences: extern (c_pointer, u32, c_pointer, u32, u64) -> i32,988    pub reset_fences: extern (c_pointer, u32, c_pointer) -> i32,989    pub queue_submit: extern (c_pointer, u32, c_pointer, u64) -> i32,990    pub begin_rendering: extern (c_pointer, c_pointer),991    pub end_rendering: extern (c_pointer),992    pub pipeline_barrier: extern (c_pointer, c_pointer),993    pub bind_pipeline: extern (c_pointer, PipelineBindPoint, u64),994    pub bind_sets: extern (c_pointer, PipelineBindPoint, u64, u32, u32, c_pointer, u32, c_pointer),995    pub bind_vertex_buffers: extern (c_pointer, u32, u32, c_pointer, c_pointer),996    pub bind_index_buffer: extern (c_pointer, u64, u64, IndexType),997    pub set_viewport: extern (c_pointer, u32, u32, c_pointer),998    pub set_scissor: extern (c_pointer, u32, u32, c_pointer),999    pub draw: extern (c_pointer, u32, u32, u32, u32),1000    pub draw_indexed: extern (c_pointer, u32, u32, u32, i32, u32),1001    pub dispatch: extern (c_pointer, u32, u32, u32),1002    pub copy_buffer: extern (c_pointer, u64, u64, u32, c_pointer),1003    pub copy_image: extern (c_pointer, u64, ImageLayout, u64, ImageLayout, u32, c_pointer),1004    pub copy_buffer_to_image: extern (c_pointer, u64, u64, ImageLayout, u32, c_pointer),1005    pub copy_image_to_buffer: extern (c_pointer, u64, ImageLayout, u64, u32, c_pointer),1006};10071008pub fn DeviceFunctions::load(get: GetProcAddr, device: c_pointer) -> DeviceFunctions {1009    return DeviceFunctions {1010        .get_queue = function(get, device, &"vkGetDeviceQueue", &""),1011        .wait_idle = function(get, device, &"vkDeviceWaitIdle", &""),1012        .create_buffer = function(get, device, &"vkCreateBuffer", &""),1013        .destroy_buffer = function(get, device, &"vkDestroyBuffer", &""),1014        .buffer_requirements = function(get, device, &"vkGetBufferMemoryRequirements", &""),1015        .allocate_memory = function(get, device, &"vkAllocateMemory", &""),1016        .free_memory = function(get, device, &"vkFreeMemory", &""),1017        .bind_buffer_memory = function(get, device, &"vkBindBufferMemory", &""),1018        .map_memory = function(get, device, &"vkMapMemory", &""),1019        .create_image = function(get, device, &"vkCreateImage", &""),1020        .destroy_image = function(get, device, &"vkDestroyImage", &""),1021        .image_requirements = function(get, device, &"vkGetImageMemoryRequirements", &""),1022        .bind_image_memory = function(get, device, &"vkBindImageMemory", &""),1023        .create_image_view = function(get, device, &"vkCreateImageView", &""),1024        .destroy_image_view = function(get, device, &"vkDestroyImageView", &""),1025        .create_sampler = function(get, device, &"vkCreateSampler", &""),1026        .destroy_sampler = function(get, device, &"vkDestroySampler", &""),1027        .create_shader_module = function(get, device, &"vkCreateShaderModule", &""),1028        .destroy_shader_module = function(get, device, &"vkDestroyShaderModule", &""),1029        .create_set_layout = function(get, device, &"vkCreateDescriptorSetLayout", &""),1030        .create_pipeline_layout = function(get, device, &"vkCreatePipelineLayout", &""),1031        .create_graphics_pipelines = function(get, device, &"vkCreateGraphicsPipelines", &""),1032        .create_compute_pipelines = function(get, device, &"vkCreateComputePipelines", &""),1033        .create_descriptor_pool = function(get, device, &"vkCreateDescriptorPool", &""),1034        .destroy_pipeline = function(get, device, &"vkDestroyPipeline", &""),1035        .allocate_sets = function(get, device, &"vkAllocateDescriptorSets", &""),1036        .free_sets = function(get, device, &"vkFreeDescriptorSets", &""),1037        .update_sets = function(get, device, &"vkUpdateDescriptorSets", &""),1038        .create_command_pool = function(get, device, &"vkCreateCommandPool", &""),1039        .allocate_command_buffers = function(get, device, &"vkAllocateCommandBuffers", &""),1040        .begin_command_buffer = function(get, device, &"vkBeginCommandBuffer", &""),1041        .end_command_buffer = function(get, device, &"vkEndCommandBuffer", &""),1042        .create_fence = function(get, device, &"vkCreateFence", &""),1043        .wait_for_fences = function(get, device, &"vkWaitForFences", &""),1044        .reset_fences = function(get, device, &"vkResetFences", &""),1045        .queue_submit = function(get, device, &"vkQueueSubmit", &""),1046        .begin_rendering = function(get, device, &"vkCmdBeginRendering", &"vkCmdBeginRenderingKHR"),1047        .end_rendering = function(get, device, &"vkCmdEndRendering", &"vkCmdEndRenderingKHR"),1048        .pipeline_barrier = function(1049            get,1050            device,1051            &"vkCmdPipelineBarrier2",1052            &"vkCmdPipelineBarrier2KHR"1053        ),1054        .bind_pipeline = function(get, device, &"vkCmdBindPipeline", &""),1055        .bind_sets = function(get, device, &"vkCmdBindDescriptorSets", &""),1056        .bind_vertex_buffers = function(get, device, &"vkCmdBindVertexBuffers", &""),1057        .bind_index_buffer = function(get, device, &"vkCmdBindIndexBuffer", &""),1058        .set_viewport = function(get, device, &"vkCmdSetViewport", &""),1059        .set_scissor = function(get, device, &"vkCmdSetScissor", &""),1060        .draw = function(get, device, &"vkCmdDraw", &""),1061        .draw_indexed = function(get, device, &"vkCmdDrawIndexed", &""),1062        .dispatch = function(get, device, &"vkCmdDispatch", &""),1063        .copy_buffer = function(get, device, &"vkCmdCopyBuffer", &""),1064        .copy_image = function(get, device, &"vkCmdCopyImage", &""),1065        .copy_buffer_to_image = function(get, device, &"vkCmdCopyBufferToImage", &""),1066        .copy_image_to_buffer = function(get, device, &"vkCmdCopyImageToBuffer", &"")1067    };1068}10691070// What surfaces need: the instance's functions of VK_KHR_surface and the1071// platform's surface extension, and the device's of VK_KHR_swapchain.1072pub type SurfaceFunctions = struct {1073    pub create_surface: Create,1074    pub destroy_surface: extern (c_pointer, u64, c_pointer),1075    pub surface_support: extern (c_pointer, u32, u64, c_pointer) -> i32,1076    pub surface_capabilities: extern (c_pointer, u64, c_pointer) -> i32,1077    pub surface_formats: extern (c_pointer, u64, c_pointer, c_pointer) -> i32,1078    pub create_swapchain: Create,1079    pub destroy_swapchain: Destroy,1080    pub swapchain_images: extern (c_pointer, u64, c_pointer, c_pointer) -> i32,1081    pub acquire_next_image: extern (c_pointer, u64, u64, u64, u64, c_pointer) -> i32,1082    pub queue_present: extern (c_pointer, c_pointer) -> i32,1083    pub create_semaphore: Create,1084    pub destroy_semaphore: Destroy,1085};10861087pub fn SurfaceFunctions::load(1088    get: GetProcAddr,1089    instance: c_pointer,1090    get_device: GetProcAddr,1091    device: c_pointer,1092    create_surface: &[u8]1093) -> SurfaceFunctions {1094    return SurfaceFunctions {1095        .create_surface = function(get, instance, &create_surface, &""),1096        .destroy_surface = function(get, instance, &"vkDestroySurfaceKHR", &""),1097        .surface_support = function(get, instance, &"vkGetPhysicalDeviceSurfaceSupportKHR", &""),1098        .surface_capabilities = function(1099            get,1100            instance,1101            &"vkGetPhysicalDeviceSurfaceCapabilitiesKHR",1102            &""1103        ),1104        .surface_formats = function(get, instance, &"vkGetPhysicalDeviceSurfaceFormatsKHR", &""),1105        .create_swapchain = function(get_device, device, &"vkCreateSwapchainKHR", &""),1106        .destroy_swapchain = function(get_device, device, &"vkDestroySwapchainKHR", &""),1107        .swapchain_images = function(get_device, device, &"vkGetSwapchainImagesKHR", &""),1108        .acquire_next_image = function(get_device, device, &"vkAcquireNextImageKHR", &""),1109        .queue_present = function(get_device, device, &"vkQueuePresentKHR", &""),1110        .create_semaphore = function(get_device, device, &"vkCreateSemaphore", &""),1111        .destroy_semaphore = function(get_device, device, &"vkDestroySemaphore", &"")1112    };1113}