null_driver.tmpl revision 275d76c8158c90ec5317b82cb10b094bca2b43cf
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// This file is generated. Do not edit manually! 47// To regenerate: $ apic template ../api/vulkan.api null_driver.tmpl 48// Requires apic from https://android.googlesource.com/platform/tools/gpu/. 49¶ 50#ifndef NULLDRV_NULL_DRIVER_H 51#define NULLDRV_NULL_DRIVER_H 1 52¶ 53#define VK_PROTOTYPES 54#include <vulkan/vk_android_native_buffer.h> 55#include <vulkan/vulkan.h> 56¶ 57namespace null_driver {« 58¶ 59PFN_vkVoidFunction GetGlobalProcAddr(const char* name); 60PFN_vkVoidFunction GetInstanceProcAddr(const char* name); 61¶ 62// clang-format off 63 {{range $f := AllCommands $}} 64 {{if (Macro "IsDriverFunction" $f)}} 65VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}}); 66 {{end}} 67 {{end}} 68VKAPI_ATTR VkResult GetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); 69VKAPI_ATTR VkResult AcquireImageANDROID(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence); 70VKAPI_ATTR VkResult QueueSignalReleaseImageANDROID(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd); 71// clang-format on 72¶ 73»} // namespace null_driver 74¶ 75#endif // NULLDRV_NULL_DRIVER_H 76¶{{end}} 77 78 79{{/* 80------------------------------------------------------------------------------- 81 null_driver_gen.cpp 82------------------------------------------------------------------------------- 83*/}} 84{{define "null_driver_gen.cpp"}} 85/* 86•* Copyright 2015 The Android Open Source Project 87•* 88•* Licensed under the Apache License, Version 2.0 (the "License"); 89•* you may not use this file except in compliance with the License. 90•* You may obtain a copy of the License at 91•* 92•* http://www.apache.org/licenses/LICENSE-2.0 93•* 94•* Unless required by applicable law or agreed to in writing, software 95•* distributed under the License is distributed on an "AS IS" BASIS, 96•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 97•* See the License for the specific language governing permissions and 98•* limitations under the License. 99•*/ 100¶ 101// This file is generated. Do not edit manually! 102// To regenerate: $ apic template ../api/vulkan.api null_driver.tmpl 103// Requires apic from https://android.googlesource.com/platform/tools/gpu/. 104¶ 105#include "null_driver_gen.h" 106#include <algorithm> 107¶ 108using namespace null_driver; 109¶ 110namespace { 111¶ 112struct NameProc { 113 const char* name; 114 PFN_vkVoidFunction proc; 115}; 116¶ 117PFN_vkVoidFunction Lookup(const char* name, 118 const NameProc* begin, 119 const NameProc* end) { 120 const auto& entry = std::lower_bound( 121 begin, end, name, 122 [](const NameProc& e, const char* n) { return strcmp(e.name, n) < 0; }); 123 if (entry == end || strcmp(entry->name, name) != 0) 124 return nullptr; 125 return entry->proc; 126} 127¶ 128template <size_t N> 129PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) { 130 return Lookup(name, procs, procs + N); 131} 132¶ 133const NameProc kGlobalProcs[] = {« 134 // clang-format off 135 {{range $f := SortBy (AllCommands $) "FunctionName"}} 136 {{if and (Macro "IsDriverFunction" $f) (eq (Macro "Vtbl" $f) "Global")}} 137 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§ 138 static_cast<{{Macro "FunctionPtrName" $f}}>(§ 139 {{Macro "BaseName" $f}}))}, 140 {{end}} 141 {{end}} 142 // clang-format on 143»}; 144¶ 145const NameProc kInstanceProcs[] = {« 146 // clang-format off 147 {{range $f := SortBy (AllCommands $) "FunctionName"}} 148 {{if (Macro "IsDriverFunction" $f)}} 149 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§ 150 static_cast<{{Macro "FunctionPtrName" $f}}>(§ 151 {{Macro "BaseName" $f}}))}, 152 {{end}} 153 {{end}} 154 // clang-format on 155»}; 156¶ 157} // namespace 158¶ 159namespace null_driver { 160¶ 161PFN_vkVoidFunction GetGlobalProcAddr(const char* name) { 162 return Lookup(name, kGlobalProcs); 163} 164¶ 165PFN_vkVoidFunction GetInstanceProcAddr(const char* name) {« 166 PFN_vkVoidFunction pfn; 167 if ((pfn = Lookup(name, kInstanceProcs))) 168 return pfn; 169 if (strcmp(name, "vkGetSwapchainGrallocUsageANDROID") == 0) 170 return reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vkGetSwapchainGrallocUsageANDROID>(GetSwapchainGrallocUsageANDROID)); 171 if (strcmp(name, "vkAcquireImageANDROID") == 0) 172 return reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vkAcquireImageANDROID>(AcquireImageANDROID)); 173 if (strcmp(name, "vkQueueSignalReleaseImageANDROID") == 0) 174 return reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vkQueueSignalReleaseImageANDROID>(QueueSignalReleaseImageANDROID)); 175 return nullptr; 176»} 177¶ 178} // namespace null_driver 179¶ 180{{end}} 181 182 183{{/* 184------------------------------------------------------------------------------- 185 Emits a function name without the "vk" prefix. 186------------------------------------------------------------------------------- 187*/}} 188{{define "BaseName"}} 189 {{AssertType $ "Function"}} 190 {{TrimPrefix "vk" $.Name}} 191{{end}} 192 193 194{{/* 195------------------------------------------------------------------------------ 196 Emits 'true' if the API function is implemented by the driver. 197------------------------------------------------------------------------------ 198*/}} 199{{define "IsDriverFunction"}} 200 {{AssertType $ "Function"}} 201 202 {{if not (GetAnnotation $ "pfn")}} 203 {{$ext := GetAnnotation $ "extension"}} 204 {{if $ext}} 205 {{Macro "IsDriverExtension" $ext}} 206 {{else}} 207 true 208 {{end}} 209 {{end}} 210{{end}} 211 212 213{{/* 214------------------------------------------------------------------------------ 215 Reports whether an extension is implemented by the driver. 216------------------------------------------------------------------------------ 217*/}} 218{{define "IsDriverExtension"}} 219 {{$ext := index $.Arguments 0}} 220 {{if eq $ext "VK_ANDROID_native_buffer"}}true 221 {{end}} 222{{end}} 223