From 703dd13d0e4ff20ae62f1b9712f82b08b909c447 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 11 Jan 2024 14:09:12 -0500 Subject: [PATCH] feat(vulkan): enable GPU-based validation for Vulkan backend Logic for doing this was sourced from page 3 of [LunarG's guide], with the following section stack: * Activating GPU-Assisted Validation * Enabling and Specifying Options with the Programmatic Interface [LunarG's guide]: https://www.lunarg.com/wp-content/uploads/2019/02/GPU-Assisted-Validation_v3_02_22_19.pdf --- CHANGELOG.md | 2 +- wgpu-hal/src/vulkan/instance.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be56b914a7a..77b3ffd5534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,7 +67,7 @@ Bottom level categories: - `tan` - `tanh` - Eager release of GPU resources comes from device.trackers. By @bradwerth in [#5075](https://github.com/gfx-rs/wgpu/pull/5075) -- Added `InstanceFlags::GPU_BASED_VALIDATION`, which enables GPU-based validation for shaders. This is currently only supported on the DX12 back end; other platforms ignore this flag, for now. +- 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` and `InstanceFlags::from_build_config`. 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. diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 1f0159413f1..1d7e79f4cfd 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -756,6 +756,15 @@ impl crate::Instance for super::Instance { create_info = create_info.push_next(vk_create_info); } + let mut gpu_assisted_validation = vk::ValidationFeaturesEXT::builder() + .enabled_validation_features(&[vk::ValidationFeatureEnableEXT::GPU_ASSISTED]); + if desc + .flags + .intersects(wgt::InstanceFlags::GPU_BASED_VALIDATION) + { + create_info = create_info.push_next(&mut gpu_assisted_validation); + } + unsafe { profiling::scope!("vkCreateInstance"); entry.create_instance(&create_info, None)