1 // Copyright (C) 2018 The Android Open Source Project
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 #ifndef __COMMON_EMULATOR_FEATURE_INFO_H
15 #define __COMMON_EMULATOR_FEATURE_INFO_H
16 
17 // SyncImpl determines the presence of host/guest OpenGL fence sync
18 // capabilities. It corresponds exactly to EGL_ANDROID_native_fence_sync
19 // capability, but for the emulator, we need to make sure that
20 // OpenGL pipe protocols match, so we use a special extension name
21 // here.
22 // SYNC_IMPL_NONE means that the native fence sync capability is
23 // not present, and we will end up using the equivalent of glFinish
24 // in order to preserve buffer swapping order.
25 // SYNC_IMPL_NATIVE_SYNC means that we do have native fence sync
26 // capability, and we will use a fence fd to synchronize buffer swaps.
27 enum SyncImpl {
28     SYNC_IMPL_NONE = 0,
29     SYNC_IMPL_NATIVE_SYNC_V2 = 1, // ANDROID_native_fence_sync
30     SYNC_IMPL_NATIVE_SYNC_V3 = 2, // KHR_wait_sync
31     SYNC_IMPL_NATIVE_SYNC_V4 = 3, // Correct eglGetSyncAttribKHR
32 };
33 
34 // Interface for native sync:
35 // Use the highest that shows up
36 static const char kRCNativeSyncV2[] = "ANDROID_EMU_native_sync_v2";
37 static const char kRCNativeSyncV3[] = "ANDROID_EMU_native_sync_v3";
38 static const char kRCNativeSyncV4[] = "ANDROID_EMU_native_sync_v4";
39 
40 // DMA for OpenGL
41 enum DmaImpl {
42     DMA_IMPL_NONE = 0,
43     DMA_IMPL_v1 = 1,
44 };
45 
46 static const char kDmaExtStr_v1[] = "ANDROID_EMU_dma_v1";
47 
48 // OpenGL ES max supported version
49 enum GLESMaxVersion {
50     GLES_MAX_VERSION_2 = 0,
51     GLES_MAX_VERSION_3_0 = 1,
52     GLES_MAX_VERSION_3_1 = 2,
53     GLES_MAX_VERSION_3_2 = 3,
54 };
55 
56 static const char kGLESMaxVersion_2[] = "ANDROID_EMU_gles_max_version_2";
57 static const char kGLESMaxVersion_3_0[] = "ANDROID_EMU_gles_max_version_3_0";
58 static const char kGLESMaxVersion_3_1[] = "ANDROID_EMU_gles_max_version_3_1";
59 static const char kGLESMaxVersion_3_2[] = "ANDROID_EMU_gles_max_version_3_2";
60 
61 enum HostComposition {
62     HOST_COMPOSITION_NONE = 0,
63     HOST_COMPOSITION_V1,
64     HOST_COMPOSITION_V2,
65 };
66 
67 static const char kHostCompositionV1[] = "ANDROID_EMU_host_composition_v1";
68 static const char kHostCompositionV2[] = "ANDROID_EMU_host_composition_v2";
69 
70 // No querying errors from host extension
71 static const char kGLESNoHostError[] = "ANDROID_EMU_gles_no_host_error";
72 
73 // Host to guest memory mapping
74 static const char kGLDirectMem[] = "ANDROID_EMU_direct_mem";
75 
76 // Vulkan host support
77 // To be delivered/enabled when at least the following is working/available:
78 // - HOST_COHERENT memory mapping
79 // - Full gralloc interop: External memory, AHB
80 static const char kVulkan[] = "ANDROID_EMU_vulkan";
81 
82 // Deferred Vulkan commands
83 static const char kDeferredVulkanCommands[] = "ANDROID_EMU_deferred_vulkan_commands";
84 
85 // Vulkan null optional strings
86 static const char kVulkanNullOptionalStrings[] = "ANDROID_EMU_vulkan_null_optional_strings";
87 
88 // Vulkan create resources with requirements
89 static const char kVulkanCreateResourcesWithRequirements[] = "ANDROID_EMU_vulkan_create_resources_with_requirements";
90 
91 // Vulkan ignored handles
92 static const char kVulkanIgnoredHandles[] = "ANDROID_EMU_vulkan_ignored_handles";
93 
94 // YUV host cache
95 static const char kYUVCache[] = "ANDROID_EMU_YUV_Cache";
96 
97 // GL protocol v2
98 static const char kAsyncUnmapBuffer[] = "ANDROID_EMU_async_unmap_buffer";
99 
100 // virtio-gpu-next
101 static const char kVirtioGpuNext[] = "ANDROID_EMU_virtio_gpu_next";
102 
103 static const char kHasSharedSlotsHostMemoryAllocator[] = "ANDROID_EMU_has_shared_slots_host_memory_allocator";
104 
105 // Vulkan free memory sync
106 static const char kVulkanFreeMemorySync[] = "ANDROID_EMU_vulkan_free_memory_sync";
107 
108 // virtio-gpu syncfd support
109 static const char kVirtioGpuNativeSync[] = "ANDROID_EMU_virtio_gpu_native_sync";
110 
111 // Vulkan extension that required a protocol update (new marshaling structs)
112 static const char kVulkanShaderFloat16Int8[] = "ANDROID_EMU_vulkan_shader_float16_int8";
113 
114 // Vulkan async queue submit
115 static const char kVulkanAsyncQueueSubmit[] = "ANDROID_EMU_vulkan_async_queue_submit";
116 
117 // Struct describing available emulator features
118 struct EmulatorFeatureInfo {
119 
EmulatorFeatureInfoEmulatorFeatureInfo120     EmulatorFeatureInfo() :
121         syncImpl(SYNC_IMPL_NONE),
122         dmaImpl(DMA_IMPL_NONE),
123         hostComposition(HOST_COMPOSITION_NONE),
124         glesMaxVersion(GLES_MAX_VERSION_2),
125         hasDirectMem(false),
126         hasVulkan(false),
127         hasDeferredVulkanCommands(false),
128         hasVulkanNullOptionalStrings(false),
129         hasVulkanCreateResourcesWithRequirements(false),
130         hasVulkanIgnoredHandles(false),
131         hasYUVCache (false),
132         hasAsyncUnmapBuffer (false),
133         hasVirtioGpuNext (false),
134         hasSharedSlotsHostMemoryAllocator(false),
135         hasVulkanFreeMemorySync(false),
136         hasVirtioGpuNativeSync(false),
137         hasVulkanShaderFloat16Int8(false),
138         hasVulkanAsyncQueueSubmit(false)
139     { }
140 
141     SyncImpl syncImpl;
142     DmaImpl dmaImpl;
143     HostComposition hostComposition;
144     GLESMaxVersion glesMaxVersion;
145     bool hasDirectMem;
146     bool hasVulkan;
147     bool hasDeferredVulkanCommands;
148     bool hasVulkanNullOptionalStrings;
149     bool hasVulkanCreateResourcesWithRequirements;
150     bool hasVulkanIgnoredHandles;
151     bool hasYUVCache;
152     bool hasAsyncUnmapBuffer;
153     bool hasVirtioGpuNext;
154     bool hasSharedSlotsHostMemoryAllocator;
155     bool hasVulkanFreeMemorySync;
156     bool hasVirtioGpuNativeSync;
157     bool hasVulkanShaderFloat16Int8;
158     bool hasVulkanAsyncQueueSubmit;
159 };
160 
161 enum HostConnectionType {
162     HOST_CONNECTION_TCP = 0,
163     HOST_CONNECTION_QEMU_PIPE = 1,
164     HOST_CONNECTION_VIRTIO_GPU = 2,
165     HOST_CONNECTION_ADDRESS_SPACE = 3,
166     HOST_CONNECTION_VIRTIO_GPU_PIPE = 4,
167     HOST_CONNECTION_VIRTIO_GPU_ADDRESS_SPACE = 5,
168 };
169 
170 enum GrallocType {
171     GRALLOC_TYPE_RANCHU = 0,
172     GRALLOC_TYPE_MINIGBM = 1,
173     GRALLOC_TYPE_DYN_ALLOC_MINIGBM = 2,
174 };
175 
176 #endif // __COMMON_EMULATOR_FEATURE_INFO_H
177