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