| {{/* |
| * Copyright 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */}} |
| |
| {{Include "../api/templates/vulkan_common.tmpl"}} |
| {{Global "clang-format" (Strings "clang-format" "-style=file")}} |
| {{Macro "DefineGlobals" $}} |
| {{$ | Macro "null_driver_gen.cpp" | Format (Global "clang-format") | Write "null_driver_gen.cpp"}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Entry point |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "null_driver_gen.cpp"}} |
| /* |
| * Copyright 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| ¶ |
| // This file is generated. Do not edit manually! |
| // To regenerate: $ apic template ../api/vulkan.api null_driver_gen.cpp.tmpl |
| // Requires apic from https://android.googlesource.com/platform/tools/gpu/. |
| ¶ |
| #include <algorithm> |
| #include "null_driver.h" |
| ¶ |
| using namespace null_driver; |
| ¶ |
| namespace { |
| ¶ |
| struct NameProcEntry { |
| const char* name; |
| PFN_vkVoidFunction proc; |
| }; |
| ¶ |
| template <size_t N> |
| PFN_vkVoidFunction LookupProcAddr(const NameProcEntry (&table)[N], const char* name) { |
| auto entry = std::lower_bound( |
| table, table + N, name, |
| [](const NameProcEntry& e, const char* n) { return strcmp(e.name, n) < 0; }); |
| if (entry != (table + N) && strcmp(entry->name, name) == 0) |
| return entry->proc; |
| return nullptr; |
| } |
| ¶ |
| // The reinterpret_cast<..>(static_cast<..>(..)) business is there to ensure |
| // that the function declaration in null_driver.h matches the function pointer |
| // type in vulkan.h. If we just used reinterpret_cast<>, the compiler wouldn't |
| // tell us if there's a mistake in null_driver.h. A better solution would be to |
| // generate the declarations in null_driver.h. |
| const NameProcEntry kInstanceProcTbl[] = {« |
| // clang-format off |
| {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| {{if not (GetAnnotation $f "extension")}} |
| {{if eq (Macro "Vtbl" $f) "Instance"}} |
| {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))}, |
| {{end}} |
| {{end}} |
| {{end}} |
| // clang-format on |
| »}; |
| ¶ |
| const NameProcEntry kDeviceProcTbl[] = {« |
| // clang-format off |
| {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| {{if not (GetAnnotation $f "extension")}} |
| {{if eq (Macro "Vtbl" $f) "Device"}} |
| {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))}, |
| {{end}} |
| {{end}} |
| {{end}} |
| // clang-format on |
| »}; |
| ¶ |
| } // namespace |
| ¶ |
| namespace null_driver { |
| ¶ |
| PFN_vkVoidFunction LookupInstanceProcAddr(const char* name) { |
| return LookupProcAddr(kInstanceProcTbl, name); |
| } |
| ¶ |
| PFN_vkVoidFunction LookupDeviceProcAddr(const char* name) { |
| return LookupProcAddr(kDeviceProcTbl, name); |
| } |
| ¶ |
| } // namespace null_driver |
| ¶ |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the name of a function without the "vk" prefix. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "FunctionNameNoPrefix"}}{{AssertType $ "Function"}}{{TrimPrefix "vk" $.Name}}{{end}} |