Skip to content

Commit

Permalink
Use Option<TextureUsages>
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Dec 17, 2024
1 parent 09b3f0e commit b7a8a2b
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
3 changes: 1 addition & 2 deletions deno_webgpu/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use deno_core::ResourceId;
use serde::Deserialize;
use std::borrow::Cow;
use std::rc::Rc;
use wgpu_types::TextureUsages;

use super::error::WebGpuResult;
pub(crate) struct WebGpuTexture {
Expand Down Expand Up @@ -116,7 +115,7 @@ pub fn op_webgpu_create_texture_view(
format: args.format,
dimension: args.dimension,
range: args.range,
usage: TextureUsages::FROM_PARENT, // FIXME: Actually obtain from parent
usage: None, // FIXME: Actually obtain from parent
};

gfx_put!(instance.texture_create_view(
Expand Down
3 changes: 1 addition & 2 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bytemuck::{Pod, Zeroable};
use std::{f32::consts, mem::size_of};
use wgpu::util::DeviceExt;
use wgpu::TextureUsages;

const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
const MIP_LEVEL_COUNT: u32 = 10;
Expand Down Expand Up @@ -128,7 +127,7 @@ impl Example {
label: Some("mip"),
format: None,
dimension: None,
usage: TextureUsages::FROM_PARENT,
usage: None,
aspect: wgpu::TextureAspect::All,
base_mip_level: mip,
mip_level_count: Some(1),
Expand Down
2 changes: 1 addition & 1 deletion examples/src/ray_cube_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl crate::framework::Example for Example {
label: None,
format: Some(wgpu::TextureFormat::Rgba8Unorm),
dimension: Some(wgpu::TextureViewDimension::D2),
usage: wgpu::TextureUsages::FROM_PARENT,
usage: None,
aspect: wgpu::TextureAspect::All,
base_mip_level: 0,
mip_level_count: None,
Expand Down
2 changes: 1 addition & 1 deletion examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl crate::framework::Example for Example {
label: Some("shadow"),
format: None,
dimension: Some(wgpu::TextureViewDimension::D2),
usage: wgpu::TextureUsages::FROM_PARENT,
usage: None,
aspect: wgpu::TextureAspect::All,
base_mip_level: 0,
mip_level_count: None,
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 @@ -44,7 +44,7 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new()
label: None,
format: None,
dimension: None,
usage: wgpu::TextureUsages::FROM_PARENT,
usage: None,
aspect: wgpu::TextureAspect::All,
base_mip_level: 0,
base_array_layer: 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf
label: None,
format: None,
dimension: None,
usage: wgpu::TextureUsages::FROM_PARENT,
usage: None,
aspect: wgt::TextureAspect::All,
base_mip_level: 0,
mip_level_count: None,
Expand Down
21 changes: 12 additions & 9 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,15 +1086,18 @@ impl Device {
.saturating_sub(desc.range.base_array_layer),
});

let resolved_usage = if desc.usage == wgt::TextureUsages::FROM_PARENT {
texture.desc.usage
} else if texture.desc.usage.contains(desc.usage) {
desc.usage
} else {
return Err(resource::CreateTextureViewError::InvalidTextureViewUsage {
view: desc.usage,
texture: texture.desc.usage,
});
let resolved_usage = {
let usage = desc.usage.unwrap_or(wgt::TextureUsages::empty());
if usage.is_empty() {
texture.desc.usage
} else if texture.desc.usage.contains(usage) {
usage
} else {
return Err(resource::CreateTextureViewError::InvalidTextureViewUsage {
view: usage,
texture: texture.desc.usage,
});
}
};

// validate TextureViewDescriptor
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,8 @@ pub struct TextureViewDescriptor<'a> {
/// - For 3D textures it must be `D3`.
pub dimension: Option<wgt::TextureViewDimension>,
/// The allowed usage(s) for the texture view. Must be a subset of the usage flags of the texture.
/// If 0, defaults to the full set of usage flags of the texture.
pub usage: wgt::TextureUsages,
/// If not provided, defaults to the full set of usage flags of the texture.
pub usage: Option<wgt::TextureUsages>,
/// Range within the texture that is accessible via this view.
pub range: wgt::ImageSubresourceRange,
}
Expand Down
8 changes: 3 additions & 5 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5505,10 +5505,8 @@ bitflags::bitflags! {
#[repr(transparent)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct TextureUsages: u32 {
/// For use in texture views, expands to the full set of usage flags of the texture
const FROM_PARENT = 0;
/// Allows a texture to be the source in a [`CommandEncoder::copy_texture_to_buffer`] or
/// [`CommandEncoder::copy_texture_to_texture`] operation.
const COPY_SRC = 1 << 0;
Expand Down Expand Up @@ -6070,8 +6068,8 @@ pub struct TextureViewDescriptor<L> {
/// `D2`, `D2Array`, `Cube`, and `CubeArray`. For 3D textures it must be `D3`
pub dimension: Option<TextureViewDimension>,
/// The allowed usage(s) for the texture view. Must be a subset of the usage flags of the texture.
/// If 0, defaults to the full set of usage flags of the texture.
pub usage: TextureUsages,
/// If not provided, defaults to the full set of usage flags of the texture.
pub usage: Option<TextureUsages>,
/// Aspect of the texture. Color textures must be [`TextureAspect::All`].
pub aspect: TextureAspect,
/// Base mip level.
Expand Down

0 comments on commit b7a8a2b

Please sign in to comment.