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

Implement Features::RG11B10UFLOAT_RENDERABLE #3701

Merged
merged 2 commits into from
Apr 19, 2023
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
1 change: 1 addition & 0 deletions deno_webgpu/02_idl_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ webidl.converters["GPUFeatureName"] = webidl.createEnumConverter(
"texture-compression-bc",
"texture-compression-etc2",
"texture-compression-astc",
"rg11b10ufloat-renderable",

// extended from spec

Expand Down
7 changes: 7 additions & 0 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC) {
return_features.push("texture-compression-astc");
}
if features.contains(wgpu_types::Features::RG11B10UFLOAT_RENDERABLE) {
return_features.push("rg11b10ufloat-renderable");
}

// extended from spec

Expand Down Expand Up @@ -404,6 +407,10 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
wgpu_types::Features::TEXTURE_COMPRESSION_ASTC,
required_features.0.contains("texture-compression-astc"),
);
features.set(
wgpu_types::Features::RG11B10UFLOAT_RENDERABLE,
required_features.0.contains("rg11b10ufloat-renderable"),
);

// extended from spec

Expand Down
1 change: 1 addition & 0 deletions deno_webgpu/webgpu.idl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ enum GPUFeatureName {
"texture-compression-bc",
"texture-compression-etc2",
"texture-compression-astc",
"rg11b10ufloat-renderable",

// extended from spec

Expand Down
7 changes: 5 additions & 2 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,10 @@ impl<A: HalApi> Device<A> {
let missing_allowed_usages = desc.usage - format_features.allowed_usages;
if !missing_allowed_usages.is_empty() {
// detect downlevel incompatibilities
let wgpu_allowed_usages = desc.format.guaranteed_format_features().allowed_usages;
let wgpu_allowed_usages = desc
.format
.guaranteed_format_features(self.features)
.allowed_usages;
let wgpu_missing_usages = desc.usage - wgpu_allowed_usages;
return Err(CreateTextureError::InvalidFormatUsages(
missing_allowed_usages,
Expand Down Expand Up @@ -3252,7 +3255,7 @@ impl<A: HalApi> Device<A> {
if using_device_features || downlevel {
Ok(adapter.get_texture_format_features(format))
} else {
Ok(format.guaranteed_format_features())
Ok(format.guaranteed_format_features(self.features))
}
}

Expand Down
3 changes: 2 additions & 1 deletion wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ impl super::Adapter {
| wgt::Features::CLEAR_TEXTURE
| wgt::Features::TEXTURE_FORMAT_16BIT_NORM
| wgt::Features::PUSH_CONSTANTS
| wgt::Features::SHADER_PRIMITIVE_INDEX;
| wgt::Features::SHADER_PRIMITIVE_INDEX
| wgt::Features::RG11B10UFLOAT_RENDERABLE;
//TODO: in order to expose this, we need to run a compute shader
// that extract the necessary statistics out of the D3D12 result.
// Alternatively, we could allocate a buffer for the query set,
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ impl super::PrivateCapabilities {
);
features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true);

features.set(F::RG11B10UFLOAT_RENDERABLE, self.format_rg11b10_all);

features
}

Expand Down
10 changes: 10 additions & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ impl PhysicalDeviceFeatures {

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

let rg11b10ufloat_renderable = supports_format(
instance,
phd,
vk::Format::B10G11R11_UFLOAT_PACK32,
vk::ImageTiling::OPTIMAL,
vk::FormatFeatureFlags::COLOR_ATTACHMENT
| vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND,
);
features.set(F::RG11B10UFLOAT_RENDERABLE, rg11b10ufloat_renderable);

(features, dl_flags)
}

Expand Down
9 changes: 7 additions & 2 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ impl TextureFormat {
/// Returns the format features guaranteed by the WebGPU spec.
///
/// Additional features are available if `Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES` is enabled.
pub fn guaranteed_format_features(&self) -> TextureFormatFeatures {
pub fn guaranteed_format_features(&self, device_features: Features) -> TextureFormatFeatures {
// Multisampling
let noaa = TextureFormatFeatureFlags::empty();
let msaa = TextureFormatFeatureFlags::MULTISAMPLE_X4;
Expand All @@ -2724,6 +2724,11 @@ impl TextureFormat {
let attachment = basic | TextureUsages::RENDER_ATTACHMENT;
let storage = basic | TextureUsages::STORAGE_BINDING;
let all_flags = TextureUsages::all();
let rg11b10f = if device_features.contains(Features::RG11B10UFLOAT_RENDERABLE) {
attachment
} else {
basic
};

#[rustfmt::skip] // lets make a nice table
let (
Expand Down Expand Up @@ -2755,7 +2760,7 @@ impl TextureFormat {
Self::Bgra8Unorm => (msaa_resolve, attachment),
Self::Bgra8UnormSrgb => (msaa_resolve, attachment),
Self::Rgb10a2Unorm => (msaa_resolve, attachment),
Self::Rg11b10Float => ( msaa, basic),
Self::Rg11b10Float => ( msaa, rg11b10f),
Self::Rg32Uint => ( noaa, all_flags),
Self::Rg32Sint => ( noaa, all_flags),
Self::Rg32Float => ( noaa, all_flags),
Expand Down
6 changes: 3 additions & 3 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,11 @@ impl crate::context::Context for Context {

fn adapter_get_texture_format_features(
&self,
_adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData,
adapter: &Self::AdapterId,
adapter_data: &Self::AdapterData,
format: wgt::TextureFormat,
) -> wgt::TextureFormatFeatures {
format.guaranteed_format_features()
format.guaranteed_format_features(self.adapter_features(adapter, adapter_data))
}

fn adapter_get_presentation_timestamp(
Expand Down