Skip to content

Commit

Permalink
Make shadow example runnable on iOS Android devices (#2433)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili authored Feb 1, 2022
1 parent 23fab7a commit b10f7ed
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,17 @@ impl framework::Example for Example {

let entity_uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
let num_entities = 1 + cube_descs.len() as wgpu::BufferAddress;
let uniform_alignment =
device.limits().min_uniform_buffer_offset_alignment as wgpu::BufferAddress;
assert!(entity_uniform_size <= uniform_alignment);
// Make the `uniform_alignment` >= `entity_uniform_size` and aligned to `min_uniform_buffer_offset_alignment`.
let uniform_alignment = {
let alignment =
device.limits().min_uniform_buffer_offset_alignment as wgpu::BufferAddress;
let rem = entity_uniform_size % alignment;
if rem != 0 {
entity_uniform_size + alignment - rem
} else {
entity_uniform_size
}
};
// Note: dynamic uniform offsets also have to be aligned to `Limits::min_uniform_buffer_offset_alignment`.
let entity_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
Expand Down

0 comments on commit b10f7ed

Please sign in to comment.