| 1 |
#!/usr/bin/python3 -i |
| 2 |
# |
| 3 |
# Copyright (c) 2015-2021 The Khronos Group Inc. |
| 4 |
# Copyright (c) 2015-2021 Valve Corporation |
| 5 |
# Copyright (c) 2015-2021 LunarG, Inc. |
| 6 |
# Copyright (c) 2015-2021 Google Inc. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
# Author: Mark Lobodzinski <[email protected]> |
| 21 |
# Author: Charles Giessen <[email protected]> |
| 22 |
|
| 23 |
import os |
| 24 |
from base_generator import BaseGenerator |
| 25 |
|
| 26 |
class VkResultToStringGenerator(BaseGenerator): |
| 27 |
def __init__(self): |
| 28 |
BaseGenerator.__init__(self) |
| 29 |
|
| 30 |
def generate(self): |
| 31 |
out = [] |
| 32 |
|
| 33 |
out.append(f'''#pragma once |
| 34 |
// *** THIS FILE IS GENERATED - DO NOT EDIT *** |
| 35 |
// See {os.path.basename(__file__)} for modifications |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (c) 2025 The Khronos Group Inc. |
| 39 |
* Copyright (c) 2025 Valve Corporation |
| 40 |
* Copyright (c) 2025 LunarG, Inc. |
| 41 |
* |
| 42 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 43 |
* you may not use this file except in compliance with the License. |
| 44 |
* You may obtain a copy of the License at |
| 45 |
* |
| 46 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 47 |
* |
| 48 |
* Unless required by applicable law or agreed to in writing, software |
| 49 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 50 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 51 |
* See the License for the specific language governing permissions and |
| 52 |
* limitations under the License. |
| 53 |
* |
| 54 |
|
| 55 |
*/ |
| 56 |
|
| 57 |
#include <ostream> |
| 58 |
#include <string> |
| 59 |
|
| 60 |
#include <vulkan/vulkan.h> |
| 61 |
|
| 62 |
''') |
| 63 |
|
| 64 |
self.OutputVkResultToStringHelper(out) |
| 65 |
out.append('\n') |
| 66 |
|
| 67 |
self.write(''.join(out)) |
| 68 |
|
| 69 |
# Create a dispatch table from the corresponding table_type and append it to out |
| 70 |
def OutputVkResultToStringHelper(self, out: list): |
| 71 |
out.append('inline std::ostream& operator<<(std::ostream& os, const VkResult& result) {\n') |
| 72 |
out.append(' switch (result) {\n') |
| 73 |
for field in self.vk.enums['VkResult'].fields: |
| 74 |
out.append(f' case({field.name}):\n') |
| 75 |
out.append(f' return os << "{field.name}";\n') |
| 76 |
out.append(' default:\n') |
| 77 |
out.append(' return os << static_cast<int32_t>(result);\n') |
| 78 |
out.append(' }\n') |
| 79 |
out.append(' }\n') |