Commit graph

229 commits

Author SHA1 Message Date
Philippe Renon 56d8507acb
fix clippy::uninlined_format_args (#705)
* ash/util: fix `clippy::seek_to_start_instead_of_rewind`

* examples: fix `clippy::uninlined_format_args`

* ash: fix `clippy::uninlined_format_args`

* generator: fix `clippy::uninlined_format_args`

* rust: upgrade to edition 2021
2023-04-02 22:29:25 +02:00
HugoPeters1024 aca947df12
examples: Fix error description in texture example (#696)
fix error description in texture example
2023-04-02 22:28:23 +02:00
Marijn Suijten 61d33d50cb
examples: Remove unneeded casts as pointed out by Rust 1.66 (#692)
Strangely some no-op cast remained in the codebase, and are only now
caught since Rust 1.66.  In both cases the input value is already of the
correct type (independent of the platform).
2022-12-19 19:47:48 +01:00
Marijn Suijten 047676a443 Replace as *... raw pointer-type changes with more explicit .cast() (#685)
`.cast()` allows changing the pointer type without hiding (accidental)
mutability changes (noting that `*mut` still coerces to `*.const`).

For mutability changes Rust 1.65 included `cast_mut()` and
`cast_const()`, but those would bump our MSRV too eagerly for now.
2022-11-22 23:39:49 +01:00
Marijn Suijten 0a96643e26 ash-window: Upgrade to raw-window-handle 0.5.0 (#645)
* ash-window: Upgrade to raw-window-handle 0.5.0

* Bump `raw-window-metal` to recently-released `0.3`

https://github.com/norse-rs/raw-window-metal/pull/5

* examples: Bump `winit` to `0.27.1` to resolve our MSRV tests

While the examples technically aren't part of our MSRV requirement (it's
nice, but core crate compatibility is much more important), it's
annoying to exempt these especially now that `winit` removed some
unneeded MSRV 1.60/1.61 requirements.

* Take `Raw{Display,Window}Handle` directly instead of through trait
2022-09-23 12:43:45 +02:00
Lucas Jenß 9406685ab9 examples: Fix validation errors on macOS and iOS (#623)
* Error: vkCreateDevice: VK_KHR_portability_subset must be enabled [...]
* Error: Attempting to create a VkDevice from a VkPhysicalDevice which is from a portability driver without the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo flags being set and the VK_KHR_portability_enumeration extension enabled.
2022-06-05 15:49:21 +02:00
Steve Wooster 1cd810653c
ash-window: Make enumerate_required_extensions return &[*const c_char] (#590)
* Constify generated extension names

* Constify hand-written extension names

* Make ash-window list extensions as &[*const c_char]

This alters enumerate_required_extensions() to return the same type that
is expected by vk::InstanceCreateInfoBuilder::enabled_extension_names(),
allowing simple Vulkan apps to omit the boilerplate of mapping to an
intermediate Vec<*const c_char>.

Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
2022-03-22 23:47:26 +01:00
Steve Wooster b16bb4e62c
Appease clippy (#591)
* Simplify .map().flatten().next() and .filter_map().next() to .find_map()

* Avoid unnecessary closures for cheap expressions

* Use character instead of string for replacement pattern

Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
2022-02-26 13:01:28 -08:00
Steve Wooster fbcc45fffe
Add conversions from Extent2D to Extent3D and Rect2D (#557)
These two conversions occur all the time in Vulkan applications. For
example, Extent2D -> Extent3D occurs whenever you need to make an image
the same size as a surface and Extent2D -> Rect2D occurs whenever you
fill out a scissors or render area from a surface resolution.

Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
2022-01-22 16:29:45 +01:00
Marijn Suijten 03068a8734
examples: Update winit to 0.26 and image to 0.23 (#551)
Examples-only excerpt of #547, as the generator and ash-window example
changes need more work.  Fixes #550.
2022-01-10 13:43:18 -08:00
Markus Siglreithmaier adf0338ed8
example: Refactor event loop handling for continuous redraw (#542)
Switch to continuous redrawing using `Poll` and `MainEventsCleared`.

Fixes hangs in case of non-Mailbox present modes.
2022-01-03 23:24:36 +01:00
Marijn Suijten 8a46a1508a Generate RGBA=R|G|B|A helper constant for ColorComponentFlags
When the misleading `all()` function was removed in #478 it also made
all color components for `ColorComponentFlags` significantly more
verbose to write, see #536.
2021-12-28 11:52:29 -08:00
Marijn Suijten afdab863d0 examples: Remove remaining CString allocations on string literals
These allocations and runtime assertions can all be replaced with a
`CStr` directly wrapping a binary-string literal, as long as it is
null-terminated.
2021-12-28 10:37:30 -08:00
Benjamin Saunders 7cf3b4f09e
Don't link Vulkan by default (#526)
This was found to be unreasonably disruptive to downstream CI
configurations.
2021-12-27 11:49:40 +01:00
Marijn Suijten 90960efded
examples: Use c_char for pointer to raw string (#521)
On platforms like Android strings use `u8` as character-type instead of
`i8` - using the appropriate `c_char` type hides this discrepancy and
allows the examples to compile for all platforms.
2021-12-21 11:42:47 -08:00
Marijn Suijten b56f39e35c examples: Rename events_loop to event_loop 2021-12-20 15:50:02 -08:00
Marijn Suijten 9d36436a53 Remove window.id() match, simply nested matches with single if-let 2021-12-20 15:50:02 -08:00
neurotok 5b53dd94cb window event keyboard input 2021-12-20 15:50:02 -08:00
neurotok 9baeb9c19f winit v0.25.0 2021-12-20 15:50:02 -08:00
Marijn Suijten f781777931 examples: Use slice::from_ref to not loose lifetime on nested slices
As per the readme `.build()` should only be called as late as possible,
and only if absolutely necessary; such cases include slices that are
passed directly to functions.  More precisely, such build calls and the
creation of temporary slices should happen inside the same expression as
the function call to be sound and completely lifetime-checked.

This pattern of `&[my_builder.build()]` is however not possible when
constructing intermediary Vulkan objects that reference the slice.  In
the first place this slice goes out of scope after the expression that
creates the Vulkan object, which is caught and disallowed by rustc
(unless this expression itself ends in `.build()`, which is completely
 unsound as it makes rustc unable to validate this lifetime dependency).

In the second place - and as is most relevant for this patch that
removes `.build()` calls that were not surrounded by temporary slice
constructors - said expression drops the lifetime checks on anything
held by `my_builder` which _could_ go out of scope before the newly
constructed Vulkan object is used, resulting yet again in Undefined
Behaviour.

Fortunately, for slices of size 1 which are typical in Vulkan,
`std::slice::as_ref` exists which is analogous to taking a pointer to an
object and considering it an array of length 1 in C(++).  This maintains
the lifetime through `Deref` and makes rustc able to fully check all
lifetimes and prevent unsound code.

Albeit improving overall consistency, the `&[my_builder.build()]`
pattern is not substituted in aforementioned Vulkan function-call
expressions as that is considered "extraneous" [1] and demonstrates the
various ways to safely construct Vulkan objects for the observant reader.

[1]: https://github.com/MaikKlein/ash/pull/506#discussion_r762630648
2021-12-19 16:17:56 -08:00
Steve Wooster ea65db4bea
Simplify triangle example's vertex input state (#512)
Co-authored-by: Steve Wooster <s.f.m.wooster@gmail.com>
2021-12-19 12:28:34 +01:00
Marijn Suijten c4dd1d6040
vk: Remove misleading all()/-/-= function/ops from bitflags (#478)
The `all()` function only represents bitflags known in the core of
Vulkan; it omits all bits added by extensions making this function
unrepresentative and has hence been scheduled for removal for quite some
time to get rid of the confusion it causes.

Alternatively the generator could be taught to collect bitflags added by
extensions, but new extensions get added over time skewing available
values in ash versus the current driver/environment.  This makes the
value from `all()` unreliable and fragile at best.

`-` and `-=` (`sub()` and `sub_assign()`) are also controversial by
nature since the underlying value represents an integer but the
implemented math uses bitwise operators.  This is a confusing design
pattern and the caller better replaces their uses - if any at all - with
`foo &= !BAR`.
2021-11-10 00:35:35 +01:00
Benjamin Saunders aa7b429f4f
Support linking Vulkan directly (#457)
* Mark EntryCustom::new_custom as unsafe

Passing a badly-behaved `load` function can invoke undefined behavior.

* Document required feature for Entry

* Support linking Vulkan directly

This is the preferred pattern in most environments when an application
cannot function without Vulkan, as it saves the libloading dependency,
eliminates an error case, and makes the Vulkan dependency visible to
the OS.

* Rename libloading feature to "loaded"

* Link by default

* Guide users towards linking the loader directly

* Remove unnecessary error type

InstanceError::LoadError was never constructed.

* Unify entry types

Simplifies the interface and allows a bunch of code to become
monomorphic.
2021-09-09 22:50:34 +02:00
Marijn Suijten 9c1abcd9ca
Fix clippy lints on Rust 1.54 and beyond (#458)
Using `cargo +nightly clippy --fix --all` on `clippy 0.1.56 (4927238
2021-07-29)`.
2021-07-30 12:01:55 +02:00
Marijn Suijten 06b4f8ef35
Vulkan 1.2.175: Provisional Video Extensions (#417)
* generator: Add edegecases for broken Video extension enum variants

* Replace deprecated `make_version()` with `make_api_version()`

* generator: Use the same predicate for push_next and its traits

Some structs turn out to be root structs when their name is not in the
`root_structs` set, even when they themselves extend another struct.
This was already taken care of for `push_next` which is emitted in this
situation, but the trait referenced by `push_next`'s `T` bound is still
relying on the `extends` field to not exist in `vk.xml` at all, leading
to it not being generated despite `push_next` needing it.

Fixes: 215511f ("Implement ExtendXXX for multiple root create infos if
there are more than 1")

* Update Vulkan-Headers to 12.175

* generator: Generate low-level structs with bindgen (for vk_video)
2021-06-06 11:00:29 +02:00
Rua f5e7cfe896
Impl trait functions directly on EntryCustom/Instance/Device (#412)
* Implement EntryV1_x, InstanceV1_x, DeviceV1_x functions directly
2021-04-30 17:13:23 +02:00
Steve Wooster cb2d94c3c7 Only scan memory_type_count memory types in examples
The example code originally checked all 32 memory types even if the
instance returned fewer memory types.
2020-10-29 12:17:08 -07:00
Steve Wooster 61476184e0
Simplify example memory selection (#329)
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>
2020-10-19 12:11:57 +02:00
Steve Wooster 5d5fc57746 Simplify example surface format selection
According to specs for vkGetPhysicalDeviceSurfaceFormatsKHR(), at least
one surface format must be returned, and returned formats must not be
VK_FORMAT_UNDEFINED.
2020-10-14 16:58:55 -07:00
Sebastian Aaltonen 64d1705730
Optimized example fences. Waited immediately. Now waits before reuse (next frame) (#327)
* Optimized example fences. Waited immediately. Now waits before reuse (next frame).

* rust fmt + clippy warning silenced

* Add comments for record_submit_commandbuffer

Co-authored-by: Sebastian Aaltonen <sebastian.aaltonen@unity3d.com>
Co-authored-by: Maik Klein <maikklein@googlemail.com>
2020-10-03 00:08:42 +02:00
Adrien Bennadji df504f8121 Update example to use ash-window 2020-09-04 14:05:16 -07:00
zedrian ac4d046d4b
Added VK_EXT_tooling_info extension support (#310)
* Added `VK_EXT_tooling_info` extension support.

* Formatting applied.

* cargo-clippy suggestions satisfied.

* cargo-clippy suggestions satisfied.
2020-07-02 12:10:05 +02:00
Maik Klein 4d6bb3949d
Fix clippy lints for 1.43 (#298) 2020-05-10 13:42:07 +02:00
Brian Merchant 93238e093b Use DebugUtils instead of DebugReport in example. 2020-04-29 12:20:54 -07:00
Friz64 da5de66ba4
Switch to VK_LAYER_KHRONOS_validation (#290) 2020-04-19 19:12:43 +02:00
Maik Klein c32f0dd739 Clippy lints for 1.42 2020-03-15 00:55:26 +01:00
Jonathan Plotner c105d2842c fix build errors for examples on osx (#260) 2020-01-26 09:29:52 +01:00
Maik Klein 855068323d
Address all the clippy lints (#233)
* Fix literals in vk.rs

* Address all the other clippy lints in ash

* Module level clippy lint

* More lints

* Make hashmaps generic for clippy

* Remove unused macro import
2019-10-20 17:18:40 +02:00
Benjamin Saunders 4e8090f0bb Replace version macros with const fns 2019-10-05 11:16:35 -07:00
maik 13398b0127 Avoid allocation for spirv shaders 2019-06-23 12:34:47 +02:00
Aaron Loucks 1b75f9eb5d Fix shader and texture data loading in examples
Load the example shader and texture files with `include_bytes!` so
that they can be run from the root project directory. Previously,
`cargn run --bin <EXAMPLE>` could only be run from the `examples`
directory.
2019-06-08 01:17:56 -04:00
bors[bot] 6d7e4bf120 Merge #215
215: Replace mem::uninitialized with mem::zeroed r=MaikKlein a=aloucks

Fixes #214

Co-authored-by: Aaron Loucks <aloucks@cofront.net>
2019-06-01 20:43:14 +00:00
Aaron Loucks 1ba1d46eb2 Update generator and examples to edition 2018 2019-05-25 15:34:18 -04:00
Aaron Loucks bd69ab969c Replace mem::uninitialized with mem::zeroed
Fixes #214
2019-05-25 15:13:17 -04:00
unknownue 9a6afac6ea Fix black screen for examples on macOS platform 2019-05-20 21:28:38 +08:00
Mac O'Brien 9139ebfd95 Formatting pass 2019-05-18 16:09:12 -05:00
Mac O'Brien 90d7218bda Return VkResult from get_physical_device_surface_support
Fixes #185
2019-05-18 15:56:26 -05:00
Maik Klein 4c1c8aa648 Remove mut 2019-03-04 10:16:56 +01:00
Maik Klein 04dbf20371 Transform the ptr chain sample into a test case 2019-03-04 09:56:53 +01:00
Maik Klein 3de2ca9a22 Implement ExtendsXXX for all builders as well 2019-02-28 10:59:46 +01:00