Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorjeremyg-lunarg <jeremyg@lunarg.com>2022-09-01 21:32:00 +0300
committerGitHub <noreply@github.com>2022-09-01 21:32:00 +0300
commit33113abf453572d3cf61b58d4378bbacb4206b1a (patch)
tree75e13ae6ebe4beb43fa91c34787016335dd51e37 /source
parentb5d1040b94f390a2981468bbf2752e79c98a4376 (diff)
Instrument: Add OpNames to generated functions and variables (#4873)
Add name annotations to the generated instrumentation code to make it easier to understand. Example spirv-cross output: vec4 _140; if (0u < inst_bindless_direct_read_4(0u, 0u, 1u, uint(_19))) { _140 = texture(textures[nonuniformEXT(_19)], inUV); } else { inst_bindless_stream_write_4(50u, 1u, uint(_19), 0u); _140 = vec4(0.0); }
Diffstat (limited to 'source')
-rw-r--r--source/opt/inst_buff_addr_check_pass.cpp2
-rw-r--r--source/opt/inst_buff_addr_check_pass.h2
-rw-r--r--source/opt/instrument_pass.cpp63
-rw-r--r--source/opt/instrument_pass.h13
4 files changed, 79 insertions, 1 deletions
diff --git a/source/opt/inst_buff_addr_check_pass.cpp b/source/opt/inst_buff_addr_check_pass.cpp
index e2336d360..3318f88f2 100644
--- a/source/opt/inst_buff_addr_check_pass.cpp
+++ b/source/opt/inst_buff_addr_check_pass.cpp
@@ -393,6 +393,8 @@ uint32_t InstBuffAddrCheckPass::GetSearchAndTestFuncId() {
get_def_use_mgr()->AnalyzeInstDefUse(&*func_end_inst);
input_func->SetFunctionEnd(std::move(func_end_inst));
context()->AddFunction(std::move(input_func));
+ context()->AddDebug2Inst(
+ NewGlobalName(search_test_func_id_, "search_and_test"));
}
return search_test_func_id_;
}
diff --git a/source/opt/inst_buff_addr_check_pass.h b/source/opt/inst_buff_addr_check_pass.h
index a82322395..fb43c397a 100644
--- a/source/opt/inst_buff_addr_check_pass.h
+++ b/source/opt/inst_buff_addr_check_pass.h
@@ -39,7 +39,7 @@ class InstBuffAddrCheckPass : public InstrumentPass {
// See optimizer.hpp for pass user documentation.
Status Process() override;
- const char* name() const override { return "inst-bindless-check-pass"; }
+ const char* name() const override { return "inst-buff-addr-check-pass"; }
private:
// Return byte alignment of type |type_id|. Must be int, float, vector,
diff --git a/source/opt/instrument_pass.cpp b/source/opt/instrument_pass.cpp
index ed34fb025..3d48b321b 100644
--- a/source/opt/instrument_pass.cpp
+++ b/source/opt/instrument_pass.cpp
@@ -88,6 +88,51 @@ std::unique_ptr<Instruction> InstrumentPass::NewLabel(uint32_t label_id) {
return newLabel;
}
+std::unique_ptr<Instruction> InstrumentPass::NewName(
+ uint32_t id, const std::string& name_str) {
+ std::unique_ptr<Instruction> new_name(new Instruction(
+ context(), SpvOpName, 0, 0,
+ std::initializer_list<Operand>{
+ {SPV_OPERAND_TYPE_ID, {id}},
+ {SPV_OPERAND_TYPE_LITERAL_STRING, utils::MakeVector(name_str)}}));
+
+ return new_name;
+}
+
+std::unique_ptr<Instruction> InstrumentPass::NewGlobalName(
+ uint32_t id, const std::string& name_str) {
+ std::string prefixed_name;
+ switch (validation_id_) {
+ case kInstValidationIdBindless:
+ prefixed_name = "inst_bindless_";
+ break;
+ case kInstValidationIdBuffAddr:
+ prefixed_name = "inst_buff_addr_";
+ break;
+ case kInstValidationIdDebugPrintf:
+ prefixed_name = "inst_printf_";
+ break;
+ default:
+ assert(false); // add new instrumentation pass here
+ prefixed_name = "inst_pass_";
+ break;
+ }
+ prefixed_name += name_str;
+ return NewName(id, prefixed_name);
+}
+
+std::unique_ptr<Instruction> InstrumentPass::NewMemberName(
+ uint32_t id, uint32_t member_index, const std::string& name_str) {
+ std::unique_ptr<Instruction> new_name(new Instruction(
+ context(), SpvOpMemberName, 0, 0,
+ std::initializer_list<Operand>{
+ {SPV_OPERAND_TYPE_ID, {id}},
+ {SPV_OPERAND_TYPE_LITERAL_INTEGER, {member_index}},
+ {SPV_OPERAND_TYPE_LITERAL_STRING, utils::MakeVector(name_str)}}));
+
+ return new_name;
+}
+
uint32_t InstrumentPass::Gen32BitCvtCode(uint32_t val_id,
InstructionBuilder* builder) {
// Convert integer value to 32-bit if necessary
@@ -525,6 +570,10 @@ uint32_t InstrumentPass::GetOutputBufferId() {
{{spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER,
{SpvStorageClassStorageBuffer}}}));
context()->AddGlobalValue(std::move(newVarOp));
+ context()->AddDebug2Inst(NewGlobalName(obufTyId, "OutputBuffer"));
+ context()->AddDebug2Inst(NewMemberName(obufTyId, 0, "written_count"));
+ context()->AddDebug2Inst(NewMemberName(obufTyId, 1, "data"));
+ context()->AddDebug2Inst(NewGlobalName(output_buffer_id_, "output_buffer"));
deco_mgr->AddDecorationVal(output_buffer_id_, SpvDecorationDescriptorSet,
desc_set_);
deco_mgr->AddDecorationVal(output_buffer_id_, SpvDecorationBinding,
@@ -569,6 +618,9 @@ uint32_t InstrumentPass::GetInputBufferId() {
{{spv_operand_type_t::SPV_OPERAND_TYPE_LITERAL_INTEGER,
{SpvStorageClassStorageBuffer}}}));
context()->AddGlobalValue(std::move(newVarOp));
+ context()->AddDebug2Inst(NewGlobalName(ibufTyId, "InputBuffer"));
+ context()->AddDebug2Inst(NewMemberName(ibufTyId, 0, "data"));
+ context()->AddDebug2Inst(NewGlobalName(input_buffer_id_, "input_buffer"));
deco_mgr->AddDecorationVal(input_buffer_id_, SpvDecorationDescriptorSet,
desc_set_);
deco_mgr->AddDecorationVal(input_buffer_id_, SpvDecorationBinding,
@@ -783,6 +835,12 @@ uint32_t InstrumentPass::GetStreamWriteFunctionId(uint32_t stage_idx,
get_def_use_mgr()->AnalyzeInstDefUse(&*func_end_inst);
output_func->SetFunctionEnd(std::move(func_end_inst));
context()->AddFunction(std::move(output_func));
+
+ std::string name("stream_write_");
+ name += std::to_string(param_cnt);
+
+ context()->AddDebug2Inst(
+ NewGlobalName(param2output_func_id_[param_cnt], name));
}
return param2output_func_id_[param_cnt];
}
@@ -863,6 +921,11 @@ uint32_t InstrumentPass::GetDirectReadFunctionId(uint32_t param_cnt) {
get_def_use_mgr()->AnalyzeInstDefUse(&*func_end_inst);
input_func->SetFunctionEnd(std::move(func_end_inst));
context()->AddFunction(std::move(input_func));
+
+ std::string name("direct_read_");
+ name += std::to_string(param_cnt);
+ context()->AddDebug2Inst(NewGlobalName(func_id, name));
+
param2input_func_id_[param_cnt] = func_id;
return func_id;
}
diff --git a/source/opt/instrument_pass.h b/source/opt/instrument_pass.h
index 90c1dd47e..215b02635 100644
--- a/source/opt/instrument_pass.h
+++ b/source/opt/instrument_pass.h
@@ -224,6 +224,19 @@ class InstrumentPass : public Pass {
// Return new label.
std::unique_ptr<Instruction> NewLabel(uint32_t label_id);
+ // Set the name function parameter or local variable
+ std::unique_ptr<Instruction> NewName(uint32_t id,
+ const std::string& name_str);
+
+ // Set the name for a function or global variable, names will be
+ // prefixed to identify which instrumentation pass generated them.
+ std::unique_ptr<Instruction> NewGlobalName(uint32_t id,
+ const std::string& name_str);
+
+ // Set the name for a structure member
+ std::unique_ptr<Instruction> NewMemberName(uint32_t id, uint32_t member_index,
+ const std::string& name_str);
+
// Return id for 32-bit unsigned type
uint32_t GetUintId();