Skip to content

Commit

Permalink
[vk] Set WEBGPU_TEXTURE_FORMAT_SUPPORT downlevel flag depending on …
Browse files Browse the repository at this point in the history
…the proper format support (#3367)
  • Loading branch information
teoxoy authored Jan 10, 2023
1 parent 98ddb40 commit 80d2377
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
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

0 comments on commit 80d2377

Please sign in to comment.