Repository navigation
Conversation
The assertion pinned sizeof(VkPhysicalDeviceFeatures2) to 240 bytes, which is the 64-bit layout. On a 32-bit ABI the struct is 228 bytes: the pointer is 4 bytes and neither the padding before it nor the tail padding applies. The assertion therefore fired and bindgen aborted on every 32-bit target whose linked FFmpeg was built with Vulkan. Select the expected size by pointer width. On a 64-bit ABI the expression still evaluates to 240, so nothing changes there. What Vulkan 1.1 froze is the member layout, not a byte count that survives a change of pointer width, so the struct definition itself needed no change. Checked with clang for armv7, i386, x86_64 and aarch64.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #137.
Summary
This is the bug reported in #137; I hit the same assertion independently on armhf
CI and had already worked out the details below, so I am sending the fix rather
than another report.
hwcontext_stubs/vulkan/vulkan.hpinssizeof(VkPhysicalDeviceFeatures2)to ahard-coded 240 bytes, which is the 64-bit layout. On a 32-bit ABI the same struct
is 228 bytes, so the
_Static_assertfires and bindgen aborts. Every 32-bittarget whose linked FFmpeg was built with Vulkan therefore fails to build.
This replaces the constant with a pointer-width branch. On a 64-bit ABI the
expression still evaluates to 240, so nothing changes there.
Reproduced with 9.1.1 and 9.0.1, whose shims are byte-identical. 8.1.0 does not
ship the shim.
Reproduction
The shim is self-contained, so this needs neither FFmpeg, nor a 32-bit sysroot,
nor a Vulkan SDK. From the crate root, before this change:
-target i386-unknown-linux-gnufails identically.x86_64-unknown-linux-gnuand
aarch64-unknown-linux-gnupass. With this change all four pass.In a real build the same assertion surfaces as a bindgen failure in the build
script, on an otherwise working armhf toolchain.
Why 228 is the correct size there
VkStructureType sTypepNextvoid *pNextVkBool32 features[55]Real Vulkan computes 228 on a 32-bit ABI too:
VkPhysicalDeviceFeatures2is aVkStructureType, avoid *, andVkPhysicalDeviceFeatures(55VkBool32).What Vulkan 1.1 froze is the member layout, not a byte count that survives a
change of pointer width, so the old assertion's premise held only on 64-bit. The
struct definition was already correct; only the constant was wrong.
Why not the form suggested in #137
#137 floats
sizeof(VkPhysicalDeviceFeatures2) - sizeof(void *) == 240 - sizeof(void *).That one does not actually unbreak the build: it subtracts a single pointer
width, but 240 → 228 is a 12-byte difference, because the 4 bytes of padding
before
pNextand the 4 bytes of tail padding disappear along with the 4 bytesof pointer. On a 32-bit ABI it reduces to
224 == 236. Checked with clang onarmv7 and i386, where it fails exactly as the current assertion does.
When it triggers
hwcontext_wrapper.hgates the Vulkan block on__has_include(<libavutil/hwcontext_vulkan.h>), andbuild.rsputshwcontext_stubsfirst on the include path, so the shim is parsed whenever thelinked FFmpeg installs that header. Debian builds FFmpeg with Vulkan, so
apt install libavutil-devon armhf or i386 is enough to reach it; no Vulkan SDKhas to be present.
What I verified, and what I did not
Verified with clang on armv7, i386, x86_64 and aarch64: the assertion accepts the
struct as the shim defines it on all four, and rejects a changed prefix (dropping
pNext) on all four. On the two 32-bit targets it also rejects a changed membercount.
One limit worth stating plainly: on a 64-bit ABI a single added member is
invisible to any
== 240check, because 16 + 55 × 4 = 236 pads up to 240, while16 + 56 × 4 = 240 exactly. The assertion as it stands today has that same blind
spot; this change neither widens nor closes it. It only stops the assertion from
rejecting a correct 32-bit layout.
This is also the only
_Static_assert, and the only hard-coded size, inhwcontext_stubs.Not verified: a complete 32-bit build, end to end. The CI I hit this in sidesteps
the Vulkan block by hiding
hwcontext_vulkan.h, so I have no evidence about whathappens after bindgen on a 32-bit target; there may be further issues behind this
one. This change is scoped to the assertion, and I did not want to imply more
than that.
Workaround for anyone hitting this before a release
A 32-bit build can make the
__has_includegate skip the Vulkan block by hidingthe header, which reproduces a libavutil configured without Vulkan:
Two details that cost me time: on Debian the header lives under the multiarch
include directory (
/usr/include/arm-linux-gnueabihf/libavutil/), not/usr/include/libavutil/. And a probe written as#include <libavutil/hwcontext_vulkan.h>cannot confirm the header is gone,because that header pulls in
<vulkan/vulkan.h>, which is absent unless theVulkan SDK is installed — such a probe fails either way.
__has_includeis whatdistinguishes the two cases.