-
Notifications
You must be signed in to change notification settings - Fork 188
Codegen rewrite to use Vulkan-Object #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
charles-lunarg
merged 3 commits into
KhronosGroup:main
from
charles-lunarg:vulkan_object
Oct 6, 2025
+3,300
−5,987
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
581 changes: 182 additions & 399 deletions
581
scripts/mock_icd_generator.py → scripts/generators/mock_icd_generator.py
Large diffs are not rendered by default.
Oops, something went wrong.
163 changes: 163 additions & 0 deletions
163
scripts/generators/vulkan_tools_helper_file_generator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #!/usr/bin/python3 -i | ||
| # | ||
| # Copyright (c) 2015-2021 The Khronos Group Inc. | ||
| # Copyright (c) 2015-2021 Valve Corporation | ||
| # Copyright (c) 2015-2021 LunarG, Inc. | ||
| # Copyright (c) 2015-2021 Google Inc. | ||
| # | ||
| # 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. | ||
| # | ||
| # Author: Mark Lobodzinski <[email protected]> | ||
| # Author: Tobin Ehlis <[email protected]> | ||
| # Author: John Zulauf <[email protected]> | ||
|
|
||
| from base_generator import BaseGenerator | ||
|
|
||
| # HelperFileOutputGenerator - subclass of OutputGenerator. Outputs Vulkan helper files | ||
| class HelperFileOutputGenerator(BaseGenerator): | ||
| def __init__(self): | ||
| BaseGenerator.__init__(self) | ||
|
|
||
|
|
||
| def generate(self): | ||
| out = [] | ||
|
|
||
| # File Comment | ||
| out.append('// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n') | ||
| out.append('// See vulkan_tools_helper_file_generator.py for modifications\n') | ||
|
|
||
| # Copyright Notice | ||
| out.append(''' | ||
|
|
||
| /*************************************************************************** | ||
| * | ||
| * Copyright (c) 2015-2017 The Khronos Group Inc. | ||
| * Copyright (c) 2015-2017 Valve Corporation | ||
| * Copyright (c) 2015-2017 LunarG, Inc. | ||
| * Copyright (c) 2015-2017 Google Inc. | ||
| * | ||
| * 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. | ||
| * | ||
| * Author: Mark Lobodzinski <[email protected]> | ||
| * Author: Courtney Goeltzenleuchter <[email protected]> | ||
| * Author: Tobin Ehlis <[email protected]> | ||
| * Author: Chris Forbes <[email protected]> | ||
| * Author: John Zulauf<[email protected]> | ||
| * | ||
| ****************************************************************************/ | ||
| ''') | ||
|
|
||
| # Generate header | ||
| out.append(''' | ||
| #pragma once | ||
| #include <vulkan/vulkan.h> | ||
|
|
||
| // These empty generic templates are specialized for each type with sType | ||
| // members and for each sType -- providing a two way map between structure | ||
| // types and sTypes | ||
|
|
||
| template <VkStructureType id> struct LvlSTypeMap {}; | ||
| template <typename T> struct LvlTypeMap {}; | ||
|
|
||
| ''') | ||
|
|
||
| # Generate the specializations for each type and stype | ||
| for struct in self.vk.structs.values(): | ||
| if struct.sType is None: | ||
| continue | ||
|
|
||
| if struct.protect is not None: | ||
| out.append(f'#ifdef {struct.protect}\n') | ||
|
|
||
| out.append(f'// Map type {struct.name} to id {struct.sType}\n') | ||
| out.append(f'template <> struct LvlTypeMap<{struct.name}> {{\n') | ||
| out.append(f' static const VkStructureType kSType = {struct.sType};\n') | ||
| out.append('};\n\n') | ||
|
|
||
|
|
||
| out.append(f'template <> struct LvlSTypeMap<{struct.sType}> {{\n') | ||
| out.append(f' typedef {struct.name} Type;\n') | ||
| out.append('};\n\n') | ||
|
|
||
| if struct.protect is not None: | ||
| out.append(f'#endif // {struct.protect}\n') | ||
|
|
||
| # Define the utilities (here so any renaming stays consistent), if this grows large, refactor to a fixed .h file | ||
|
|
||
| out.append('''// Header "base class" for pNext chain traversal | ||
| struct LvlGenericHeader { | ||
| VkStructureType sType; | ||
| const LvlGenericHeader *pNext; | ||
| }; | ||
| struct LvlGenericModHeader { | ||
| VkStructureType sType; | ||
| LvlGenericModHeader *pNext; | ||
| }; | ||
|
|
||
| // Find an entry of the given type in the pNext chain | ||
| template <typename T> const T *lvl_find_in_chain(const void *next) { | ||
| const LvlGenericHeader *current = reinterpret_cast<const LvlGenericHeader *>(next); | ||
| const T *found = nullptr; | ||
| while (current) { | ||
| if (LvlTypeMap<T>::kSType == current->sType) { | ||
| found = reinterpret_cast<const T*>(current); | ||
| current = nullptr; | ||
| } else { | ||
| current = current->pNext; | ||
| } | ||
| } | ||
| return found; | ||
| } | ||
| // Find an entry of the given type in the pNext chain | ||
| template <typename T> T *lvl_find_mod_in_chain(void *next) { | ||
| LvlGenericModHeader *current = reinterpret_cast<LvlGenericModHeader *>(next); | ||
| T *found = nullptr; | ||
| while (current) { | ||
| if (LvlTypeMap<T>::kSType == current->sType) { | ||
| found = reinterpret_cast<T*>(current); | ||
| current = nullptr; | ||
| } else { | ||
| current = current->pNext; | ||
| } | ||
| } | ||
| return found; | ||
| } | ||
|
|
||
| // Init the header of an sType struct with pNext | ||
| template <typename T> T lvl_init_struct(void *p_next) { | ||
| T out = {}; | ||
| out.sType = LvlTypeMap<T>::kSType; | ||
| out.pNext = p_next; | ||
| return out; | ||
| } | ||
|
|
||
| // Init the header of an sType struct | ||
| template <typename T> T lvl_init_struct() { | ||
| T out = {}; | ||
| out.sType = LvlTypeMap<T>::kSType; | ||
| return out; | ||
| } | ||
| ''') | ||
|
|
||
| self.write(''.join(out)) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit