Skip to content

Commit

Permalink
WIP: refactor(types)!: SampleCount newtype
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jul 5, 2024
1 parent 25bc704 commit 46f1943
Show file tree
Hide file tree
Showing 67 changed files with 254 additions and 164 deletions.
4 changes: 2 additions & 2 deletions benches/benches/renderpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl RenderpassState {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: wgpu::SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::TEXTURE_BINDING,
Expand Down Expand Up @@ -220,7 +220,7 @@ impl RenderpassState {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: wgpu::SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct CreateRenderBundleEncoderArgs {
label: String,
color_formats: Vec<Option<wgpu_types::TextureFormat>>,
depth_stencil_format: Option<wgpu_types::TextureFormat>,
sample_count: u32,
sample_count: wgpu_types::SampleCount,
depth_read_only: bool,
stencil_read_only: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ struct GpuVertexState {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct GpuMultisampleState {
count: u32,
count: wgpu_types::SampleCount,
mask: u64,
alpha_to_coverage_enabled: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct CreateTextureArgs {
label: String,
size: wgpu_types::Extent3d,
mip_level_count: u32,
sample_count: u32,
sample_count: wgpu_types::SampleCount,
dimension: wgpu_types::TextureDimension,
format: wgpu_types::TextureFormat,
usage: u32,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bunnymark/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bytemuck::{Pod, Zeroable};
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, mem};
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, SampleCount};
use winit::{
event::{ElementState, KeyEvent},
keyboard::{Key, NamedKey},
Expand Down Expand Up @@ -243,7 +243,7 @@ impl crate::framework::Example for Example {
label: None,
size,
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING,
Expand Down
4 changes: 3 additions & 1 deletion examples/src/conservative_raster/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::borrow::Cow;

use wgpu::SampleCount;

const RENDER_TARGET_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;

struct Example {
Expand Down Expand Up @@ -28,7 +30,7 @@ impl Example {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: RENDER_TARGET_FORMAT,
usage: wgpu::TextureUsages::TEXTURE_BINDING
Expand Down
4 changes: 2 additions & 2 deletions examples/src/cube/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts, mem};
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, SampleCount};

#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
Expand Down Expand Up @@ -173,7 +173,7 @@ impl crate::framework::Example for Example {
label: None,
size: texture_extent,
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::R8Uint,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
Expand Down
2 changes: 1 addition & 1 deletion examples/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl<E: Example + wgpu::WasmNotSendSync> From<ExampleTestParams<E>>
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: wgpu::SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts, mem};
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, SampleCount};

const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
const MIP_LEVEL_COUNT: u32 = 10;
Expand Down Expand Up @@ -232,7 +232,7 @@ impl crate::framework::Example for Example {
let texture = device.create_texture(&wgpu::TextureDescriptor {
size: texture_extent,
mip_level_count: MIP_LEVEL_COUNT,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: TEXTURE_FORMAT,
usage: wgpu::TextureUsages::TEXTURE_BINDING
Expand Down
16 changes: 8 additions & 8 deletions examples/src/msaa_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use std::{borrow::Cow, iter};

use bytemuck::{Pod, Zeroable};
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, SampleCount};

use winit::{
event::{ElementState, KeyEvent, WindowEvent},
Expand All @@ -31,10 +31,10 @@ struct Example {
multisampled_framebuffer: wgpu::TextureView,
vertex_buffer: wgpu::Buffer,
vertex_count: u32,
sample_count: u32,
sample_count: SampleCount,
rebuild_bundle: bool,
config: wgpu::SurfaceConfiguration,
max_sample_count: u32,
max_sample_count: SampleCount,
}

impl Example {
Expand All @@ -43,7 +43,7 @@ impl Example {
config: &wgpu::SurfaceConfiguration,
shader: &wgpu::ShaderModule,
pipeline_layout: &wgpu::PipelineLayout,
sample_count: u32,
sample_count: SampleCount,
vertex_buffer: &wgpu::Buffer,
vertex_count: u32,
) -> wgpu::RenderBundle {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Example {
fn create_multisampled_framebuffer(
device: &wgpu::Device,
config: &wgpu::SurfaceConfiguration,
sample_count: u32,
sample_count: SampleCount,
) -> wgpu::TextureView {
let multisampled_texture_extent = wgpu::Extent3d {
width: config.width,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl crate::framework::Example for Example {
.get_texture_format_features(config.view_formats[0])
.flags;

let max_sample_count = {
let max_sample_count = SampleCount::new({
if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X16) {
16
} else if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X8) {
Expand All @@ -152,7 +152,7 @@ impl crate::framework::Example for Example {
} else {
1
}
};
});

let sample_count = max_sample_count;

Expand Down Expand Up @@ -233,7 +233,7 @@ impl crate::framework::Example for Example {
// supported sample counts to the user.
Key::Named(NamedKey::ArrowLeft) => {
if self.sample_count == self.max_sample_count {
self.sample_count = 1;
self.sample_count = SampleCount::new(1);
self.rebuild_bundle = true;
}
}
Expand Down
4 changes: 3 additions & 1 deletion examples/src/render_to_texture/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use wgpu::SampleCount;

#[cfg(not(target_arch = "wasm32"))]
use crate::utils::output_image_native;
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -40,7 +42,7 @@ async fn run(_path: Option<String>) {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC,
Expand Down
9 changes: 6 additions & 3 deletions examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::{borrow::Cow, f32::consts, iter, mem, ops::Range, sync::Arc};

use bytemuck::{Pod, Zeroable};
use wgpu::util::{align_to, DeviceExt};
use wgpu::{
util::{align_to, DeviceExt},
SampleCount,
};

#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
Expand Down Expand Up @@ -189,7 +192,7 @@ impl Example {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: Self::DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
Expand Down Expand Up @@ -378,7 +381,7 @@ impl crate::framework::Example for Example {
let shadow_texture = device.create_texture(&wgpu::TextureDescriptor {
size: Self::SHADOW_SIZE,
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: Self::SHADOW_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
Expand Down
6 changes: 3 additions & 3 deletions examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, f32::consts};
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel, SampleCount};

const IMAGE_SIZE: u32 = 256;

Expand Down Expand Up @@ -77,7 +77,7 @@ impl Example {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: Self::DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
Expand Down Expand Up @@ -332,7 +332,7 @@ impl crate::framework::Example for Example {
&wgpu::TextureDescriptor {
size,
mip_level_count: header.level_count,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: skybox_format,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
Expand Down
5 changes: 3 additions & 2 deletions examples/src/stencil_triangles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bytemuck::{Pod, Zeroable};
use std::borrow::Cow;
use std::mem;
use wgpu::util::DeviceExt;
use wgpu::SampleCount;

#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
Expand Down Expand Up @@ -153,7 +154,7 @@ impl crate::framework::Example for Example {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Stencil8,
view_formats: &[],
Expand Down Expand Up @@ -188,7 +189,7 @@ impl crate::framework::Example for Example {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Stencil8,
view_formats: &[],
Expand Down
4 changes: 3 additions & 1 deletion examples/src/storage_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//! A lot of things aren't explained here via comments. See hello-compute and
//! repeated-compute for code that is more thoroughly commented.

use wgpu::SampleCount;

#[cfg(not(target_arch = "wasm32"))]
use crate::utils::output_image_native;
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -54,7 +56,7 @@ async fn run(_path: Option<String>) {
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/texture_arrays/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use std::num::{NonZeroU32, NonZeroU64};
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, SampleCount};

#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
Expand Down Expand Up @@ -156,7 +156,7 @@ impl crate::framework::Example for Example {
let texture_descriptor = wgpu::TextureDescriptor {
size: wgpu::Extent3d::default(),
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! The period, i.e. the unit of time, of the timestamps in wgpu is undetermined and needs to be queried with `wgpu::Queue::get_timestamp_period`
//! in order to get comparable results.

use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, SampleCount};

struct Queries {
set: wgpu::QuerySet,
Expand Down Expand Up @@ -377,7 +377,7 @@ fn render_pass(
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
Expand Down
8 changes: 4 additions & 4 deletions examples/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bytemuck::{Pod, Zeroable};
use glam::Vec3;
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, f32::consts, iter, mem};
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, SampleCount};

///
/// Radius of the terrain.
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Example {
label: Some("Reflection Render Texture"),
size: texture_extent,
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: config.view_formats[0],
usage: wgpu::TextureUsages::TEXTURE_BINDING
Expand All @@ -201,7 +201,7 @@ impl Example {
label: Some("Depth Buffer"),
size: texture_extent,
mip_level_count: 1,
sample_count: 1,
sample_count: SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Depth32Float,
usage: wgpu::TextureUsages::TEXTURE_BINDING
Expand Down Expand Up @@ -626,7 +626,7 @@ impl crate::framework::Example for Example {
depth_read_only: false,
stencil_read_only: true,
}),
sample_count: 1,
sample_count: SampleCount::new(1),
multiview: None,
});
encoder.set_pipeline(&terrain_pipeline);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/bgra8unorm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new()
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
sample_count: wgpu::SampleCount::new(1),
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Bgra8Unorm,
usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC,
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/clear_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async fn single_texture_clear_test(
// arbitrary value between 2 and max
3
},
sample_count: 1, // multisampling is not supported for clear
sample_count: wgpu::SampleCount::new(1), // multisampling is not supported for clear
dimension,
format,
usage: wgpu::TextureUsages::COPY_SRC | extra_usages,
Expand Down
Loading

0 comments on commit 46f1943

Please sign in to comment.