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

[vk] Set WEBGPU_TEXTURE_FORMAT_SUPPORT downlevel flag depending on the proper format support #3367

Merged
merged 3 commits into from
Jan 10, 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Additionally `Surface::get_default_config` now returns an Option and returns Non

#### Vulkan

- Set `WEBGPU_TEXTURE_FORMAT_SUPPORT` downlevel flag depending on the proper format support by @teoxoy in [#3367](https://github.com/gfx-rs/wgpu/pull/3367).
- Set `COPY_SRC`/`COPY_DST` only based on Vulkan's `TRANSFER_SRC`/`TRANSFER_DST` by @teoxoy in [#3366](https://github.com/gfx-rs/wgpu/pull/3366).

### Added/New Features
Expand Down
71 changes: 44 additions & 27 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use parking_lot::Mutex;

use std::{collections::BTreeMap, ffi::CStr, sync::Arc};

fn depth_stencil_required_flags() -> vk::FormatFeatureFlags {
vk::FormatFeatureFlags::SAMPLED_IMAGE | vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT
}

//TODO: const fn?
fn indexing_features() -> wgt::Features {
wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING
Expand Down Expand Up @@ -325,7 +329,6 @@ impl PhysicalDeviceFeatures {
| Df::VERTEX_STORAGE
| Df::FRAGMENT_STORAGE
| Df::DEPTH_TEXTURE_AND_BUFFER_COPIES
| Df::WEBGPU_TEXTURE_FORMAT_SUPPORT
| Df::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED
| Df::UNRESTRICTED_INDEX_BUFFER
| Df::INDIRECT_EXECUTION;
Expand Down Expand Up @@ -487,17 +490,31 @@ impl PhysicalDeviceFeatures {
);
}

features.set(
F::DEPTH32FLOAT_STENCIL8,
let supports_depth_format = |format| {
supports_format(
instance,
phd,
vk::Format::D32_SFLOAT_S8_UINT,
format,
vk::ImageTiling::OPTIMAL,
vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT,
),
depth_stencil_required_flags(),
)
};

let texture_s8 = supports_depth_format(vk::Format::S8_UINT);
let texture_d32 = supports_depth_format(vk::Format::D32_SFLOAT);
let texture_d24_s8 = supports_depth_format(vk::Format::D24_UNORM_S8_UINT);
let texture_d32_s8 = supports_depth_format(vk::Format::D32_SFLOAT_S8_UINT);

let stencil8 = texture_s8 || texture_d24_s8;
let depth24_plus_stencil8 = texture_d24_s8 || texture_d32_s8;

dl_flags.set(
Df::WEBGPU_TEXTURE_FORMAT_SUPPORT,
stencil8 && depth24_plus_stencil8 && texture_d32,
);

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

(features, dl_flags)
}

Expand Down Expand Up @@ -1041,27 +1058,27 @@ impl super::Instance {
.timeline_semaphore
.map_or(false, |ext| ext.timeline_semaphore != 0),
},
texture_d24: unsafe {
self.shared
.raw
.get_physical_device_format_properties(phd, vk::Format::X8_D24_UNORM_PACK32)
.optimal_tiling_features
.contains(vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT)
},
texture_d24_s8: unsafe {
self.shared
.raw
.get_physical_device_format_properties(phd, vk::Format::D24_UNORM_S8_UINT)
.optimal_tiling_features
.contains(vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT)
},
texture_s8: unsafe {
self.shared
.raw
.get_physical_device_format_properties(phd, vk::Format::S8_UINT)
.optimal_tiling_features
.contains(vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT)
},
texture_d24: supports_format(
&self.shared.raw,
phd,
vk::Format::X8_D24_UNORM_PACK32,
vk::ImageTiling::OPTIMAL,
depth_stencil_required_flags(),
),
texture_d24_s8: supports_format(
&self.shared.raw,
phd,
vk::Format::D24_UNORM_S8_UINT,
vk::ImageTiling::OPTIMAL,
depth_stencil_required_flags(),
),
texture_s8: supports_format(
&self.shared.raw,
phd,
vk::Format::S8_UINT,
vk::ImageTiling::OPTIMAL,
depth_stencil_required_flags(),
),
non_coherent_map_mask: phd_capabilities.properties.limits.non_coherent_atom_size - 1,
can_present: true,
//TODO: make configurable
Expand Down