@@ -1060,6 +1060,7 @@ impl Texture {
1060
1060
bind_groups : Mutex :: new ( rank:: TEXTURE_BIND_GROUPS , WeakVec :: new ( ) ) ,
1061
1061
}
1062
1062
}
1063
+
1063
1064
/// Checks that the given texture usage contains the required texture usage,
1064
1065
/// returns an error otherwise.
1065
1066
pub ( crate ) fn check_usage (
@@ -1552,6 +1553,9 @@ pub struct TextureViewDescriptor<'a> {
1552
1553
/// - For 2D textures it must be one of `D2`, `D2Array`, `Cube`, or `CubeArray`.
1553
1554
/// - For 3D textures it must be `D3`.
1554
1555
pub dimension : Option < wgt:: TextureViewDimension > ,
1556
+ /// The allowed usage(s) for the texture view. Must be a subset of the usage flags of the texture.
1557
+ /// If not provided, defaults to the full set of usage flags of the texture.
1558
+ pub usage : Option < wgt:: TextureUsages > ,
1555
1559
/// Range within the texture that is accessible via this view.
1556
1560
pub range : wgt:: ImageSubresourceRange ,
1557
1561
}
@@ -1560,6 +1564,7 @@ pub struct TextureViewDescriptor<'a> {
1560
1564
pub ( crate ) struct HalTextureViewDescriptor {
1561
1565
pub texture_format : wgt:: TextureFormat ,
1562
1566
pub format : wgt:: TextureFormat ,
1567
+ pub usage : wgt:: TextureUsages ,
1563
1568
pub dimension : wgt:: TextureViewDimension ,
1564
1569
pub range : wgt:: ImageSubresourceRange ,
1565
1570
}
@@ -1631,6 +1636,23 @@ impl TextureView {
1631
1636
. map ( |it| it. as_ref ( ) )
1632
1637
. ok_or_else ( || DestroyedResourceError ( self . error_ident ( ) ) )
1633
1638
}
1639
+
1640
+ /// Checks that the given texture usage contains the required texture usage,
1641
+ /// returns an error otherwise.
1642
+ pub ( crate ) fn check_usage (
1643
+ & self ,
1644
+ expected : wgt:: TextureUsages ,
1645
+ ) -> Result < ( ) , MissingTextureUsageError > {
1646
+ if self . desc . usage . contains ( expected) {
1647
+ Ok ( ( ) )
1648
+ } else {
1649
+ Err ( MissingTextureUsageError {
1650
+ res : self . error_ident ( ) ,
1651
+ actual : self . desc . usage ,
1652
+ expected,
1653
+ } )
1654
+ }
1655
+ }
1634
1656
}
1635
1657
1636
1658
#[ derive( Clone , Debug , Error ) ]
@@ -1645,6 +1667,15 @@ pub enum CreateTextureViewError {
1645
1667
view : wgt:: TextureViewDimension ,
1646
1668
texture : wgt:: TextureDimension ,
1647
1669
} ,
1670
+ #[ error( "Texture view format `{0:?}` is not renderable" ) ]
1671
+ TextureViewFormatNotRenderable ( wgt:: TextureFormat ) ,
1672
+ #[ error( "Texture view format `{0:?}` is not storage bindable" ) ]
1673
+ TextureViewFormatNotStorage ( wgt:: TextureFormat ) ,
1674
+ #[ error( "Invalid texture view usage `{view:?}` with texture of usage `{texture:?}`" ) ]
1675
+ InvalidTextureViewUsage {
1676
+ view : wgt:: TextureUsages ,
1677
+ texture : wgt:: TextureUsages ,
1678
+ } ,
1648
1679
#[ error( "Invalid texture view dimension `{0:?}` of a multisampled texture" ) ]
1649
1680
InvalidMultisampledTextureViewDimension ( wgt:: TextureViewDimension ) ,
1650
1681
#[ error( "Invalid texture depth `{depth}` for texture view of dimension `Cubemap`. Cubemap views must use images of size 6." ) ]
@@ -1680,6 +1711,8 @@ pub enum CreateTextureViewError {
1680
1711
} ,
1681
1712
#[ error( transparent) ]
1682
1713
InvalidResource ( #[ from] InvalidResourceError ) ,
1714
+ #[ error( transparent) ]
1715
+ MissingFeatures ( #[ from] MissingFeatures ) ,
1683
1716
}
1684
1717
1685
1718
#[ derive( Clone , Debug , Error ) ]
0 commit comments