Skip to content

Commit b93bab5

Browse files
feat: support blendable f32 textures on vulkan (gfx-rs#8963)
Co-authored-by: Erich Gubler <[email protected]>
1 parent c82e37b commit b93bab5

5 files changed

Lines changed: 39 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Bottom level categories:
5050
- Added support for no-perspective barycentric coordinates. By @atlv24 in [#8852](https://github.com/gfx-rs/wgpu/issues/8852).
5151
- Added support for obtaining `AdapterInfo` from `Device`. By @sagudev in [#8807](https://github.com/gfx-rs/wgpu/pull/8807).
5252
- Added `Limits::or_worse_values_from`. By @atlv24 in [#8870](https://github.com/gfx-rs/wgpu/pull/8870).
53+
- Added `Features::FLOAT32_BLENDABLE`. By @timokoesters in [#8963](https://github.com/gfx-rs/wgpu/pull/8963).
5354
- Made the following available in `const` contexts:
5455
- `naga`
5556
- `Arena::len`

cts_runner/test.lst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ webgpu:api,operation,compute,basic:memcpy:*
3333
webgpu:api,operation,device,lost:*
3434
webgpu:api,operation,render_pass,storeOp:*
3535
webgpu:api,operation,render_pipeline,overrides:*
36+
webgpu:api,operation,render_pipeline,pipeline_output_targets:color,component_count,blend:*
3637
webgpu:api,operation,rendering,3d_texture_slices:*
3738
webgpu:api,operation,rendering,basic:clear:*
3839
webgpu:api,operation,rendering,basic:fullscreen_quad:*
@@ -163,6 +164,7 @@ webgpu:api,validation,render_pass,render_pass_descriptor:resolveTarget,*
163164
webgpu:api,validation,render_pass,resolve:resolve_attachment:*
164165
webgpu:api,validation,render_pipeline,depth_stencil_state:format:*
165166
webgpu:api,validation,render_pipeline,depth_stencil_state:stencil_write:*
167+
webgpu:api,validation,render_pipeline,float32_blendable:*
166168
webgpu:api,validation,render_pipeline,inter_stage:location,*
167169
webgpu:api,validation,render_pipeline,inter_stage:max_shader_variable_location:*
168170
webgpu:api,validation,render_pipeline,inter_stage:max_variables_count,*
@@ -255,3 +257,4 @@ webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="l
255257
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="loop8"
256258
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="switch1"
257259
//FAIL: 9 invalid_statements subtests due to https://github.com/gfx-rs/wgpu/issues/7733
260+
webgpu:util,texture,texture_ok:*

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,11 @@ impl PhysicalDeviceFeatures {
928928
is_float32_filterable_supported(instance, phd),
929929
);
930930

931+
features.set(
932+
F::FLOAT32_BLENDABLE,
933+
is_float32_blendable_supported(instance, phd),
934+
);
935+
931936
if let Some(ref _sampler_ycbcr_conversion) = self.sampler_ycbcr_conversion {
932937
features.set(
933938
F::TEXTURE_FORMAT_NV12,
@@ -2834,6 +2839,21 @@ fn is_float32_filterable_supported(instance: &ash::Instance, phd: vk::PhysicalDe
28342839
r_float && rg_float && rgba_float
28352840
}
28362841

2842+
fn is_float32_blendable_supported(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
2843+
let tiling = vk::ImageTiling::OPTIMAL;
2844+
let features = vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND;
2845+
let r_float = supports_format(instance, phd, vk::Format::R32_SFLOAT, tiling, features);
2846+
let rg_float = supports_format(instance, phd, vk::Format::R32G32_SFLOAT, tiling, features);
2847+
let rgba_float = supports_format(
2848+
instance,
2849+
phd,
2850+
vk::Format::R32G32B32A32_SFLOAT,
2851+
tiling,
2852+
features,
2853+
);
2854+
r_float && rg_float && rgba_float
2855+
}
2856+
28372857
fn supports_format(
28382858
instance: &ash::Instance,
28392859
phd: vk::PhysicalDevice,

wgpu-types/src/features.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ mod webgpu_impl {
5858
pub const WEBGPU_FEATURE_FLOAT32_FILTERABLE: u64 = 1 << 12;
5959

6060
#[doc(hidden)]
61-
pub const WEBGPU_FEATURE_DUAL_SOURCE_BLENDING: u64 = 1 << 13;
61+
pub const WEBGPU_FEATURE_FLOAT32_BLENDABLE: u64 = 1 << 13;
6262

6363
#[doc(hidden)]
64-
pub const WEBGPU_FEATURE_CLIP_DISTANCES: u64 = 1 << 14;
64+
pub const WEBGPU_FEATURE_DUAL_SOURCE_BLENDING: u64 = 1 << 14;
6565

6666
#[doc(hidden)]
67-
pub const WEBGPU_FEATURE_IMMEDIATES: u64 = 1 << 15;
67+
pub const WEBGPU_FEATURE_CLIP_DISTANCES: u64 = 1 << 15;
68+
69+
#[doc(hidden)]
70+
pub const WEBGPU_FEATURE_IMMEDIATES: u64 = 1 << 16;
6871
}
6972

7073
macro_rules! bitflags_array_impl {
@@ -574,7 +577,6 @@ bitflags_array! {
574577
// ? const RW_STORAGE_TEXTURE_TIER_1 = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3838)
575578
// ? const NORM16_FILTERABLE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3839)
576579
// ? const NORM16_RESOLVE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3839)
577-
// ? const FLOAT32_BLENDABLE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3556)
578580
// ? const 32BIT_FORMAT_MULTISAMPLE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
579581
// ? const 32BIT_FORMAT_RESOLVE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
580582
// ? const TEXTURE_COMPRESSION_ASTC_HDR = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3856)
@@ -1509,6 +1511,12 @@ bitflags_array! {
15091511
/// This is a web and native feature.
15101512
const FLOAT32_FILTERABLE = WEBGPU_FEATURE_FLOAT32_FILTERABLE;
15111513

1514+
/// Allows textures with formats "r32float", "rg32float", and "rgba32float" to be blendable.
1515+
///
1516+
/// Supported Platforms:
1517+
/// - Vulkan
1518+
const FLOAT32_BLENDABLE = WEBGPU_FEATURE_FLOAT32_BLENDABLE;
1519+
15121520
/// Allows two outputs from a shader to be used for blending.
15131521
/// Note that dual-source blending doesn't support multiple render targets.
15141522
///

wgpu-types/src/texture/format.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,9 @@ impl TextureFormat {
920920

921921
// Features that enable filtering don't affect blendability
922922
let sample_type2 = self.sample_type(None, None);
923-
let is_blendable = sample_type2 == Some(TextureSampleType::Float { filterable: true });
923+
let is_blendable = sample_type2 == Some(TextureSampleType::Float { filterable: true })
924+
|| device_features.contains(Features::FLOAT32_BLENDABLE)
925+
&& matches!(self, Self::R32Float | Self::Rg32Float | Self::Rgba32Float);
924926

925927
flags.set(TextureFormatFeatureFlags::FILTERABLE, is_filterable);
926928
flags.set(TextureFormatFeatureFlags::BLENDABLE, is_blendable);

0 commit comments

Comments
 (0)