Skip to content

Commit

Permalink
Add missing DEPTH_BIAS_CLAMP and FULL_DRAW_INDEX_UINT32 downlevel…
Browse files Browse the repository at this point in the history
… flags (#3316)

* add missing `DEPTH_BIAS_CLAMP` and `FULL_DRAW_INDEX_UINT32` downlevel flags

* add changelog entry

* use require_downlevel_flags
  • Loading branch information
teoxoy authored Dec 20, 2022
1 parent c91cae4 commit 62e932b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Additionally `Surface::get_default_config` now returns an Option and returns Non
- Lower the `max_buffer_size` limit value for compatibility with Apple2 and WebGPU compliance. By @jinleili in [#3255](https://github.com/gfx-rs/wgpu/pull/3255)
- Dereferencing a buffer view is now marked inline. By @Wumpf in [#3307](https://github.com/gfx-rs/wgpu/pull/3307)
- The `strict_assert` family of macros was moved to `wgpu-types`. By @i509VCB in [#3051](https://github.com/gfx-rs/wgpu/pull/3051)
- Add missing `DEPTH_BIAS_CLAMP` and `FULL_DRAW_INDEX_UINT32` downlevel flags. By @teoxoy in [#3316](https://github.com/gfx-rs/wgpu/pull/3316)

#### WebGPU

Expand Down
4 changes: 4 additions & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2738,6 +2738,10 @@ impl<A: HalApi> Device<A> {
if let Some(e) = error {
return Err(pipeline::CreateRenderPipelineError::DepthStencilState(e));
}

if ds.bias.clamp != 0.0 {
self.require_downlevel_flags(wgt::DownlevelFlags::DEPTH_BIAS_CLAMP)?;
}
}

if desc.layout.is_none() {
Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/dx11/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ impl super::Adapter {
downlevel |= wgt::DownlevelFlags::INDEPENDENT_BLEND;
// formally FL9_1 supports aniso 2, but we don't support that level of distinction
downlevel |= wgt::DownlevelFlags::ANISOTROPIC_FILTERING;
// this is actually the first FL that supports u32 at all
downlevel |= wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32;
}

if feature_level >= FL9_3 {
Expand All @@ -120,6 +122,7 @@ impl super::Adapter {
downlevel |= wgt::DownlevelFlags::INDEPENDENT_BLEND;
downlevel |= wgt::DownlevelFlags::FRAGMENT_STORAGE;
downlevel |= wgt::DownlevelFlags::FRAGMENT_WRITABLE_STORAGE;
downlevel |= wgt::DownlevelFlags::DEPTH_BIAS_CLAMP;
features |= wgt::Features::DEPTH_CLIP_CONTROL;
features |= wgt::Features::TIMESTAMP_QUERY;
features |= wgt::Features::PIPELINE_STATISTICS_QUERY;
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl super::Adapter {
} else {
0
};
let max_element_index = unsafe { gl.get_parameter_i32(glow::MAX_ELEMENT_INDEX) } as u32;

// WORKAROUND: In order to work around an issue with GL on RPI4 and similar, we ignore a
// zero vertex ssbo count if there are vertex sstos. (more info:
Expand Down Expand Up @@ -316,6 +317,10 @@ impl super::Adapter {
wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER,
!cfg!(target_arch = "wasm32"),
);
downlevel_flags.set(
wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32,
max_element_index == u32::MAX,
);

let mut features = wgt::Features::empty()
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES
Expand Down
18 changes: 17 additions & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,18 @@ impl PhysicalDeviceFeatures {
| F::WRITE_TIMESTAMP_INSIDE_PASSES
| F::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES
| F::CLEAR_TEXTURE;
let mut dl_flags = Df::all();

let mut dl_flags = Df::COMPUTE_SHADERS
| Df::BASE_VERTEX
| Df::READ_ONLY_DEPTH_STENCIL
| Df::NON_POWER_OF_TWO_MIPMAPPED_TEXTURES
| Df::COMPARISON_SAMPLERS
| 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;

dl_flags.set(Df::CUBE_ARRAY_TEXTURES, self.core.image_cube_array != 0);
dl_flags.set(Df::ANISOTROPIC_FILTERING, self.core.sampler_anisotropy != 0);
Expand All @@ -326,6 +337,11 @@ impl PhysicalDeviceFeatures {
);
dl_flags.set(Df::MULTISAMPLED_SHADING, self.core.sample_rate_shading != 0);
dl_flags.set(Df::INDEPENDENT_BLEND, self.core.independent_blend != 0);
dl_flags.set(
Df::FULL_DRAW_INDEX_UINT32,
self.core.full_draw_index_uint32 != 0,
);
dl_flags.set(Df::DEPTH_BIAS_CLAMP, self.core.depth_bias_clamp != 0);

features.set(
F::INDIRECT_FIRST_INSTANCE,
Expand Down
10 changes: 10 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,16 @@ bitflags::bitflags! {
///
/// WebGL doesn't support this.
const UNRESTRICTED_INDEX_BUFFER = 1 << 16;

/// Supports full 32-bit range indices (2^32-1 as opposed to 2^24-1 without this flag)
///
/// Corresponds to Vulkan's `VkPhysicalDeviceFeatures.fullDrawIndexUint32`
const FULL_DRAW_INDEX_UINT32 = 1 << 17;

/// Supports depth bias clamping
///
/// Corresponds to Vulkan's `VkPhysicalDeviceFeatures.depthBiasClamp`
const DEPTH_BIAS_CLAMP = 1 << 18;
}
}

Expand Down

0 comments on commit 62e932b

Please sign in to comment.