Skip to content

Commit

Permalink
gpu: Move DebugPrintf Validation Object into GPU-AV
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Oct 1, 2024
1 parent b218fb7 commit a1492d4
Show file tree
Hide file tree
Showing 33 changed files with 1,052 additions and 1,214 deletions.
9 changes: 5 additions & 4 deletions docs/debug_printf.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ The Debug Printf settings are managed by configuring the Validation Layer. These

Debug Printf settings can also be managed using the [Vulkan Configurator](https://vulkan.lunarg.com/doc/sdk/latest/windows/vkconfig.html) included with the Vulkan SDK.

For those who "just need to quick use it" there is also a `set VK_LAYER_PRINTF_ONLY_PRESET=1` environment variable that will turn on DebugPrintf and turn off all of the other validation logic.

### Settings

> All settings are found in Vulkan Configurator (`VkConfig`)
>
> Even if you use `VK_LAYER_PRINTF_ONLY_PRESET` you need to set this settings yourself as desired
There are currently 3 environment variables that are used for settings in Debug Printf

Expand Down Expand Up @@ -182,8 +186,6 @@ Would print **"Here's a vector of floats 1.20, 2.20, 3.20, 4.20"**
Would print **"Unsigned long as decimal 2305843009213693953 and as hex 0x2000000000000001"**

### Limitations
* Debug Printf cannot be used at the same time as GPU Assisted Validation.
* https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/8192
* Debug Printf consumes a descriptor set. If your application uses every last
descriptor set on the GPU, Debug Printf will not work.
* Suggest using `VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT`
Expand All @@ -193,8 +195,7 @@ buffer size.
* Can be controlled with `VK_LAYER_PRINTF_BUFFER_SIZE`
* Validation Layers version: `1.2.135.0` or later is required
* Vulkan API version 1.1 or greater is required
* VkPhysicalDevice features: `fragmentStoresAndAtomics` and `vertexPipelineStoresAndAtomics`
are required
* When using Validation Layers, the `fragmentStoresAndAtomics`, `vertexPipelineStoresAndAtomics`, and `timelineSemaphore` features are required
* The `VK_KHR_shader_non_semantic_info` extension must be supported and enabled
* If using the Validation Layers, we attempt to strip it out to allow wider range of users to still use Debug Printf
* RenderDoc release 1.14 or later
Expand Down
972 changes: 531 additions & 441 deletions layers/VkLayer_khronos_validation.json.in

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions layers/gpu/core/gpu_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ struct GpuAVSettings {
bool cache_instrumented_shaders = true;
bool select_instrumented_shaders = false;

bool buffers_validation_enabled = true;
// Turned off until we can fix things
// see https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/8579
bool validate_indirect_draws_buffers = false;
Expand All @@ -40,7 +39,9 @@ struct GpuAVSettings {
uint32_t debug_max_instrumented_count = 0; // zero is same as "unlimited"
bool debug_print_instrumentation_info = false;

bool shader_instrumentation_enabled = true;
// Note - even though DebugPrintf basically fits in here, from the user point of view they are different and that is reflected
// in the settings (which are reflected in VkConfig). To make our lives easier, we just make these settings with the hierarchy
// of the settings exposed
struct ShaderInstrumentation {
bool bindless_descriptor = true;
bool buffer_device_address = true;
Expand All @@ -53,8 +54,6 @@ struct GpuAVSettings {
}
// Also disables shader caching and select shader instrumentation
void DisableShaderInstrumentationAndOptions() {
shader_instrumentation_enabled = false;

shader_instrumentation.bindless_descriptor = false;
shader_instrumentation.buffer_device_address = false;
shader_instrumentation.ray_query = false;
Expand All @@ -73,6 +72,18 @@ struct GpuAVSettings {
validate_buffer_copies = enabled;
}

// For people who are using VkValidationFeatureEnableEXT to set only DebugPrintf (and want the rest of GPU-AV off)
bool debug_printf_only = false;
void SetOnlyDebugPrintf() {
DisableShaderInstrumentationAndOptions();
SetBufferValidationEnabled(false);

// Turn on the minmal settings for DebugPrintf
debug_printf_enabled = true;
debug_printf_only = true;
}

bool debug_printf_enabled = false;
bool debug_printf_to_stdout = false;
bool debug_printf_verbose = false;
uint32_t debug_printf_buffer_size = 1024;
Expand Down
5 changes: 1 addition & 4 deletions layers/gpu/core/gpuav.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ class Validator : public gpu::GpuShaderInstrumentor {
using Field = vvl::Field;

public:
Validator() {
container_type = LayerObjectTypeGpuAssisted;
gpuav_enabled = true;
}
Validator() { container_type = LayerObjectTypeGpuAssisted; }

// gpuav_setup.cpp
// -------------
Expand Down
103 changes: 67 additions & 36 deletions layers/gpu/core/gpuav_record.cpp

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions layers/gpu/core/gpuav_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ void Validator::PostCreateDevice(const VkDeviceCreateInfo *pCreateInfo, const Lo
desc_heap_.emplace(*this, 0, loc);

instrumentation_bindings_ = {
// DebugPrintf Output buffer
{glsl::kBindingInstDebugPrintf, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Error output buffer
{glsl::kBindingInstErrorBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Current bindless buffer
Expand All @@ -223,7 +225,6 @@ void Validator::PostCreateDevice(const VkDeviceCreateInfo *pCreateInfo, const Lo
{glsl::kBindingInstCmdErrorsCount, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
};

// Currently, both GPU-AV and DebugPrintf set their own instrumentation_bindings_ that this call will use
BaseClass::PostCreateDevice(pCreateInfo, loc);
// We might fail in parent class device creation if global requirements are not met
if (aborted_) return;
Expand Down Expand Up @@ -390,7 +391,7 @@ void Validator::InitSettings(const Location &loc) {
InternalWarning(
device, loc,
"VK_EXT_descriptor_buffer is enabled, but GPU-AV does not currently support validation of descriptor buffers. "
"[Disabling shader_instrumentation_enabled]");
"[Disabling all shader instrumentation checks]");
// Because of VUs like VUID-VkPipelineLayoutCreateInfo-pSetLayouts-08008 we currently would need to rework the entire shader
// instrumentation logic
gpuav_settings.DisableShaderInstrumentationAndOptions();
Expand Down
Loading

0 comments on commit a1492d4

Please sign in to comment.