Skip to content

Commit 7215968

Browse files
committed
User-configurable gpuav indices_count. This can be used by apps using large amounts of draw commands to not run into the internal limit.
1 parent bee5e6c commit 7215968

File tree

10 files changed

+54
-50
lines changed

10 files changed

+54
-50
lines changed

layers/gpuav/core/gpuav_constants.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ namespace gpuav {
2323
// constant
2424
namespace cst {
2525

26-
// Number of indices held in the buffer used to index commands and validation resources
27-
inline constexpr uint32_t indices_count = 1u << 13; // 8192
28-
// If we hit our limit, we will use this to signal to the app what they are seeing is likely garbage.
29-
// This is required because we still need to bind our descriptors regardless.
30-
inline constexpr uint32_t invalid_index_command = indices_count - 1;
31-
3226
// TODO - Need to develop a proper way to gather ALL binding between shader instrumentation and command validation
3327
// For now we get enough for DebugPrintf
3428
inline constexpr uint32_t total_internal_descriptors = 64;

layers/gpuav/core/gpuav_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ bool GpuAVSettings::IsShaderInstrumentationEnabled() const {
3636
shader_instrumentation.sanitizer;
3737
}
3838
bool GpuAVSettings::IsSpirvModified() const { return IsShaderInstrumentationEnabled() || debug_printf_enabled; }
39+
uint32_t GpuAVSettings::GetInvalidIndexCommand() const { return indices_count - 1; }
3940

4041
// Also disables shader caching and select shader instrumentation
4142
void GpuAVSettings::DisableShaderInstrumentationAndOptions() {

layers/gpuav/core/gpuav_settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct GpuAVSettings {
4545
bool debug_dump_instrumented_shaders = false;
4646
uint32_t debug_max_instrumentations_count = 0; // zero is same as "unlimited"
4747
bool debug_print_instrumentation_info = false;
48+
uint32_t indices_count = 1u << 13;
4849

4950
bool descriptor_buffer_override = false;
5051

@@ -64,6 +65,7 @@ struct GpuAVSettings {
6465

6566
bool IsShaderInstrumentationEnabled() const;
6667
bool IsSpirvModified() const;
68+
uint32_t GetInvalidIndexCommand() const;
6769

6870
// Also disables shader caching and select shader instrumentation
6971
void DisableShaderInstrumentationAndOptions();

layers/gpuav/core/gpuav_setup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void Validator::FinishDeviceSetup(const VkDeviceCreateInfo *pCreateInfo, const L
285285

286286
VkBufferCreateInfo buffer_info = vku::InitStructHelper();
287287
buffer_info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
288-
buffer_info.size = cst::indices_count * indices_buffer_alignment_;
288+
buffer_info.size = gpuav_settings.indices_count * indices_buffer_alignment_;
289289
VmaAllocationCreateInfo alloc_info = {};
290290
alloc_info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
291291
alloc_info.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
@@ -296,7 +296,7 @@ void Validator::FinishDeviceSetup(const VkDeviceCreateInfo *pCreateInfo, const L
296296

297297
uint32_t stride = indices_buffer_alignment_ / sizeof(uint32_t);
298298
uint32_t *indices_ptr = (uint32_t *)global_indices_buffer_.GetMappedPtr();
299-
for (uint32_t i = 0; i < cst::indices_count; ++i) {
299+
for (uint32_t i = 0; i < gpuav_settings.indices_count; ++i) {
300300
const uint32_t offset = i * stride;
301301
indices_ptr[offset] = i;
302302
}

layers/gpuav/instrumentation/gpuav_instrumentation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ void PreCallSetupShaderInstrumentationResourcesClassic(Validator &gpuav, Command
393393

394394
const uint32_t error_logger_index = cb_state.GetErrorLoggerIndex();
395395

396-
assert(error_logger_index < cst::indices_count);
397-
assert(error_info.action_command_index < cst::indices_count);
396+
assert(error_logger_index < gpuav.gpuav_settings.indices_count);
397+
assert(error_info.action_command_index < gpuav.gpuav_settings.indices_count);
398398
const std::array<uint32_t, 2> dynamic_offsets = {
399399
{error_info.action_command_index * gpuav.indices_buffer_alignment_, error_logger_index * gpuav.indices_buffer_alignment_}};
400400

layers/gpuav/instrumentation/gpuav_shader_instrumentor.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -820,31 +820,30 @@ void GpuShaderInstrumentor::PostCallRecordCreateRayTracingPipelinesKHR(
820820
return;
821821
}
822822

823-
deferred_op_post_checks.emplace_back(
824-
[this, held_chassis_state = chassis_state](std::pair<uint32_t, VkPipeline *> pipelines) mutable {
825-
for (const auto [pipe_i, pipe] : vvl::enumerate(pipelines.second, pipelines.first)) {
826-
std::shared_ptr<vvl::Pipeline> pipeline_state = ((GpuShaderInstrumentor *)this)->Get<vvl::Pipeline>(pipe);
827-
ASSERT_AND_CONTINUE(pipeline_state);
828-
if (pipeline_state->ray_tracing_library_ci) {
829-
for (VkPipeline lib : vvl::make_span(pipeline_state->ray_tracing_library_ci->pLibraries,
830-
pipeline_state->ray_tracing_library_ci->libraryCount)) {
831-
auto lib_state = ((GpuShaderInstrumentor *)this)->Get<vvl::Pipeline>(lib);
832-
ASSERT_AND_CONTINUE(lib_state);
833-
pipeline_state->instrumentation_data.was_instrumented |=
834-
lib_state->instrumentation_data.was_instrumented;
835-
}
823+
deferred_op_post_checks.emplace_back([this, held_chassis_state =
824+
chassis_state](std::pair<uint32_t, VkPipeline *> pipelines) mutable {
825+
for (const auto [pipe_i, pipe] : vvl::enumerate(pipelines.second, pipelines.first)) {
826+
std::shared_ptr<vvl::Pipeline> pipeline_state = ((GpuShaderInstrumentor *)this)->Get<vvl::Pipeline>(pipe);
827+
ASSERT_AND_CONTINUE(pipeline_state);
828+
if (pipeline_state->ray_tracing_library_ci) {
829+
for (VkPipeline lib : vvl::make_span(pipeline_state->ray_tracing_library_ci->pLibraries,
830+
pipeline_state->ray_tracing_library_ci->libraryCount)) {
831+
auto lib_state = ((GpuShaderInstrumentor *)this)->Get<vvl::Pipeline>(lib);
832+
ASSERT_AND_CONTINUE(lib_state);
833+
pipeline_state->instrumentation_data.was_instrumented |= lib_state->instrumentation_data.was_instrumented;
836834
}
837-
auto &shader_instrumentation_metadata = held_chassis_state->shader_instrumentations_metadata[pipe_i];
838-
// Ray tracing pipelines can be made of libraries, but contrary to GPL instrumentation is not postponed
839-
// to final link time, and done at ray tracing library creation time.
840-
// => No need to iterate over shader stages coming from libraries,
841-
// stop at VkRayTracingPipelineCreateInfoKHR::stageCount
842-
// Note: This code implicitly relies on the fact that in pipeline_state->stage_states,
843-
// stages coming from libraries are added last.
844-
PostCallRecordPipelineCreationShaderInstrumentation(
845-
*pipeline_state, pipeline_state->RayTracingCreateInfo().stageCount, shader_instrumentation_metadata);
846835
}
847-
});
836+
auto &shader_instrumentation_metadata = held_chassis_state->shader_instrumentations_metadata[pipe_i];
837+
// Ray tracing pipelines can be made of libraries, but contrary to GPL instrumentation is not postponed
838+
// to final link time, and done at ray tracing library creation time.
839+
// => No need to iterate over shader stages coming from libraries,
840+
// stop at VkRayTracingPipelineCreateInfoKHR::stageCount
841+
// Note: This code implicitly relies on the fact that in pipeline_state->stage_states,
842+
// stages coming from libraries are added last.
843+
PostCallRecordPipelineCreationShaderInstrumentation(
844+
*pipeline_state, pipeline_state->RayTracingCreateInfo().stageCount, shader_instrumentation_metadata);
845+
}
846+
});
848847
dispatch_device_->deferred_operation_post_check.insert(deferredOperation, std::move(deferred_op_post_checks));
849848
} else {
850849
for (uint32_t i = 0; i < count; ++i) {
@@ -1129,7 +1128,7 @@ bool GpuShaderInstrumentor::PreCallRecordPipelineCreationShaderInstrumentation(
11291128
auto modified_module_state = std::const_pointer_cast<vvl::ShaderModule>(stage_state.module_state);
11301129
ASSERT_AND_CONTINUE(modified_module_state);
11311130
if (!modified_module_state->spirv) {
1132-
continue; // Hit when using VK_KHR_pipeline_binary
1131+
continue; // Hit when using VK_KHR_pipeline_binary
11331132
}
11341133
std::unique_lock<std::mutex> module_lock(modified_module_state->module_mutex_);
11351134

@@ -1818,8 +1817,9 @@ std::string GpuShaderInstrumentor::GenerateDebugInfoMessage(VkCommandBuffer comm
18181817
ss << "Unknown Pipeline Operation ";
18191818
}
18201819

1821-
if (action_command_index == cst::invalid_index_command) {
1822-
ss << "Index Unknown (After " << cst::invalid_index_command << " commands, we stop tracking) \n";
1820+
uint32_t invalid_index_command = dispatch_instance_->settings.gpuav_settings.GetInvalidIndexCommand();
1821+
if (action_command_index == invalid_index_command) {
1822+
ss << "Index Unknown (After " << invalid_index_command << " commands, we stop tracking) \n";
18231823
} else {
18241824
ss << "Index " << action_command_index << '\n';
18251825
}

layers/gpuav/instrumentation/post_process_descriptor_indexing.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ void RegisterPostProcessingValidation(Validator& gpuav, CommandBufferSubState& c
197197

198198
context.SetOriginalSpirv(&it->second.original_spirv);
199199

200+
uint32_t invalid_index_command = gpuav.gpuav_settings.GetInvalidIndexCommand();
200201
for (const DescriptorAccess& descriptor_access : descriptor_accesses) {
201-
if (descriptor_access.error_logger_i == cst::invalid_index_command) {
202+
if (descriptor_access.error_logger_i == invalid_index_command) {
202203
gpuav.LogError("GPUAV-Overflow-Unknown", LogObjectList(), Location(vvl::Func::Empty),
203204
"Cannot perform runtime descriptor access validation, access was done in a command past the "
204205
"internal limit of %" PRIu32 " draw/dispatch/traceRays in a command buffer.",
205-
cst::indices_count);
206+
gpuav.gpuav_settings.indices_count);
206207
continue;
207208
}
208209

layers/gpuav/resources/gpuav_state_trackers.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void CommandBufferSubState::RecordEndRenderPass(const VkSubpassEndInfo *, const
152152
// For things like vkCmdCopyImage there is no "last bound" as not shaders are attached to it
153153
void CommandBufferSubState::AddCommandErrorLogger(const Location &loc, const LastBound *last_bound,
154154
ErrorLoggerFunc error_logger_func) {
155-
if (command_error_loggers_.size() == cst::invalid_index_command) {
155+
if (command_error_loggers_.size() == gpuav_.gpuav_settings.GetInvalidIndexCommand()) {
156156
return;
157157
}
158158

@@ -203,18 +203,18 @@ void CommandBufferSubState::ResetCBState(bool should_destroy) {
203203
void CommandBufferSubState::IncrementActionCommandCount(VkPipelineBindPoint bind_point) {
204204
if (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) {
205205
draw_index++;
206-
if (draw_index > cst::invalid_index_command) {
207-
draw_index = cst::invalid_index_command;
206+
if (draw_index > gpuav_.gpuav_settings.GetInvalidIndexCommand()) {
207+
draw_index = gpuav_.gpuav_settings.GetInvalidIndexCommand();
208208
}
209209
} else if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) {
210210
compute_index++;
211-
if (compute_index > cst::invalid_index_command) {
212-
compute_index = cst::invalid_index_command;
211+
if (compute_index > gpuav_.gpuav_settings.GetInvalidIndexCommand()) {
212+
compute_index = gpuav_.gpuav_settings.GetInvalidIndexCommand();
213213
}
214214
} else if (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) {
215215
trace_rays_index++;
216-
if (trace_rays_index > cst::invalid_index_command) {
217-
trace_rays_index = cst::invalid_index_command;
216+
if (trace_rays_index > gpuav_.gpuav_settings.GetInvalidIndexCommand()) {
217+
trace_rays_index = gpuav_.gpuav_settings.GetInvalidIndexCommand();
218218
}
219219
}
220220
}
@@ -351,14 +351,14 @@ void CommandBufferSubState::OnCompletion(VkQueue queue, const std::vector<std::s
351351
const uint32_t error_logger_i =
352352
error_record_ptr[glsl::kHeader_ActionIdErrorLoggerIdOffset] & glsl::kErrorLoggerId_Mask;
353353

354-
assert(error_logger_i < cst::indices_count);
355-
if (error_logger_i == cst::invalid_index_command) {
354+
assert(error_logger_i < gpuav_.gpuav_settings.indices_count);
355+
if (error_logger_i == gpuav_.gpuav_settings.GetInvalidIndexCommand()) {
356356
const LogObjectList objlist(queue, VkHandle());
357357
gpuav_.LogError(
358358
"GPUAV-Overflow-Unknown", queue, loc,
359359
"An error was detected, but after internal limit of %" PRIu32
360360
" draw/dispatch/traceRays in a command buffer, we are unable to track which validation error occured.",
361-
cst::indices_count);
361+
gpuav_.gpuav_settings.indices_count);
362362
} else {
363363
// normal case
364364
const CommandErrorLogger &error_logger = GetErrorLogger(error_logger_i);

layers/gpuav/validation_cmd/gpuav_validation_cmd_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace valcmd {
3030
namespace internal {
3131
static void BindErrorLoggingDescSet(Validator &gpuav, CommandBufferSubState &cb_state, VkPipelineBindPoint bind_point,
3232
VkPipelineLayout pipeline_layout, uint32_t cmd_index, uint32_t error_logger_index) {
33-
assert(cmd_index < cst::indices_count);
34-
assert(error_logger_index < cst::indices_count);
33+
assert(cmd_index < gpuav.gpuav_settings.indices_count);
34+
assert(error_logger_index < gpuav.gpuav_settings.indices_count);
3535
std::array<uint32_t, 2> dynamic_offsets = {
3636
{cmd_index * gpuav.indices_buffer_alignment_, error_logger_index * gpuav.indices_buffer_alignment_}};
3737

layers/layer_options.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ const char *VK_LAYER_GPUAV_DEBUG_VALIDATE_INSTRUMENTED_SHADERS = "gpuav_debug_va
218218
const char *VK_LAYER_GPUAV_DEBUG_DUMP_INSTRUMENTED_SHADERS = "gpuav_debug_dump_instrumented_shaders";
219219
const char *VK_LAYER_GPUAV_DEBUG_MAX_INSTRUMENTATIONS_COUNT = "gpuav_debug_max_instrumentations_count";
220220
const char *VK_LAYER_GPUAV_DEBUG_PRINT_INSTRUMENTATION_INFO = "gpuav_debug_print_instrumentation_info";
221+
const char *VK_LAYER_GPUAV_INDICES_COUNT = "gpuav_indices_count";
221222

222223
// SyncVal
223224
// ---
@@ -1084,6 +1085,11 @@ void ProcessConfigAndEnvSettings(ConfigAndEnvSettings *settings_data) {
10841085
gpuav_settings.debug_print_instrumentation_info);
10851086
}
10861087

1088+
if (vkuHasLayerSetting(layer_setting_set, VK_LAYER_GPUAV_INDICES_COUNT)) {
1089+
vkuGetLayerSettingValue(layer_setting_set, VK_LAYER_GPUAV_INDICES_COUNT,
1090+
gpuav_settings.indices_count);
1091+
}
1092+
10871093
if (vkuHasLayerSetting(layer_setting_set, VK_LAYER_PRINTF_TO_STDOUT)) {
10881094
vkuGetLayerSettingValue(layer_setting_set, VK_LAYER_PRINTF_TO_STDOUT, gpuav_settings.debug_printf_to_stdout);
10891095
}

0 commit comments

Comments
 (0)