Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ vvl_sources = [
"layers/gpuav/validation_cmd/gpuav_ray_tracing.h",
"layers/gpuav/core/gpuav_settings.h",
"layers/gpuav/core/gpuav.h",
"layers/gpuav/core/gpuav_constants.h",
"layers/gpuav/core/gpuav_record.cpp",
"layers/gpuav/core/gpuav_settings.cpp",
"layers/gpuav/core/gpuav_settings.h",
Expand Down
1 change: 0 additions & 1 deletion layers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ target_sources(vvl PRIVATE
${API_TYPE}/generated/extended_flags_helper_generator.h
${API_TYPE}/generated/extended_flags_helper_generator.cpp
gpuav/core/gpuav.h
gpuav/core/gpuav_constants.h
gpuav/core/gpuav_features.cpp
gpuav/core/gpuav_record.cpp
gpuav/core/gpuav_setup.cpp
Expand Down
2 changes: 2 additions & 0 deletions layers/chassis/chassis.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ VKAPI_ATTR VkResult VKAPI_CALL AllocateDescriptorSets(VkDevice device, const VkD
VkDescriptorSet* pDescriptorSets);
VKAPI_ATTR VkResult VKAPI_CALL CreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer);
VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory);
VKAPI_ATTR VkResult VKAPI_CALL QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo);
VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo);
VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
Expand Down
56 changes: 56 additions & 0 deletions layers/chassis/chassis_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,62 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateBuffer(VkDevice device, const VkBufferCreat
return result;
}

// This API needs the ability to modify a down-chain parameter
VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory) {
VVL_ZoneScoped;

auto device_dispatch = vvl::GetDispatchDevice(device);
bool skip = false;
ErrorObject error_obj(vvl::Func::vkAllocateMemory, VulkanTypedHandle(device, kVulkanObjectTypeDevice));

{
VVL_ZoneScopedN("PreCallValidate_AllocateMemory");
for (const auto& vo : device_dispatch->intercept_vectors[InterceptIdPreCallValidateAllocateMemory]) {
if (!vo) {
continue;
}
auto lock = vo->ReadLock();
skip |= vo->PreCallValidateAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, error_obj);
if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
}
}

chassis::AllocateMemory chassis_state{};
chassis_state.allocate_info_copy = pAllocateInfo;

RecordObject record_obj(vvl::Func::vkAllocateMemory);
{
VVL_ZoneScopedN("PreCallRecord_AllocateMemory");
for (auto& vo : device_dispatch->object_dispatch) {
if (!vo) {
continue;
}
auto lock = vo->WriteLock();
vo->PreCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, record_obj, chassis_state);
}
}

VkResult result;
{
VVL_ZoneScopedN("Dispatch_AllocateMemory");
result = device_dispatch->AllocateMemory(device, chassis_state.allocate_info_copy, pAllocator, pMemory);
}
record_obj.result = result;

{
VVL_ZoneScopedN("PostCallRecord_AllocateMemory");
for (auto& vo : device_dispatch->intercept_vectors[InterceptIdPostCallRecordAllocateMemory]) {
if (!vo) {
continue;
}
auto lock = vo->WriteLock();
vo->PostCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, record_obj);
}
}
return result;
}

// This API needs to ensure that per-swapchain VkResult results are available
VKAPI_ATTR VkResult VKAPI_CALL QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) {
VVL_ZoneScoped;
Expand Down
7 changes: 7 additions & 0 deletions layers/chassis/chassis_modification_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,11 @@ struct CreateBuffer {
vku::safe_VkBufferCreateInfo modified_create_info;
};

struct AllocateMemory {
// 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
// pointer of the Safe Struct
const VkMemoryAllocateInfo* allocate_info_copy;
vku::safe_VkMemoryAllocateInfo modified_allocate_info;
};

} // namespace chassis
8 changes: 8 additions & 0 deletions layers/chassis/validation_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct ShaderBinaryData;
struct CreatePipelineLayout;
struct CreateBuffer;
struct CmdBindDescriptorBuffers;
struct AllocateMemory;
} // namespace chassis

namespace vvl {
Expand Down Expand Up @@ -462,6 +463,13 @@ class BaseDevice : public Logger {
PreCallRecordCmdBindDescriptorBuffersEXT(commandBuffer, bufferCount, pBindingInfos, record_obj);
}

// Modify a parameter to AllocateMemory
virtual void PreCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory,
const RecordObject& record_obj, chassis::AllocateMemory& chassis_state) {
PreCallRecordAllocateMemory(device, pAllocateInfo, pAllocator, pMemory, record_obj);
}

#include "generated/validation_object_device_methods.h"
};

Expand Down
3 changes: 3 additions & 0 deletions layers/gpuav/core/gpuav.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class Validator : public GpuShaderInstrumentor {
VkBuffer* pBuffer, const RecordObject& record_obj) final;
void PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator,
const RecordObject& record_obj) final;
void PreCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory,
const RecordObject& record_obj, chassis::AllocateMemory& chassis_state) final;
void PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator,
const RecordObject& record_obj) final;
void PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset,
Expand Down
50 changes: 0 additions & 50 deletions layers/gpuav/core/gpuav_constants.h

This file was deleted.

25 changes: 25 additions & 0 deletions layers/gpuav/core/gpuav_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ void Validator::PreCallRecordCreateBuffer(VkDevice device, const VkBufferCreateI

VkBufferUsageFlags2 extra_usage = 0;

if (!enabled_features.descriptorHeap) {
extra_usage |= VK_BUFFER_USAGE_2_SHADER_DEVICE_ADDRESS_BIT;
}

// Ray tracing acceleration structure instance buffers also need the storage buffer usage as
// acceleration structure build validation will find and replace invalid acceleration structure
// handles inside of a compute shader.
Expand Down Expand Up @@ -103,6 +107,27 @@ void Validator::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, con
descriptor_buffer.resource_handles_.erase(buffer);
}

void Validator::PreCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo,
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory,
const RecordObject& record_obj, chassis::AllocateMemory& chassis_state) {
if (!enabled_features.descriptorHeap) {
return;
}

chassis_state.modified_allocate_info.initialize(pAllocateInfo);

if (auto* alloc_flags_info = const_cast<VkMemoryAllocateFlagsInfo*>(
vku::FindStructInPNextChain<VkMemoryAllocateFlagsInfo>(chassis_state.modified_allocate_info.pNext))) {
alloc_flags_info->flags |= VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT;
} else {
VkMemoryAllocateFlagsInfo new_alloc_flags_info = vku::InitStructHelper();
new_alloc_flags_info.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT;
vku::AddToPnext(chassis_state.modified_allocate_info, new_alloc_flags_info);
}

chassis_state.allocate_info_copy = chassis_state.modified_allocate_info.ptr();
}

void Validator::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator,
const RecordObject& record_obj) {
if (descriptor_buffer.resource_memory_handles_.find(memory) != descriptor_buffer.resource_memory_handles_.end()) {
Expand Down
1 change: 0 additions & 1 deletion layers/gpuav/core/gpuav_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#endif
#include "chassis/dispatch_object.h"
#include "gpuav/core/gpuav.h"
#include "gpuav/core/gpuav_constants.h"
#include "gpuav/instrumentation/descriptor_checks_classic.h"
#include "gpuav/resources/gpuav_state_trackers.h"
#include "gpuav/shaders/gpuav_error_header.h"
Expand Down
Loading
Loading