Use new struct AnimationTimer instead of Instant to prevent random test failures. (#7685)
@ -1,4 +1,4 @@
|
|||||||
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task, time::Instant};
|
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task};
|
||||||
|
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use glam::{Affine3A, Mat4, Quat, Vec3};
|
use glam::{Affine3A, Mat4, Quat, Vec3};
|
||||||
@ -6,6 +6,8 @@ use wgpu::util::DeviceExt;
|
|||||||
|
|
||||||
use wgpu::StoreOp;
|
use wgpu::StoreOp;
|
||||||
|
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
// from cube
|
// from cube
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||||
@ -135,7 +137,7 @@ struct Example {
|
|||||||
compute_bind_group: wgpu::BindGroup,
|
compute_bind_group: wgpu::BindGroup,
|
||||||
blit_pipeline: wgpu::RenderPipeline,
|
blit_pipeline: wgpu::RenderPipeline,
|
||||||
blit_bind_group: wgpu::BindGroup,
|
blit_bind_group: wgpu::BindGroup,
|
||||||
start_inst: Instant,
|
animation_timer: utils::AnimationTimer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::framework::Example for Example {
|
impl crate::framework::Example for Example {
|
||||||
@ -392,8 +394,6 @@ impl crate::framework::Example for Example {
|
|||||||
|
|
||||||
queue.submit(Some(encoder.finish()));
|
queue.submit(Some(encoder.finish()));
|
||||||
|
|
||||||
let start_inst = Instant::now();
|
|
||||||
|
|
||||||
Example {
|
Example {
|
||||||
rt_target,
|
rt_target,
|
||||||
rt_view,
|
rt_view,
|
||||||
@ -406,7 +406,7 @@ impl crate::framework::Example for Example {
|
|||||||
compute_bind_group,
|
compute_bind_group,
|
||||||
blit_pipeline,
|
blit_pipeline,
|
||||||
blit_bind_group,
|
blit_bind_group,
|
||||||
start_inst,
|
animation_timer: utils::AnimationTimer::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,7 +425,7 @@ impl crate::framework::Example for Example {
|
|||||||
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
|
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
|
||||||
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
||||||
|
|
||||||
let anim_time = self.start_inst.elapsed().as_secs_f64() as f32;
|
let anim_time = self.animation_timer.time();
|
||||||
|
|
||||||
self.tlas_package[0].as_mut().unwrap().transform =
|
self.tlas_package[0].as_mut().unwrap().transform =
|
||||||
affine_to_rows(&Affine3A::from_rotation_translation(
|
affine_to_rows(&Affine3A::from_rotation_translation(
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 479 KiB After Width: | Height: | Size: 310 KiB |
@ -1,7 +1,8 @@
|
|||||||
|
use crate::utils;
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use glam::{Mat4, Quat, Vec3};
|
use glam::{Mat4, Quat, Vec3};
|
||||||
use std::ops::IndexMut;
|
use std::ops::IndexMut;
|
||||||
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task, time::Instant};
|
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task};
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
|
|
||||||
// from cube
|
// from cube
|
||||||
@ -101,7 +102,7 @@ struct Example {
|
|||||||
tlas_package: wgpu::TlasPackage,
|
tlas_package: wgpu::TlasPackage,
|
||||||
pipeline: wgpu::RenderPipeline,
|
pipeline: wgpu::RenderPipeline,
|
||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
start_inst: Instant,
|
animation_timer: utils::AnimationTimer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::framework::Example for Example {
|
impl crate::framework::Example for Example {
|
||||||
@ -264,8 +265,6 @@ impl crate::framework::Example for Example {
|
|||||||
|
|
||||||
queue.submit(Some(encoder.finish()));
|
queue.submit(Some(encoder.finish()));
|
||||||
|
|
||||||
let start_inst = Instant::now();
|
|
||||||
|
|
||||||
Example {
|
Example {
|
||||||
uniforms,
|
uniforms,
|
||||||
uniform_buf,
|
uniform_buf,
|
||||||
@ -273,7 +272,7 @@ impl crate::framework::Example for Example {
|
|||||||
tlas_package,
|
tlas_package,
|
||||||
pipeline,
|
pipeline,
|
||||||
bind_group,
|
bind_group,
|
||||||
start_inst,
|
animation_timer: utils::AnimationTimer::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +305,7 @@ impl crate::framework::Example for Example {
|
|||||||
|
|
||||||
let side_count = 8;
|
let side_count = 8;
|
||||||
|
|
||||||
let anim_time = self.start_inst.elapsed().as_secs_f64() as f32;
|
let anim_time = self.animation_timer.time();
|
||||||
|
|
||||||
for x in 0..side_count {
|
for x in 0..side_count {
|
||||||
for y in 0..side_count {
|
for y in 0..side_count {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 584 KiB After Width: | Height: | Size: 336 KiB |
@ -1,9 +1,10 @@
|
|||||||
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task, time::Instant};
|
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task};
|
||||||
|
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use glam::{Affine3A, Mat4, Quat, Vec3};
|
use glam::{Affine3A, Mat4, Quat, Vec3};
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
|
|
||||||
|
use crate::utils;
|
||||||
use wgpu::StoreOp;
|
use wgpu::StoreOp;
|
||||||
|
|
||||||
// from cube
|
// from cube
|
||||||
@ -125,7 +126,7 @@ struct Example {
|
|||||||
compute_bind_group: wgpu::BindGroup,
|
compute_bind_group: wgpu::BindGroup,
|
||||||
blit_pipeline: wgpu::RenderPipeline,
|
blit_pipeline: wgpu::RenderPipeline,
|
||||||
blit_bind_group: wgpu::BindGroup,
|
blit_bind_group: wgpu::BindGroup,
|
||||||
start_inst: Instant,
|
animation_timer: utils::AnimationTimer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::framework::Example for Example {
|
impl crate::framework::Example for Example {
|
||||||
@ -385,8 +386,6 @@ impl crate::framework::Example for Example {
|
|||||||
|
|
||||||
queue.submit(Some(encoder.finish()));
|
queue.submit(Some(encoder.finish()));
|
||||||
|
|
||||||
let start_inst = Instant::now();
|
|
||||||
|
|
||||||
Example {
|
Example {
|
||||||
rt_target,
|
rt_target,
|
||||||
tlas_package,
|
tlas_package,
|
||||||
@ -394,7 +393,7 @@ impl crate::framework::Example for Example {
|
|||||||
compute_bind_group,
|
compute_bind_group,
|
||||||
blit_pipeline,
|
blit_pipeline,
|
||||||
blit_bind_group,
|
blit_bind_group,
|
||||||
start_inst,
|
animation_timer: utils::AnimationTimer::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +412,7 @@ impl crate::framework::Example for Example {
|
|||||||
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
|
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
|
||||||
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
||||||
|
|
||||||
let anim_time = self.start_inst.elapsed().as_secs_f64() as f32;
|
let anim_time = self.animation_timer.time();
|
||||||
|
|
||||||
self.tlas_package[0].as_mut().unwrap().transform =
|
self.tlas_package[0].as_mut().unwrap().transform =
|
||||||
affine_to_rows(&Affine3A::from_rotation_translation(
|
affine_to_rows(&Affine3A::from_rotation_translation(
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
|
use crate::utils;
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use glam::{Mat4, Quat, Vec3};
|
use glam::{Mat4, Quat, Vec3};
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::ops::IndexMut;
|
use std::ops::IndexMut;
|
||||||
use std::{borrow::Cow, future::Future, iter, mem, ops::Range, pin::Pin, task, time::Instant};
|
use std::{borrow::Cow, future::Future, iter, mem, ops::Range, pin::Pin, task};
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
|
|
||||||
// from cube
|
// from cube
|
||||||
@ -310,8 +311,8 @@ struct Example {
|
|||||||
tlas_package: wgpu::TlasPackage,
|
tlas_package: wgpu::TlasPackage,
|
||||||
pipeline: wgpu::RenderPipeline,
|
pipeline: wgpu::RenderPipeline,
|
||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
start_inst: Instant,
|
|
||||||
scene_components: SceneComponents,
|
scene_components: SceneComponents,
|
||||||
|
animation_timer: utils::AnimationTimer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::framework::Example for Example {
|
impl crate::framework::Example for Example {
|
||||||
@ -434,16 +435,14 @@ impl crate::framework::Example for Example {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
let start_inst = Instant::now();
|
|
||||||
|
|
||||||
Example {
|
Example {
|
||||||
uniforms,
|
uniforms,
|
||||||
uniform_buf,
|
uniform_buf,
|
||||||
tlas_package,
|
tlas_package,
|
||||||
pipeline,
|
pipeline,
|
||||||
bind_group,
|
bind_group,
|
||||||
start_inst,
|
|
||||||
scene_components,
|
scene_components,
|
||||||
|
animation_timer: utils::AnimationTimer::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +475,7 @@ impl crate::framework::Example for Example {
|
|||||||
|
|
||||||
let side_count = 2;
|
let side_count = 2;
|
||||||
|
|
||||||
let anim_time = self.start_inst.elapsed().as_secs_f64() as f32;
|
let anim_time = self.animation_timer.time();
|
||||||
|
|
||||||
for x in 0..side_count {
|
for x in 0..side_count {
|
||||||
for y in 0..side_count {
|
for y in 0..side_count {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 77 KiB |
@ -1,10 +1,12 @@
|
|||||||
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task, time::Instant};
|
use std::{borrow::Cow, future::Future, iter, mem, pin::Pin, task};
|
||||||
|
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use glam::{Mat4, Vec3};
|
use glam::{Mat4, Vec3};
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
use wgpu::{vertex_attr_array, IndexFormat, VertexBufferLayout};
|
use wgpu::{vertex_attr_array, IndexFormat, VertexBufferLayout};
|
||||||
|
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
// from cube
|
// from cube
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||||
@ -79,7 +81,7 @@ struct Example {
|
|||||||
index_buf: wgpu::Buffer,
|
index_buf: wgpu::Buffer,
|
||||||
pipeline: wgpu::RenderPipeline,
|
pipeline: wgpu::RenderPipeline,
|
||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
start_inst: Instant,
|
animation_timer: utils::AnimationTimer,
|
||||||
}
|
}
|
||||||
|
|
||||||
const CAM_LOOK_AT: Vec3 = Vec3::new(0.0, 1.0, -1.5);
|
const CAM_LOOK_AT: Vec3 = Vec3::new(0.0, 1.0, -1.5);
|
||||||
@ -290,7 +292,7 @@ impl crate::framework::Example for Example {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
let start_inst = Instant::now();
|
let animation_timer = utils::AnimationTimer::default();
|
||||||
|
|
||||||
Example {
|
Example {
|
||||||
uniforms,
|
uniforms,
|
||||||
@ -299,7 +301,7 @@ impl crate::framework::Example for Example {
|
|||||||
index_buf,
|
index_buf,
|
||||||
pipeline,
|
pipeline,
|
||||||
bind_group,
|
bind_group,
|
||||||
start_inst,
|
animation_timer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,10 +324,9 @@ impl crate::framework::Example for Example {
|
|||||||
const LIGHT_DISTANCE: f32 = 5.0;
|
const LIGHT_DISTANCE: f32 = 5.0;
|
||||||
const TIME_SCALE: f32 = -0.2;
|
const TIME_SCALE: f32 = -0.2;
|
||||||
const INITIAL_TIME: f32 = 1.0;
|
const INITIAL_TIME: f32 = 1.0;
|
||||||
let cos = (self.start_inst.elapsed().as_secs_f32() * TIME_SCALE + INITIAL_TIME).cos()
|
let time = self.animation_timer.time();
|
||||||
* LIGHT_DISTANCE;
|
let cos = (time * TIME_SCALE + INITIAL_TIME).cos() * LIGHT_DISTANCE;
|
||||||
let sin = (self.start_inst.elapsed().as_secs_f32() * TIME_SCALE + INITIAL_TIME).sin()
|
let sin = (time * TIME_SCALE + INITIAL_TIME).sin() * LIGHT_DISTANCE;
|
||||||
* LIGHT_DISTANCE;
|
|
||||||
|
|
||||||
let mut encoder =
|
let mut encoder =
|
||||||
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@ -1,6 +1,5 @@
|
|||||||
use glam::{Mat4, Vec3};
|
use glam::{Mat4, Vec3};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::time::Instant;
|
|
||||||
use wgpu::util::{BufferInitDescriptor, DeviceExt};
|
use wgpu::util::{BufferInitDescriptor, DeviceExt};
|
||||||
use wgpu::{include_wgsl, BufferUsages, IndexFormat, SamplerDescriptor};
|
use wgpu::{include_wgsl, BufferUsages, IndexFormat, SamplerDescriptor};
|
||||||
use wgpu::{
|
use wgpu::{
|
||||||
@ -9,6 +8,8 @@ use wgpu::{
|
|||||||
CreateBlasDescriptor, CreateTlasDescriptor, TlasInstance, TlasPackage,
|
CreateBlasDescriptor, CreateTlasDescriptor, TlasInstance, TlasPackage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
struct Example {
|
struct Example {
|
||||||
tlas_package: TlasPackage,
|
tlas_package: TlasPackage,
|
||||||
compute_pipeline: wgpu::ComputePipeline,
|
compute_pipeline: wgpu::ComputePipeline,
|
||||||
@ -16,7 +17,7 @@ struct Example {
|
|||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
blit_bind_group: wgpu::BindGroup,
|
blit_bind_group: wgpu::BindGroup,
|
||||||
storage_texture: wgpu::Texture,
|
storage_texture: wgpu::Texture,
|
||||||
start: Instant,
|
animation_timer: utils::AnimationTimer,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -360,7 +361,7 @@ impl crate::framework::Example for Example {
|
|||||||
bind_group,
|
bind_group,
|
||||||
blit_bind_group,
|
blit_bind_group,
|
||||||
storage_texture: storage_tex,
|
storage_texture: storage_tex,
|
||||||
start: Instant::now(),
|
animation_timer: utils::AnimationTimer::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +377,7 @@ impl crate::framework::Example for Example {
|
|||||||
|
|
||||||
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
|
fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
|
||||||
self.tlas_package[0].as_mut().unwrap().transform =
|
self.tlas_package[0].as_mut().unwrap().transform =
|
||||||
Mat4::from_rotation_y(self.start.elapsed().as_secs_f32())
|
Mat4::from_rotation_y(self.animation_timer.time())
|
||||||
.transpose()
|
.transpose()
|
||||||
.to_cols_array()[..12]
|
.to_cols_array()[..12]
|
||||||
.try_into()
|
.try_into()
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
@ -1,5 +1,6 @@
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::time::Instant;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
@ -264,3 +265,23 @@ pub(crate) async fn get_adapter_with_capabilities_or_from_env(
|
|||||||
);
|
);
|
||||||
adapter
|
adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A custom timer that only starts counting after the first call to get its time value.
|
||||||
|
/// Useful because some examples have animations that would otherwise get started at initialization
|
||||||
|
/// leading to random CI fails.
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct AnimationTimer {
|
||||||
|
start_time: Option<Instant>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AnimationTimer {
|
||||||
|
pub fn time(&mut self) -> f32 {
|
||||||
|
match self.start_time {
|
||||||
|
None => {
|
||||||
|
self.start_time = Some(Instant::now());
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
Some(ref instant) => instant.elapsed().as_secs_f32(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||