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
10 changes: 10 additions & 0 deletions .github/workflows/historical-registry-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ jobs:
python src/main.py -registry vulkandocs/xml/vk.xml vulkan.v
python src/main.py -registry vulkandocs/xml/video.xml vulkan_video.v

grep -F 'pub const khr_xlib_surface_extension_name' src/vulkan.v
grep -F '$if vulkan_xlib ? {' src/vulkan.v
grep -F '#flag -DVK_USE_PLATFORM_XLIB_KHR' src/vulkan.v
grep -F '$if vulkan_win32 ? {' src/vulkan.v

grep -F 'pub type StdVideoH264ScalingListsScalingList4x4Array' \
src/vulkan_video.v
if grep -E '^[[:space:]]+[A-Z][A-Za-z0-9_]*[[:space:]]+\[' \
Expand All @@ -95,6 +100,8 @@ jobs:
ln -s "$GITHUB_WORKSPACE/published" \
"$RUNNER_TEMP/vmodules/antono2/vulkan"
VMODULES="$RUNNER_TEMP/vmodules" v -new-compiler -check test/main.c.v
VMODULES="$RUNNER_TEMP/vmodules" v -new-compiler -d vulkan_xlib \
-check test/main.c.v

generate-and-compile:
name: Vulkan-Docs ${{ matrix.version }}
Expand Down Expand Up @@ -146,6 +153,9 @@ jobs:
--output "$VULKAN_SDK/include/volk/volk.c"
ln -s "$GITHUB_WORKSPACE/published" "$HOME/.vmodules/antono2/vulkan"
v -cc gcc run test
if [[ "$VERSION" == v1.4.335 ]]; then
v -d vulkan_xlib -cc gcc run test
fi

required-checks:
if: always()
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ The script refuses to switch an existing `vulkandocs` checkout if it contains
local changes. Generated files are written to `src/vulkan.v` and
`src/vulkan_video.v`; review their diff before committing.

Platform extensions are selected with V compile flags derived from the
registry's `<platform>` names. For example, `-d vulkan_xlib` includes the
Xlib declarations and supplies `VK_USE_PLATFORM_XLIB_KHR` to the C compiler.
XCB and Wayland have separate flags (`vulkan_xcb` and `vulkan_wayland`).
The same rule applies to Android, Win32, Metal, and the other registry
platforms. Extension name and spec-version constants remain available without
the flag; platform types and commands require it and the platform's native
development headers.

## Manual generation

The generator imports helper modules from a `vulkandocs` checkout at the
Expand Down
39 changes: 39 additions & 0 deletions src/vgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def __init__(self, *args, **kwargs):
self.feature_not_empty = False
self.may_alias = None
self.fixed_array_aliases = []
self.emitted_platform_flags = set()

def beginFile(self, genOpts):
OutputGenerator.beginFile(self, genOpts)
Expand Down Expand Up @@ -401,6 +402,15 @@ def endFile(self):
def beginFeature(self, interface, emit):
# Start processing in superclass
OutputGenerator.beginFeature(self, interface, emit)
platform = interface.get('platform')
self.feature_platform_flag = None
self.feature_platform_protect = None
if platform:
platform_elem = self.registry.tree.find(f"./platforms/platform[@name='{platform}']")
if platform_elem is None or not platform_elem.get('protect'):
raise RuntimeError(f'Missing Vulkan guard for platform {platform}')
self.feature_platform_flag = f'vulkan_{platform}'
self.feature_platform_protect = platform_elem.get('protect')
# C-specific
# Accumulate includes, defines, types, enums, function pointer typedefs,
# end function prototypes separately for this feature. They are only
Expand Down Expand Up @@ -447,8 +457,35 @@ def endFeature(self):
self.newline()

self.featureName = self.removeVk(self.featureName)
# Extension name/version constants are useful when checking
# support, even when their platform declarations are off.
if self.feature_platform_flag and self.sections['define']:
write('\n'.join(self.sections['define']), file=self.outFile)
public_constants = []
if self.feature_platform_flag:
constant_prefix = f'pub const {self.featureName}_'
for entry in self.sections['enum']:
stripped = entry.strip()
if stripped.startswith(constant_prefix) and (
stripped.startswith(constant_prefix + 'spec_version') or
stripped.startswith(constant_prefix + 'extension_name')
):
public_constants.append(entry)
if public_constants:
write('\n'.join(public_constants), file=self.outFile)
if self.feature_platform_flag:
if self.feature_platform_flag not in self.emitted_platform_flags:
write(f'$if {self.feature_platform_flag} ? {{', file=self.outFile)
write(f'#flag -D{self.feature_platform_protect}', file=self.outFile)
write('}', file=self.outFile)
self.emitted_platform_flags.add(self.feature_platform_flag)
write(f'$if {self.feature_platform_flag} ? {{', file=self.outFile)
for section in self.TYPE_SECTIONS:
if self.feature_platform_flag and section == 'define':
continue
contents = self.sections[section]
if self.feature_platform_flag and section == 'enum':
contents = [entry for entry in contents if entry not in public_constants]
if contents:
write('\n'.join(contents), file=self.outFile)
if self.genOpts.genFuncPointers and self.sections['commandPointer']:
Expand All @@ -475,6 +512,8 @@ def endFeature(self):
file=self.outFile)
else:
self.newline()
if self.feature_platform_flag:
write('}', file=self.outFile)
if self.featureExtraProtect is not None:
write('#endif' +
self._endProtectComment(protect_str=self.featureExtraProtect),
Expand Down
Loading