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

Replace cgmath with glam in the examples #2475

Merged
merged 8 commits into from
Feb 21, 2024

Conversation

stefnotch
Copy link
Contributor

  1. Update documentation to reflect any user-facing changes - in this repository.

  2. Make sure that the changes are covered by unit-tests.

  3. Run cargo clippy on the changes.

  4. Run cargo +nightly fmt on the changes.

  5. Please put changelog entries in the description of this Pull Request
    if knowledge of this change could be valuable to users. No need to put the
    entries to the changelog directly, they will be transferred to the changelog
    file by maintainers right after the Pull Request merge.

    Please remove any items from the template below that are not applicable.

  6. Describe in common words what is the purpose of this change, related
    Github Issues, and highlight important implementation aspects.

Changelog:

### Additions
- Support for the `glam` crate in the type_for_format! macro.

Changes the examples to use glam instead of cgmath.

I also added support for the glam crate in the type_for_format! macro.
However, I did not do any checking. Which means that code like

let x: vulkano::type_for_format!(glam, R16G16B16_SFLOAT) = Default::default();

will fail, since glam doesn't have a f16 floating point type. Is that fine?

The error message does tell the user roughly what went wrong, which is better than nothing.

   Compiling teapot v0.0.0 (C:\Coding\GitHub\Libraries\vulkano\examples\teapot)
error[E0433]: failed to resolve: could not find `f16` in `glam`
  --> examples\teapot\main.rs:62:12
   |
62 |     let x: vulkano::type_for_format!(glam, R16G16B16_SFLOAT) = Default::default();
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `f16` in `glam`
   |
   = note: this error originates in the macro `vulkano::type_for_format` (in Nightly

Cargo.toml Outdated Show resolved Hide resolved
Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
vulkano/autogen/formats.rs Show resolved Hide resolved
vulkano/autogen/formats.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@stefnotch
Copy link
Contributor Author

I fixed and tested the glam type_for_format code.

I used this for testing. I'll happily add some testing code along these lines, but am unsure of where one would add it.

fn print_type_of<T>(_: &T) {
    println!("{}", std::any::type_name::<T>())
}

    let x: vulkano::type_for_format!(glam, R8G8_UNORM) = Default::default();
    print_type_of(&x); // [u8; 2]
    let x: vulkano::type_for_format!(glam, R16G16_UNORM) = Default::default();
    print_type_of(&x); // glam::u16::u16vec2::U16Vec2
    let x: vulkano::type_for_format!(glam, R16G16_UINT) = Default::default();
    print_type_of(&x); // glam::u16::u16vec2::U16Vec2
    let x: vulkano::type_for_format!(glam, R16G16_SINT) = Default::default();
    print_type_of(&x); // glam::i16::i16vec2::I16Vec2

    // let x: vulkano::type_for_format!(glam, R16G16_SFLOAT) = Default::default();
    // print_type_of(&x); // Rust doesn't have a f16 type

    let x: vulkano::type_for_format!(glam, R32G32_UINT) = Default::default();
    print_type_of(&x); // glam::u32::uvec2::UVec2
    let x: vulkano::type_for_format!(glam, R32G32_SINT) = Default::default();
    print_type_of(&x); // glam::i32::ivec2::IVec2
    let x: vulkano::type_for_format!(glam, R32G32_SFLOAT) = Default::default();
    print_type_of(&x); // glam::f32::vec2::Vec2

    let x: vulkano::type_for_format!(glam, R64G64B64_UINT) = Default::default();
    print_type_of(&x); // glam::u64::u64vec3::U64Vec3
    let x: vulkano::type_for_format!(glam, R64G64B64_SINT) = Default::default();
    print_type_of(&x); // glam::i64::i64vec3::I64Vec3
    let x: vulkano::type_for_format!(glam, R64G64B64_SFLOAT) = Default::default();
    print_type_of(&x); // glam::f64::dvec3::DVec3

    let x: vulkano::type_for_format!(glam, ASTC_12x10_SFLOAT_BLOCK) = Default::default();
    print_type_of(&x); // [u8; 16]

@marc0246
Copy link
Contributor

We used to have a doc test for each of the crates but I removed it because it felt silly to pull in the behemoth that is nalgebra for one test.

@marc0246
Copy link
Contributor

Thank you for the work!

@marc0246 marc0246 merged commit d60677b into vulkano-rs:master Feb 21, 2024
5 checks passed
marc0246 added a commit that referenced this pull request Feb 21, 2024
AustinJ235 pushed a commit that referenced this pull request Mar 3, 2024
* Add runtime SPIR-V validation

* Remove copyright message

* fmt

* Up vk version in shader compilation (#2467)

* Up vk version in shader compilation

* Update test in codegen.rs

* cargo +nightly fmt

* Update lib.rs

* clippy + fmt fixes

* simplify changes

* post merge

* #2467 changelog

* Remove windows specific dnd disable (#2474)

* Fix unnecessarily strict validation for DRM format modifiers (#2469)

* #2469 changelog

* Add support for querying memory requirements directly from the device (#2470)

* #2470 changelog

* Make image_index and final_views accessible, and add new example. (#2473)

* Make image_index and final_views accessible, and new example.

The first 2 changes should make creating frame buffers easier.
The new example should make it easier to learn vulkano-util.

* Remove unnecessary imports, and run clippy.

* Run fmt.

* .acquire() no longer returns image_index

* rename final_views() to swapchain_image_views()

The name change makes it more consistent with swapchain_image_view().

Personally I don't understand why the field name is final_views, yet we externally in function names refer to it as swapchain image views and such like.

* Fractal example no longer creates framebuffer every frame.

* Game of life example no longer creates framebuffer every frame.

(Also removed a piece of code I had commented out, but had forgotten to remove from the fractal example.)

* Rename if_recreate_swapchain to on_recreate_swapchain and update acquire() documentation. to on_recreate_swapchain

* on_recreate_swapchain is now impl FnOnce instead of generics based FnMut

Thanks marc0246!

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* Replace empty comment with an actual comment.

---------

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* Fix `VulkanoWindowRenderer::swapchain_image_views` return type

I have only noticed this as I was writing the changelog.

@coolcatcoder for future reference, `&Vec<T>` is an anti-pattern. There's nothing more you can do with it than with `&[T]` (because the reference is immutable) and it means that we can't use a different underlying buffer without a breaking change.

* #2473 changelog

* Fix `VulkanoWindowRenderer::acquire` taking `&Vec<T>` as well

* Replace cgmath with glam in the examples (#2475)

* Replace cgmath with glam in the examples

* Implement type_for_format! for glam

* Remove comment where I'm freaking out because of OpenGL flashbacks

* Update Cargo.toml

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* Update vulkano/autogen/formats.rs

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* Fix glam type_for_format

* Format the code

---------

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* #2475 changelog

* Fix alignment checks when allocating buffers (#2476)

* #2476 changelog

* Add `DepthState::reverse` helper method (#2483)

* #2483 changelog

* Add runtime SPIR-V validation

* Remove copyright message

* fmt

---------

Co-authored-by: maratik123 <marat.buharov@gmail.com>
Co-authored-by: Okko Hakola <okkohakola@gmail.com>
Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
Co-authored-by: Katt <51190960+coolcatcoder@users.noreply.github.com>
Co-authored-by: stefnotch <stefnotch@users.noreply.github.com>
Co-authored-by: José Miguel Sánchez García <soy.jmi2k@gmail.com>
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.

2 participants