Constants (enumeration bitflags) containing the word `external` were not
stripped of their common typename, and quick debugging showed the word
`VKTERNAL_...` in `struct_name`. `_EXT` would be the first extension to
match in `VK_EXTERNAL_...` messing up `struct_name` with a global
`.replace`, in turn not removing it from the variant name.
It isn't too uncommon to pass a single builder element into another
builder, and `slice::from_ref` fits perfectly while preserving lifetime
of the builder without calling `.build()`. We have used this
successfully in our codebase to uncover and prevent numerous
use-after-free bugs, and thought it's worth to share on the front page.
* khr/acceleration_structure: Fix fn signature of indirect build cmd
max_primitive_counts is an array of arrays, not an array of references
to single u32's.
* khr/acceleration_structure: Validate array length against geometry_count
This is a safe wrapper that already iterates over all the slice
references (fat pointers) to collect just the pointers for use in the
Vulkan API. It can and should at the same time make sure these slices
are of the specified length to prevent accidental out-of-bounds reads.
CString::new needs to perform an allocation to own the `&'static str`
and append a NULL byte to it. We can instead perform this "allocation"
in the generator and emit a byte-string literal with trailing NULL byte
that can immediately be used by the function loader.
This handle is already held onto when creating the safe wrapper object,
but is inconsistently required again in some but not all functions.
Remove it from every function and use the internal handle instead.
Closes: #377
Fixes: 05747b2 ("Update Vulkan-Headers to 1.2.162 with stable ray-tracing spec (#341)")
This new version marks `Library::new` as unsafe, because loading a
library invokes the libraries' entrypoint which may or may not have
certain preconditions and perform unsafe/undefined operations, just like
any other native function loaded through `libloading`.
`c_void` is not the same as Rust's void type, `()`, making function
pointers like `PFN_vkFreeFunction` pretty much impossible to implement
without casting. Instead of just turning this into `-> ()`, remove the
return type altogether, and add some asserts to prevent types of this
kind from being accidentally generated.
The `VK_KHR_ray_query` extension has no functions and this safe wrapper
(specifically to re-wrap functions) was added by accident (by me).
To prevent confusion, remove it before a new crate version is released.
Applications can easily access the name (which is the only useful thing
reexported here) from `ash::vk::extensions:KhrRayQueryFn::name()`.
In rust references to DSTs (Dynamically Sized Types) like slices and
trait objects are 16-bytes instead of 8 (leaking into the next parameter
of a function call). The static-sized array generated here has its size
known beforehand and will not suffer from this issue [1], but might be
confusing for future readers/authors: convert it to a raw pointer just
to be safe.
[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=88acb9736455f7262ecf4af2077f3a59
The API for vkCmdTraceRaysKHR mandates a single non-null pointer per SBT
region to a VkStridedDeviceAddressRegionKHR. While providing more than
one such region isn't harmful, passing a slice of length 0 will cause
reads in uninitialized memory and undefined behaviour.
Converting these parameters from slices to references rids the
unnecessary confusion and prevents zero regions from being passed.
* Update Vulkan-Headers subproject to 1.2.162 (ray tracing)
* Generate against vk.xml 1.2.162
* generator: Shim IDirectFB and IDirectFBSurface to c_void
* generator: Edgecase for name-clash in p_geometries and pp_geometries
* extensions: Migrate acceleration structure to separate extension
* extensions: Migrate RT safe wrapper functions to ray_tracing_pipeline
* Add high level wrapper for currently-empty RayQuery extension
* vk: definition: Turn host/device AS handle into type safe union
Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
Co-authored-by: Darius Bouma <darius1@live.nl>
* Fix clippy::manual_strip
* Fix clippy::comparison_to_empty
* Fix clippy::needless_lifetimes
* generator: Drop unnecessary edgecase for charptr array in builder
* generator: Make array type handling more linear
* prelude: Provide Result -> VkResult<()> conversion
* Add #[must_use] to Result type
* Fix all unchecked vk::Result cases
* generator: Fix typos
* generator: Assert char ptrs have `"null-terminated"` len attribute
* prelude: Provide result_with_success helper for Result -> VKresult
* Cleanup match{success} blocks with SSR
{let $p = $f; match $q { vk::Result::SUCCESS => Ok($r), _ => Err($z), }} ==>> {$f.result_with_success($r)}
* Simplify matching on Result::SUCCESS
Using the following regex replacement:
let err_code =\s*(.*\((\n|[^;])*?\));\s*match err_code \{\s*vk::Result::SUCCESS => Ok\((.*)\),\s*_ => Err\(err_code\),\s*\}
$1.result_with_success($3)
* Simplify intermediate error return
let err_code =\s*(.*\((\n|[^;])*?\));\s*if err_code != vk::Result::SUCCESS \{\s*return Err\(err_code\);\s*\}
$1.result()?;
* Simplify error checking with .result()? and .result_with_success()
* generator: Ignore empty basetype in typedef (forward declaration)
ANativeWindow and AHardwareBuffer were [recently changed] to the
basetype category, but without an actual basetype, consequently failing
the Ident constructor with an empty name.
Since these types are already dealt with in platform_types, and there
doesn't seem to be anything sensical to define them to right now, just
ignore these cases.
[recently changed]: 0c5351f5e9 (diff-0ff049f722e55de41ee15b2c91ef380fL179-R180)
* Suggestion: Allocate data in get_ray_tracing_shader_group_handles
* generator: Update nom to 6.0
* generator: Generalize C expression conversion to TokenStream
* generator: Simplify ReferenceType::to_tokens with quote!
* generator: Refactor to not parse our own stringified token stream
* generator: Deal with pointers to static-sized arrays
* generator: Apply static-sized array pointer to size containing `*`
* generator: setter: Interpret all references as ptr, not just p_/pp_
* generator: quote::* is already imported
* generator: Replace manual fn to_tokens with quote::ToTokens trait impl
* generator: Return str reference from constant_name
* generator: Replace unused to_type_tokens with name_to_tokens
The reference argument was always None; replace it with a direct call to
name_to_tokens.
* generator: setters: Use safe mutable references instead of raw ptrs
According to specs for Device Memory (section 10.2), memory types are
topologically sorted by their property flags so the two-pass memory
type selection is unnecessary.
Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
According to specs for vkGetPhysicalDeviceSurfaceFormatsKHR(), at least
one surface format must be returned, and returned formats must not be
VK_FORMAT_UNDEFINED.
This avoids an obnoxious error when attemting to use `dbg!()` while
debugging the generator.
Unfortunately there seems to be no way to import * except `dbg`, or
shadow `dbg` (using eg. `use nom::{dbg as _nom_dbg, *};`).
It is in some cases necessary to load a specific Vulkan dll/so with a
different name and/or from a different location.
Instead of copying this function to a downstream project (and making the
LoadingError constructor public to retain the same interface), split
Entry::new() such that downstream projects can easily specify and use an
alternate Vulkan implementation.
* Deprecate the DebugMarker and DebugReport extension modules
* Allow deprecated modules only in mod.rs, to suppress clippy warning
Co-authored-by: Apoorva Joshi <apoorva.ramesh.joshi@gmail.com>
* Add ash-window as workspace member
* ash-window: fix repository link
* ash-window: Address CI fmt&clippy issues
* ash-window: Try fix SDL2 CI issues
* ash-window: Remove beryllium example
* Allow the generator to be run from project root dir
* Split vk.rs into multiple files
* Breakup and remove generated vk/prelude.rs
Generator changes:
- No longer convert current dir to a string when checking if the
path ends with 'generator'
- Pass the 'ash/src' dir instead of the 'vk.rs' path
Generated and generated output changes:
- The majority of prelude.rs has been moved to macros.rs
- The pointer chain and Handle are now included in vk.rs
- Platform types has been moved to its own file.