Skip to content

Commit

Permalink
Cleanups for WebGPU (#3671)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Fitzgerald <connor@modyfi.io>
  • Loading branch information
cwfitzgerald and cwfitzgerald authored Apr 12, 2023
1 parent 618d4f0 commit a7defb7
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 55 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ SamplerDescriptor {

By @cwfitzgerald in [#3610](https://github.com/gfx-rs/wgpu/pull/3610).

#### TextureFormat Names

Some texture format names have changed to get back in line with the spec.

```diff
- TextureFormat::Bc6hRgbSfloat
+ TextureFormat::Bc6hRgbFloat
```

By @cwfitzgerald in [#3671](https://github.com/gfx-rs/wgpu/pull/3671).

#### General

- Change type of `mip_level_count` and `array_layer_count` (members of `TextureViewDescriptor` and `ImageSubresourceRange`) from `Option<NonZeroU32>` to `Option<u32>`. By @teoxoy in [#3445](https://github.com/gfx-rs/wgpu/pull/3445)
Expand Down
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/auxil/dxgi/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option<dxgifor
Tf::Bc5RgUnorm => DXGI_FORMAT_BC5_UNORM,
Tf::Bc5RgSnorm => DXGI_FORMAT_BC5_SNORM,
Tf::Bc6hRgbUfloat => DXGI_FORMAT_BC6H_UF16,
Tf::Bc6hRgbSfloat => DXGI_FORMAT_BC6H_SF16,
Tf::Bc6hRgbFloat => DXGI_FORMAT_BC6H_SF16,
Tf::Bc7RgbaUnorm => DXGI_FORMAT_BC7_UNORM,
Tf::Bc7RgbaUnormSrgb => DXGI_FORMAT_BC7_UNORM_SRGB,
Tf::Etc2Rgb8Unorm
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
4 changes: 2 additions & 2 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
| Tf::Bc5RgUnorm
| Tf::Bc5RgSnorm
| Tf::Bc6hRgbUfloat
| Tf::Bc6hRgbSfloat
| Tf::Bc6hRgbFloat
| Tf::Bc7RgbaUnorm
| Tf::Bc7RgbaUnormSrgb => {
if pc.format_bc {
Expand Down Expand Up @@ -939,7 +939,7 @@ impl super::PrivateCapabilities {
Tf::Bc4RSnorm => BC4_RSnorm,
Tf::Bc5RgUnorm => BC5_RGUnorm,
Tf::Bc5RgSnorm => BC5_RGSnorm,
Tf::Bc6hRgbSfloat => BC6H_RGBFloat,
Tf::Bc6hRgbFloat => BC6H_RGBFloat,
Tf::Bc6hRgbUfloat => BC6H_RGBUfloat,
Tf::Bc7RgbaUnorm => BC7_RGBAUnorm,
Tf::Bc7RgbaUnormSrgb => BC7_RGBAUnorm_sRGB,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/vulkan/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl super::PrivateCapabilities {
Tf::Bc5RgUnorm => F::BC5_UNORM_BLOCK,
Tf::Bc5RgSnorm => F::BC5_SNORM_BLOCK,
Tf::Bc6hRgbUfloat => F::BC6H_UFLOAT_BLOCK,
Tf::Bc6hRgbSfloat => F::BC6H_SFLOAT_BLOCK,
Tf::Bc6hRgbFloat => F::BC6H_SFLOAT_BLOCK,
Tf::Bc7RgbaUnorm => F::BC7_UNORM_BLOCK,
Tf::Bc7RgbaUnormSrgb => F::BC7_SRGB_BLOCK,
Tf::Etc2Rgb8Unorm => F::ETC2_R8G8B8_UNORM_BLOCK,
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
11 changes: 7 additions & 4 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 Expand Up @@ -547,7 +550,7 @@ pub fn test<E: Example>(mut params: FrameworkRefTest) {
height: params.height,
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![wgpu::TextureFormat::Rgba8Unorm],
view_formats: vec![wgpu::TextureFormat::Rgba8UnormSrgb],
},
&ctx.adapter,
&ctx.device,
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
Loading

0 comments on commit a7defb7

Please sign in to comment.