Skip to content

Commit 411c2fc

Browse files
committed
debug: Test stricter alignments, fix conflicts
1 parent 9f58dad commit 411c2fc

22 files changed

+321
-333
lines changed

layers/gpuav/core/gpuav_setup.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,7 @@ void Validator::FinishDeviceSetup(const VkDeviceCreateInfo *pCreateInfo, const L
264264

265265
// Create command indices buffer
266266
{
267-
indices_buffer_alignment_ =
268-
sizeof(uint32_t) *
269-
static_cast<uint32_t>(
270-
phys_dev_props.limits.minStorageBufferOffsetAlignment); // #ARNO_TODO need to find correct alignment, we align
271-
// buffer device addresses
267+
indices_buffer_alignment_ = sizeof(uint32_t) * static_cast<uint32_t>(phys_dev_props.limits.minStorageBufferOffsetAlignment);
272268
VkBufferCreateInfo buffer_info = vku::InitStructHelper();
273269
buffer_info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
274270
buffer_info.size = cst::indices_count * indices_buffer_alignment_;

layers/gpuav/instrumentation/gpuav_instrumentation.cpp

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#include "state_tracker/shader_module.h"
4040
#include "utils/action_command_utils.h"
4141

42-
#include <iostream>
43-
4442
namespace gpuav {
4543

4644
// If application is using shader objects, bindings count will be computed from bound shaders
@@ -304,9 +302,9 @@ void UpdateInstrumentationDescSet(Validator &gpuav, CommandBufferSubState &cb_st
304302
assert(root_node_ptr->inst_action_index_buffer);
305303

306304
// Buffer holding a resource index from the per command buffer command resources list
307-
root_node_ptr->inst_cmd_resource_index_buffer =
305+
root_node_ptr->inst_error_logger_index_buffer =
308306
gpuav.indices_buffer_.Address() + error_logger_i * gpuav.indices_buffer_alignment_;
309-
assert(root_node_ptr->inst_cmd_resource_index_buffer);
307+
assert(root_node_ptr->inst_error_logger_index_buffer);
310308

311309
// Errors count buffer
312310
root_node_ptr->inst_cmd_errors_count_buffer = cb_state.GetCmdErrorsCountsBuffer().Address();
@@ -379,24 +377,6 @@ void UpdateInstrumentationDescSet(Validator &gpuav, CommandBufferSubState &cb_st
379377
wds.pBufferInfo = &dbi;
380378

381379
DispatchUpdateDescriptorSets(gpuav.device, 1, &wds, 0, nullptr);
382-
#if 0
383-
std::cout << "root_node_ptr:\n---\n";
384-
std::cout << "root_node_ptr: " << std::hex << "0x" << root_node_ptr_buffer_range.offset_address << std::endl;
385-
std::cout << "root_node_ptr->debug_printf_buffer: " << std::hex << "0x" << root_node_ptr->debug_printf_buffer << std::endl;
386-
std::cout << "root_node_ptr->inst_errors_buffer: " << std::hex << "0x" << root_node_ptr->inst_errors_buffer << std::endl;
387-
std::cout << "root_node_ptr->inst_action_index_buffer: " << std::hex << "0x" << root_node_ptr->inst_action_index_buffer
388-
<< std::endl;
389-
std::cout << "root_node_ptr->inst_cmd_resource_index_buffer: " << std::hex << "0x"
390-
<< root_node_ptr->inst_cmd_resource_index_buffer << std::endl;
391-
std::cout << "root_node_ptr->inst_cmd_errors_count_buffer: " << std::hex << "0x" << root_node_ptr->inst_cmd_errors_count_buffer
392-
<< std::endl;
393-
std::cout << "root_node_ptr->vertex_attribute_fetch_limits_buffer: " << std::hex << "0x"
394-
<< root_node_ptr->vertex_attribute_fetch_limits_buffer << std::endl;
395-
std::cout << "root_node_ptr->bda_input_buffer: " << std::hex << "0x" << root_node_ptr->bda_input_buffer << std::endl;
396-
std::cout << "root_node_ptr->post_process_ssbo: " << std::hex << "0x" << root_node_ptr->post_process_ssbo << std::endl;
397-
std::cout << "root_node_ptr->bound_desc_sets_state_ssbo: " << std::hex << "0x" << root_node_ptr->bound_desc_sets_state_ssbo
398-
<< std::endl;
399-
#endif
400380
}
401381

402382
static bool WasInstrumented(const LastBound &last_bound) {
@@ -456,11 +436,11 @@ void PreCallSetupShaderInstrumentationResources(Validator &gpuav, CommandBufferS
456436
assert(gpuav.instrumentation_bindings_.size() == 1);
457437

458438
InstrumentationErrorBlob instrumentation_error_blob;
459-
instrumentation_error_blob.operation_index = (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) ? cb_state.draw_index
460-
: (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) ? cb_state.compute_index
461-
: (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR)
462-
? cb_state.trace_rays_index
463-
: 0;
439+
instrumentation_error_blob.action_command_i = (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) ? cb_state.draw_index
440+
: (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) ? cb_state.compute_index
441+
: (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR)
442+
? cb_state.trace_rays_index
443+
: 0;
464444

465445
instrumentation_error_blob.pipeline_bind_point = bind_point;
466446
instrumentation_error_blob.uses_shader_object = last_bound.pipeline_state == nullptr;
@@ -507,13 +487,14 @@ void PreCallSetupShaderInstrumentationResources(Validator &gpuav, CommandBufferS
507487

508488
// TODO: Using cb_state.per_command_resources.size() is kind of a hack? Worth considering passing the resource index as a
509489
// parameter
510-
const uint32_t error_logger_i = static_cast<uint32_t>(cb_state.per_command_error_loggers.size());
490+
const uint32_t error_logger_i = static_cast<uint32_t>(cb_state.command_error_loggers.size());
511491

512492
UpdateInstrumentationDescSet(gpuav, cb_state, bind_point, instrumentation_desc_set, loc,
513-
instrumentation_error_blob.operation_index, error_logger_i, instrumentation_error_blob);
493+
instrumentation_error_blob.action_command_i, error_logger_i, instrumentation_error_blob);
514494

515-
if (inst_binding_pipe_layout_state) {
516-
if ((uint32_t)inst_binding_pipe_layout_state->set_layouts.size() > gpuav.instrumentation_desc_set_bind_index_) {
495+
if (inst_binding_pipe_layout) {
496+
if (inst_binding_pipe_layout_state &&
497+
(uint32_t)inst_binding_pipe_layout_state->set_layouts.size() > gpuav.instrumentation_desc_set_bind_index_) {
517498
gpuav.InternalWarning(cb_state.Handle(), loc,
518499
"Unable to bind instrumentation descriptor set, it would override application's bound set");
519500
return;
@@ -525,7 +506,7 @@ void PreCallSetupShaderInstrumentationResources(Validator &gpuav, CommandBufferS
525506
assert(false);
526507
break;
527508
case PipelineLayoutSource::LastBoundPipeline:
528-
DispatchCmdBindDescriptorSets(cb_state.VkHandle(), bind_point, inst_binding_pipe_layout_state->VkHandle(),
509+
DispatchCmdBindDescriptorSets(cb_state.VkHandle(), bind_point, inst_binding_pipe_layout,
529510
gpuav.instrumentation_desc_set_bind_index_, 1, &instrumentation_desc_set, 0, nullptr);
530511
break;
531512
case PipelineLayoutSource::LastBoundDescriptorSet:

layers/gpuav/resources/gpuav_vulkan_objects.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -247,44 +247,39 @@ GpuResourcesManager::GpuResourcesManager(Validator &gpuav) : gpuav_(gpuav) {
247247
VmaAllocationCreateInfo alloc_ci = {};
248248
alloc_ci.usage = VMA_MEMORY_USAGE_AUTO;
249249
alloc_ci.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT;
250-
host_visible_buffer_cache_.Create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
251-
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
252-
alloc_ci);
250+
host_visible_buffer_cache_.Create(
251+
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, alloc_ci);
253252
}
254253

255254
{
256255
VmaAllocationCreateInfo alloc_ci = {};
257256
alloc_ci.usage = VMA_MEMORY_USAGE_AUTO;
258257
alloc_ci.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT;
259-
host_cached_buffer_cache_.Create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
260-
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
261-
alloc_ci);
258+
host_cached_buffer_cache_.Create(
259+
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, alloc_ci);
262260
}
263261

264262
{
265263
VmaAllocationCreateInfo alloc_ci = {};
266264
alloc_ci.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
267-
device_local_buffer_cache_.Create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
268-
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
269-
alloc_ci);
265+
device_local_buffer_cache_.Create(
266+
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, alloc_ci);
270267
}
271268

272269
{
273270
VmaAllocationCreateInfo alloc_ci = {};
274271
alloc_ci.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
275-
device_local_indirect_buffer_cache_.Create(
276-
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
277-
alloc_ci);
272+
device_local_indirect_buffer_cache_.Create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT,
273+
alloc_ci);
278274
}
279275

280276
{
281277
VmaAllocationCreateInfo alloc_ci = {};
282278
alloc_ci.usage = VMA_MEMORY_USAGE_AUTO;
283279
alloc_ci.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT |
284280
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT;
285-
staging_buffer_cache_.Create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
286-
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
287-
alloc_ci);
281+
staging_buffer_cache_.Create(
282+
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, alloc_ci);
288283
}
289284
}
290285

@@ -319,7 +314,7 @@ VkDescriptorSet GpuResourcesManager::GetManagedDescriptorSet(VkDescriptorSetLayo
319314
}
320315

321316
// Arbitrary, big enough
322-
constexpr VkDeviceSize buffer_address_alignment = 256;
317+
constexpr VkDeviceSize buffer_address_alignment = 128;
323318

324319
vko::BufferRange GpuResourcesManager::GetHostVisibleBufferRange(VkDeviceSize size) {
325320
// Kind of arbitrary, considered "big enough"
@@ -403,7 +398,7 @@ void GpuResourcesManager::DestroyResources() {
403398
}
404399

405400
void GpuResourcesManager::BufferCache::Create(VkBufferUsageFlags buffer_usage_flags, const VmaAllocationCreateInfo allocation_ci) {
406-
buffer_usage_flags_ = buffer_usage_flags;
401+
buffer_usage_flags_ = buffer_usage_flags | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
407402
allocation_ci_ = allocation_ci;
408403
}
409404

layers/gpuav/shaders/gpuav_shaders_constants.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,14 @@ const uint kMaxErrorsPerCmd = 6;
4444
// (Basically our own implementaiton of Specialization Constant)
4545
const uint kLinkShaderId = 0x0DEAD001;
4646

47-
// #ARNO_TODO will be 0, once I get rid of validation pipeline specific descriptor set
48-
const int kInstDefaultDescriptorSet = 1;
47+
const int kInstDefaultDescriptorSet = 0;
4948

5049
const int kBindingInstRootNode = 0;
5150

5251
// Validation pipelines
5352
// ---
5453
const int kValPipeDescSet = 0;
5554

56-
// Diagnostic calls
57-
// ---
58-
const int kDiagCommonDescriptorSet = kValPipeDescSet + 1;
59-
6055
// Diagnostic calls bindings in common descriptor set
6156
const int kBindingDiagErrorBuffer = 0;
6257
const int kBindingDiagActionIndex = 1;

layers/gpuav/shaders/instrumentation/buffer_device_address.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Range {
2727
uint64_t end;
2828
};
2929

30-
layout(buffer_reference) buffer BDARanges {
30+
layout(buffer_reference, buffer_reference_align = 8, std430) buffer BDARanges {
3131
uint ranges_count;
3232
uint padding_unused;
3333
Range ranges[];
@@ -36,7 +36,7 @@ layout(buffer_reference) buffer BDARanges {
3636
// Ranges are supposed to:
3737
// 1) be stored from low to high
3838
// 2) not overlap
39-
layout(buffer_reference) buffer BDAInputBuffer {
39+
layout(buffer_reference, buffer_reference_align = 16, std430) buffer BDAInputBuffer {
4040
BDARanges bda_ranges_ptr;
4141
};
4242

layers/gpuav/shaders/instrumentation/descriptor_class_general_buffer.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ layout(buffer_reference, buffer_reference_align = 8, std430) buffer DescriptorSe
2929
uvec2 data[];
3030
};
3131

32-
layout(buffer_reference, buffer_reference_align = 8, std430) buffer UnusedInitializedStatus;
32+
layout(buffer_reference) buffer UnusedInitializedStatus;
3333

34-
layout(buffer_reference) buffer BoundDescriptorSetsStateSSBO {
34+
layout(buffer_reference, buffer_reference_align = 8, std430) buffer BoundDescriptorSetsStateSSBO {
3535
UnusedInitializedStatus unused_initialized_status;
3636
DescriptorSetType descriptor_set_types[kDebugInputBindlessMaxDescSets];
3737
};

layers/gpuav/shaders/instrumentation/descriptor_class_texel_buffer.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ layout(buffer_reference, buffer_reference_align = 8, std430) buffer DescriptorSe
2929
uvec2 data[];
3030
};
3131

32-
layout(buffer_reference, buffer_reference_align = 8, std430) buffer UnusedInitializedStatus;
32+
layout(buffer_reference) buffer UnusedInitializedStatus;
3333

34-
layout(buffer_reference) buffer BoundDescriptorSetsStateSSBO {
34+
layout(buffer_reference, buffer_reference_align = 8, std430) buffer BoundDescriptorSetsStateSSBO {
3535
UnusedInitializedStatus unused_initialized_status;
3636
DescriptorSetType descriptor_set_types[kDebugInputBindlessMaxDescSets];
3737
};

layers/gpuav/shaders/instrumentation/descriptor_indexing_oob.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ layout(buffer_reference, buffer_reference_align = 8, std430) buffer InitializedS
3535
uint data[];
3636
};
3737

38-
layout(buffer_reference) buffer BoundDescriptorSetsStateSSBO {
38+
layout(buffer_reference, buffer_reference_align = 8, std430) buffer BoundDescriptorSetsStateSSBO {
3939
InitializedStatus descriptor_init_status;
4040
DescriptorSetType descriptor_set_types[kDebugInputBindlessMaxDescSets];
4141
};

layers/gpuav/shaders/instrumentation/post_process_descriptor_index.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ layout(buffer_reference, buffer_reference_align = 8, std430) buffer DescriptorIn
2626
uvec2 slot[]; // PostProcessDescriptorIndexSlot
2727
};
2828

29-
layout(buffer_reference) buffer PostProcessSSBO {
29+
layout(buffer_reference, buffer_reference_align = 8, std430) buffer PostProcessSSBO {
3030
// There is a chance 2 sets are aliased to the same pointer
3131
// ex - descriptor_index_post_process_buffers[0] == descriptor_index_post_process_buffers[1]
3232
// But that is ok as we use the variable_id to extract thet set on the CPU

layers/gpuav/shaders/instrumentation/vertex_attribute_fetch_oob.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#extension GL_GOOGLE_include_directive : enable
2121
#include "root_node.h"
2222

23-
layout(buffer_reference) buffer VertexAttributeFetchLimits {
23+
layout(buffer_reference, buffer_reference_align = 4, std430) buffer VertexAttributeFetchLimits {
2424
uint has_max_vbb_vertex_input_rate;
2525
uint vertex_attribute_fetch_limit_vertex_input_rate;
2626

0 commit comments

Comments
 (0)