Skip to content

Commit

Permalink
printf: Remove stage specific information
Browse files Browse the repository at this point in the history
Remove stage specific debug info that is only needed by GPU-AV.
This allows debug printfs to be used in multi stage shader modules.

Requires KhronosGroup/SPIRV-Tools#5495

Fixes KhronosGroup#4350
  • Loading branch information
jeremyg-lunarg committed Dec 4, 2023
1 parent fc1b1cb commit 8062899
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 31 deletions.
24 changes: 7 additions & 17 deletions layers/gpu_validation/debug_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,9 @@ void debug_printf::Validator::AnalyzeAndGenerateMessages(VkCommandBuffer command
// 1 Size of output record, including this word
// 2 Shader ID
// 3 Instruction Position
// 4 Stage Ordinal
// 5 Stage - specific Info Word 0
// 6 Stage - specific Info Word 1
// 7 Stage - specific Info Word 2
// 8 Printf Format String Id
// 9 Printf Values Word 0 (optional)
// 10 Printf Values Word 1 (optional)
// 4 Printf Format String Id
// 5 Printf Values Word 0 (optional)
// 6 Printf Values Word 1 (optional)
uint32_t expect = debug_output_buffer[1];
if (!expect) return;

Expand Down Expand Up @@ -387,19 +383,17 @@ void debug_printf::Validator::AnalyzeAndGenerateMessages(VkCommandBuffer command
}

if (verbose) {
std::string stage_message;
std::string common_message;
std::string filename_message;
std::string source_message;
UtilGenerateStageMessage(&debug_output_buffer[index], stage_message);
UtilGenerateCommonMessage(report_data, command_buffer, &debug_output_buffer[index], shader_module_handle,
pipeline_handle, shader_object_handle, buffer_info.pipeline_bind_point, operation_index, common_message);
UtilGenerateSourceMessages(pgm, &debug_output_buffer[index], true, filename_message, source_message);
if (use_stdout) {
std::cout << "UNASSIGNED-DEBUG-PRINTF " << common_message.c_str() << " " << stage_message.c_str() << " "
std::cout << "UNASSIGNED-DEBUG-PRINTF " << common_message.c_str() << " "
<< shader_message.str().c_str() << " " << filename_message.c_str() << " " << source_message.c_str();
} else {
LogInfo("UNASSIGNED-DEBUG-PRINTF", queue, loc, "%s %s %s %s%s", common_message.c_str(), stage_message.c_str(),
LogInfo("UNASSIGNED-DEBUG-PRINTF", queue, loc, "%s %s %s%s", common_message.c_str(),
shader_message.str().c_str(), filename_message.c_str(), source_message.c_str());
}
} else {
Expand Down Expand Up @@ -467,9 +461,7 @@ void debug_printf::Validator::PreCallRecordCmdDrawMultiEXT(VkCommandBuffer comma
const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
uint32_t firstInstance, uint32_t stride,
const RecordObject &record_obj) {
for (uint32_t i = 0; i < drawCount; i++) {
AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS);
}
AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS);
}

void debug_printf::Validator::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
Expand All @@ -482,9 +474,7 @@ void debug_printf::Validator::PreCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffe
const VkMultiDrawIndexedInfoEXT *pIndexInfo,
uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
const int32_t *pVertexOffset, const RecordObject &record_obj) {
for (uint32_t i = 0; i < drawCount; i++) {
AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS);
}
AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS);
}

void debug_printf::Validator::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
Expand Down
4 changes: 0 additions & 4 deletions layers/gpu_validation/debug_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ struct OutputRecord {
uint32_t size;
uint32_t shader_id;
uint32_t instruction_position;
uint32_t stage;
uint32_t stage_word_1;
uint32_t stage_word_2;
uint32_t stage_word_3;
uint32_t format_string_id;
uint32_t values;
};
Expand Down
8 changes: 4 additions & 4 deletions layers/gpu_validation/gpu_error_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <regex>

