xref: /aosp_15_r20/frameworks/native/vulkan/include/hardware/hwvulkan.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2015 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_HWVULKAN_H
18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_HWVULKAN_H
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <hardware/hardware.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <vulkan/vulkan.h>
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker __BEGIN_DECLS
24*38e8c45fSAndroid Build Coastguard Worker 
25*38e8c45fSAndroid Build Coastguard Worker #define HWVULKAN_HARDWARE_MODULE_ID "vulkan"
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker #define HWVULKAN_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
28*38e8c45fSAndroid Build Coastguard Worker #define HWVULKAN_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, 0)
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker #define HWVULKAN_DEVICE_0 "vk0"
31*38e8c45fSAndroid Build Coastguard Worker 
32*38e8c45fSAndroid Build Coastguard Worker typedef struct hwvulkan_module_t {
33*38e8c45fSAndroid Build Coastguard Worker     struct hw_module_t common;
34*38e8c45fSAndroid Build Coastguard Worker } hwvulkan_module_t;
35*38e8c45fSAndroid Build Coastguard Worker 
36*38e8c45fSAndroid Build Coastguard Worker /* Dispatchable Vulkan object handles must be pointers, which must point to
37*38e8c45fSAndroid Build Coastguard Worker  * instances of hwvulkan_dispatch_t (potentially followed by additional
38*38e8c45fSAndroid Build Coastguard Worker  * implementation-defined data). On return from the creation function, the
39*38e8c45fSAndroid Build Coastguard Worker  * 'magic' field must contain HWVULKAN_DISPATCH_MAGIC; the loader will overwrite
40*38e8c45fSAndroid Build Coastguard Worker  * the 'vtbl' field.
41*38e8c45fSAndroid Build Coastguard Worker  *
42*38e8c45fSAndroid Build Coastguard Worker  * NOTE: The magic value and the layout of hwvulkan_dispatch_t match the LunarG
43*38e8c45fSAndroid Build Coastguard Worker  * loader used on platforms, to avoid pointless annoying differences for
44*38e8c45fSAndroid Build Coastguard Worker  * multi-platform drivers. Don't change them without a good reason. If there is
45*38e8c45fSAndroid Build Coastguard Worker  * an opportunity to change it, using a magic value that doesn't leave the
46*38e8c45fSAndroid Build Coastguard Worker  * upper 32-bits zero on 64-bit platforms would be nice.
47*38e8c45fSAndroid Build Coastguard Worker  */
48*38e8c45fSAndroid Build Coastguard Worker #define HWVULKAN_DISPATCH_MAGIC 0x01CDC0DE
49*38e8c45fSAndroid Build Coastguard Worker typedef union {
50*38e8c45fSAndroid Build Coastguard Worker     uintptr_t magic;
51*38e8c45fSAndroid Build Coastguard Worker     const void* vtbl;
52*38e8c45fSAndroid Build Coastguard Worker } hwvulkan_dispatch_t;
53*38e8c45fSAndroid Build Coastguard Worker 
54*38e8c45fSAndroid Build Coastguard Worker /* A hwvulkan_device_t corresponds to an ICD on other systems. Currently there
55*38e8c45fSAndroid Build Coastguard Worker  * can only be one on a system (HWVULKAN_DEVICE_0). It is opened once per
56*38e8c45fSAndroid Build Coastguard Worker  * process when the Vulkan API is first used; the hw_device_t::close() function
57*38e8c45fSAndroid Build Coastguard Worker  * is called upon driver unloading. Any non-trivial resource allocation should
58*38e8c45fSAndroid Build Coastguard Worker  * be done when the VkInstance is created rather than when the hwvulkan_device_t
59*38e8c45fSAndroid Build Coastguard Worker  * is opened.
60*38e8c45fSAndroid Build Coastguard Worker  */
61*38e8c45fSAndroid Build Coastguard Worker typedef struct hwvulkan_device_t {
62*38e8c45fSAndroid Build Coastguard Worker     struct hw_device_t common;
63*38e8c45fSAndroid Build Coastguard Worker 
64*38e8c45fSAndroid Build Coastguard Worker     PFN_vkEnumerateInstanceExtensionProperties
65*38e8c45fSAndroid Build Coastguard Worker         EnumerateInstanceExtensionProperties;
66*38e8c45fSAndroid Build Coastguard Worker     PFN_vkCreateInstance CreateInstance;
67*38e8c45fSAndroid Build Coastguard Worker     PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
68*38e8c45fSAndroid Build Coastguard Worker } hwvulkan_device_t;
69*38e8c45fSAndroid Build Coastguard Worker 
70*38e8c45fSAndroid Build Coastguard Worker __END_DECLS
71*38e8c45fSAndroid Build Coastguard Worker 
72*38e8c45fSAndroid Build Coastguard Worker #endif  // ANDROID_HWVULKAN_H
73