Skip to content

Commit e2ead62

Browse files
committed
gpuav: Support desc heaps in buffer validation
- Create a descriptor heap variant of every validation compute pipeline, picked from the command buffer's last used descriptor mode, binding resources, push constants and error logging buffers as push data addresses instead of descriptor sets - Stop skipping validation commands in heap mode, only skip descriptor buffer mode - Force device address usage on all buffers and allocations, adding a manual chassis vkAllocateMemory so GPU-AV can modify VkMemoryAllocateInfo - Store the error buffer dword size in the buffer itself instead of querying the runtime array length, and move its offsets into gpuav_shaders_constants.h Done because buffer descriptors are now managed through buffer addresses in push data, so cannot access their metadata anymore - Tidy ComputePipeline: hide handles behind Valid()/Bind* methods, make SharedResourcesCache re-entrant - Add descriptor heap tests for index buffer OOB, invalid BLAS reference and vertex attribute fetch OOB
1 parent b5f924b commit e2ead62

44 files changed

Lines changed: 3555 additions & 2893 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ vvl_sources = [
188188
"layers/gpuav/validation_cmd/gpuav_ray_tracing.h",
189189
"layers/gpuav/core/gpuav_settings.h",
190190
"layers/gpuav/core/gpuav.h",
191-
"layers/gpuav/core/gpuav_constants.h",
192191
"layers/gpuav/core/gpuav_record.cpp",
193192
"layers/gpuav/core/gpuav_settings.cpp",
194193
"layers/gpuav/core/gpuav_settings.h",

layers/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ target_sources(vvl PRIVATE
314314
${API_TYPE}/generated/extended_flags_helper_generator.h
315315
${API_TYPE}/generated/extended_flags_helper_generator.cpp
316316
gpuav/core/gpuav.h
317-
gpuav/core/gpuav_constants.h
318317
gpuav/core/gpuav_features.cpp
319318
gpuav/core/gpuav_record.cpp
320319
gpuav/core/gpuav_setup.cpp

layers/chassis/chassis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ VKAPI_ATTR VkResult VKAPI_CALL AllocateDescriptorSets(VkDevice device, const VkD
7474
VkDescriptorSet* pDescriptorSets);
7575
VKAPI_ATTR VkResult VKAPI_CALL CreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo,
7676
const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer);
77+
VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
78+
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory);
7779
VKAPI_ATTR VkResult VKAPI_CALL QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo);
7880
VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo);
7981
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,

layers/chassis/chassis_manual.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,62 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateBuffer(VkDevice device, const VkBufferCreat
11601160
return result;
11611161
}
11621162

1163+
// This API needs the ability to modify a down-chain parameter
1164+
VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
1165+
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) {
1166+
VVL_ZoneScoped;
1167+
1168+
auto device_dispatch = vvl::GetDispatchDevice(device);
1169+
bool skip = false;
1170+
ErrorObject error_obj(vvl::Func::vkAllocateMemory, VulkanTypedHandle(device, kVulkanObjectTypeDevice));
1171+
1172+
{
1173+
VVL_ZoneScopedN("PreCallValidate_AllocateMemory");
1174+
for (const auto& vo : device_dispatch->intercept_vectors[InterceptIdPreCallValidateAllocateMemory]) {
1175+
if (!vo) {
1176+
continue;
1177+
}
1178+
auto lock = vo->ReadLock();
1179+
skip |= vo->PreCallValidateAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, error_obj);
1180+
if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
1181+
}
1182+
}
1183+
1184+
chassis::AllocateMemory chassis_state{};
1185+
chassis_state.allocate_info_copy = pAllocateInfo;
1186+
1187+
RecordObject record_obj(vvl::Func::vkAllocateMemory);
1188+
{
1189+
VVL_ZoneScopedN("PreCallRecord_AllocateMemory");
1190+
for (auto& vo : device_dispatch->object_dispatch) {
1191+
if (!vo) {
1192+
continue;
1193+
}
1194+
auto lock = vo->WriteLock();
1195+
vo->PreCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, record_obj, chassis_state);
1196+
}
1197+
}
1198+
1199+
VkResult result;
1200+
{
1201+
VVL_ZoneScopedN("Dispatch_AllocateMemory");
1202+
result = device_dispatch->AllocateMemory(device, chassis_state.allocate_info_copy, pAllocator, pMemory);
1203+
}
1204+
record_obj.result = result;
1205+
1206+
{
1207+
VVL_ZoneScopedN("PostCallRecord_AllocateMemory");
1208+
for (auto& vo : device_dispatch->intercept_vectors[InterceptIdPostCallRecordAllocateMemory]) {
1209+
if (!vo) {
1210+
continue;
1211+
}
1212+
auto lock = vo->WriteLock();
1213+
vo->PostCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, record_obj);
1214+
}
1215+
}
1216+
return result;
1217+
}
1218+
11631219
// This API needs to ensure that per-swapchain VkResult results are available
11641220
VKAPI_ATTR VkResult VKAPI_CALL QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) {
11651221
VVL_ZoneScoped;

layers/chassis/chassis_modification_state.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,11 @@ struct CreateBuffer {
167167
vku::safe_VkBufferCreateInfo modified_create_info;
168168
};
169169

170+
struct AllocateMemory {
171+
// To not waste time for CoreChecks we just copy the pointer, but if GPU-AV want to modifiy it, it will update pointer to be a
172+
// pointer of the Safe Struct
173+
const VkMemoryAllocateInfo* allocate_info_copy;
174+
vku::safe_VkMemoryAllocateInfo modified_allocate_info;
175+
};
176+
170177
} // namespace chassis

