Skip to content

Commit 1180abc

Browse files
committed
Implement Features::RG11B10UFLOAT_RENDERABLE
1 parent 562ad0d commit 1180abc

File tree

9 files changed

+35
-6
lines changed

9 files changed

+35
-6
lines changed

deno_webgpu/02_idl_types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ webidl.converters["GPUFeatureName"] = webidl.createEnumConverter(
114114
"texture-compression-bc",
115115
"texture-compression-etc2",
116116
"texture-compression-astc",
117+
"rg11b10ufloat-renderable",
117118

118119
// extended from spec
119120

deno_webgpu/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
186186
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC) {
187187
return_features.push("texture-compression-astc");
188188
}
189+
if features.contains(wgpu_types::Features::RG11B10UFLOAT_RENDERABLE) {
190+
return_features.push("rg11b10ufloat-renderable");
191+
}
189192

190193
// extended from spec
191194

@@ -404,6 +407,10 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
404407
wgpu_types::Features::TEXTURE_COMPRESSION_ASTC,
405408
required_features.0.contains("texture-compression-astc"),
406409
);
410+
features.set(
411+
wgpu_types::Features::RG11B10UFLOAT_RENDERABLE,
412+
required_features.0.contains("rg11b10ufloat-renderable"),
413+
);
407414

408415
// extended from spec
409416

deno_webgpu/webgpu.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ enum GPUFeatureName {
9999
"texture-compression-bc",
100100
"texture-compression-etc2",
101101
"texture-compression-astc",
102+
"rg11b10ufloat-renderable",
102103

103104
// extended from spec
104105

wgpu-core/src/device/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,10 @@ impl<A: HalApi> Device<A> {
880880
let missing_allowed_usages = desc.usage - format_features.allowed_usages;
881881
if !missing_allowed_usages.is_empty() {
882882
// detect downlevel incompatibilities
883-
let wgpu_allowed_usages = desc.format.guaranteed_format_features().allowed_usages;
883+
let wgpu_allowed_usages = desc
884+
.format
885+
.guaranteed_format_features(self.features)
886+
.allowed_usages;
884887
let wgpu_missing_usages = desc.usage - wgpu_allowed_usages;
885888
return Err(CreateTextureError::InvalidFormatUsages(
886889
missing_allowed_usages,
@@ -3252,7 +3255,7 @@ impl<A: HalApi> Device<A> {
32523255
if using_device_features || downlevel {
32533256
Ok(adapter.get_texture_format_features(format))
32543257
} else {
3255-
Ok(format.guaranteed_format_features())
3258+
Ok(format.guaranteed_format_features(self.features))
32563259
}
32573260
}
32583261

wgpu-hal/src/dx12/adapter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ impl super::Adapter {
223223
| wgt::Features::CLEAR_TEXTURE
224224
| wgt::Features::TEXTURE_FORMAT_16BIT_NORM
225225
| wgt::Features::PUSH_CONSTANTS
226-
| wgt::Features::SHADER_PRIMITIVE_INDEX;
226+
| wgt::Features::SHADER_PRIMITIVE_INDEX
227+
| wgt::Features::RG11B10UFLOAT_RENDERABLE;
227228
//TODO: in order to expose this, we need to run a compute shader
228229
// that extract the necessary statistics out of the D3D12 result.
229230
// Alternatively, we could allocate a buffer for the query set,

wgpu-hal/src/metal/adapter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,8 @@ impl super::PrivateCapabilities {
800800
);
801801
features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true);
802802

803+
features.set(F::RG11B10UFLOAT_RENDERABLE, self.format_rg11b10_all);
804+
803805
features
804806
}
805807

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ impl PhysicalDeviceFeatures {
526526

527527
features.set(F::DEPTH32FLOAT_STENCIL8, texture_d32_s8);
528528

529+
let rg11b10ufloat_renderable = supports_format(
530+
instance,
531+
phd,
532+
vk::Format::B10G11R11_UFLOAT_PACK32,
533+
vk::ImageTiling::OPTIMAL,
534+
vk::FormatFeatureFlags::COLOR_ATTACHMENT | vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND,
535+
);
536+
features.set(F::RG11B10UFLOAT_RENDERABLE, rg11b10ufloat_renderable);
537+
529538
(features, dl_flags)
530539
}
531540

wgpu-types/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,7 @@ impl TextureFormat {
27122712
/// Returns the format features guaranteed by the WebGPU spec.
27132713
///
27142714
/// Additional features are available if `Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES` is enabled.
2715-
pub fn guaranteed_format_features(&self) -> TextureFormatFeatures {
2715+
pub fn guaranteed_format_features(&self, device_features: Features) -> TextureFormatFeatures {
27162716
// Multisampling
27172717
let noaa = TextureFormatFeatureFlags::empty();
27182718
let msaa = TextureFormatFeatureFlags::MULTISAMPLE_X4;
@@ -2724,6 +2724,11 @@ impl TextureFormat {
27242724
let attachment = basic | TextureUsages::RENDER_ATTACHMENT;
27252725
let storage = basic | TextureUsages::STORAGE_BINDING;
27262726
let all_flags = TextureUsages::all();
2727+
let rg11b10f = if device_features.contains(Features::RG11B10UFLOAT_RENDERABLE) {
2728+
attachment
2729+
} else {
2730+
basic
2731+
};
27272732

27282733
#[rustfmt::skip] // lets make a nice table
27292734
let (
@@ -2755,7 +2760,7 @@ impl TextureFormat {
27552760
Self::Bgra8Unorm => (msaa_resolve, attachment),
27562761
Self::Bgra8UnormSrgb => (msaa_resolve, attachment),
27572762
Self::Rgb10a2Unorm => (msaa_resolve, attachment),
2758-
Self::Rg11b10Float => ( msaa, basic),
2763+
Self::Rg11b10Float => ( msaa, rg11b10f),
27592764
Self::Rg32Uint => ( noaa, all_flags),
27602765
Self::Rg32Sint => ( noaa, all_flags),
27612766
Self::Rg32Float => ( noaa, all_flags),

wgpu/src/backend/web.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ impl crate::context::Context for Context {
10991099
_adapter_data: &Self::AdapterData,
11001100
format: wgt::TextureFormat,
11011101
) -> wgt::TextureFormatFeatures {
1102-
format.guaranteed_format_features()
1102+
format.guaranteed_format_features(wgt::Features::empty())
11031103
}
11041104

11051105
fn adapter_get_presentation_timestamp(

0 commit comments

Comments
 (0)