Commit graph

1138 commits

Author SHA1 Message Date
Marijn Suijten 92084df65f
generator: Wrap _as_c_str() getter for possibly-pointers in Option (#860)
While this function is already marked `unsafe` to represent cases where
an invalid pointer might be dereferenced, it should at least be obvious
to the caller that there is a real chance for `NULL` pointers in these
`CStr` getters, which will now be returned as `None`.  This function
won't be used in `Debug` now as the dereference operation is still
`unsafe`.

The `_as_c_str()` getters for static arrays is left untouched, as the
data is read directly from the known-valid struct here.
2024-01-12 00:08:38 +01:00
Marijn Suijten e99222521e
generator: Derive slice getters/setters for runtime-bounded static arrays (#858)
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.
2024-01-11 00:33:32 +01:00
Marijn Suijten 51080bd522
Fix Rust 1.75 clippy lints (#859)
Rust 1.75 has once again gotten a bit more complete/strict when
linting code.  `.get(0)` is now recommended to be replaced with
`.first()`, and needless glob reexports are equally denied (the modules
in question either contain macros which are already reexported via
`#[macro_export]`, or contain `impl` blocks exclusively which cannot be
referred to as item paths either).
2024-01-11 00:18:28 +01:00
Marijn Suijten e7dab7cb66
Clean up unused std::XXX:: qualifications in examples and extensions (#852) 2023-12-24 00:36:21 +01:00
Marijn Suijten e6d80badc3
generator: Apply must_use attributes to all Vulkan structs (#845)
All structs are marked as `Copy`, and builders move `self` for a
convenient builder pattern directly on `default()` (using `&mut`
requires requires first keeping the instance alive in a `let` binding).
This however leads to builder functions accidentally moving a copy of
`self`, mutating it, and dropping the result directly when the caller
did not consume the returned value in ad-hoc field updates, in turn
leaving the author confused why their code compiles without warnings
while the struct was not updated.

Annotating all Vulkan structs with `#[must_use]` should at least give
them an idea why.
2023-12-05 22:09:44 +01:00
Marijn Suijten befb8cdd36
Switch to safe CStr::from_bytes_until_nul on sized c_char array wrapper (#746)
Certain structs contain sized character arrays that are converted to
`CStr` for convenient accss to the user and our `Debug` implementation
using unsafe `CStr::from_ptr(...as_ptr())`.  There is no need to
round-trip to a pointer and possibly read out of bounds if the
NUL-terminator index (string length) is instead searched for by the
newly stabilized `CStr::from_bytes_until_nul()` fn since Rust 1.69
(which panics if no NUL-terminator is found before the end of the
slice).

Unfortunately `unsafe` is still needed to cast the array from a `c_char`
(`i8` on most platforms) to `u8`, which is what `from_bytes_until_nul()`
accepts.
2023-12-02 20:04:57 +01:00
Marijn Suijten e5b08732db
generator: Work around invariance for assigning mutable pointer of lifetimed slice (#841)
In essence this builder function needs to adhere to two rules:
1. No ref-after-free: the slice must outlive (uses of) the builder
   object;
2. No aliasing: the slice cannot be (im)mutably used while it is mutably
   borrowed within a live builder object.

These two rules have been tested and are satisfied by the given builder
implementation.  Without this change `timings` seems to be borrowing
itself, hence is not allowed to be used after it has been temporarily
mutably borrowed inside the builder, even after that builder was
dropped.  Thus defeating the purpose of this "getter" API via a struct.

Without the `.cast()`, because mutable raw pointers are invariant
(i.e. there is no subtyping relationship) the compiler complains about
requiring `self` to outlive `timings` instead, which does not satisfy
the two rules above.
2023-12-02 19:52:35 +01:00
Marijn Suijten 4e99de1cbb
Convert mem::zeroed() / 0 to MaybeUninit::uninit() (#798)
* Convert `mem::zeroed()` / `0` to `MaybeUninit::uninit()`

As noted in #792 changes like this might help us more strictly identify
and validate that the argument in question is only relevant as an output
argument (i.e. structs with `sType` are read by the function call, even
if the caller strictly expects return values there, so that it can fill
in multiple structures in a `pNext` chain, and must hence be `Default`-
initialized).

* Use uninit `Vec`s with late `set_len()` call instead of zero-initialization

* Use `uninit()` instead of `-1` for file descriptors

* Introduce `set_vec_len_on_success()` helper for `Vec::with_capacity()`
2023-12-01 22:25:45 +01:00
Marijn Suijten 02c7a83592
Provide CStr getters and setters for c_char pointers and arrays (#831)
It is a common operation to read and write NUL-terminated C string in
the Vulkan API, yet the only helpers for that were thus far open-coded
in the `Debug` printing implementations.

Move them to separate functions that are exposed to the user, in hopes
of helping them no longer misunderstand NUL-terminated strings (see
e.g. #830).

Important to note is that the array-copy for a static-sized `c_char`
array has also been replaced with a `CStr` wrapper: this forces the user
and our implementation to have a NUL-terminator at the end of the string,
and the setter returns `Err()` when the given `CStr (with NUL-terminator)
is too large for the static-sized array it has to be written to.
2023-11-29 00:37:21 +01:00
Marijn Suijten 5938fd2633
Update Vulkan-Headers to 1.3.271 (#816)
* Update Vulkan-Headers to 1.3.270

* Update Vulkan-Headers to 1.3.271

* extensions/nv/low_latency2: Support extension revision 2

Upon request the VK_NV_low_latency2 spec and API has been updated to move
the count pointer from the `vkGetLatencyTimingsNV()` function to
the `vkGetLatencyMarkerInfoNV` struct where the array pointer already
resided.

This got uncovered when it was realized that the `latency_marker_info`
argument isn't an array at all (which the original design of this
extension suggested), but a pointer to a single struct that _contains_
a pointer to an array, with the length passed as a separate argument to
the function instead.

The move of this count argument to a struct field - together with proper
array length annotations - gets our generator to automatically emit a
setter based on a slice argument.
2023-11-28 15:05:27 +01:00
dependabot[bot] ccf6be8be3
build(deps): update syn requirement from 1.0 to 2.0 (#834)
Updates the requirements on [syn](https://github.com/dtolnay/syn) to permit the latest version.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/1.0.0...2.0.39)

---
updated-dependencies:
- dependency-name: syn
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-27 09:33:50 +01:00
Marijn Suijten b358b9dd8d
extensions/khr/ray_tracing_pipeline: Pass indirect SBT regions as single item (#829)
In an identical fashion to commit 84624fd ("ray_tracing_pipeline:
Pass SBT regions as reference instead of slice (#350)")
`cmd_trace_rays_indirect()` also only needs a pointer to a single
`StridedDeviceAddressRegionKHR` structure.  After all no length is ever
passed to the API anywhere, and this could also lead to users passing
empty slices, or passing too many elements that are never used.

Clear up the confusion by replacing the slice argument with a direct
borrow of the struct.
2023-11-25 11:08:48 +01:00
Marijn Suijten 7005a490b2 cargo: Set resolver = "2" and avoid warning
Since a few Rust versions `cargo` complains:

  warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`

Avoid that by setting the resolver for the virtual manifest to `"2"`
explicitly.
2023-11-21 11:14:32 +01:00
dependabot[bot] c045383ab1
build(deps): update bindgen requirement from 0.64 to 0.69 (#823)
Updates the requirements on [bindgen](https://github.com/rust-lang/rust-bindgen) to permit the latest version.
- [Release notes](https://github.com/rust-lang/rust-bindgen/releases)
- [Changelog](https://github.com/rust-lang/rust-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/rust-bindgen/compare/v0.64.0...v0.69.1)

---
updated-dependencies:
- dependency-name: bindgen
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 09:53:08 +01:00
dependabot[bot] 5952227dc4
build(deps): update itertools requirement from 0.10 to 0.12 (#824)
Updates the requirements on [itertools](https://github.com/rust-itertools/itertools) to permit the latest version.
- [Changelog](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-itertools/itertools/compare/v0.10.0...v0.12.0)

---
updated-dependencies:
- dependency-name: itertools
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 09:39:32 +01:00
dependabot[bot] 7a73f011c8
build(deps): update vk-parse requirement from 0.10 to 0.12 (#825)
Updates the requirements on [vk-parse](https://github.com/krolli/vk-parse) to permit the latest version.
- [Commits](https://github.com/krolli/vk-parse/compare/vk-parse-0.10.0...vk-parse-0.12.0)

---
updated-dependencies:
- dependency-name: vk-parse
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 09:39:24 +01:00
Marijn Suijten 4bbfa54146
Rename examples to ash-examples (#820)
[Dependabot complains] that:

     the binary target name `examples` is forbidden, it conflicts with with cargo's build directory names

And fails to provide dependency upgrades for Rust code.  Fix that by
renaming the folder and crate to `ash-examples`.

[Dependabot complains]: https://github.com/ash-rs/ash/network/updates/748770724
2023-11-17 17:27:28 +01:00
Marijn Suijten c87eb53b92
Update repository links and crate keywords/categories (#819)
Some links were still pointing to the (moved) `MaikKlein/ash` repo,
instead of the new shared `ash-rs/ash` repository under this
organisation, GitHub still provides a redirect, but we should aim to
provide the correct link from the get-go.  Only the gitter channel
remains as it was impossible to get the room to be renamed.  The
`ash-rs/ash` channel exists but there is currently no activity.
2023-11-17 16:55:05 +01:00
David Koloski d40ab4b367
Bump libloading to 0.8 (#739) 2023-11-15 10:19:14 +01:00
dependabot[bot] d0c5e97826
build(deps): bump actions/checkout from 1 to 4 in /.github/workflows (#812)
Bumps [actions/checkout](https://github.com/actions/checkout) from 1 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v1...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-03 18:38:00 +01:00
Marijn Suijten 6c7540473a
Add simple dependabot config for cargo and github-actions (#810)
Even though we don't have many dependencies, our GitHub Actions are
getting severely out of date and are best updated to the latest version.
Let dependabot help us with this, together with the few `cargo` crate
dependencies that we have (mainly in examples).
2023-11-03 18:20:47 +01:00
Marijn Suijten 335251d383
Enable descriptor_count() setter on ash::vk::WriteDescriptorSet (#809)
This parameter is not only used for the length of `pImageInfo`,
`pBufferInfo` or `pTexelBufferView`, but also matching the value
of `dataSize` when `VkWriteDescriptorSetInlineUniformBlock` is
appended in `pNext`, or the value of `accelerationStructureCount`
when `VkWriteDescriptorSetAccelerationStructureKHR` is in `pNext`.
Having the count setter directly avaialble makes builder code more
natural, instead of having to use a `mut` variable and manually assign
`.descriptor_count = xx.len();` afterwards.

https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkWriteDescriptorSet.html
2023-10-31 10:16:34 +01:00
Marijn Suijten 4180359ba7
gitmodules: Disable update to prevent cloning on cargo checkout (#808)
When using a `git` reference on this repo, `cargo` will unnecessarily
clone the `Vulkan-Headers` submodule (which is only needed by maintainers
together with the `generator`).  By setting the update mode to `none`
(https://git-scm.com/docs/gitmodules#Documentation/gitmodules.txt-submoduleltnamegtupdate)
this is disabled, and `git submodule update` will now also no longer
fetch/clone/update the repository unless `--checkout` is used
(https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-checkout).

I.e. running `cargo update` on a repo with a `git` dependency on `ash`:

    Updating git repository `https://github.com/ash-rs/ash`
    Skipping git submodule `https://github.com/KhronosGroup/Vulkan-Headers` due to update strategy in .gitmodules
2023-10-30 12:20:28 +01:00
Marijn Suijten f5e7606c03
extensions/nv: Add VK_NV_cuda_kernel_launch extension (#805) 2023-10-26 23:03:22 +02:00
Marijn Suijten a6f8450edf
extensions/ext: Add VK_EXT_hdr_metadata extension (#804) 2023-10-26 09:05:14 +02:00
Marijn Suijten ff54d22a15
Resolve lint warnings for deprecated_in_future, rust_2018_idioms and unused_qualifications (#803)
* generator: Add many missing lifetime parameters

* Globally find-replace common patterns that need a `<'_>` lifetime annotation

    perl -pi -E "s/(&(mut )?\[?vk::(?\!\w+(V1_\d|Fn|<))\w+)/\$1<'_>/" **/*.{rs,md}

* generator: Include aliased types in `has_lifetime` lookup table

* Manually revert wrong find-replace lifetimes

* Resolve lint warnings for `deprecated_in_future`, `rust_2018_idioms` and `unused_qualifications`

These are 3 non-default lints that cause a lot of violations in this
project that are sensible to resolve, and reduce noise when
test-including a local `ash` checkout in other projects that have
stricter lint setups.
2023-10-26 08:30:16 +02:00
Marijn Suijten 2d2aeac84a
extensions/nv: Add VK_NV_low_latency2 extension (#802) 2023-10-25 20:02:19 +02:00
Marijn Suijten 11647de859
Update Vulkan-Headers to 1.3.269 (#783)
* Update Vulkan-Headers to 1.3.261

* Update Vulkan-Headers to 1.3.262

* Update Vulkan-Headers to 1.3.263

* Update Vulkan-Headers to 1.3.264

* Update Vulkan-Headers to 1.3.266

* generator: Fix `clippy::filter_map_bool_then`

* Update Vulkan-Headers to 1.3.267

* Update Vulkan-Headers to 1.3.268

* Update Vulkan-Headers to 1.3.269
2023-10-21 00:47:28 +02:00
Marijn Suijten d0d5ea1370
platform_types: Convert Windows HANDLE types to isize (#797)
The `windows` crate treats these as `isize` rather than raw void
pointers:
https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Foundation/struct.HWND.html

And `raw-window-handle 0.6` recently started to do the same:
https://github.com/rust-windowing/raw-window-handle/pull/136

However, the win32 documentation still states that these should be
`PVOID`:
https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types
2023-10-14 11:18:23 +02:00
Marijn Suijten 49de0341a0
CI: Cross-lint for Mac, iOS and Windows (#796)
* CI: Cross-lint for Mac, iOS and Windows

We have some conditional code specific to Mac and iOS which is currently
untested in the CI, allowing non-compiling code in PRs like #795 to go
unnoticed.

* Fix new clippy lints
2023-10-11 20:58:21 +02:00
Marijn Suijten 3f5b96b363
nv/ray_tracing: Initialize tagged struct with default() (#792) 2023-09-06 01:17:20 +02:00
Marijn Suijten 0652aee695
extensions/ext: Add VK_EXT_swapchain_maintenance1 (#786) 2023-08-15 21:43:01 +02:00
Chris Spencer 5a9d779eef
extensions/khr: Add VK_KHR_sampler_ycbcr_conversion (#785) 2023-08-14 17:13:07 +02:00
Felipe 43d4a68ab2
extensions/ext: Add VK_EXT_vertex_input_dynamic_state (#784) 2023-08-14 16:57:11 +02:00
Marijn Suijten 39dc6d607c
extensions/khr: Add VK_KHR_cooperative_matrix (#782) 2023-08-14 16:49:32 +02:00
Marijn Suijten 3fa908c70a
extensions/nv: Add VK_NV_device_generated_commands_compute (#781) 2023-08-14 16:42:57 +02:00
Marijn Suijten b91c2aac92
extensions/khr: Add VK_KHR_maintenance5 (#780) 2023-08-14 16:09:06 +02:00
Marijn Suijten 95ff15ff72
extensions/ext: Add VK_EXT_host_image_copy (#779) 2023-08-14 15:56:42 +02:00
Marijn Suijten c3f322f65e
extensions/amdx: Add VK_AMDX_shader_enqueue (#776) 2023-08-14 15:51:20 +02:00
Marijn Suijten f558761997
extensions/amd: Add VK_AMD_shader_info (#773) 2023-07-29 10:51:03 +02:00
Marijn Suijten 884ac46e82
extensions/amd: Add VK_AMD_buffer_marker (#772) 2023-07-29 10:45:11 +02:00
Marijn Suijten 010df1b1b3
Update Vulkan-Headers to 1.3.260 (#763)
* Update Vulkan-Headers to 1.3.255

* Update Vulkan-Headers to 1.3.257

* Update Vulkan-Headers to 1.3.258

* Update Vulkan-Headers to 1.3.259

* Update Vulkan-Headers to 1.3.260
2023-07-29 10:44:49 +02:00
Chris Spencer 6b56444e79
extensions/android: Add VK_ANDROID_external_memory_android_hardware_buffer (#769) 2023-07-12 12:09:08 +02:00
Chris Spencer 369fe05e79
extensions/google: Add VK_GOOGLE_display_timing (#765) 2023-07-11 15:45:04 +02:00
Jesse Natalie a0f8b9cf3e
Add MSFT vendor tag for enum variants (#762)
Otherwise enums with the MSFT suffix fail to parse.
2023-06-22 01:08:33 +02:00
BeastLe9enD 75089f487f
extensions/nv: Add VK_NV_memory_decompression (#761) 2023-06-21 22:14:38 +02:00
Marijn Suijten eb1712944e
Update Vulkan-Headers to 1.3.254 (#760)
* Update Vulkan-Headers to 1.3.252

* Update Vulkan-Headers to 1.3.253

* Update Vulkan-Headers to 1.3.254

* vk/platform_types: Add `_screen_buffer` type for QNX
2023-06-16 17:05:11 +02:00
Marijn Suijten 9985b2ca69
Rename vk::Instance-returning function from device() to instance() (#759) 2023-05-29 13:11:55 -07:00
Marijn Suijten d588de01aa
changelog: Import from and synchronize with 0.37.3 release 2023-05-29 21:25:48 +02:00
Marijn Suijten 1e7ee6762f
Remove "drop" mention from create_* docs when the result doesn't implement Drop (#625)
Ash doesn't implement `Drop` intentionally, to not be too opinionated
about holding (heap) references to their parent objects
(`Device`->`Instance`->`Entry`) and ensuring they are destroyed in the
right order.  As such, reword the `create` documentation for `Instance`
and `Device` to mention their respective `destroy_*` function instead of
referring to them as being "droppable".

Note that `Entry` is droppable as it does not have a Vulkan `destroy`
function _and_ the dynamically loaded library (behind the "loaded"
feature) is kept alive only for the lifetime of `Entry`.
2023-05-29 20:40:08 +02:00