layers/chassis/validation_object.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct ShaderBinaryData;
5858
struct CreatePipelineLayout;
5959
struct CreateBuffer;
6060
struct CmdBindDescriptorBuffers;
61+
struct AllocateMemory;
6162
} // namespace chassis
6263

6364
namespace vvl {
@@ -462,6 +463,13 @@ class BaseDevice : public Logger {
462463
PreCallRecordCmdBindDescriptorBuffersEXT(commandBuffer, bufferCount, pBindingInfos, record_obj);
463464
}
464465

466+
// Modify a parameter to AllocateMemory
467+
virtual void PreCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
468+
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory,
469+
const RecordObject& record_obj, chassis::AllocateMemory& chassis_state) {
470+
PreCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, record_obj);
471+
}
472+
465473
#include "generated/validation_object_device_methods.h"
466474
};
467475

layers/gpuav/core/gpuav.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class Validator : public GpuShaderInstrumentor {
102102
VkBuffer* pBuffer, const RecordObject& record_obj) final;
103103
void PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator,
104104
const RecordObject& record_obj) final;
105+
void PreCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
106+
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory,
107+
const RecordObject& record_obj, chassis::AllocateMemory& chassis_state) final;
105108
void PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator,
106109
const RecordObject& record_obj) final;
107110
void PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset,

layers/gpuav/core/gpuav_constants.h

Lines changed: 0 additions & 50 deletions
This file was deleted.

layers/gpuav/core/gpuav_record.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ void Validator::PreCallRecordCreateBuffer(VkDevice device, const VkBufferCreateI
5050

5151
VkBufferUsageFlags2 extra_usage = 0;
5252

53+
if (!enabled_features.descriptorHeap) {
54+
extra_usage |= VK_BUFFER_USAGE_2_SHADER_DEVICE_ADDRESS_BIT;
55+
}
56+
5357
// Ray tracing acceleration structure instance buffers also need the storage buffer usage as
5458
// acceleration structure build validation will find and replace invalid acceleration structure
5559
// handles inside of a compute shader.
@@ -103,6 +107,27 @@ void Validator::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, con
103107
descriptor_buffer.resource_handles_.erase(buffer);
104108
}
105109

110+
void Validator::PreCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
111+
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory,
112+
const RecordObject& record_obj, chassis::AllocateMemory& chassis_state) {
113+
if (!enabled_features.descriptorHeap) {
114+
return;
115+
}
116+
117+
chassis_state.modified_allocate_info.initialize(pAllocateInfo);
118+
119+
if (auto* alloc_flags_info = const_cast<VkMemoryAllocateFlagsInfo*>(
120+
vku::FindStructInPNextChain<VkMemoryAllocateFlagsInfo>(chassis_state.modified_allocate_info.pNext))) {
121+
alloc_flags_info->flags |= VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT;
122+
} else {
123+
VkMemoryAllocateFlagsInfo new_alloc_flags_info = vku::InitStructHelper();
124+
new_alloc_flags_info.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT;
125+
vku::AddToPnext(chassis_state.modified_allocate_info, new_alloc_flags_info);
126+
}
127+
128+
chassis_state.allocate_info_copy = chassis_state.modified_allocate_info.ptr();
129+
}
130+
106131
void Validator::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator,
107132
const RecordObject& record_obj) {
108133
if (descriptor_buffer.resource_memory_handles_.find(memory) != descriptor_buffer.resource_memory_handles_.end()) {

layers/gpuav/core/gpuav_setup.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#endif
2424
#include "chassis/dispatch_object.h"
2525
#include "gpuav/core/gpuav.h"
26-
#include "gpuav/core/gpuav_constants.h"
2726
#include "gpuav/instrumentation/descriptor_checks_classic.h"
2827
#include "gpuav/resources/gpuav_state_trackers.h"
2928
#include "gpuav/shaders/gpuav_error_header.h"

0 commit comments

Comments
 (0)