// Generate the stage-specific part of the message.
void UtilGenerateStageMessage(const uint32_t *debug_record, std::string &msg) {
using namespace spvtools;
static void GenerateStageMessage(const uint32_t *debug_record, std::string &msg) {
using namespace gpuav::glsl;
std::ostringstream strm;
switch (debug_record[kInstCommonOutStageIdx]) {
case spv::ExecutionModelVertex: {
Expand Down Expand Up @@ -499,7 +499,7 @@ bool gpuav::Validator::AnalyzeAndGenerateMessages(VkCommandBuffer cmd_buffer, Vk
std::string common_message;
std::string filename_message;
std::string source_message;
UtilGenerateStageMessage(debug_record, stage_message);
GenerateStageMessage(debug_record, stage_message);
UtilGenerateCommonMessage(report_data, cmd_buffer, debug_record, shader_module_handle, pipeline_handle,
shader_object_handle, cmd_resources.pipeline_bind_point, operation_index, common_message);
UtilGenerateSourceMessages(pgm, debug_record, false, filename_message, source_message);
Expand Down Expand Up @@ -711,4 +711,4 @@ bool gpuav::PreTraceRaysResources::LogValidationMessage(gpuav::Validator &valida
}

return error_logged;
}
}
1 change: 0 additions & 1 deletion layers/gpu_validation/gpu_error_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#pragma once
#include "generated/chassis.h"

void UtilGenerateStageMessage(const uint32_t *debug_record, std::string &msg);
void UtilGenerateCommonMessage(const debug_report_data *report_data, const VkCommandBuffer commandBuffer,
const uint32_t *debug_record, const VkShaderModule shader_module_handle,
const VkPipeline pipeline_handle, const VkShaderEXT shader_object_handle,
Expand Down
2 changes: 1 addition & 1 deletion layers/vulkan/generated/spirv_tools_commit_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

#pragma once

#define SPIRV_TOOLS_COMMIT_ID "360d469b9eac54d6c6e20f609f9ec35e3a5380ad"
#define SPIRV_TOOLS_COMMIT_ID "b5d60826e9d2ad130fd9eb140ea633c349159952"
2 changes: 1 addition & 1 deletion scripts/known_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"-DSPIRV_SKIP_TESTS=ON",
"-DSPIRV_SKIP_EXECUTABLES=ON"
],
"commit": "360d469b9eac54d6c6e20f609f9ec35e3a5380ad"
"commit": "b5d60826e9d2ad130fd9eb140ea633c349159952"
},
{
"name": "robin-hood-hashing",
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/debug_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ TEST_F(NegativeDebugPrintf, BasicUsage) {
void main() {
float myfloat = 3.1415f;
int foo = -135;
if (gl_VertexIndex == 0) {
// referencing gl_InstanceIndex appears to be required to ensure this shader runs multiple times
// when called from vkCmdDrawMultiEXT().
if (gl_VertexIndex == 0 && gl_InstanceIndex < 10000) {
switch(u_info.whichtest) {
case 0:
debugPrintfEXT("Here are two float values %f, %f", 1.0, myfloat);
Expand Down Expand Up @@ -433,7 +435,9 @@ TEST_F(NegativeDebugPrintf, GPL) {
void main() {
float myfloat = 3.1415f;
int foo = -135;
if (gl_VertexIndex == 0) {
// referencing gl_InstanceIndex appears to be required to ensure this shader runs multiple times
// when called from vkCmdDrawMultiEXT().
if (gl_VertexIndex == 0 && gl_InstanceIndex < 10000) {
switch(u_info.whichtest) {
case 0:
debugPrintfEXT("Here are two float values %f, %f", 1.0, myfloat);
Expand Down Expand Up @@ -1005,7 +1009,9 @@ TEST_F(NegativeDebugPrintf, BasicUsageShaderObjects) {
void main() {
float myfloat = 3.1415f;
int foo = -135;
if (gl_VertexIndex == 0) {
// referencing gl_InstanceIndex appears to be required to ensure this shader runs multiple times
// when called from vkCmdDrawMultiEXT().
if (gl_VertexIndex == 0 && gl_InstanceIndex < 10000) {
switch(u_info.whichtest) {
case 0:
debugPrintfEXT("Here are two float values %f, %f", 1.0, myfloat);
Expand Down

0 comments on commit 8062899

Please sign in to comment.