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// WARNING: This file is generated. See ../README.md for instructions.
4748#ifndef NULLDRV_NULL_DRIVER_H
49#define NULLDRV_NULL_DRIVER_H 1
5051#include <vulkan/vk_android_native_buffer.h>
52#include <vulkan/vulkan.h>
5354namespace null_driver {«
5556PFN_vkVoidFunction GetGlobalProcAddr(const char* name);
57PFN_vkVoidFunction GetInstanceProcAddr(const char* name);
5859// 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
6970»}  // namespace null_driver
7172#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•*/
9798// WARNING: This file is generated. See ../README.md for instructions.
99100#include "null_driver_gen.h"
101#include <algorithm>
102103using namespace null_driver;
104105namespace {
106107struct NameProc {
108    const char* name;
109    PFN_vkVoidFunction proc;
110};
111112PFN_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}
122123template <size_t N>
124PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) {
125    return Lookup(name, procs, procs + N);
126}
127128const 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»};
139140const 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»};
151152} // namespace
153154namespace null_driver {
155156PFN_vkVoidFunction GetGlobalProcAddr(const char* name) {
157    return Lookup(name, kGlobalProcs);
158}
159160PFN_vkVoidFunction GetInstanceProcAddr(const char* name) {«
161    return Lookup(name, kInstanceProcs);
162»}
163164} // namespace null_driver
165166{{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