Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator: Derive slice getters/setters for runtime-bounded static arrays #858

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

MarijnS95
Copy link
Collaborator

Upstream Vulkan is okay with the request to annotate static arrays with a len="structField" annotation when the size of the static arrary is bounded by a value at runtime. This allows us to generate more convenient builder functions that copy slices into the target "builder" struct while also updating the length, rather than forcing the caller to move an array of the desired length with zeroed elements and setting the length field separately.

In addition provide a safe getter (and use it in the Debug implementation) to return a slice view containing only valid items per the length field. As with strings this is only possible for static-sized arrays as we can never safely dereference a random pointer.

ash/src/vk/definitions.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Nice improvement!

ash/src/vk.rs Outdated Show resolved Hide resolved
ash/src/vk/definitions.rs Outdated Show resolved Hide resolved
…rays

Upstream Vulkan is okay with the request to annotate static arrays with
a `len="structField"` annotation when the size of the static arrary
is bounded by a value at runtime.  This allows us to generate more
convenient builder functions that copy slices into the target "builder"
struct while _also_ updating the length, rather than forcing the caller
to move an array of the desired length with zeroed elements and setting
the length field separately.

In addition provide a safe getter (and use it in the `Debug`
implementation) to return a slice view containing only valid items
per the length field.  As with strings this is only possible for
static-sized arrays as we can never safely dereference a random pointer.
@MarijnS95 MarijnS95 force-pushed the runtime-bounded-static-arrays branch from f91aefa to 2154f2b Compare January 10, 2024 23:19
@MarijnS95 MarijnS95 merged commit e992225 into master Jan 10, 2024
20 checks passed
@MarijnS95 MarijnS95 deleted the runtime-bounded-static-arrays branch January 10, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants