From 60b7365605c56422a881cde3758954699b7fd350 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Sat, 4 Jun 2022 01:35:50 +0200 Subject: [PATCH 1/8] Add a downlevel capability for rendering to floating point textures --- wgpu-core/src/instance.rs | 2 +- wgpu-hal/src/dx11/adapter.rs | 1 + wgpu-hal/src/dx12/adapter.rs | 1 + wgpu-hal/src/empty.rs | 1 + wgpu-hal/src/gles/adapter.rs | 26 +++++++++++++++++++------- wgpu-hal/src/lib.rs | 1 + wgpu-hal/src/metal/adapter.rs | 1 + wgpu-hal/src/vulkan/adapter.rs | 1 + wgpu-types/src/lib.rs | 3 +++ 9 files changed, 29 insertions(+), 8 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 907c65d08c..a48025b94a 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -209,7 +209,7 @@ impl Adapter { ) -> wgt::TextureFormatFeatures { use hal::TextureFormatCapabilities as Tfc; - let caps = unsafe { self.raw.adapter.texture_format_capabilities(format) }; + let caps = unsafe { self.raw.adapter.texture_format_capabilities(format, &self.raw.capabilities) }; let mut allowed_usages = format.describe().guaranteed_format_features.allowed_usages; allowed_usages.set( diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index 576eb810f6..8a4c48baae 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -14,6 +14,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, + capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { todo!() } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 039eb9ab11..7de8e39bd6 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -327,6 +327,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, + capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; diff --git a/wgpu-hal/src/empty.rs b/wgpu-hal/src/empty.rs index be5708da38..7948982a9d 100644 --- a/wgpu-hal/src/empty.rs +++ b/wgpu-hal/src/empty.rs @@ -84,6 +84,7 @@ impl crate::Adapter for Context { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, + capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { crate::TextureFormatCapabilities::empty() } diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 90f845813b..4601acc1c6 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -289,6 +289,10 @@ impl super::Adapter { wgt::DownlevelFlags::ANISOTROPIC_FILTERING, extensions.contains("EXT_texture_filter_anisotropic"), ); + downlevel_flags.set( + wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT, + extensions.contains("EXT_color_buffer_float"), + ); let mut features = wgt::Features::empty() | wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES @@ -603,6 +607,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, + capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; use wgt::TextureFormat as Tf; @@ -619,6 +624,13 @@ impl crate::Adapter for super::Adapter { unfilterable | Tfc::COLOR_ATTACHMENT | Tfc::MULTISAMPLE | Tfc::MULTISAMPLE_RESOLVE; let filterable_renderable = filterable | renderable | Tfc::COLOR_ATTACHMENT_BLEND; let storage = Tfc::STORAGE | Tfc::STORAGE_READ_WRITE; + + let float_renderable = if capabilities.downlevel.flags.contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT) { + Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND + } else { + Tfc::empty() + }; + match format { Tf::R8Unorm => filterable_renderable, Tf::R8Snorm => filterable, @@ -628,37 +640,37 @@ impl crate::Adapter for super::Adapter { Tf::R16Sint => renderable, Tf::R16Unorm => empty, Tf::R16Snorm => empty, - Tf::R16Float => filterable, + Tf::R16Float => filterable | float_renderable, Tf::Rg8Unorm => filterable_renderable, Tf::Rg8Snorm => filterable, Tf::Rg8Uint => renderable, Tf::Rg8Sint => renderable, Tf::R32Uint => renderable | storage, Tf::R32Sint => renderable | storage, - Tf::R32Float => unfilterable | storage, + Tf::R32Float => unfilterable | storage | float_renderable, Tf::Rg16Uint => renderable, Tf::Rg16Sint => renderable, Tf::Rg16Unorm => empty, Tf::Rg16Snorm => empty, - Tf::Rg16Float => filterable, + Tf::Rg16Float => filterable | float_renderable, Tf::Rgba8Unorm | Tf::Rgba8UnormSrgb => filterable_renderable | storage, Tf::Bgra8Unorm | Tf::Bgra8UnormSrgb => filterable_renderable, Tf::Rgba8Snorm => filterable, Tf::Rgba8Uint => renderable | storage, Tf::Rgba8Sint => renderable | storage, Tf::Rgb10a2Unorm => filterable_renderable, - Tf::Rg11b10Float => filterable, + Tf::Rg11b10Float => filterable | float_renderable, Tf::Rg32Uint => renderable, Tf::Rg32Sint => renderable, - Tf::Rg32Float => unfilterable, + Tf::Rg32Float => unfilterable | float_renderable, Tf::Rgba16Uint => renderable | storage, Tf::Rgba16Sint => renderable | storage, Tf::Rgba16Unorm => empty, Tf::Rgba16Snorm => empty, - Tf::Rgba16Float => filterable | storage, + Tf::Rgba16Float => filterable | storage | float_renderable, Tf::Rgba32Uint => renderable | storage, Tf::Rgba32Sint => renderable | storage, - Tf::Rgba32Float => unfilterable | storage, + Tf::Rgba32Float => unfilterable | storage | float_renderable, Tf::Depth32Float | Tf::Depth32FloatStencil8 | Tf::Depth24Plus diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 1ce7c657ba..56a62ea364 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -212,6 +212,7 @@ pub trait Adapter: Send + Sync { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, + capabilities: &Capabilities ) -> TextureFormatCapabilities; /// Returns the capabilities of working with a specified surface. diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index f59237100f..cb45c61f74 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -41,6 +41,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, + capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; use wgt::TextureFormat as Tf; diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index e2b914cb6a..cc22d1db2a 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1426,6 +1426,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, + _capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 5e3a010b5a..e8ae028157 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1026,6 +1026,9 @@ bitflags::bitflags! { /// /// GLES/WebGL don't support this. const DEPTH_TEXTURE_AND_BUFFER_COPIES = 1 << 13; + + /// Supports rendering to floating-point textures. + const COLOR_ATTACHMENT_FLOAT = 1 << 14; } } From bbec7d0ef2e6c1df0000ac23d9d79b96d783b235 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Sat, 4 Jun 2022 01:46:10 +0200 Subject: [PATCH 2/8] Rename capabilities to _capabilities --- wgpu-hal/src/dx12/adapter.rs | 2 +- wgpu-hal/src/metal/adapter.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 7de8e39bd6..605f1d1c81 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -327,7 +327,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities + _capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index cb45c61f74..ec4c93b697 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -41,7 +41,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities + _capabilities: &crate::Capabilities ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; use wgt::TextureFormat as Tf; From 04d947401301ff40bdf7d8749f6b6cd235987503 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Sat, 4 Jun 2022 01:47:28 +0200 Subject: [PATCH 3/8] Run cargo fmt --- wgpu-core/src/instance.rs | 6 +++++- wgpu-hal/src/dx11/adapter.rs | 2 +- wgpu-hal/src/dx12/adapter.rs | 2 +- wgpu-hal/src/empty.rs | 2 +- wgpu-hal/src/gles/adapter.rs | 8 ++++++-- wgpu-hal/src/lib.rs | 2 +- wgpu-hal/src/metal/adapter.rs | 2 +- wgpu-hal/src/vulkan/adapter.rs | 2 +- 8 files changed, 17 insertions(+), 9 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index a48025b94a..fbb36a14fe 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -209,7 +209,11 @@ impl Adapter { ) -> wgt::TextureFormatFeatures { use hal::TextureFormatCapabilities as Tfc; - let caps = unsafe { self.raw.adapter.texture_format_capabilities(format, &self.raw.capabilities) }; + let caps = unsafe { + self.raw + .adapter + .texture_format_capabilities(format, &self.raw.capabilities) + }; let mut allowed_usages = format.describe().guaranteed_format_features.allowed_usages; allowed_usages.set( diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index 8a4c48baae..ef5345d17b 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -14,7 +14,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities + capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { todo!() } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 605f1d1c81..7c6d1c10ab 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -327,7 +327,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - _capabilities: &crate::Capabilities + _capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; diff --git a/wgpu-hal/src/empty.rs b/wgpu-hal/src/empty.rs index 7948982a9d..f9d6ae733d 100644 --- a/wgpu-hal/src/empty.rs +++ b/wgpu-hal/src/empty.rs @@ -84,7 +84,7 @@ impl crate::Adapter for Context { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities + capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { crate::TextureFormatCapabilities::empty() } diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 4601acc1c6..abfde4fe08 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -607,7 +607,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities + capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; use wgt::TextureFormat as Tf; @@ -625,7 +625,11 @@ impl crate::Adapter for super::Adapter { let filterable_renderable = filterable | renderable | Tfc::COLOR_ATTACHMENT_BLEND; let storage = Tfc::STORAGE | Tfc::STORAGE_READ_WRITE; - let float_renderable = if capabilities.downlevel.flags.contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT) { + let float_renderable = if capabilities + .downlevel + .flags + .contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT) + { Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND } else { Tfc::empty() diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 56a62ea364..11d41236d6 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -212,7 +212,7 @@ pub trait Adapter: Send + Sync { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &Capabilities + capabilities: &Capabilities, ) -> TextureFormatCapabilities; /// Returns the capabilities of working with a specified surface. diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index ec4c93b697..df45db2c27 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -41,7 +41,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - _capabilities: &crate::Capabilities + _capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; use wgt::TextureFormat as Tf; diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index cc22d1db2a..5e9f08a285 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1426,7 +1426,7 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - _capabilities: &crate::Capabilities + _capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; From 423c1adf6b750d32282a28e0127c9f90d9608d5e Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Sat, 4 Jun 2022 23:06:45 +0200 Subject: [PATCH 4/8] Pass downlevel_flags to the adapter --- wgpu-core/src/instance.rs | 6 +----- wgpu-hal/src/dx11/adapter.rs | 1 - wgpu-hal/src/dx12/adapter.rs | 1 - wgpu-hal/src/empty.rs | 1 - wgpu-hal/src/gles/adapter.rs | 7 +++---- wgpu-hal/src/gles/mod.rs | 1 + wgpu-hal/src/lib.rs | 1 - wgpu-hal/src/metal/adapter.rs | 1 - wgpu-hal/src/vulkan/adapter.rs | 1 - 9 files changed, 5 insertions(+), 15 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index fbb36a14fe..907c65d08c 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -209,11 +209,7 @@ impl Adapter { ) -> wgt::TextureFormatFeatures { use hal::TextureFormatCapabilities as Tfc; - let caps = unsafe { - self.raw - .adapter - .texture_format_capabilities(format, &self.raw.capabilities) - }; + let caps = unsafe { self.raw.adapter.texture_format_capabilities(format) }; let mut allowed_usages = format.describe().guaranteed_format_features.allowed_usages; allowed_usages.set( diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index ef5345d17b..576eb810f6 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -14,7 +14,6 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { todo!() } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 7c6d1c10ab..039eb9ab11 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -327,7 +327,6 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - _capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; diff --git a/wgpu-hal/src/empty.rs b/wgpu-hal/src/empty.rs index f9d6ae733d..be5708da38 100644 --- a/wgpu-hal/src/empty.rs +++ b/wgpu-hal/src/empty.rs @@ -84,7 +84,6 @@ impl crate::Adapter for Context { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { crate::TextureFormatCapabilities::empty() } diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index abfde4fe08..8d8bc85918 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -505,6 +505,7 @@ impl super::Adapter { shading_language_version, max_texture_size, }), + downlevel_flags, }, info: Self::make_info(vendor, renderer), features, @@ -607,7 +608,6 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; use wgt::TextureFormat as Tf; @@ -625,9 +625,8 @@ impl crate::Adapter for super::Adapter { let filterable_renderable = filterable | renderable | Tfc::COLOR_ATTACHMENT_BLEND; let storage = Tfc::STORAGE | Tfc::STORAGE_READ_WRITE; - let float_renderable = if capabilities - .downlevel - .flags + let float_renderable = if self + .downlevel_flags .contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT) { Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 338cbca774..21c91eaf17 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -188,6 +188,7 @@ struct AdapterShared { pub struct Adapter { shared: Arc, + downlevel_flags: wgt::DownlevelFlags, } pub struct Device { diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 11d41236d6..1ce7c657ba 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -212,7 +212,6 @@ pub trait Adapter: Send + Sync { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - capabilities: &Capabilities, ) -> TextureFormatCapabilities; /// Returns the capabilities of working with a specified surface. diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index df45db2c27..f59237100f 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -41,7 +41,6 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - _capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; use wgt::TextureFormat as Tf; diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 5e9f08a285..e2b914cb6a 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1426,7 +1426,6 @@ impl crate::Adapter for super::Adapter { unsafe fn texture_format_capabilities( &self, format: wgt::TextureFormat, - _capabilities: &crate::Capabilities, ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; From ba43ed303486c98e46b1ebf49d75f6431f13732a Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 6 Jun 2022 00:56:40 +0200 Subject: [PATCH 5/8] Add wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT to dx11 --- wgpu-hal/src/dx11/adapter.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index 576eb810f6..024434f6c5 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -91,8 +91,9 @@ impl super::Adapter { | wgt::Features::CLEAR_TEXTURE | wgt::Features::TEXTURE_FORMAT_16BIT_NORM | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO; - let mut downlevel = - wgt::DownlevelFlags::BASE_VERTEX | wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL; + let mut downlevel = wgt::DownlevelFlags::BASE_VERTEX + | wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL + | wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT; // Features from queries downlevel.set( From 9b0b7c9259ecba388717babb9541b78cf879c8cc Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 6 Jun 2022 12:49:17 +0200 Subject: [PATCH 6/8] Remove downlevel_flags from the adapter and use is_ext_color_buffer_float_supported instead --- wgpu-hal/src/gles/adapter.rs | 8 +++----- wgpu-hal/src/gles/mod.rs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 8d8bc85918..33f62cb696 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -504,8 +504,9 @@ impl super::Adapter { workarounds, shading_language_version, max_texture_size, + is_ext_color_buffer_float_supported: downlevel_flags + .contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT), }), - downlevel_flags, }, info: Self::make_info(vendor, renderer), features, @@ -625,10 +626,7 @@ impl crate::Adapter for super::Adapter { let filterable_renderable = filterable | renderable | Tfc::COLOR_ATTACHMENT_BLEND; let storage = Tfc::STORAGE | Tfc::STORAGE_READ_WRITE; - let float_renderable = if self - .downlevel_flags - .contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT) - { + let float_renderable = if self.shared.is_ext_color_buffer_float_supported { Tfc::COLOR_ATTACHMENT | Tfc::COLOR_ATTACHMENT_BLEND } else { Tfc::empty() diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 187cf94e15..469213752d 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -184,11 +184,11 @@ struct AdapterShared { workarounds: Workarounds, shading_language_version: naga::back::glsl::Version, max_texture_size: u32, + is_ext_color_buffer_float_supported: bool, } pub struct Adapter { shared: Arc, - downlevel_flags: wgt::DownlevelFlags, } pub struct Device { From 4e7db2c6b2a9b6a48da40c6ef5bcc879e4773ba3 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 6 Jun 2022 16:34:19 +0200 Subject: [PATCH 7/8] Add DownlevelFlags::WEBGPU_TEXTURE_FORMAT_SUPPORT --- wgpu-hal/src/dx11/adapter.rs | 3 ++- wgpu-types/src/lib.rs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index 024434f6c5..11cda99190 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -130,7 +130,8 @@ impl super::Adapter { } if feature_level >= FL11_0 { - downlevel |= wgt::DownlevelFlags::INDIRECT_EXECUTION; + downlevel |= wgt::DownlevelFlags::INDIRECT_EXECUTION + | wgt::DownlevelFlags::WEBGPU_TEXTURE_FORMAT_SUPPORT; features |= wgt::Features::TEXTURE_COMPRESSION_BC; } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index fa0f4f6b58..2aa8ac9b9e 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1029,6 +1029,10 @@ bitflags::bitflags! { /// Supports rendering to floating-point textures. const COLOR_ATTACHMENT_FLOAT = 1 << 14; + + /// Supports all the texture usages described in WebGPU. If this isn't supported, you + /// should call `get_texture_format_features` to get how you can use textures of a given format + const WEBGPU_TEXTURE_FORMAT_SUPPORT = 1 << 15; } } From 206016cb7f92137561bd4f5d18b113e49c1c920d Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 13 Jun 2022 16:45:32 +0200 Subject: [PATCH 8/8] Apply suggestions --- wgpu-hal/src/dx11/adapter.rs | 9 ++++----- wgpu-hal/src/gles/adapter.rs | 9 +++------ wgpu-types/src/lib.rs | 3 --- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index 11cda99190..3bc531eaee 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -91,9 +91,8 @@ impl super::Adapter { | wgt::Features::CLEAR_TEXTURE | wgt::Features::TEXTURE_FORMAT_16BIT_NORM | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO; - let mut downlevel = wgt::DownlevelFlags::BASE_VERTEX - | wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL - | wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT; + let mut downlevel = + wgt::DownlevelFlags::BASE_VERTEX | wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL; // Features from queries downlevel.set( @@ -130,8 +129,8 @@ impl super::Adapter { } if feature_level >= FL11_0 { - downlevel |= wgt::DownlevelFlags::INDIRECT_EXECUTION - | wgt::DownlevelFlags::WEBGPU_TEXTURE_FORMAT_SUPPORT; + downlevel |= wgt::DownlevelFlags::INDIRECT_EXECUTION; + downlevel |= wgt::DownlevelFlags::WEBGPU_TEXTURE_FORMAT_SUPPORT; features |= wgt::Features::TEXTURE_COMPRESSION_BC; } diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 33f62cb696..7a7b1b09a5 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -289,10 +289,8 @@ impl super::Adapter { wgt::DownlevelFlags::ANISOTROPIC_FILTERING, extensions.contains("EXT_texture_filter_anisotropic"), ); - downlevel_flags.set( - wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT, - extensions.contains("EXT_color_buffer_float"), - ); + + let is_ext_color_buffer_float_supported = extensions.contains("EXT_color_buffer_float"); let mut features = wgt::Features::empty() | wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES @@ -504,8 +502,7 @@ impl super::Adapter { workarounds, shading_language_version, max_texture_size, - is_ext_color_buffer_float_supported: downlevel_flags - .contains(wgt::DownlevelFlags::COLOR_ATTACHMENT_FLOAT), + is_ext_color_buffer_float_supported, }), }, info: Self::make_info(vendor, renderer), diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index ac6f42d3ff..f664a45437 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1028,9 +1028,6 @@ bitflags::bitflags! { /// GLES/WebGL don't support this. const DEPTH_TEXTURE_AND_BUFFER_COPIES = 1 << 13; - /// Supports rendering to floating-point textures. - const COLOR_ATTACHMENT_FLOAT = 1 << 14; - /// Supports all the texture usages described in WebGPU. If this isn't supported, you /// should call `get_texture_format_features` to get how you can use textures of a given format const WEBGPU_TEXTURE_FORMAT_SUPPORT = 1 << 15;