Skip to content

Commit

Permalink
Merge pull request #17 from Wumpf/wgpu-upgrade-0.13-followup
Browse files Browse the repository at this point in the history
Wgpu upgrade 0.13 followup
  • Loading branch information
Wumpf authored Jul 10, 2022
2 parents ac08b0a + eb7870c commit d83c396
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wgpu-profiler"
version = "0.8.0"
version = "0.9.0"
authors = ["Andreas Reich <[email protected]>"]
edition = "2018"
description = "Simple profiler scopes for wgpu using timer queries"
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: GpuProfiler::REQUIRED_WGPU_FEATURES,
features: GpuProfiler::ALL_WGPU_TIMER_FEATURES,
limits: wgpu::Limits::default(),
},
None,
Expand Down
16 changes: 8 additions & 8 deletions examples/shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
struct VertexOutput {
[[location(0)]] coord: vec2<f32>;
[[location(1)]] instance: f32;
[[builtin(position)]] pos: vec4<f32>;
@location(0) coord: vec2<f32>,
@location(1) instance: f32,
@builtin(position) pos: vec4<f32>,
};

[[stage(vertex)]]
@vertex
fn vs_main(
[[builtin(vertex_index)]] vertex_index: u32,
[[builtin(instance_index)]] instance_index: u32,
@builtin(vertex_index) vertex_index: u32,
@builtin(instance_index) instance_index: u32,
) -> VertexOutput {
var out: VertexOutput;

Expand All @@ -24,8 +24,8 @@ fn vs_main(
return out;
}

[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
var c: vec2<f32> = vec2<f32>(-0.79, 0.15);
if (in.instance == 0.0) {
c = vec2<f32>(-1.476, 0.0);
Expand Down
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ pub struct GpuProfiler {
// Public interface
#[deny(missing_docs)]
impl GpuProfiler {
/// Required wgpu features for timer scopes.
pub const REQUIRED_WGPU_FEATURES: wgpu::Features = wgpu::Features::TIMESTAMP_QUERY.union(wgpu::Features::WRITE_TIMESTAMP_INSIDE_PASSES);
/// Combination of all timer query features GpuProfiler can leverage.
pub const ALL_WGPU_TIMER_FEATURES: wgpu::Features = wgpu::Features::TIMESTAMP_QUERY.union(wgpu::Features::WRITE_TIMESTAMP_INSIDE_PASSES);

/// Combination of all timer query features GpuProfiler can leverage.
#[deprecated(since = "0.9.0", note = "Use ALL_WGPU_TIMER_FEATURES instead")]
pub const REQUIRED_WGPU_FEATURES: wgpu::Features = GpuProfiler::ALL_WGPU_TIMER_FEATURES;

/// Creates a new Profiler object.
///
Expand All @@ -45,7 +49,7 @@ impl GpuProfiler {
/// `active_features` should contain the features enabled on the device to
/// be used in the profiler scopes, these will be used to determine what
/// queries are supported and configure the profiler accordingly
/// (see [`GpuProfiler::REQUIRED_WGPU_FEATURES`])
/// (see [`GpuProfiler::ALL_WGPU_TIMER_FEATURES`])
///
/// A profiler queues up to `max_num_pending_frames` "profiler-frames" at a time.
/// A profiler-frame is in-flight until its queries have been successfully resolved using [`GpuProfiler::process_finished_frame`].
Expand Down Expand Up @@ -179,7 +183,7 @@ impl GpuProfiler {
let mapped_buffers = self.active_frame.mapped_buffers.clone();
pool.resolved_buffer_slice().map_async(wgpu::MapMode::Read, move |res| {
res.unwrap();
mapped_buffers.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
mapped_buffers.fetch_add(1, std::sync::atomic::Ordering::Release);
});
}

Expand All @@ -198,7 +202,7 @@ impl GpuProfiler {
let frame = self.pending_frames.first_mut()?;

// We only process if all mappings succeed.
if frame.mapped_buffers.load(std::sync::atomic::Ordering::SeqCst) != frame.query_pools.len() {
if frame.mapped_buffers.load(std::sync::atomic::Ordering::Acquire) != frame.query_pools.len() {
return None;
}

Expand Down

0 comments on commit d83c396

Please sign in to comment.