Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,394 changes: 498 additions & 896 deletions icd/generated/function_declarations.h

Large diffs are not rendered by default.

1,225 changes: 4 additions & 1,221 deletions icd/generated/function_definitions.h

Large diffs are not rendered by default.

295 changes: 203 additions & 92 deletions scripts/generate_source.py

Large diffs are not rendered by default.

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions scripts/generators/vulkan_tools_helper_file_generator.py
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out.append('// See vulkan_tools_helper_file_generator.py for modifications\n')
out.append(f'// See {os.path.basename(__file__)} for modifications\n')

nit


# 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))

Loading
Loading