Skip to content

Commit

Permalink
gpu:: Add support when shader is inline in pNext
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jun 18, 2024
1 parent 475401e commit 9016c26
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 90 deletions.
6 changes: 5 additions & 1 deletion layers/chassis/chassis_modification_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ struct CreateGraphicsPipelines {
std::vector<ShaderModuleUniqueIds> shader_unique_id_maps;
const VkGraphicsPipelineCreateInfo* pCreateInfos;
// Used to if VkShaderModuleCreateInfo is passed down VkPipelineShaderStageCreateInfo
spirv::StatelessData stateless_data[spirv::kCommonMaxShaderStages];
bool passed_in_shader_stage_ci;
spirv::StatelessData stateless_data[spirv::kCommonMaxGraphicsShaderStages];

CreateGraphicsPipelines(const VkGraphicsPipelineCreateInfo* create_info) { pCreateInfos = create_info; }
};
Expand All @@ -92,6 +93,7 @@ struct CreateComputePipelines {
std::vector<ShaderModuleUniqueIds> shader_unique_id_maps; // not used, here for template function
const VkComputePipelineCreateInfo* pCreateInfos;
// Used to if VkShaderModuleCreateInfo is passed down VkPipelineShaderStageCreateInfo
bool passed_in_shader_stage_ci;
spirv::StatelessData stateless_data;

CreateComputePipelines(const VkComputePipelineCreateInfo* create_info) { pCreateInfos = create_info; }
Expand All @@ -101,6 +103,7 @@ struct CreateRayTracingPipelinesNV {
std::vector<vku::safe_VkRayTracingPipelineCreateInfoCommon> modified_create_infos;
std::vector<ShaderModuleUniqueIds> shader_unique_id_maps; // not used, here for template function
const VkRayTracingPipelineCreateInfoNV* pCreateInfos;
bool passed_in_shader_stage_ci;

CreateRayTracingPipelinesNV(const VkRayTracingPipelineCreateInfoNV* create_info) { pCreateInfos = create_info; }
};
Expand All @@ -109,6 +112,7 @@ struct CreateRayTracingPipelinesKHR {
std::vector<vku::safe_VkRayTracingPipelineCreateInfoCommon> modified_create_infos;
std::vector<ShaderModuleUniqueIds> shader_unique_id_maps; // not used, here for template function
const VkRayTracingPipelineCreateInfoKHR* pCreateInfos;
bool passed_in_shader_stage_ci;

CreateRayTracingPipelinesKHR(const VkRayTracingPipelineCreateInfoKHR* create_info) { pCreateInfos = create_info; }
};
Expand Down
2 changes: 1 addition & 1 deletion layers/core_checks/cc_pipeline_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool CoreChecks::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipel
// at state tracking time, and we state track pipelines first)
if (i == 0) {
for (uint32_t stage = 0; stage < pCreateInfos[0].stageCount; stage++) {
if (chassis_state.stateless_data[stage].pipeline_pnext_module) {
if (stage < spirv::kCommonMaxGraphicsShaderStages && chassis_state.stateless_data[stage].pipeline_pnext_module) {
skip |= ValidateSpirvStateless(
*chassis_state.stateless_data[stage].pipeline_pnext_module, chassis_state.stateless_data[stage],
create_info_loc.dot(Field::pStages, stage).pNext(Struct::VkShaderModuleCreateInfo, Field::pCode));
Expand Down
2 changes: 2 additions & 0 deletions layers/core_checks/cc_spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,8 @@ bool CoreChecks::ValidateEmitMeshTasksSize(const spirv::Module &module_state, co
bool CoreChecks::ValidateSpirvStateless(const spirv::Module &module_state, const spirv::StatelessData &stateless_data,
const Location &loc) const {
bool skip = false;
if (!module_state.valid_spirv) return skip;

skip |= ValidateShaderClock(module_state, stateless_data, loc);
skip |= ValidateAtomicsTypes(module_state, stateless_data, loc);
skip |= ValidateVariables(module_state, loc);
Expand Down
8 changes: 4 additions & 4 deletions layers/gpu/debug_printf/debug_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void Validator::AnalyzeAndGenerateMessage(VkCommandBuffer command_buffer, VkQueu
shader_object_handle = it->second.shader_object;
instrumented_spirv = it->second.instrumented_spirv;
}
assert(instrumented_spirv.size() != 0);
ASSERT_AND_RETURN(!instrumented_spirv.empty());
std::vector<spirv::Instruction> instructions;
spirv::GenerateInstructions(instrumented_spirv, instructions);

Expand Down Expand Up @@ -387,10 +387,10 @@ void Validator::AnalyzeAndGenerateMessage(VkCommandBuffer command_buffer, VkQueu
common_message);
UtilGenerateSourceMessages(instructions, &debug_output_buffer[index], true, filename_message, source_message);
if (use_stdout) {
std::cout << "WARNING-DEBUG-PRINTF " << common_message.c_str() << " " << shader_message.str().c_str() << " "
<< filename_message.c_str() << " " << source_message.c_str();
std::cout << "WARNING-DEBUG-PRINTF " << shader_message.str().c_str() << "\n"
<< common_message.c_str() << " " << filename_message.c_str() << " " << source_message.c_str();
} else {
LogInfo("WARNING-DEBUG-PRINTF", queue, loc, "%s %s %s%s", common_message.c_str(), shader_message.str().c_str(),
LogInfo("WARNING-DEBUG-PRINTF", queue, loc, "%s\n%s%s%s", shader_message.str().c_str(), common_message.c_str(),
filename_message.c_str(), source_message.c_str());
}
} else {
Expand Down
50 changes: 27 additions & 23 deletions layers/gpu/error_message/gpuav_error_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ void UtilGenerateCommonMessage(const DebugReport *debug_report, const VkCommandB
std::unique_lock<std::mutex> lock(debug_report->debug_output_mutex);
strm << std::hex << std::showbase << "Internal Error: Unable to locate information for shader used in command buffer "
<< LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(commandBuffer)) << "(" << HandleToUint64(commandBuffer)
<< "). ";
<< ")\n";
assert(true);
} else {
std::unique_lock<std::mutex> lock(debug_report->debug_output_mutex);
strm << std::hex << std::showbase << "Command buffer "
<< LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(commandBuffer)) << "(" << HandleToUint64(commandBuffer)
<< "). ";
<< ")\n";

if (pipeline_bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) {
strm << "Draw ";
} else if (pipeline_bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) {
Expand All @@ -158,20 +159,24 @@ void UtilGenerateCommonMessage(const DebugReport *debug_report, const VkCommandB
assert(false);
strm << "Unknown Pipeline Operation ";
}
if (shader_module_handle) {
strm << "Index " << operation_index << ". "
<< "Pipeline " << LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(pipeline_handle)) << "("
<< HandleToUint64(pipeline_handle) << "). "
<< "Shader Module " << LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(shader_module_handle)) << "("
<< HandleToUint64(shader_module_handle) << "). ";

strm << "Index " << operation_index << "\n";
if (shader_module_handle == VK_NULL_HANDLE) {
strm << "Shader Object " << LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(shader_object_handle)) << "("
<< HandleToUint64(shader_object_handle) << ")\n";
} else {
strm << "Index " << operation_index << ". "
<< "Shader Object " << LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(shader_object_handle)) << "("
<< HandleToUint64(shader_object_handle) << "). ";
strm << "Pipeline " << LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(pipeline_handle)) << "("
<< HandleToUint64(pipeline_handle) << ")\n";
if (shader_module_handle == gpu::kPipelineStageInfoHandle) {
strm << "Shader Module was passed in via VkPipelineShaderStageCreateInfo::pNext\n";
} else {
strm << "Shader Module " << LookupDebugUtilsNameNoLock(debug_report, HandleToUint64(shader_module_handle)) << "("
<< HandleToUint64(shader_module_handle) << ")\n";
}
}
}
strm << std::dec << std::noshowbase;
strm << "Shader Instruction Index = " << debug_record[gpuav::glsl::kHeaderInstructionIdOffset] << ". ";
strm << "Shader Instruction Index = " << debug_record[gpuav::glsl::kHeaderInstructionIdOffset] << "\n";
msg = strm.str();
}

Expand Down Expand Up @@ -281,7 +286,7 @@ void UtilGenerateSourceMessages(const std::vector<spirv::Instruction> &instructi
std::string reported_filename;
if (reported_file_id == 0) {
filename_stream
<< "Unable to find SPIR-V OpLine for source information. Build shader with debug info to get source information.";
<< "Unable to find SPIR-V OpLine for source information. Build shader with debug info to get source information.\n";
} else {
bool found_opstring = false;
std::string prefix;
Expand All @@ -303,16 +308,15 @@ void UtilGenerateSourceMessages(const std::vector<spirv::Instruction> &instructi
if (reported_column_number > 0) {
filename_stream << ", column " << reported_column_number;
}
filename_stream << ".";
filename_stream << "\n";
break;
}
}

if (!found_opstring) {
filename_stream << "Unable to find SPIR-V OpString for file id " << reported_file_id << " from OpLine instruction."
<< std::endl;
filename_stream << "Unable to find SPIR-V OpString for file id " << reported_file_id << " from OpLine instruction.\n";
filename_stream << "File ID = " << reported_file_id << ", Line Number = " << reported_line_number
<< ", Column = " << reported_column_number << std::endl;
<< ", Column = " << reported_column_number << "\n";
}
}
filename_msg = filename_stream.str();
Expand Down Expand Up @@ -355,16 +359,16 @@ void UtilGenerateSourceMessages(const std::vector<spirv::Instruction> &instructi
std::vector<std::string>::size_type opsource_index =
(reported_line_number - saved_line_number) + 1 + saved_opsource_offset;
if (opsource_index < opsource_lines.size()) {
source_stream << "\n" << reported_line_number << ": " << opsource_lines[opsource_index].c_str();
source_stream << "\n" << reported_line_number << ": " << opsource_lines[opsource_index].c_str() << "\n";
} else {
source_stream << "Internal error: calculated source line of " << opsource_index << " for source size of "
<< opsource_lines.size() << " lines.";
<< opsource_lines.size() << " lines\n";
}
} else {
source_stream << "Unable to find suitable #line directive in SPIR-V OpSource.";
source_stream << "Unable to find suitable #line directive in SPIR-V OpSource\n";
}
} else {
source_stream << "Unable to find SPIR-V OpSource.";
source_stream << "Unable to find SPIR-V OpSource\n";
}
}
source_msg = source_stream.str();
Expand Down Expand Up @@ -613,11 +617,11 @@ bool Validator::AnalyzeAndGenerateMessage(VkCommandBuffer cmd_buffer, const LogO

if (uses_robustness && oob_access) {
if (gpuav_settings.warn_on_robust_oob) {
LogWarning(vuid_msg.c_str(), objlist, loc, "%s %s %s %s%s", error_msg.c_str(), common_message.c_str(),
LogWarning(vuid_msg.c_str(), objlist, loc, "%s\n%s%s%s%s", error_msg.c_str(), common_message.c_str(),
stage_message.c_str(), filename_message.c_str(), source_message.c_str());
}
} else {
LogError(vuid_msg.c_str(), objlist, loc, "%s %s %s %s%s", error_msg.c_str(), common_message.c_str(),
LogError(vuid_msg.c_str(), objlist, loc, "%s\n%s%s%s%s", error_msg.c_str(), common_message.c_str(),
stage_message.c_str(), filename_message.c_str(), source_message.c_str());
}
}
Expand Down
Loading

0 comments on commit 9016c26

Please sign in to comment.