Skip to content

Commit

Permalink
gpuav: Vertex attributes OOB
Browse files Browse the repository at this point in the history
- Move vertex attributes OOB validation to instrumentation
=> faster, simpler
- Handle VK_VERTEX_INPUT_RATE_INSTANCE
  • Loading branch information
arno-lunarg committed Jan 23, 2025
1 parent 7f8007a commit 4c7add4
Show file tree
Hide file tree
Showing 28 changed files with 1,102 additions and 842 deletions.
28 changes: 18 additions & 10 deletions layers/VkLayer_khronos_validation.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "@JSON_LAYER_NAME@",
"type": "GLOBAL",
"library_path": "@JSON_LIBRARY_PATH@",
"api_version": "1.4.305",
"api_version": "1.4.304",
"implementation_version": "1",
"description": "Khronos Validation Layer",
"introduction": "The main, comprehensive Khronos validation layer.\n\nVulkan is an Explicit API, enabling direct control over how GPUs actually work. By design, minimal error checking is done inside a Vulkan driver. Applications have full control and responsibility for correct operation. Any errors in how Vulkan is used can result in a crash. \n\nThe Khronos Validation Layer can be enabled to assist development by enabling developers to verify their applications correctly use the Vulkan API.",
Expand Down Expand Up @@ -683,6 +683,22 @@
]
}
},
{
"key": "gpuav_vertex_attribute_fetch_oob",
"label": "Out of bounds vertex attribute fetching",
"description": "Validate that no vertex attribute fetching is out of bonds",
"type": "BOOL",
"default": true,
"platforms": [ "WINDOWS", "LINUX" ],
"dependence": {
"mode": "ALL",
"settings": [
{ "key": "gpuav_enable", "value": true },
{ "key": "gpuav_shader_instrumentation", "value": true }
]
}
},

{
"key": "gpuav_select_instrumented_shaders",
"label": "Enable instrumenting shaders selectively",
Expand Down Expand Up @@ -779,7 +795,7 @@
"label": "Index buffers",
"type": "BOOL",
"default": true,
"description": "Validate that indexed draws do not fetch indices outside of the bounds of the index buffer.",
"description": "(Warning - still experimental) Validate that indexed draws do not fetch indices outside of the bounds of the index buffer.",
"platforms": [ "WINDOWS", "LINUX" ],
"dependence": {
"mode": "ALL",
Expand Down Expand Up @@ -1145,14 +1161,6 @@
"type": "BOOL",
"default": false,
"platforms": [ "WINDOWS", "LINUX", "MACOS", "ANDROID" ]
},
{
"key": "debug_stable_messages",
"label": "Stable messages",
"view": "ADVANCED",
"description": "Improves the reproducibility of error messages by removing fields that can vary between application runs (e.g., dispatchable handles) for comparison purposes.",
"type": "BOOL",
"default": false
}
]
},
Expand Down
15 changes: 3 additions & 12 deletions layers/gpuav/core/gpuav_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ void Validator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint3
InternalError(commandBuffer, record_obj.location, "Unrecognized command buffer.");
return;
}
valcmd::DrawIndexed(*this, *cb_state, record_obj.location, indexCount, firstIndex, vertexOffset,
"VUID-vkCmdDrawIndexed-None-02721");

PreCallSetupShaderInstrumentationResources(*this, *cb_state, VK_PIPELINE_BIND_POINT_GRAPHICS, record_obj.location);
descriptor::PreCallActionCommand(*this, *cb_state, VK_PIPELINE_BIND_POINT_GRAPHICS, record_obj.location);
}
Expand Down Expand Up @@ -557,11 +556,7 @@ void Validator::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffe

valcmd::DrawIndexedIndirectIndexBuffer(*this, *cb_state, record_obj.location, buffer, offset, stride, count, VK_NULL_HANDLE, 0,
"VUID-VkDrawIndexedIndirectCommand-robustBufferAccess2-08798");
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9163
#if 0
valcmd::DrawIndexedIndirectVertexBuffer(*this, *cb_state, record_obj.location, buffer, offset, stride, count, VK_NULL_HANDLE, 0,
"VUID-vkCmdDrawIndexedIndirect-None-02721");
#endif

valcmd::FirstInstance<VkDrawIndexedIndirectCommand>(*this, *cb_state, record_obj.location, buffer, offset, count,
VK_NULL_HANDLE, 0, "VUID-VkDrawIndexedIndirectCommand-firstInstance-00554");
PreCallSetupShaderInstrumentationResources(*this, *cb_state, VK_PIPELINE_BIND_POINT_GRAPHICS, record_obj.location);
Expand Down Expand Up @@ -705,11 +700,7 @@ void Validator::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer command

valcmd::DrawIndexedIndirectIndexBuffer(*this, *cb_state, record_obj.location, buffer, offset, stride, maxDrawCount, countBuffer,
countBufferOffset, "VUID-VkDrawIndexedIndirectCommand-robustBufferAccess2-08798");
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9163
#if 0
valcmd::DrawIndexedIndirectVertexBuffer(*this, *cb_state, record_obj.location, buffer, offset, stride, maxDrawCount,
countBuffer, countBufferOffset, "VUID-vkCmdDrawIndexedIndirectCount-None-02721");
#endif

PreCallSetupShaderInstrumentationResources(*this, *cb_state, VK_PIPELINE_BIND_POINT_GRAPHICS, record_obj.location);
descriptor::PreCallActionCommand(*this, *cb_state, VK_PIPELINE_BIND_POINT_GRAPHICS, record_obj.location);
}
Expand Down
11 changes: 5 additions & 6 deletions layers/gpuav/core/gpuav_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ struct GpuAVSettings {
bool buffer_device_address = true;
bool ray_query = true;
bool post_process_descriptor_index = true;
bool vertex_index = true;
} shader_instrumentation;

bool IsShaderInstrumentationEnabled() const {
return shader_instrumentation.descriptor_checks || shader_instrumentation.buffer_device_address ||
shader_instrumentation.ray_query || shader_instrumentation.post_process_descriptor_index;
return shader_instrumentation.vertex_index || shader_instrumentation.descriptor_checks ||
shader_instrumentation.buffer_device_address || shader_instrumentation.ray_query ||
shader_instrumentation.post_process_descriptor_index;
}
bool IsSpirvModified() const { return IsShaderInstrumentationEnabled() || debug_printf_enabled; }

// Also disables shader caching and select shader instrumentation
void DisableShaderInstrumentationAndOptions() {
shader_instrumentation.descriptor_checks = false;
shader_instrumentation.buffer_device_address = false;
shader_instrumentation.ray_query = false;
shader_instrumentation.post_process_descriptor_index = false;
std::memset(&shader_instrumentation, 0, sizeof(shader_instrumentation));
// Because of this setting, cannot really have an "enabled" parameter to pass to this method
select_instrumented_shaders = false;
}
Expand Down
2 changes: 2 additions & 0 deletions layers/gpuav/core/gpuav_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ void Validator::PostCreateDevice(const VkDeviceCreateInfo *pCreateInfo, const Lo
{glsl::kBindingInstCmdResourceIndex, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1, VK_SHADER_STAGE_ALL, nullptr},
// Commands errors counts buffer
{glsl::kBindingInstCmdErrorsCount, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr},
// Smallest vertex buffer binding
{glsl::kBindingInstSmallestVertexBufferBinding, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, nullptr},
};

// TODO - Now that GPU-AV and DebugPrintf are merged, we should just have a single PostCreateDevice if possible (or at least
Expand Down
Loading

0 comments on commit 4c7add4

Please sign in to comment.