Skip to content

Commit

Permalink
Cleanups for WebGPU
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Apr 12, 2023
1 parent d781bb7 commit 47a2b05
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 50 deletions.
2 changes: 1 addition & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ impl NumericType {
Tf::Bc5RgUnorm | Tf::Bc5RgSnorm | Tf::EacRg11Unorm | Tf::EacRg11Snorm => {
(NumericDimension::Vector(Vs::Bi), Sk::Float)
}
Tf::Bc6hRgbUfloat | Tf::Bc6hRgbSfloat | Tf::Etc2Rgb8Unorm | Tf::Etc2Rgb8UnormSrgb => {
Tf::Bc6hRgbUfloat | Tf::Bc6hRgbFloat | Tf::Etc2Rgb8Unorm | Tf::Etc2Rgb8UnormSrgb => {
(NumericDimension::Vector(Vs::Tri), Sk::Float)
}
Tf::Astc {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
| Tf::Bc4RSnorm
| Tf::Bc5RgUnorm
| Tf::Bc5RgSnorm
| Tf::Bc6hRgbSfloat
| Tf::Bc6hRgbFloat
| Tf::Bc6hRgbUfloat
| Tf::Bc7RgbaUnorm
| Tf::Bc7RgbaUnormSrgb => bcn_features,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl super::AdapterShared {
Tf::Bc5RgUnorm => (glow::COMPRESSED_RG_RGTC2, glow::RG, 0),
Tf::Bc5RgSnorm => (glow::COMPRESSED_SIGNED_RG_RGTC2, glow::RG, 0),
Tf::Bc6hRgbUfloat => (glow::COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, glow::RGB, 0),
Tf::Bc6hRgbSfloat => (glow::COMPRESSED_RGB_BPTC_SIGNED_FLOAT, glow::RGB, 0),
Tf::Bc6hRgbFloat => (glow::COMPRESSED_RGB_BPTC_SIGNED_FLOAT, glow::RGB, 0),
Tf::Bc7RgbaUnorm => (glow::COMPRESSED_RGBA_BPTC_UNORM, glow::RGBA, 0),
Tf::Bc7RgbaUnormSrgb => (glow::COMPRESSED_SRGB_ALPHA_BPTC_UNORM, glow::RGBA, 0),
Tf::Etc2Rgb8Unorm => (glow::COMPRESSED_RGB8_ETC2, glow::RGB, 0),
Expand Down
2 changes: 1 addition & 1 deletion wgpu-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod inner {
wgpu::TextureFormat::Bc5RgUnorm,
wgpu::TextureFormat::Bc5RgSnorm,
wgpu::TextureFormat::Bc6hRgbUfloat,
wgpu::TextureFormat::Bc6hRgbSfloat,
wgpu::TextureFormat::Bc6hRgbFloat,
wgpu::TextureFormat::Bc7RgbaUnorm,
wgpu::TextureFormat::Bc7RgbaUnormSrgb,
wgpu::TextureFormat::Etc2Rgb8Unorm,
Expand Down
30 changes: 18 additions & 12 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ pub enum TextureFormat {
/// Also known as BPTC (float).
///
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
Bc6hRgbSfloat,
Bc6hRgbFloat,
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA.
/// [0, 255] converted to/from float [0, 1] in shader.
///
Expand Down Expand Up @@ -2258,7 +2258,7 @@ impl<'de> Deserialize<'de> for TextureFormat {
"bc5-rg-unorm" => TextureFormat::Bc5RgUnorm,
"bc5-rg-snorm" => TextureFormat::Bc5RgSnorm,
"bc6h-rgb-ufloat" => TextureFormat::Bc6hRgbUfloat,
"bc6h-rgb-float" => TextureFormat::Bc6hRgbSfloat,
"bc6h-rgb-float" => TextureFormat::Bc6hRgbFloat,
"bc7-rgba-unorm" => TextureFormat::Bc7RgbaUnorm,
"bc7-rgba-unorm-srgb" => TextureFormat::Bc7RgbaUnormSrgb,
"etc2-rgb8unorm" => TextureFormat::Etc2Rgb8Unorm,
Expand Down Expand Up @@ -2384,7 +2384,7 @@ impl Serialize for TextureFormat {
TextureFormat::Bc5RgUnorm => "bc5-rg-unorm",
TextureFormat::Bc5RgSnorm => "bc5-rg-snorm",
TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat",
TextureFormat::Bc6hRgbSfloat => "bc6h-rgb-float",
TextureFormat::Bc6hRgbFloat => "bc6h-rgb-float",
TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm",
TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb",
TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm",
Expand Down Expand Up @@ -2574,7 +2574,7 @@ impl TextureFormat {
| Self::Bc5RgUnorm
| Self::Bc5RgSnorm
| Self::Bc6hRgbUfloat
| Self::Bc6hRgbSfloat
| Self::Bc6hRgbFloat
| Self::Bc7RgbaUnorm
| Self::Bc7RgbaUnormSrgb => (4, 4),

Expand Down Expand Up @@ -2678,7 +2678,7 @@ impl TextureFormat {
| Self::Bc5RgUnorm
| Self::Bc5RgSnorm
| Self::Bc6hRgbUfloat
| Self::Bc6hRgbSfloat
| Self::Bc6hRgbFloat
| Self::Bc7RgbaUnorm
| Self::Bc7RgbaUnormSrgb => Features::TEXTURE_COMPRESSION_BC,

Expand Down Expand Up @@ -2784,7 +2784,7 @@ impl TextureFormat {
Self::Bc5RgUnorm => ( noaa, basic),
Self::Bc5RgSnorm => ( noaa, basic),
Self::Bc6hRgbUfloat => ( noaa, basic),
Self::Bc6hRgbSfloat => ( noaa, basic),
Self::Bc6hRgbFloat => ( noaa, basic),
Self::Bc7RgbaUnorm => ( noaa, basic),
Self::Bc7RgbaUnormSrgb => ( noaa, basic),

Expand Down Expand Up @@ -2890,7 +2890,7 @@ impl TextureFormat {
| Self::Bc5RgUnorm
| Self::Bc5RgSnorm
| Self::Bc6hRgbUfloat
| Self::Bc6hRgbSfloat
| Self::Bc6hRgbFloat
| Self::Bc7RgbaUnorm
| Self::Bc7RgbaUnormSrgb => Some(float),

Expand Down Expand Up @@ -2974,7 +2974,7 @@ impl TextureFormat {
| Self::Bc5RgUnorm
| Self::Bc5RgSnorm
| Self::Bc6hRgbUfloat
| Self::Bc6hRgbSfloat
| Self::Bc6hRgbFloat
| Self::Bc7RgbaUnorm
| Self::Bc7RgbaUnormSrgb => Some(16),

Expand Down Expand Up @@ -3284,7 +3284,7 @@ fn texture_format_serialize() {
"\"bc6h-rgb-ufloat\"".to_string()
);
assert_eq!(
serde_json::to_string(&TextureFormat::Bc6hRgbSfloat).unwrap(),
serde_json::to_string(&TextureFormat::Bc6hRgbFloat).unwrap(),
"\"bc6h-rgb-float\"".to_string()
);
assert_eq!(
Expand Down Expand Up @@ -3577,7 +3577,7 @@ fn texture_format_deserialize() {
);
assert_eq!(
serde_json::from_str::<TextureFormat>("\"bc6h-rgb-float\"").unwrap(),
TextureFormat::Bc6hRgbSfloat
TextureFormat::Bc6hRgbFloat
);
assert_eq!(
serde_json::from_str::<TextureFormat>("\"bc7-rgba-unorm\"").unwrap(),
Expand Down Expand Up @@ -5160,9 +5160,15 @@ impl<L> CommandBufferDescriptor<L> {
pub struct RenderBundleDepthStencil {
/// Format of the attachment.
pub format: TextureFormat,
/// True if the depth aspect is used but not modified.
/// If the depth aspect of the depth stencil attachment is going to be written to.
///
/// This must match the [`RenderPassDepthStencilAttachment::depth_ops`] of the renderpass this render bundle is executed in.
/// If depth_ops is `Some(..)` this must be false. If it is `None` this must be true.
pub depth_read_only: bool,
/// True if the stencil aspect is used but not modified.
/// If the stencil aspect of the depth stencil attachment is going to be written to.
///
/// This must match the [`RenderPassDepthStencilAttachment::stencil_ops`] of the renderpass this render bundle is executed in.
/// If depth_ops is `Some(..)` this must be false. If it is `None` this must be true.
pub stencil_read_only: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/boids/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl framework::Example for Example {
fragment: Some(wgpu::FragmentState {
module: &draw_shader,
entry_point: "main_fs",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl framework::Example for Example {
module: &shader,
entry_point: "fs_main",
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
format: config.view_formats[0],
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrites::default(),
})],
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/conservative-raster/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl framework::Example for Example {
fragment: Some(wgpu::FragmentState {
module: &shader_triangle_and_lines,
entry_point: "fs_main_white",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
polygon_mode: wgpu::PolygonMode::Line,
Expand Down Expand Up @@ -213,7 +213,7 @@ impl framework::Example for Example {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl framework::Example for Example {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
cull_mode: Some(wgpu::Face::Back),
Expand All @@ -298,7 +298,7 @@ impl framework::Example for Example {
module: &shader,
entry_point: "fs_wire",
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
format: config.view_formats[0],
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent {
operation: wgpu::BlendOperation::Add,
Expand Down
9 changes: 6 additions & 3 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ fn start<E: Example>(
let mut config = surface
.get_default_config(&adapter, size.width, size.height)
.expect("Surface isn't supported by the adapter.");
let surface_view_format = config.format.add_srgb_suffix();
config.view_formats.push(surface_view_format);
surface.configure(&device, &config);

log::info!("Initializing the example...");
Expand Down Expand Up @@ -369,9 +371,10 @@ fn start<E: Example>(
.expect("Failed to acquire next surface texture!")
}
};
let view = frame
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let view = frame.texture.create_view(&wgpu::TextureViewDescriptor {
format: Some(surface_view_format),
..wgpu::TextureViewDescriptor::default()
});

example.render(&view, &device, &queue, &spawner);

Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/mipmap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl framework::Example for Example {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
Expand Down
10 changes: 6 additions & 4 deletions wgpu/examples/msaa-line/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Example {
fragment: Some(wgpu::FragmentState {
module: shader,
entry_point: "fs_main",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::LineList,
Expand All @@ -78,7 +78,7 @@ impl Example {
let mut encoder =
device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor {
label: None,
color_formats: &[Some(config.format)],
color_formats: &[Some(config.view_formats[0])],
depth_stencil: None,
sample_count,
multiview: None,
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Example {
mip_level_count: 1,
sample_count,
dimension: wgpu::TextureDimension::D2,
format: config.format,
format: config.view_formats[0],
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
label: None,
view_formats: &[],
Expand All @@ -131,7 +131,9 @@ impl framework::Example for Example {
) -> Self {
log::info!("Press left/right arrow keys to change sample_count.");

let sample_flags = _adapter.get_texture_format_features(config.format).flags;
let sample_flags = _adapter
.get_texture_format_features(config.view_formats[0])
.flags;

let max_sample_count = {
if sample_flags.contains(wgpu::TextureFormatFeatureFlags::MULTISAMPLE_X16) {
Expand Down
8 changes: 4 additions & 4 deletions wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl framework::Example for Example {
}

fn init(
sc_desc: &wgpu::SurfaceConfiguration,
config: &wgpu::SurfaceConfiguration,
adapter: &wgpu::Adapter,
device: &wgpu::Device,
_queue: &wgpu::Queue,
Expand Down Expand Up @@ -593,7 +593,7 @@ impl framework::Example for Example {
push_constant_ranges: &[],
});

let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
let mx_total = Self::generate_matrix(config.width as f32 / config.height as f32);
let forward_uniforms = GlobalUniforms {
proj: mx_total.to_cols_array_2d(),
num_lights: [lights.len() as u32, 0, 0, 0],
Expand Down Expand Up @@ -644,7 +644,7 @@ impl framework::Example for Example {
} else {
"fs_main_without_storage"
},
targets: &[Some(sc_desc.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
front_face: wgpu::FrontFace::Ccw,
Expand All @@ -669,7 +669,7 @@ impl framework::Example for Example {
}
};

let forward_depth = Self::create_depth_texture(sc_desc, device);
let forward_depth = Self::create_depth_texture(config, device);

Example {
entities,
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/shadow/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn vs_main(
let w = u_entity.world;
let world_pos = u_entity.world * vec4<f32>(position);
var result: VertexOutput;
result.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
result.world_normal = mat3x3<f32>(w[0].xyz, w[1].xyz, w[2].xyz) * vec3<f32>(normal.xyz);
result.world_position = world_pos;
result.proj_position = u_globals.view_proj * world_pos;
return result;
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/skybox/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl framework::Example for Skybox {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_sky",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
front_face: wgpu::FrontFace::Cw,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl framework::Example for Skybox {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_entity",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
front_face: wgpu::FrontFace::Cw,
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/skybox/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
);

// transposition = inversion for this orthonormal matrix
let inv_model_view = transpose(mat3x3<f32>(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz));
let inv_model_view = transpose(mat3x3<f32>(r_data.view[0].xyz, r_data.view[1].xyz, r_data.view[2].xyz));
let unprojected = r_data.proj_inv * pos;

var result: SkyOutput;
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/stencil-triangles/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl framework::Example for Triangles {
module: &shader,
entry_point: "fs_main",
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
format: config.view_formats[0],
blend: None,
write_mask: wgpu::ColorWrites::empty(),
})],
Expand Down Expand Up @@ -120,7 +120,7 @@ impl framework::Example for Triangles {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: Default::default(),
depth_stencil: Some(wgpu::DepthStencilState {
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/texture-arrays/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl framework::Example for Example {
fragment: Some(wgpu::FragmentState {
module: fragment_shader_module,
entry_point: fragment_entry_point,
targets: &[Some(config.format.into())],
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
front_face: wgpu::FrontFace::Ccw,
Expand Down
Loading

0 comments on commit 47a2b05

Please sign in to comment.