Skip to content

Commit

Permalink
Merge branch 'main' into buffercontenttraitonly
Browse files Browse the repository at this point in the history
updating this feature branch after years of neglect
  • Loading branch information
jonathandw743 committed Dec 11, 2024
2 parents cc70ad2 + 55e27bc commit e377e42
Show file tree
Hide file tree
Showing 25 changed files with 438 additions and 122 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ env:
CARGO_INCREMENTAL: false
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
NIGHTLY: nightly-2023-02-11
NIGHTLY: nightly-2023-12-28

jobs:
msrv_and_minimal_versions:
name: Check MSRV and minimal-versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install tools
uses: taiki-e/install-action@v2
Expand All @@ -43,30 +43,30 @@ jobs:
name: Check format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: cargo fmt --check --all

clippy:
name: Check clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: cargo clippy --all-targets --workspace --all-features -- -D warnings

doc_tests:
name: Run doc tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: cargo test --doc --workspace --features mint,glam

docs:
name: Build docs
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: --cfg docs
RUSTDOCFLAGS: --cfg docsrs
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install nightly toolchain
run: rustup toolchain install $NIGHTLY --no-self-update --profile=minimal
Expand All @@ -77,7 +77,7 @@ jobs:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install tools
uses: taiki-e/install-action@v2
Expand All @@ -90,3 +90,16 @@ jobs:
sudo apt install -y mesa-vulkan-drivers vulkan-validationlayers
- run: cargo llvm-cov nextest --workspace --features mint,glam --fail-under-lines 80

tests_miri:
name: Run MIRI tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install nightly toolchain
run: |
rustup toolchain install $NIGHTLY --no-self-update --profile=minimal
rustup +$NIGHTLY component add miri
- run: cargo +$NIGHTLY miri test --workspace --features mint,glam
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## v0.10.0 (2024-09-13)

- Updated `glam` to v0.29
- Updated `nalgebra` to v0.33

## v0.9.0 (2024-06-22)

- Updated `glam` to v0.28
- Updated `vek` to v0.17
- Updated `imbl` to v3

## v0.8.0 (2024-04-24)

- Internal optimization: faster copying of POD types
- Added support for writing to uninitialized memory
- Increased MSRV to 1.68.2
- Updated `glam` to v0.27

## v0.7.0 (2024-01-02)

- Allow buffer types to accept `?Sized` types
- Fix min `syn` version (v2.0.1)
- Updated `glam` to v0.25
- Updated `vek` to v0.16
- Updated `rpds` to v1
- Updated `archery` to v1

## v0.6.1 (2023-05-09)

- Fix erroring on attributes not owned by this crate
Expand Down
17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "encase"
version = "0.6.1"
version = "0.10.0"
edition = "2021"
rust-version = "1.63"
rust-version = "1.68.2"

license = "MIT-0"
readme = "./README.md"
Expand All @@ -14,7 +14,6 @@ categories = ["rendering"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docs"]

[profile.bench]
lto = "thin"
Expand All @@ -29,17 +28,17 @@ harness = false
members = ["derive", "derive/impl"]

[dependencies]
encase_derive = { version = "=0.6.1", path = "derive" }
encase_derive = { version = "=0.10.0", path = "derive" }

thiserror = { version = "1", default-features = false }
const_panic = { version = "0.2", default-features = false }

mint = { version = "0.5.9", default-features = false, optional = true }
cgmath = { version = "0.18", default-features = false, optional = true }
glam = { version = "0.24", features = ["std"], default-features = false, optional = true }
nalgebra = { version = "0.32", default-features = false, optional = true }
glam = { version = "0.29", features = ["std"], default-features = false, optional = true }
nalgebra = { version = "0.33", default-features = false, optional = true }
ultraviolet = { version = "0.9", features = ["int"], default-features = false, optional = true }
vek = { version = "0.16", default-features = false, optional = true }
vek = { version = "0.17", default-features = false, optional = true }
smallvec = { version = "1.8.0", features = ["const_generics"], default-features = false, optional = true }
arrayvec = { version = "0.7", default-features = false, optional = true }
tinyvec = { version = "1.4", features = ["rustc_1_55", "alloc"], default-features = false, optional = true }
Expand All @@ -48,14 +47,14 @@ rpds = { version = "1", default-features = false, optional = true }
archery = { version = "1", default-features = false, optional = true }
im = { version = "15", default-features = false, optional = true }
im-rc = { version = "15", default-features = false, optional = true }
imbl = { version = "2", default-features = false, optional = true }
imbl = { version = "3", default-features = false, optional = true }
static-rc = { version = "0.6", features = ["alloc"], default-features = false, optional = true }

[dev-dependencies]
criterion = { version = "0.4", features = ["cargo_bench_support", "html_reports"], default-features = false }
rand = { version = "0.8", features = ["std_rng"], default-features = false }
mimalloc = { version = "0.1", default-features = false }
wgpu = { version = "0.17", features = ["wgsl"], default-features = false }
wgpu = { version = "22.0.0", features = ["wgsl"] }
futures = { version = "0.3", features = ["executor"], default-features = false }
pprof = { version = "0.11", features = ["criterion", "flamegraph"], default-features = false }
trybuild = { version = "1", default-features = false }
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let transform = AffineTransform2D {
translate: glam::Vec2::ZERO,
};

let mut buffer = UniformBuffer::new(Vec::new());
let mut buffer = UniformBuffer::new(Vec::<u8>::new());
buffer.write(&transform).unwrap();
let byte_buffer = buffer.into_inner();

Expand Down Expand Up @@ -94,7 +94,7 @@ let mut positions = Positions {
])
};

let mut byte_buffer = Vec::new();
let mut byte_buffer: Vec<u8> = Vec::new();

