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¶ 54namespace null_driver {« 55¶ 56PFN_vkVoidFunction GetGlobalProcAddr(const char* name); 57PFN_vkVoidFunction GetInstanceProcAddr(const char* name); 58¶ 59// clang-format off 60 {{range $f := AllCommands $}} 61 {{if (Macro "IsDriverFunction" $f)}} 62VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}}); 63 {{end}} 64 {{end}} 65VKAPI_ATTR VkResult GetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); 66VKAPI_ATTR VkResult AcquireImageANDROID(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence); 67VKAPI_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¶ 103using namespace null_driver; 104¶ 105namespace { 106¶ 107struct NameProc { 108 const char* name; 109 PFN_vkVoidFunction proc; 110}; 111¶ 112PFN_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¶ 123template <size_t N> 124PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) { 125 return Lookup(name, procs, procs + N); 126} 127¶ 128const 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¶ 140const 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¶ 154namespace null_driver { 155¶ 156PFN_vkVoidFunction GetGlobalProcAddr(const char* name) { 157 return Lookup(name, kGlobalProcs); 158} 159¶ 160PFN_vkVoidFunction GetInstanceProcAddr(const char* name) {« 161 PFN_vkVoidFunction pfn; 162 if ((pfn = Lookup(name, kInstanceProcs))) 163 return pfn; 164 if (strcmp(name, "vkGetSwapchainGrallocUsageANDROID") == 0) 165 return reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vkGetSwapchainGrallocUsageANDROID>(GetSwapchainGrallocUsageANDROID)); 166 if (strcmp(name, "vkAcquireImageANDROID") == 0) 167 return reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vkAcquireImageANDROID>(AcquireImageANDROID)); 168 if (strcmp(name, "vkQueueSignalReleaseImageANDROID") == 0) 169 return reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vkQueueSignalReleaseImageANDROID>(QueueSignalReleaseImageANDROID)); 170 return nullptr; 171»} 172¶ 173} // namespace null_driver 174¶ 175{{end}} 176 177 178{{/* 179------------------------------------------------------------------------------- 180 Emits a function name without the "vk" prefix. 181------------------------------------------------------------------------------- 182*/}} 183{{define "BaseName"}} 184 {{AssertType $ "Function"}} 185 {{TrimPrefix "vk" $.Name}} 186{{end}} 187 188 189{{/* 190------------------------------------------------------------------------------ 191 Emits 'true' if the API function is implemented by the driver. 192------------------------------------------------------------------------------ 193*/}} 194{{define "IsDriverFunction"}} 195 {{AssertType $ "Function"}} 196 197 {{if not (GetAnnotation $ "pfn")}} 198 {{$ext := GetAnnotation $ "extension"}} 199 {{if $ext}} 200 {{Macro "IsDriverExtension" $ext}} 201 {{else}} 202 true 203 {{end}} 204 {{end}} 205{{end}} 206 207 208{{/* 209------------------------------------------------------------------------------ 210 Reports whether an extension is implemented by the driver. 211------------------------------------------------------------------------------ 212*/}} 213{{define "IsDriverExtension"}} 214 {{$ext := index $.Arguments 0}} 215 {{ if eq $ext "VK_ANDROID_native_buffer"}}true 216 {{else if eq $ext "VK_EXT_debug_report"}}true 217 {{end}} 218{{end}} 219