1 {{/* 2 * Copyright 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */}} 16 17 {{Include "../api/templates/vulkan_common.tmpl"}} 18 {{Global "clang-format" (Strings "clang-format" "-style=file")}} 19 {{Macro "DefineGlobals" $}} 20 {{$ | Macro "null_driver_gen.h" | Format (Global "clang-format") | Write "null_driver_gen.h" }} 21 {{$ | Macro "null_driver_gen.cpp" | Format (Global "clang-format") | Write "null_driver_gen.cpp"}} 22 23 24 {{/* 25 ------------------------------------------------------------------------------- 26 null_driver_gen.h 27 ------------------------------------------------------------------------------- 28 */}} 29 {{define "null_driver_gen.h"}} 30 /* 31 * Copyright 2015 The Android Open Source Project 32 * 33 * Licensed under the Apache License, Version 2.0 (the "License"); 34 * you may not use this file except in compliance with the License. 35 * You may obtain a copy of the License at 36 * 37 * http://www.apache.org/licenses/LICENSE-2.0 38 * 39 * Unless required by applicable law or agreed to in writing, software 40 * distributed under the License is distributed on an "AS IS" BASIS, 41 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 42 * See the License for the specific language governing permissions and 43 * limitations under the License. 44 */ 45 46 // WARNING: This file is generated. See ../README.md for instructions. 47 48 #ifndef NULLDRV_NULL_DRIVER_H 49 #define NULLDRV_NULL_DRIVER_H 1 50 51 #include <vulkan/vk_android_native_buffer.h> 52 #include <vulkan/vulkan.h> 53 54 namespace null_driver { 55 56 PFN_vkVoidFunction GetGlobalProcAddr(const char* name); 57 PFN_vkVoidFunction GetInstanceProcAddr(const char* name); 58 59 // clang-format off 60 {{range $f := AllCommands $}} 61 {{if (Macro "IsDriverFunction" $f)}} 62 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}}); 63 {{end}} 64 {{end}} 65 VKAPI_ATTR VkResult GetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); 66 VKAPI_ATTR VkResult AcquireImageANDROID(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence); 67 VKAPI_ATTR VkResult QueueSignalReleaseImageANDROID(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd); 68 // clang-format on 69 70 } // namespace null_driver 71 72 #endif // NULLDRV_NULL_DRIVER_H 73 {{end}} 74 75 76 {{/* 77 ------------------------------------------------------------------------------- 78 null_driver_gen.cpp 79 ------------------------------------------------------------------------------- 80 */}} 81 {{define "null_driver_gen.cpp"}} 82 /* 83 * Copyright 2015 The Android Open Source Project 84 * 85 * Licensed under the Apache License, Version 2.0 (the "License"); 86 * you may not use this file except in compliance with the License. 87 * You may obtain a copy of the License at 88 * 89 * http://www.apache.org/licenses/LICENSE-2.0 90 * 91 * Unless required by applicable law or agreed to in writing, software 92 * distributed under the License is distributed on an "AS IS" BASIS, 93 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 94 * See the License for the specific language governing permissions and 95 * limitations under the License. 96 */ 97 98 // WARNING: This file is generated. See ../README.md for instructions. 99 100 #include "null_driver_gen.h" 101 #include <algorithm> 102 103 using namespace null_driver; 104 105 namespace { 106 107 struct NameProc { 108 const char* name; 109 PFN_vkVoidFunction proc; 110 }; 111 112 PFN_vkVoidFunction Lookup(const char* name, 113 const NameProc* begin, 114 const NameProc* end) { 115 const auto& entry = std::lower_bound( 116 begin, end, name, 117 [](const NameProc& e, const char* n) { return strcmp(e.name, n) < 0; }); 118 if (entry == end || strcmp(entry->name, name) != 0) 119 return nullptr; 120 return entry->proc; 121 } 122 123 template <size_t N> 124 PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) { 125 return Lookup(name, procs, procs + N); 126 } 127 128 const NameProc kGlobalProcs[] = { 129 // clang-format off 130 {{range $f := SortBy (AllCommands $) "FunctionName"}} 131 {{if and (Macro "IsDriverFunction" $f) (eq (Macro "Vtbl" $f) "Global")}} 132 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>( 133 static_cast<{{Macro "FunctionPtrName" $f}}>( 134 {{Macro "BaseName" $f}}))}, 135 {{end}} 136 {{end}} 137 // clang-format on 138 }; 139 140 const NameProc kInstanceProcs[] = { 141 // clang-format off 142 {{range $f := SortBy (AllCommands $) "FunctionName"}} 143 {{if (Macro "IsDriverFunction" $f)}} 144 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>( 145 static_cast<{{Macro "FunctionPtrName" $f}}>( 146 {{Macro "BaseName" $f}}))}, 147 {{end}} 148 {{end}} 149 // clang-format on 150 }; 151 152 } // namespace 153 154 namespace null_driver { 155 156 PFN_vkVoidFunction GetGlobalProcAddr(const char* name) { 157 return Lookup(name, kGlobalProcs); 158 } 159 160 PFN_vkVoidFunction GetInstanceProcAddr(const char* name) { 161 return Lookup(name, kInstanceProcs); 162 } 163 164 } // namespace null_driver 165 166 {{end}} 167 168 169 {{/* 170 ------------------------------------------------------------------------------- 171 Emits a function name without the "vk" prefix. 172 ------------------------------------------------------------------------------- 173 */}} 174 {{define "BaseName"}} 175 {{AssertType $ "Function"}} 176 {{TrimPrefix "vk" $.Name}} 177 {{end}} 178 179 180 {{/* 181 ------------------------------------------------------------------------------ 182 Emits 'true' if the API function is implemented by the driver. 183 ------------------------------------------------------------------------------ 184 */}} 185 {{define "IsDriverFunction"}} 186 {{AssertType $ "Function"}} 187 188 {{if not (GetAnnotation $ "pfn")}} 189 {{$ext := GetAnnotation $ "extension"}} 190 {{if $ext}} 191 {{Macro "IsDriverExtension" $ext}} 192 {{else}} 193 true 194 {{end}} 195 {{end}} 196 {{end}} 197 198 199 {{/* 200 ------------------------------------------------------------------------------ 201 Reports whether an extension is implemented by the driver. 202 ------------------------------------------------------------------------------ 203 */}} 204 {{define "IsDriverExtension"}} 205 {{$ext := index $.Arguments 0}} 206 {{ if eq $ext "VK_ANDROID_native_buffer"}}true 207 {{else if eq $ext "VK_EXT_debug_report"}}true 208 {{else if eq $ext "VK_KHR_get_physical_device_properties2"}}true 209 {{end}} 210 {{end}} 211