Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DEPTH32FLOAT_STENCIL8 featue #2664

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions deno_webgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
if features.contains(wgpu_types::Features::DEPTH_CLIP_CONTROL) {
return_features.push("depth-clip-control");
}
if features.contains(wgpu_types::Features::DEPTH32FLOAT_STENCIL8) {
return_features.push("depth32float-stencil8");
}
if features.contains(wgpu_types::Features::PIPELINE_STATISTICS_QUERY) {
return_features.push("pipeline-statistics-query");
}
Expand Down Expand Up @@ -285,6 +288,10 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
wgpu_types::Features::DEPTH_CLIP_CONTROL,
required_features.0.contains("depth-clip-control"),
);
features.set(
wgpu_types::Features::DEPTH32FLOAT_STENCIL8,
required_features.0.contains("depth32float-stencil8"),
);
features.set(
wgpu_types::Features::PIPELINE_STATISTICS_QUERY,
required_features.0.contains("pipeline-statistics-query"),
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/pipeline-statistics-query.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0000_0000_0000_0010, // PIPELINE_STATISTICS_QUERY
features: 0x0000_0000_0000_0020, // PIPELINE_STATISTICS_QUERY
expectations: [
(
name: "Queried number of compute invocations is correct",
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ pub(crate) fn validate_texture_copy_range(

match desc.format {
wgt::TextureFormat::Depth32Float
| wgt::TextureFormat::Depth32FloatStencil8
| wgt::TextureFormat::Depth24Plus
| wgt::TextureFormat::Depth24PlusStencil8 => {
if *copy_size != extent {
Expand Down
4 changes: 3 additions & 1 deletion wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub fn is_valid_copy_src_texture_format(format: wgt::TextureFormat) -> bool {
pub fn is_valid_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
use wgt::TextureFormat as Tf;
match format {
Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => false,
Tf::Depth32Float | Tf::Depth32FloatStencil8 | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => {
false
}
_ => true,
}
}
Expand Down
5 changes: 4 additions & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,10 @@ impl NumericType {
(NumericDimension::Vector(Vs::Quad), Sk::Sint)
}
Tf::Rg11b10Float => (NumericDimension::Vector(Vs::Tri), Sk::Float),
Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => {
Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8 => {
panic!("Unexpected depth format")
}
Tf::Rgb9e5Ufloat => (NumericDimension::Vector(Vs::Tri), Sk::Float),
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/auxil/dxgi/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn map_texture_format(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT
Tf::Rgba32Sint => DXGI_FORMAT_R32G32B32A32_SINT,
Tf::Rgba32Float => DXGI_FORMAT_R32G32B32A32_FLOAT,
Tf::Depth32Float => DXGI_FORMAT_D32_FLOAT,
Tf::Depth32FloatStencil8 => DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT,
Tf::Depth24PlusStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT,
Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
Expand Down Expand Up @@ -96,6 +97,9 @@ pub fn map_texture_format_nosrgb(format: wgt::TextureFormat) -> dxgiformat::DXGI
pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT {
match format {
wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_FLOAT,
wgt::TextureFormat::Depth32FloatStencil8 => {
dxgiformat::DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS
}
wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => {
dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS
}
Expand All @@ -112,6 +116,7 @@ pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXG
pub fn map_texture_format_depth_typeless(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT {
match format {
wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_TYPELESS,
wgt::TextureFormat::Depth32FloatStencil8 => dxgiformat::DXGI_FORMAT_R32G8X24_TYPELESS,
wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => {
dxgiformat::DXGI_FORMAT_R24G8_TYPELESS
}
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl super::Adapter {

let mut features = wgt::Features::empty()
| wgt::Features::DEPTH_CLIP_CONTROL
| wgt::Features::DEPTH32FLOAT_STENCIL8
| wgt::Features::INDIRECT_FIRST_INSTANCE
| wgt::Features::MAPPABLE_PRIMARY_BUFFERS
| wgt::Features::MULTI_DRAW_INDIRECT
Expand Down
5 changes: 4 additions & 1 deletion wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ impl crate::Adapter<super::Api> for super::Adapter {
Tf::Rgba32Uint => renderable | storage,
Tf::Rgba32Sint => renderable | storage,
Tf::Rgba32Float => unfilterable | storage,
Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => depth,
Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8 => depth,
Tf::Rgb9e5Ufloat
| Tf::Bc1RgbaUnorm
| Tf::Bc1RgbaUnormSrgb
Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ impl super::AdapterShared {
Tf::Rgba32Sint => (glow::RGBA32I, glow::RGBA_INTEGER, glow::INT),
Tf::Rgba32Float => (glow::RGBA32F, glow::RGBA, glow::FLOAT),
Tf::Depth32Float => (glow::DEPTH_COMPONENT32F, glow::DEPTH_COMPONENT, glow::FLOAT),
Tf::Depth32FloatStencil8 => {
(glow::DEPTH32F_STENCIL8, glow::DEPTH_COMPONENT, glow::FLOAT)
}
Tf::Depth24Plus => (
glow::DEPTH_COMPONENT24,
glow::DEPTH_COMPONENT,
Expand Down
4 changes: 3 additions & 1 deletion wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ impl From<wgt::TextureFormat> for FormatAspects {
fn from(format: wgt::TextureFormat) -> Self {
match format {
wgt::TextureFormat::Depth32Float | wgt::TextureFormat::Depth24Plus => Self::DEPTH,
wgt::TextureFormat::Depth24PlusStencil8 => Self::DEPTH | Self::STENCIL,
wgt::TextureFormat::Depth32FloatStencil8 | wgt::TextureFormat::Depth24PlusStencil8 => {
Self::DEPTH | Self::STENCIL
}
_ => Self::COLOR,
}
}
Expand Down
6 changes: 4 additions & 2 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
};
flags
}
Tf::Depth32Float => {
Tf::Depth32Float | Tf::Depth32FloatStencil8 => {
let mut flats =
Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if;
if pc.format_depth32float_filter {
Expand Down Expand Up @@ -749,7 +749,8 @@ impl super::PrivateCapabilities {
| F::POLYGON_MODE_LINE
| F::CLEAR_TEXTURE
| F::TEXTURE_FORMAT_16BIT_NORM
| F::SHADER_FLOAT16;
| F::SHADER_FLOAT16
| F::DEPTH32FLOAT_STENCIL8;

features.set(F::TEXTURE_COMPRESSION_ASTC_LDR, self.format_astc);
features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr);
Expand Down Expand Up @@ -889,6 +890,7 @@ impl super::PrivateCapabilities {
Tf::Rgba32Sint => RGBA32Sint,
Tf::Rgba32Float => RGBA32Float,
Tf::Depth32Float => Depth32Float,
Tf::Depth32FloatStencil8 => Depth32Float_Stencil8,
Tf::Depth24Plus => {
if self.format_depth24_stencil8 {
Depth24Unorm_Stencil8
Expand Down
11 changes: 11 additions & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,17 @@ impl PhysicalDeviceFeatures {
);
}

features.set(
F::DEPTH32FLOAT_STENCIL8,
caps.supports_format(
vk::Format::D32_SFLOAT_S8_UINT,
vk::ImageTiling::OPTIMAL,
vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT
| vk::FormatFeatureFlags::SAMPLED_IMAGE
| vk::FormatFeatureFlags::TRANSFER_SRC,
),
);

(features, dl_flags)
}

Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/vulkan/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl super::PrivateCapabilities {
Tf::Rgba32Sint => F::R32G32B32A32_SINT,
Tf::Rgba32Float => F::R32G32B32A32_SFLOAT,
Tf::Depth32Float => F::D32_SFLOAT,
Tf::Depth32FloatStencil8 => F::D32_SFLOAT_S8_UINT,
Tf::Depth24Plus => {
if self.texture_d24 {
F::X8_D24_UNORM_PACK32
Expand Down
24 changes: 19 additions & 5 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ bitflags::bitflags! {
///
/// This is a web and native feature.
const DEPTH_CLIP_CONTROL = 1 << 0;
/// Allows for explicit creation of textures of format [`TextureFormat::Depth32FloatStencil8`]
///
/// Supported platforms:
/// - Vulkan (mostly)
/// - DX12
/// - Metal
///
/// This is a web and native feature.
const DEPTH32FLOAT_STENCIL8 = 1 << 1;
/// Enables BCn family of compressed textures. All BCn textures use 4x4 pixel blocks
/// with 8 or 16 bytes per block.
///
Expand All @@ -198,7 +207,7 @@ bitflags::bitflags! {
/// - desktops
///
/// This is a web and native feature.
const TEXTURE_COMPRESSION_BC = 1 << 1;
const TEXTURE_COMPRESSION_BC = 1 << 2;
/// Allows non-zero value for the "first instance" in indirect draw calls.
///
/// Supported Platforms:
Expand All @@ -207,7 +216,7 @@ bitflags::bitflags! {
/// - Metal
///
/// This is a web and native feature.
const INDIRECT_FIRST_INSTANCE = 1 << 2;
const INDIRECT_FIRST_INSTANCE = 1 << 3;
/// Enables use of Timestamp Queries. These queries tell the current gpu timestamp when
/// all work before the query is finished. Call [`CommandEncoder::write_timestamp`],
/// [`RenderPassEncoder::write_timestamp`], or [`ComputePassEncoder::write_timestamp`] to
Expand All @@ -225,7 +234,7 @@ bitflags::bitflags! {
/// - DX12 (works)
///
/// This is a web and native feature.
const TIMESTAMP_QUERY = 1 << 3;
const TIMESTAMP_QUERY = 1 << 4;
/// Enables use of Pipeline Statistics Queries. These queries tell the count of various operations
/// performed between the start and stop call. Call [`RenderPassEncoder::begin_pipeline_statistics_query`] to start
/// a query, then call [`RenderPassEncoder::end_pipeline_statistics_query`] to stop one.
Expand All @@ -240,7 +249,7 @@ bitflags::bitflags! {
/// - DX12 (works)
///
/// This is a web and native feature.
const PIPELINE_STATISTICS_QUERY = 1 << 4;
const PIPELINE_STATISTICS_QUERY = 1 << 5;
/// Allows shaders to acquire the FP16 ability
///
/// Note: this is not supported in naga yet,only through spir-v passthrough right now.
Expand All @@ -250,7 +259,7 @@ bitflags::bitflags! {
/// - Metal
///
/// This is a web and native feature.
const SHADER_FLOAT16 = 1 << 5;
const SHADER_FLOAT16 = 1 << 6;
/// Webgpu only allows the MAP_READ and MAP_WRITE buffer usage to be matched with
/// COPY_DST and COPY_SRC respectively. This removes this requirement.
///
Expand Down Expand Up @@ -1838,6 +1847,9 @@ pub enum TextureFormat {
/// Special depth format with 32 bit floating point depth.
#[cfg_attr(feature = "serde", serde(rename = "depth32float"))]
Depth32Float,
/// Special depth/stencil format with 32 bit floating point depth and 8 bits integer stencil.
#[cfg_attr(feature = "serde", serde(rename = "depth32float-stencil8"))]
Depth32FloatStencil8,
/// Special depth format with at least 24 bit integer depth.
#[cfg_attr(feature = "serde", serde(rename = "depth24plus"))]
Depth24Plus,
Expand Down Expand Up @@ -2046,6 +2058,7 @@ impl TextureFormat {
let astc_ldr = Features::TEXTURE_COMPRESSION_ASTC_LDR;
let astc_hdr = Features::TEXTURE_COMPRESSION_ASTC_HDR;
let norm16bit = Features::TEXTURE_FORMAT_16BIT_NORM;
let d32_s8 = Features::DEPTH32FLOAT_STENCIL8;

// Sample Types
let uint = TextureSampleType::Uint;
Expand Down Expand Up @@ -2135,6 +2148,7 @@ impl TextureFormat {

// Depth-stencil textures
Self::Depth32Float => ( native, depth, linear, msaa, (1, 1), 4, attachment, 1),
Self::Depth32FloatStencil8 =>( d32_s8, depth, linear, msaa, (1, 1), 4, attachment, 2),
Self::Depth24Plus => ( native, depth, linear, msaa, (1, 1), 4, attachment, 1),
Self::Depth24PlusStencil8 => ( native, depth, linear, msaa, (1, 1), 4, attachment, 2),

Expand Down
2 changes: 2 additions & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTexture
TextureFormat::Rgba32Sint => tf::Rgba32sint,
TextureFormat::Rgba32Float => tf::Rgba32float,
TextureFormat::Depth32Float => tf::Depth32float,
TextureFormat::Depth32FloatStencil8 => tf::Depth32floatStencil8,
TextureFormat::Depth24Plus => tf::Depth24plus,
TextureFormat::Depth24PlusStencil8 => tf::Depth24plusStencil8,
_ => unimplemented!(),
Expand Down Expand Up @@ -591,6 +592,7 @@ fn map_texture_format_from_web_sys(
tf::Rgba32sint => TextureFormat::Rgba32Sint,
tf::Rgba32float => TextureFormat::Rgba32Float,
tf::Depth32float => TextureFormat::Depth32Float,
tf::Depth32floatStencil8 => TextureFormat::Depth32FloatStencil8,
tf::Depth24plus => TextureFormat::Depth24Plus,
tf::Depth24plusStencil8 => TextureFormat::Depth24PlusStencil8,
_ => unimplemented!(),
Expand Down
16 changes: 16 additions & 0 deletions wgpu/tests/clear_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,22 @@ fn clear_texture_2d_uncompressed() {
)
}

#[test]
fn clear_texture_d32_s8() {
initialize_test(
TestParameters::default()
.features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::DEPTH32FLOAT_STENCIL8),
|ctx| {
clear_texture_tests(
&ctx,
&[wgpu::TextureFormat::Depth32FloatStencil8],
false,
false,
);
},
)
}

#[test]
fn clear_texture_2d_bc() {
initialize_test(
Expand Down