Skip to content

Commit

Permalink
WIP: feat(dx12,vulkan): make GPU-based validation opt-in with new `In…
Browse files Browse the repository at this point in the history
…stanceFlags::GPU_BASED_VALIDATION`

TODO: actually do it 😆
  • Loading branch information
ErichDonGubler committed Jan 11, 2024
1 parent f01934a commit 96c8aef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ Wgpu now exposes backend feature for the Direct3D 12 (`dx12`) and Metal (`metal`
- GPU buffer memory is released during "lose the device". By @bradwerth in [#4851](https://github.com/gfx-rs/wgpu/pull/4851)
- wgpu and wgpu-core features are now documented on docs.rs. By @wumpf in [#4886](https://github.com/gfx-rs/wgpu/pull/4886)
- DeviceLostClosure is guaranteed to be invoked exactly once. By @bradwerth in [#4862](https://github.com/gfx-rs/wgpu/pull/4862)
- Added `InstanceFlags::GPU_BASED_VALIDATION`, which enables GPU-based validation for shaders. This is currently only supported on the DX12 and Vulkan back ends; other platforms ignore this flag, for now.
- This has been added to the set of flags set by `InstanceFlags::debugging`.
If you notice your graphics workloads running more slowly, this may be the
culprit.
- As with other instance flags, this flag can be changed in calls to
`InstanceFlags::with_env` with the new `WGPU_GPU_BASED_VALIDATION`
environment variable.

By @ErichDonGubler in [#5046](https://github.com/gfx-rs/wgpu/pull/5046).

#### OpenGL
- `@builtin(instance_index)` now properly reflects the range provided in the draw call instead of always counting from 0. By @cwfitzgerald in [#4722](https://github.com/gfx-rs/wgpu/pull/4722).
Expand Down
16 changes: 13 additions & 3 deletions wgpu-hal/src/dx12/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ impl crate::Instance<super::Api> for super::Instance {
crate::InstanceError::with_source(String::from("failed to load d3d12.dll"), e)
})?;

if desc.flags.contains(wgt::InstanceFlags::VALIDATION) {
if desc
.flags
.intersects(wgt::InstanceFlags::VALIDATION | wgt::InstanceFlags::GPU_BASED_VALIDATION)
{
// Enable debug layer
match lib_main.get_debug_interface() {
Ok(pair) => match pair.into_result() {
Ok(debug_controller) => {
debug_controller.enable_layer();
debug_controller.enable_gpu_based_validation();
if desc.flags.intersects(wgt::InstanceFlags::VALIDATION) {
debug_controller.enable_layer();
}
if desc
.flags
.intersects(wgt::InstanceFlags::GPU_BASED_VALIDATION)
{
debug_controller.enable_gpu_based_validation();
}
}
Err(err) => {
log::warn!("Unable to enable D3D12 debug interface: {}", err);
Expand Down
7 changes: 6 additions & 1 deletion wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,12 @@ impl crate::Instance<super::Api> for super::Instance {
let mut gpu_assisted_validation = vk::ValidationFeaturesEXT::builder()
.enabled_validation_features(gpu_assisted_validation)
.build();
create_info = create_info.push_next(&mut gpu_assisted_validation);
if desc
.flags
.intersects(wgt::InstanceFlags::GPU_BASED_VALIDATION)
{
create_info = create_info.push_next(&mut gpu_assisted_validation);
}

unsafe {
profiling::scope!("vkCreateInstance");
Expand Down
17 changes: 16 additions & 1 deletion wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,18 @@ bitflags::bitflags! {
/// This mainly applies to a Vulkan driver's compliance version. If the major compliance version
/// is `0`, then the driver is ignored. This flag allows that driver to be enabled for testing.
const ALLOW_UNDERLYING_NONCOMPLIANT_ADAPTER = 1 << 3;
/// Enable GPU-based validation. Currently, this only changes behavior on DX12 and Vulkan
/// back ends.
///
/// Supported platforms:
///
/// - D3D12; called ["GPU-based validation", or
/// "GBV"](https://web.archive.org/web/20230206120404/https://learn.microsoft.com/en-us/windows/win32/direct3d12/using-d3d12-debug-layer-gpu-based-validation)
/// - Vulkan, via the `VK_LAYER_KHRONOS_validation` layer; called ["GPU-Assisted
/// Validation"](https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/e45aeb85079e0835694cb8f03e6681fd18ae72c9/docs/gpu_validation.md#gpu-assisted-validation)
/// - Apple; called ["shader
/// validation"](https://developer.apple.com/documentation/xcode/validating-your-apps-metal-shader-usage)
const GPU_BASED_VALIDATION = 1 << 4;
}
}

Expand All @@ -902,7 +914,7 @@ impl Default for InstanceFlags {
impl InstanceFlags {
/// Enable debugging and validation flags.
pub fn debugging() -> Self {
InstanceFlags::DEBUG | InstanceFlags::VALIDATION
InstanceFlags::DEBUG | InstanceFlags::VALIDATION | InstanceFlags::GPU_BASED_VALIDATION
}

/// Infer good defaults from the build type
Expand Down Expand Up @@ -945,6 +957,9 @@ impl InstanceFlags {
if let Some(bit) = env("WGPU_ALLOW_UNDERLYING_NONCOMPLIANT_ADAPTER") {
self.set(Self::ALLOW_UNDERLYING_NONCOMPLIANT_ADAPTER, bit);
}
if let Some(bit) = env("WGPU_GPU_BASED_VALIDATION") {
self.set(Self::GPU_BASED_VALIDATION, bit);
}

self
}
Expand Down

0 comments on commit 96c8aef

Please sign in to comment.