vulkan_layer\bindings/vk_layer.rs
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![allow(non_camel_case_types)]
16#![allow(non_snake_case)]
17#![allow(non_upper_case_globals)]
18#![allow(dead_code)]
19
20use std::mem::MaybeUninit;
21
22use ash::vk;
23
24mod generated;
25
26/// Bindings for the C `PFN_vkLayerCreateDevice` type defined in the `vk_layer.h` file.
27pub use generated::PFN_vkLayerCreateDevice;
28/// Bindings for the C `PFN_vkLayerDestroyDevice` type defined in the `vk_layer.h` file.
29pub use generated::PFN_vkLayerDestroyDevice;
30/// Bindings for the C `PFN_vkSetInstanceLoaderData` type defined in the `vk_layer.h` file.
31pub use generated::PFN_vkSetInstanceLoaderData;
32/// Sub type of structure for instance and device loader ext of CreateInfo. Bindings for the C
33/// `VkLayerDeviceCreateInfo` type defined in the `vk_layer.h` file.
34///
35/// When `sType` is
36/// [`VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkStructureType.html)
37/// then [`VkLayerFunction`] indicates struct type pointed to by pNext.
38pub use generated::VkLayerDeviceCreateInfo;
39/// A list node that contains the next entity's `vkGetInstanceProcAddr` and
40/// `vkGetDeviceProcAddr` used by a layer. One possible payload of [`VkLayerDeviceCreateInfo`]
41pub use generated::VkLayerDeviceLink;
42/// Bindings for the C `VkLayerFunction` type defined in the `vk_layer.h` file.
43///
44/// Used to distinguish the payload of the loader extension of CreateInfo:
45/// [`VkLayerDeviceCreateInfo`], [`VkLayerInstanceCreateInfo`].
46pub use generated::VkLayerFunction;
47/// A list node that contains the next entity's vkGetInstanceProcAddr used by a layer. One
48/// possible payload of [`VkLayerInstanceCreateInfo`].
49pub use generated::VkLayerInstanceLink;
50
51type VkInstance = vk::Instance;
52type VkPhysicalDevice = vk::PhysicalDevice;
53type VkDevice = vk::Device;
54type VkStructureType = vk::StructureType;
55type VkResult = vk::Result;
56type VkDeviceCreateInfo = vk::DeviceCreateInfo;
57type VkAllocationCallbacks = vk::AllocationCallbacks;
58
59#[repr(transparent)]
60#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
61pub struct VkLoaderFeatureFlags(vk::Flags);
62ash::vk_bitflags_wrapped!(VkLoaderFeatureFlags, vk::Flags);
63impl VkLoaderFeatureFlags {
64 pub const _PHYSICAL_DEVICE_SORTING: Self = Self(0x00000001);
65}
66
67#[repr(C)]
68#[derive(Debug, Default, Copy, Clone)]
69pub struct VkLayerInstanceCreateInfoUFieldLayerDeviceField {
70 pub pfnLayerCreateDevice: PFN_vkLayerCreateDevice,
71 pub pfnLayerDestroyDevice: PFN_vkLayerDestroyDevice,
72}
73
74#[repr(C)]
75#[derive(Copy, Clone)]
76pub union VkLayerInstanceCreateInfoUField {
77 pub pLayerInfo: *mut VkLayerInstanceLink,
78 pub pfnSetInstanceLoaderData: PFN_vkSetInstanceLoaderData,
79 pub layerDevice: VkLayerInstanceCreateInfoUFieldLayerDeviceField,
80 pub loaderFeatures: VkLoaderFeatureFlags,
81}
82
83impl Default for VkLayerInstanceCreateInfoUField {
84 fn default() -> Self {
85 let mut s = MaybeUninit::<Self>::uninit();
86 unsafe {
87 std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
88 s.assume_init()
89 }
90 }
91}
92
93#[repr(C)]
94/// Sub type of structure for instance and device loader ext of CreateInfo.
95///
96/// When `sType` is
97/// [`VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkStructureType.html)
98/// then [`VkLayerFunction`] indicates struct type pointed to by pNext.
99pub struct VkLayerInstanceCreateInfo {
100 /// A `VkStructureType` value identifying this struct. Must be
101 /// `VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO`.
102 pub sType: VkStructureType,
103 /// Either `NULL` or a pointer to a structure extending this structure.
104 pub pNext: *const ::std::os::raw::c_void,
105 /// A [`VkLayerFunction`] value identifying the payload in the `u` field.
106 pub function: VkLayerFunction,
107 /// The actual payload.
108 pub u: VkLayerInstanceCreateInfoUField,
109}
110
111unsafe impl vk::TaggedStructure for VkLayerInstanceCreateInfo {
112 const STRUCTURE_TYPE: vk::StructureType = vk::StructureType::LOADER_INSTANCE_CREATE_INFO;
113}
114
115unsafe impl vk::ExtendsInstanceCreateInfo for VkLayerInstanceCreateInfo {}
116
117unsafe impl vk::TaggedStructure for VkLayerDeviceCreateInfo {
118 const STRUCTURE_TYPE: vk::StructureType = vk::StructureType::LOADER_DEVICE_CREATE_INFO;
119}
120
121unsafe impl vk::ExtendsDeviceCreateInfo for VkLayerDeviceCreateInfo {}