let mut buffer = StorageBuffer::new(&mut byte_buffer);
buffer.write(&positions).unwrap();
Expand All @@ -118,7 +118,7 @@ Write different data types to dynamic storage buffer
```rust
use encase::{ShaderType, DynamicStorageBuffer};

let mut byte_buffer = Vec::new();
let mut byte_buffer: Vec<u8> = Vec::new();

let mut buffer = DynamicStorageBuffer::new_with_alignment(&mut byte_buffer, 64);
let offsets = [
Expand All @@ -133,6 +133,38 @@ assert_eq!(offsets, [0, 64, 192]);

```

Supports writing to uninitialized memory as well.

```rust
use std::mem::MaybeUninit;
use encase::{ShaderType, DynamicStorageBuffer};

let mut uninit_buffer: Vec<MaybeUninit<u8>> = Vec::new();

let mut buffer = DynamicStorageBuffer::new_with_alignment(&mut uninit_buffer, 64);
let offsets = [
buffer.write(&[5.; 10]).unwrap(),
buffer.write(&vec![3u32; 20]).unwrap(),
buffer.write(&glam::Vec3::ONE).unwrap(),
];

// SAFETY: Vec<u8> and Vec<MaybeUninit<u8>> share the same layout.
let byte_buffer: Vec<u8> = unsafe {
Vec::from_raw_parts(
uninit_buffer.as_mut_ptr().cast(),
uninit_buffer.len(),
uninit_buffer.capacity()
)
};

std::mem::forget(uninit_buffer);

// write byte_buffer to GPU

assert_eq!(offsets, [0, 64, 192]);

```

[host-shareable types]: https://gpuweb.github.io/gpuweb/wgsl/#host-shareable-types
[features]: https://docs.rs/crate/encase/latest/features
[`ShaderType`]: https://docs.rs/encase/latest/encase/trait.ShaderType.html
Expand Down
10 changes: 5 additions & 5 deletions benches/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,35 @@ fn bench(c: &mut Criterion) {
|| create_vecs(a, size),
|(src, dst)| dst.write(src).unwrap(),
criterion::BatchSize::LargeInput,
)
);
});
group.bench_function(format!("{name}_read"), |b| {
b.iter_batched_ref(
|| create_vecs(a, size),
|(src, dst)| dst.read(src).unwrap(),
criterion::BatchSize::LargeInput,
)
);
});
group.bench_function(format!("{name}_create"), |b| {
b.iter_batched_ref(
|| create_vecs(a, size),
|(_src, dst)| dst.create::<Vec<A>>().unwrap(),
criterion::BatchSize::LargeInput,
)
);
});
group.bench_function(format!("{name}_manual"), |b| {
b.iter_batched_ref(
|| create_aligned_vecs(size),
|(dst, src)| manual_memcpy(dst, src),
criterion::BatchSize::LargeInput,
)
);
});
group.bench_function(format!("{name}_stdlib"), |b| {
b.iter_batched_ref(
|| create_aligned_vecs(size),
|(dst, src)| dst.copy_from_slice(src),
criterion::BatchSize::LargeInput,
)
);
});
}

Expand Down
4 changes: 2 additions & 2 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "encase_derive"
version = "0.6.1"
version = "0.10.0"
edition = "2021"

license = "MIT-0"
Expand All @@ -14,4 +14,4 @@ categories = ["rendering"]
proc-macro = true

[dependencies]
encase_derive_impl = { version = "=0.6.1", path = "./impl" }
encase_derive_impl = { version = "=0.10.0", path = "./impl" }
2 changes: 1 addition & 1 deletion derive/impl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "encase_derive_impl"
version = "0.6.1"
version = "0.10.0"
edition = "2021"

license = "MIT-0"
Expand Down
4 changes: 4 additions & 0 deletions derive/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
alignment: struct_alignment,
has_uniform_min_alignment: true,
min_size,
is_pod: false,
extra,
}
};
Expand All @@ -614,6 +615,7 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
Self: #root::ShaderType<ExtraMetadata = #root::StructMetadata<#nr_of_fields>>,
#( for<'__> #field_types_2: #root::WriteInto, )*
{
#[inline]
fn write_into<B: #root::BufferMut>(&self, writer: &mut #root::Writer<B>) {
#set_contained_rt_sized_array_length
#( #write_into_buffer_body )*
Expand All @@ -625,6 +627,7 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
Self: #root::ShaderType<ExtraMetadata = #root::StructMetadata<#nr_of_fields>>,
#( for<'__> #field_types_3: #root::ReadFrom, )*
{
#[inline]
fn read_from<B: #root::BufferRef>(&mut self, reader: &mut #root::Reader<B>) {
#( #read_from_buffer_body )*
}
Expand All @@ -635,6 +638,7 @@ pub fn derive_shader_type(input: DeriveInput, root: &Path) -> TokenStream {
Self: #root::ShaderType<ExtraMetadata = #root::StructMetadata<#nr_of_fields>>,
#( for<'__> #field_types_4: #root::CreateFrom, )*
{
#[inline]
fn create_from<B: #root::BufferRef>(reader: &mut #root::Reader<B>) -> Self {
#( #create_from_buffer_body )*

Expand Down
2 changes: 1 addition & 1 deletion src/core/alignment_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl AlignmentValue {
#[inline]
pub const fn from_next_power_of_two_size(size: SizeValue) -> Self {
match size.get().checked_next_power_of_two() {
None => panic!("Overflow occured while getting the next power of 2!"),
None => panic!("Overflow occurred while getting the next power of 2!"),
Some(val) => {
// SAFETY: This is safe since we got the next_power_of_two
Self(unsafe { NonZeroU64::new_unchecked(val) })
Expand Down
Loading

0 comments on commit e377e42

Please sign in to comment.