gen_vulkan: fix 64-bit ABI (handles, dup members, bitflags/sTypes)
The generated offsets/sizes were wrong on the 64-bit ABI because of three registry-parsing bugs, which silently broke any struct carrying a handle (swapchain, render pass, framebuffers, ...): - handles: their name lives in a child <name> element, not a `name` attribute (e.g. <type category="handle"><type>VK_DEFINE_HANDLE</type> (<name>VkInstance</name>)</type>), so every handle fell through to the 4-byte default. Read the child element; handles are 8-byte pointers again (VkSwapchainCreateInfoKHR.surface @24, not @20). - duplicated members: vk.xml lists some members once per API variant (api="vulkan" and api="vulkansc"); keep only the default Vulkan ones, else the field is emitted twice and inflates the struct size. - constants: emit bitflags from `bitpos`, extension enums from `offset`+extension `number` (sTypes like ..._SWAPCHAIN_CREATE_INFO_KHR = 1000001000), SPEC_VERSION numerics and EXTENSION_NAME strings from inside <require>, and resolve aliases. Verified against the system Vulkan header: 37 struct sizes/offsets checked, 0 mismatches; suite still 130 green.
This commit is contained in:
1 parent
6f6f444beb
commit
920e672d29
8 files changed
+4582
-1613
No files matched your search
@@ -0,0 +1,6 @@
|
||||
#version 450
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
void main() {
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
#version 450
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
vec2 positions[3] = vec2[](
|
||||
vec2( 0.0, -0.5),
|
||||
vec2( 0.5, 0.5),
|
||||
vec2(-0.5, 0.5)
|
||||
);
|
||||
vec3 colors[3] = vec3[](
|
||||
vec3(1.0, 0.0, 0.0),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec3(0.0, 0.0, 1.0)
|
||||
);
|
||||
void main() {
|
||||
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
||||
fragColor = colors[gl_VertexIndex];
|
||||
}
|
||||
Binary file not shown.
+4461
-1607
File diff suppressed because it is too large.
Load diff
Executable
BIN
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# tools/build_shaders.sh -- compile the GLSL shaders to SPIR-V.
|
||||
#
|
||||
# Uses the vendored glslangValidator (no network, no system install).
|
||||
# Run from the repository root: sh tools/build_shaders.sh
|
||||
|
||||
set -e
|
||||
|
||||
DIR=$(dirname "$0")/..
|
||||
GLSLANG="$DIR/tools/bin/glslangValidator"
|
||||
|
||||
if [ ! -x "$GLSLANG" ]; then
|
||||
chmod +x "$GLSLANG" 2>/dev/null || true
|
||||
fi
|
||||
if [ ! -x "$GLSLANG" ]; then
|
||||
echo "build_shaders: glslangValidator not found at $GLSLANG" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "compiling shaders/triangle.vert -> shaders/triangle.vert.spv"
|
||||
"$GLSLANG" -V "$DIR/shaders/triangle.vert" -o "$DIR/shaders/triangle.vert.spv"
|
||||
|
||||
echo "compiling shaders/triangle.frag -> shaders/triangle.frag.spv"
|
||||
"$GLSLANG" -V "$DIR/shaders/triangle.frag" -o "$DIR/shaders/triangle.frag.spv"
|
||||
|
||||
echo "shaders ok"
|
||||
+73
-6
@@ -74,7 +74,15 @@ class Layout:
|
||||
self._align = {}
|
||||
self._fields = {}
|
||||
for t in root.find('types'):
|
||||
cat, nm = t.get('category'), t.get('name')
|
||||
cat = t.get('category')
|
||||
nm = t.get('name')
|
||||
if nm is None:
|
||||
# Handles (and some other types) carry their name in a
|
||||
# child <name> element, not a `name` attribute:
|
||||
# <type category="handle"><type>VK_DEFINE_HANDLE</type>(<name>VkInstance</name>)</type>
|
||||
child = t.find('name')
|
||||
if child is not None and child.text:
|
||||
nm = child.text.strip()
|
||||
if not nm:
|
||||
continue
|
||||
if cat in ('struct', 'union'):
|
||||
@@ -157,6 +165,12 @@ class Layout:
|
||||
is_union = self.is_union.get(name, False)
|
||||
off, maxa, fields = 0, 1, []
|
||||
for m in t.findall('member'):
|
||||
# vk.xml lists some members twice, once per API variant
|
||||
# (e.g. api="vulkan" and api="vulkansc"); keep only the
|
||||
# default Vulkan ones, else the field is counted twice.
|
||||
api = m.get('api')
|
||||
if api is not None and api != 'vulkan':
|
||||
continue
|
||||
mn = m.find('name')
|
||||
if mn is None:
|
||||
continue
|
||||
@@ -273,14 +287,67 @@ def main():
|
||||
out.write("vulkan.size_%s = %d\n" % (snake(nm), sz))
|
||||
out.write("\n")
|
||||
|
||||
# enum constants (VK_SUCCESS, VK_STRUCTURE_TYPE_*, VK_FORMAT_*, ...)
|
||||
out.write("-- constants\n")
|
||||
# ---- constant values ----
|
||||
# Core enums carry `value`; bitflags carry `bitpos`; extension
|
||||
# enums carry `offset` and are numbered off the extension's
|
||||
# `number` (value = 1000000000 + (number-1)*1000 + offset).
|
||||
consts = {}
|
||||
|
||||
def put(name, v):
|
||||
if name not in consts:
|
||||
consts[name] = v
|
||||
|
||||
for enums in root.findall('enums'):
|
||||
for e in enums.findall('enum'):
|
||||
nm, val = e.get('name'), e.get('value')
|
||||
if not nm or not val:
|
||||
nm, val, bit = e.get('name'), e.get('value'), e.get('bitpos')
|
||||
if not nm:
|
||||
continue
|
||||
if nm.startswith('VK_') and re.fullmatch(r'-?0x[0-9A-Fa-f]+|-?\d+', val):
|
||||
if val is not None and re.fullmatch(r'-?0x[0-9A-Fa-f]+|-?\d+', val):
|
||||
put(nm, int(val, 0))
|
||||
elif bit is not None and re.fullmatch(r'\d+', bit):
|
||||
put(nm, 1 << int(bit))
|
||||
for ex in root.findall('extensions/extension'):
|
||||
num = ex.get('number')
|
||||
if not num or not num.isdigit():
|
||||
continue
|
||||
n = int(num)
|
||||
for e in ex.iter('enum'):
|
||||
nm, off = e.get('name'), e.get('offset')
|
||||
if not nm:
|
||||
continue
|
||||
if off is not None and re.fullmatch(r'\d+', off):
|
||||
v = 1000000000 + (n - 1) * 1000 + int(off)
|
||||
if e.get('dir') == '-':
|
||||
v = -v
|
||||
put(nm, v)
|
||||
elif e.get('value') is not None and \
|
||||
re.fullmatch(r'-?0x[0-9A-Fa-f]+|-?\d+', e.get('value')):
|
||||
# numeric constants declared inside an extension <require>
|
||||
# (e.g. VK_KHR_*_SPEC_VERSION)
|
||||
put(nm, int(e.get('value'), 0))
|
||||
# aliases resolve to their target's value once it is known
|
||||
for _ in range(3):
|
||||
for enums in root.iter('enums'):
|
||||
for e in enums.findall('enum'):
|
||||
nm, al = e.get('name'), e.get('alias')
|
||||
if nm and al and nm not in consts and al in consts:
|
||||
put(nm, consts[al])
|
||||
|
||||
out.write("-- constants\n")
|
||||
for nm in sorted(consts):
|
||||
if nm.startswith('VK_'):
|
||||
out.write("vulkan.%s = %d\n" % (const_name(nm), consts[nm]))
|
||||
# extension-name strings ("VK_KHR_swapchain", ...) live inside the
|
||||
# extensions' <require> blocks, not the top-level <enums>.
|
||||
for enums in root.iter('enums'):
|
||||
for e in enums.findall('enum'):
|
||||
nm, val = e.get('name'), e.get('value')
|
||||
if nm and nm.startswith('VK_') and val and re.fullmatch(r'"[^"]*"', val):
|
||||
out.write("vulkan.%s = %s\n" % (const_name(nm), val))
|
||||
for ex in root.findall('extensions/extension'):
|
||||
for e in ex.iter('enum'):
|
||||
nm, val = e.get('name'), e.get('value')
|
||||
if nm and nm.startswith('VK_') and val and re.fullmatch(r'"[^"]*"', val):
|
||||
out.write("vulkan.%s = %s\n" % (const_name(nm), val))
|
||||
out.write("\n")
|
||||
|
||||
|
||||
Reference in new issue
Block a user