MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-ValidationLayers / Instrument

Method Instrument

layers/gpuav/spirv/debug_printf_pass.cpp:519–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517}
518
519bool DebugPrintfPass::Instrument() {
520 for (const auto& inst : module_.ext_inst_imports_) {
521 const char* import_string = inst->GetAsString(2);
522 if (strcmp(import_string, "NonSemantic.DebugPrintf") == 0) {
523 ext_import_id_ = inst->ResultId();
524 break;
525 }
526 }
527
528 if (ext_import_id_ == 0) {
529 return false; // no printf strings found, early return
530 }
531
532 for (Function& function : module_.functions_) {
533 if (!function.called_from_target_ && !function.AddedFromInstrumentation()) {
534 continue;
535 }
536
537 for (auto block_it = function.blocks_.begin(); block_it != function.blocks_.end(); ++block_it) {
538 BasicBlock& current_block = **block_it;
539
540 // This is a silly hack, sorry
541 // We use to only add the |functions_| at parsing and linking.
542 // But in order to run debug printf on our own GLSL, we do this pass AFTER linking, which means the |functions_| list
543 // could have been expanded and now the |function_| reference in |block| is dangling, but just setting it here, before
544 // potentially updating the block is a simple-enough-fix
545 current_block.function_ = &function;
546
547 cf_.Update(current_block);
548 if (debug_disable_loops_ && cf_.in_loop) continue;
549
550 auto& block_instructions = current_block.instructions_;
551 for (auto inst_it = block_instructions.begin(); inst_it != block_instructions.end(); ++inst_it) {
552 InstructionMeta meta;
553 if (!RequiresInstrumentation(*(inst_it->get()), meta)) continue;
554 if (!Validate(function, meta)) continue; // if not valid, don't attempt to instrument it
555 instrumentations_count_++;
556
557 // Save the OpString here so we can use it later
558 if (function.AddedFromInstrumentation()) {
559 for (const auto& debug_inst : module_.debug_source_) {
560 const uint32_t string_id = (*inst_it)->Word(5);
561 if (debug_inst->Opcode() == spv::OpString && debug_inst->ResultId() == string_id) {
562 internal_only_debug_printf_.emplace_back(InternalOnlyDebugPrintf{
563 module_.interface_.unique_shader_id, string_id, debug_inst->GetAsString(2)});
564 }
565 }
566 }
567
568 CreateFunctionCall(current_block, &inst_it, meta);
569
570 // remove the OpExtInst incase they don't support VK_KHR_non_semantic_info
571 if (!module_.settings_.support_non_semantic_info) {
572 inst_it = block_instructions.erase(inst_it);
573 inst_it--;
574 }
575 }
576 }

Callers

nothing calls this directly

Calls 10

GetAsStringMethod · 0.80
ResultIdMethod · 0.80
WordMethod · 0.80
OpcodeMethod · 0.80
emplace_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
UpdateMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected