Skip to content

Commit

Permalink
layers: Add VK_EXT_device_generated_commands
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Sep 26, 2024
1 parent bfa2ad4 commit f166b6c
Show file tree
Hide file tree
Showing 41 changed files with 5,447 additions and 11 deletions.
4 changes: 4 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ vvl_sources = [
"layers/core_checks/cc_descriptor.cpp",
"layers/core_checks/cc_device.cpp",
"layers/core_checks/cc_device_memory.cpp",
"layers/core_checks/cc_device_generated_commands.cpp",
"layers/core_checks/cc_drawdispatch.cpp",
"layers/core_checks/cc_external_object.cpp",
"layers/core_checks/cc_image.cpp",
Expand Down Expand Up @@ -225,6 +226,8 @@ vvl_sources = [
"layers/state_tracker/cmd_buffer_state.h",
"layers/state_tracker/descriptor_sets.cpp",
"layers/state_tracker/descriptor_sets.h",
"layers/state_tracker/device_generated_commands_state.cpp",
"layers/state_tracker/device_generated_commands_state.h",
"layers/state_tracker/device_memory_state.cpp",
"layers/state_tracker/device_memory_state.h",
"layers/state_tracker/device_state.cpp",
Expand Down Expand Up @@ -270,6 +273,7 @@ vvl_sources = [
"layers/stateless/sl_cmd_buffer.cpp",
"layers/stateless/sl_cmd_buffer_dynamic.cpp",
"layers/stateless/sl_descriptor.cpp",
"layers/stateless/sl_device_generated_commands.cpp",
"layers/stateless/sl_device_memory.cpp",
"layers/stateless/sl_external_object.cpp",
"layers/stateless/sl_framebuffer.cpp",
Expand Down
4 changes: 4 additions & 0 deletions layers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ target_sources(vvl PRIVATE
core_checks/cc_descriptor.cpp
core_checks/cc_device.cpp
core_checks/cc_device_memory.cpp
core_checks/cc_device_generated_commands.cpp
core_checks/cc_drawdispatch.cpp
core_checks/cc_external_object.cpp
core_checks/cc_image.cpp
Expand Down Expand Up @@ -266,6 +267,8 @@ target_sources(vvl PRIVATE
state_tracker/cmd_buffer_state.h
state_tracker/descriptor_sets.cpp
state_tracker/descriptor_sets.h
state_tracker/device_generated_commands_state.cpp
state_tracker/device_generated_commands_state.h
state_tracker/device_memory_state.cpp
state_tracker/device_memory_state.h
state_tracker/device_state.cpp
Expand Down Expand Up @@ -311,6 +314,7 @@ target_sources(vvl PRIVATE
stateless/sl_cmd_buffer_dynamic.cpp
stateless/sl_cmd_buffer.cpp
stateless/sl_descriptor.cpp
stateless/sl_device_generated_commands.cpp
stateless/sl_device_memory.cpp
stateless/sl_external_object.cpp
stateless/sl_framebuffer.cpp
Expand Down
2 changes: 1 addition & 1 deletion layers/chassis/layer_chassis_dispatch_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,4 +1714,4 @@ VkResult DispatchCreateIndirectExecutionSetEXT(VkDevice device, const VkIndirect
*pIndirectExecutionSet = layer_data->WrapNew(*pIndirectExecutionSet);
}
return result;
}
}
1,050 changes: 1,050 additions & 0 deletions layers/core_checks/cc_device_generated_commands.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions layers/core_checks/cc_render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5060,7 +5060,7 @@ bool CoreChecks::ValidateRenderingAttachmentLocationsKHR(const VkRenderingAttach

if (unique.find(location) != unique.end()) {
skip |= LogError("VUID-VkRenderingAttachmentLocationInfoKHR-pColorAttachmentLocations-09513", objlist, loc,
"= %" PRIu32 " have same value as pColorAttachmentLocations[%" PRIu32 "] = %" PRIu32, location,
"= %" PRIu32 " has same value as pColorAttachmentLocations[%" PRIu32 "] = %" PRIu32, location,
unique[location], location);
} else
unique[location] = i;
Expand Down Expand Up @@ -5164,7 +5164,7 @@ bool CoreChecks::ValidateRenderingInputAttachmentIndicesKHR(const VkRenderingInp
skip |=
LogError("VUID-VkRenderingInputAttachmentIndexInfoKHR-pColorAttachmentInputIndices-09522", objlist,
loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfoKHR, Field::pColorAttachmentInputIndices, i),
"= %" PRIu32 " have same value as in pColorAttachmentInputIndices[%" PRIu32 "] = %" PRIu32, index,
"= %" PRIu32 " has same value as in pColorAttachmentInputIndices[%" PRIu32 "] = %" PRIu32, index,
unique[index], index_info.pColorAttachmentInputIndices[unique[index]]);
} else
unique[index] = i;
Expand All @@ -5173,7 +5173,7 @@ bool CoreChecks::ValidateRenderingInputAttachmentIndicesKHR(const VkRenderingInp
unique.find(*index_info.pDepthInputAttachmentIndex) != unique.end()) {
const Location loc = loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfoKHR, Field::pDepthInputAttachmentIndex, 0);
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfoKHR-pColorAttachmentInputIndices-09523", objlist, loc,
"= %" PRIu32 " have same value as in pColorAttachmentInputIndices[%" PRIu32 "] = %" PRIu32,
"= %" PRIu32 " has same value as in pColorAttachmentInputIndices[%" PRIu32 "] = %" PRIu32,
*index_info.pDepthInputAttachmentIndex, unique[*index_info.pDepthInputAttachmentIndex],
index_info.pColorAttachmentInputIndices[unique[*index_info.pDepthInputAttachmentIndex]]);
}
Expand All @@ -5182,7 +5182,7 @@ bool CoreChecks::ValidateRenderingInputAttachmentIndicesKHR(const VkRenderingInp
const Location loc =
loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfoKHR, Field::pStencilInputAttachmentIndex, 0);
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfoKHR-pColorAttachmentInputIndices-09524", objlist, loc,
"= %" PRIu32 " have same value as in pColorAttachmentInputIndices[%" PRIu32 "] = %" PRIu32,
"= %" PRIu32 " has same value as in pColorAttachmentInputIndices[%" PRIu32 "] = %" PRIu32,
*index_info.pStencilInputAttachmentIndex, unique[*index_info.pStencilInputAttachmentIndex],
index_info.pColorAttachmentInputIndices[unique[*index_info.pStencilInputAttachmentIndex]]);
}
Expand Down
6 changes: 6 additions & 0 deletions layers/core_checks/cc_shader_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ bool CoreChecks::ValidateCreateShadersLinking(uint32_t createInfoCount, const Vk
"VUID-VkShaderCreateInfoEXT-flags-09405", device, create_info_loc.dot(Field::flags),
"contains VK_SHADER_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT, but computeFullSubgroups feature is not enabled.");
}
if ((create_info.flags & VK_SHADER_CREATE_INDIRECT_BINDABLE_BIT_EXT) != 0 &&
enabled_features.deviceGeneratedCommands == VK_FALSE) {
skip |= LogError(
" VUID-VkShaderCreateInfoEXT-flags-11005", device, create_info_loc.dot(Field::flags),
"contains VK_SHADER_CREATE_INDIRECT_BINDABLE_BIT_EXT, but deviceGeneratedCommands feature is not enabled.");
}
}

if (linked_stage != invalid && non_linked_graphics_stage != invalid) {
Expand Down
17 changes: 12 additions & 5 deletions layers/core_checks/cc_spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1844,11 +1844,18 @@ bool CoreChecks::ValidateTransformFeedbackPipeline(const spirv::Module &module_s
string_VkShaderStageFlags(pipeline.create_info_shaders).c_str());
}

if (pipeline.pre_raster_state && (entrypoint.stage != pipeline.pre_raster_state->last_stage)) {
skip |= LogError("VUID-VkGraphicsPipelineCreateInfo-pStages-02318", module_state.handle(), loc,
"SPIR-V has OpExecutionMode of Xfb in %s, but %s is the last last pre-rasterization shader stage.",
string_VkShaderStageFlagBits(entrypoint.stage),
string_VkShaderStageFlagBits(pipeline.pre_raster_state->last_stage));
if (pipeline.pre_raster_state) {
if (entrypoint.stage != pipeline.pre_raster_state->last_stage) {
skip |= LogError("VUID-VkGraphicsPipelineCreateInfo-pStages-02318", module_state.handle(), loc,
"SPIR-V has OpExecutionMode of Xfb in %s, but %s is the last last pre-rasterization shader stage.",
string_VkShaderStageFlagBits(entrypoint.stage),
string_VkShaderStageFlagBits(pipeline.pre_raster_state->last_stage));
}
if ((pipeline.create_flags & VK_PIPELINE_CREATE_2_INDIRECT_BINDABLE_BIT_EXT) != 0) {
skip |= LogError("VUID-VkGraphicsPipelineCreateInfo-flags-11001", module_state.handle(), loc,
"SPIR-V has OpExecutionMode of Xfb but this pipeline is being created with "
"VK_PIPELINE_CREATE_2_INDIRECT_BINDABLE_BIT_EXT.");
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions layers/core_checks/core_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,61 @@ class CoreChecks : public ValidationStateTracker {
bool PreCallValidateGetCalibratedTimestampsKHR(VkDevice device, uint32_t timestampCount,
const VkCalibratedTimestampInfoEXT* pTimestampInfos, uint64_t* pTimestamps,
uint64_t* pMaxDeviation, const ErrorObject& error_obj) const override;

bool PreCallValidateCreateIndirectCommandsLayoutEXT(VkDevice device, const VkIndirectCommandsLayoutCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkIndirectCommandsLayoutEXT* pIndirectCommandsLayout,
const ErrorObject& error_obj) const override;
bool PreCallValidateDestroyIndirectCommandsLayoutEXT(VkDevice device, VkIndirectCommandsLayoutEXT indirectCommandsLayout,
const VkAllocationCallbacks* pAllocator,
const ErrorObject& error_obj) const override;

bool ValidateIndirectExecutionSetPipelineInfo(const VkIndirectExecutionSetPipelineInfoEXT& pipeline_info,
const Location& pipeline_info_loc) const;
bool ValidateIndirectExecutionSetShaderInfo(const VkIndirectExecutionSetShaderInfoEXT& shader_info,
const Location& shader_info_loc) const;
bool PreCallValidateCreateIndirectExecutionSetEXT(VkDevice device, const VkIndirectExecutionSetCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkIndirectExecutionSetEXT* pIndirectExecutionSet,
const ErrorObject& error_obj) const override;
bool PreCallValidateDestroyIndirectExecutionSetEXT(VkDevice device, VkIndirectExecutionSetEXT indirectExecutionSet,
const VkAllocationCallbacks* pAllocator,
const ErrorObject& error_obj) const override;

bool PreCallValidateCmdExecuteGeneratedCommandsEXT(VkCommandBuffer commandBuffer, VkBool32 isPreprocessed,
const VkGeneratedCommandsInfoEXT* pGeneratedCommandsInfo,
const ErrorObject& error_obj) const override;
bool ValidateGeneratedCommandsInitialShaderState(const vvl::CommandBuffer& cb_state,
const vvl::IndirectCommandsLayout& indirect_commands_layout,
const vvl::IndirectExecutionSet& indirect_execution_set,
VkShaderStageFlags shader_stage_flags, const LogObjectList& objlist,
const Location cb_loc) const;
bool ValidatePreprocessGeneratedCommandsStateCommandBuffer(const vvl::CommandBuffer& command_buffer,
const vvl::CommandBuffer& state_command_buffer,
const vvl::IndirectCommandsLayout& indirect_commands_layout,
const VkGeneratedCommandsInfoEXT& generated_commands_info,
const Location loc) const;
bool PreCallValidateCmdPreprocessGeneratedCommandsEXT(VkCommandBuffer commandBuffer,
const VkGeneratedCommandsInfoEXT* pGeneratedCommandsInfo,
VkCommandBuffer stateCommandBuffer,
const ErrorObject& error_obj) const override;
bool PreCallValidateGetGeneratedCommandsMemoryRequirementsEXT(VkDevice device,
const VkGeneratedCommandsMemoryRequirementsInfoEXT* pInfo,
VkMemoryRequirements2* pMemoryRequirements,
const ErrorObject& error_obj) const override;
bool PreCallValidateUpdateIndirectExecutionSetPipelineEXT(VkDevice device, VkIndirectExecutionSetEXT indirectExecutionSet,
uint32_t executionSetWriteCount,
const VkWriteIndirectExecutionSetPipelineEXT* pExecutionSetWrites,
const ErrorObject& error_obj) const override;
bool PreCallValidateUpdateIndirectExecutionSetShaderEXT(VkDevice device, VkIndirectExecutionSetEXT indirectExecutionSet,
uint32_t executionSetWriteCount,
const VkWriteIndirectExecutionSetShaderEXT* pExecutionSetWrites,
const ErrorObject& error_obj) const override;
bool ValidateGeneratedCommandsInfo(const vvl::CommandBuffer& cb_state,
const vvl::IndirectCommandsLayout& indirect_commands_layout,
const VkGeneratedCommandsInfoEXT& generated_commands_info, bool preprocessed,
const Location& info_loc) const;

bool ValidateRenderingAttachmentLocationsKHR(const VkRenderingAttachmentLocationInfoKHR& location_info,
const LogObjectList objlist, const Location& loc_info) const;
bool PreCallValidateCmdSetRenderingAttachmentLocationsKHR(VkCommandBuffer commandBuffer,
Expand Down
6 changes: 6 additions & 0 deletions layers/error_message/error_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@
}
return ss.str();
}

[[maybe_unused]] static std::string string_VkPushConstantRange(VkPushConstantRange range) {
std::stringstream ss;
ss << "[" << range.offset << ", " << (range.offset + range.size) << "]";
return ss.str();
}
3 changes: 3 additions & 0 deletions layers/error_message/unimplementable_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const char* unimplementable_validation[] = {
"VUID-VkPipelineCacheHeaderVersionOne-headerVersion-04968",
"VUID-VkPipelineCacheHeaderVersionOne-headerSize-08990",

// https://gitlab.khronos.org/vulkan/vulkan/-/merge_requests/6639#note_468463
"VUID-VkIndirectCommandsVertexBufferTokenEXT-vertexBindingUnit-11134",

// These implicit VUs ask to check for a valid structure that has no sType,
// there is nothing that can actually be validated
//
Expand Down
6 changes: 6 additions & 0 deletions layers/gpu/core/gpuav.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ class Validator : public gpu::GpuShaderInstrumentor {
const RecordObject& record_obj) final;
void PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer, VkDeviceAddress indirectDeviceAddress,
const RecordObject& record_obj) final;
void PreCallRecordCmdExecuteGeneratedCommandsEXT(VkCommandBuffer commandBuffer, VkBool32 isPreprocessed,
const VkGeneratedCommandsInfoEXT* pGeneratedCommandsInfo,
const RecordObject& record_obj) final;
void PostCallRecordCmdExecuteGeneratedCommandsEXT(VkCommandBuffer commandBuffer, VkBool32 isPreprocessed,
const VkGeneratedCommandsInfoEXT* pGeneratedCommandsInfo,
const RecordObject& record_obj) final;

void PostCallRecordGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties2* pPhysicalDeviceProperties2,
Expand Down
28 changes: 28 additions & 0 deletions layers/gpu/core/gpuav_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,4 +981,32 @@ void Validator::PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBu
PostCallSetupShaderInstrumentationResources(*this, *cb_state, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, record_obj.location);
}

void Validator::PreCallRecordCmdExecuteGeneratedCommandsEXT(VkCommandBuffer commandBuffer, VkBool32 isPreprocessed,
const VkGeneratedCommandsInfoEXT *pGeneratedCommandsInfo,
const RecordObject &record_obj) {
BaseClass::PreCallRecordCmdExecuteGeneratedCommandsEXT(commandBuffer, isPreprocessed, pGeneratedCommandsInfo, record_obj);

auto cb_state = GetWrite<CommandBuffer>(commandBuffer);
if (!cb_state) {
InternalError(commandBuffer, record_obj.location, "Unrecognized command buffer.");
return;
}
const VkPipelineBindPoint bind_point = ConvertToPipelineBindPoint(pGeneratedCommandsInfo->shaderStages);
PreCallSetupShaderInstrumentationResources(*this, *cb_state, bind_point, record_obj.location);
};

void Validator::PostCallRecordCmdExecuteGeneratedCommandsEXT(VkCommandBuffer commandBuffer, VkBool32 isPreprocessed,
const VkGeneratedCommandsInfoEXT *pGeneratedCommandsInfo,
const RecordObject &record_obj) {
BaseClass::PostCallRecordCmdExecuteGeneratedCommandsEXT(commandBuffer, isPreprocessed, pGeneratedCommandsInfo, record_obj);

auto cb_state = GetWrite<CommandBuffer>(commandBuffer);
if (!cb_state) {
InternalError(commandBuffer, record_obj.location, "Unrecognized command buffer.");
return;
}
const VkPipelineBindPoint bind_point = ConvertToPipelineBindPoint(pGeneratedCommandsInfo->shaderStages);
PostCallSetupShaderInstrumentationResources(*this, *cb_state, bind_point, record_obj.location);
}

} // namespace gpuav
7 changes: 7 additions & 0 deletions layers/gpu/debug_printf/debug_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,13 @@ void Validator::PreCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuf
AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, record_obj.location);
}

void Validator::PreCallRecordCmdExecuteGeneratedCommandsEXT(VkCommandBuffer commandBuffer, VkBool32 isPreprocessed,
const VkGeneratedCommandsInfoEXT *pGeneratedCommandsInfo,
const RecordObject &record_obj) {
const VkPipelineBindPoint bind_point = ConvertToPipelineBindPoint(pGeneratedCommandsInfo->shaderStages);
AllocateDebugPrintfResources(commandBuffer, bind_point, record_obj.location);
};

void Validator::AllocateDebugPrintfResources(const VkCommandBuffer cmd_buffer, const VkPipelineBindPoint bind_point,
const Location &loc) {
assert(bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS || bind_point == VK_PIPELINE_BIND_POINT_COMPUTE ||
Expand Down
Loading

0 comments on commit f166b6c

Please sign in to comment.