SpiecsEngine
 
Loading...
Searching...
No Matches

◆ DrawPipelineStatistics()

void Spices::ImguiRendererProfilerHUD::DrawPipelineStatistics ( int bit) const
private

Store bit as static variable.

Tree node.

Instance a Tree.

Write scene data to tree.

0: NoSort, 1: Ascending, 2: Descending.

Function of quick sort to PipelineResult.

Function of sort whole tree.

Function of draw whole tree.

Store bit as static variable.

Tree node.

Instance a Tree.

Write scene data to tree.

0: NoSort, 1: Ascending, 2: Descending.

Function of quick sort to PipelineResult.

Function of sort whole tree.

Function of draw whole tree.

Definition at line 372 of file ImguiRendererProfilerHUD.cpp.

373 {
375
379 static int selectBit;
380 selectBit = bit;
381
385 struct PipelineResult
386 {
387 PipelineStatisticsQuerier::Result result;
388 std::string name;
389 };
390
394 scl::tree<PipelineResult> totalResult;
395 totalResult.GetData().name = "Scene ( Viewport 0 )";
396
400 {
401 SPICES_PROFILE_ZONEN("Fetch Statistics Caches");
402
403 RendererManager::IterRenderer([&](const std::string& rendererName, const std::shared_ptr<Renderer>& renderer) {
404
405 auto rendererResult = totalResult.AddChild();
406 rendererResult->GetData().name = rendererName;
407
408 renderer->IterStatistics([&](const std::string& subPassName, const std::shared_ptr<RenderPassStatistics>& statistics) {
409
410 auto subPassResult = rendererResult->AddChild();
411 subPassResult->GetData().name = subPassName;
412
413 statistics->IterStatisticsResult(Querier::Pipeline, [&](const Querier::StatisticsBits& type, std::shared_ptr<Querier::Result>& result) {
414
415 PipelineStatisticsQuerier::Result* res = static_cast<PipelineStatisticsQuerier::Result*>(result.get());
416 if (res->valid)
417 {
418 subPassResult->GetData().result = *res;
419
420 rendererResult->GetData().result.Combine(res);
421 rendererResult->GetData().result.valid = true;
422
423 totalResult.GetData().result.Combine(res);
424 totalResult.GetData().result.valid = true;
425 }
426 });
427
428 return false;
429 });
430
431 return false;
432 });
433 }
434
435 {
436 SPICES_PROFILE_ZONEN("Draw Statistics Caches");
437
438 static ImGuiTableFlags flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBody |
439 ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_SortMulti | ImGuiTableFlags_Hideable |
440 ImGuiTableFlags_ScrollY | ImGuiTableFlags_SortTristate;
441 static ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_SpanAllColumns;
442
446 static int sortState = 0;
447
451 static auto SortTimestampTreeMethod = [](const void* lhs, const void* rhs) -> int {
452
453 const auto l = static_cast<const std::unique_ptr<scl::tree<PipelineResult>>*>(lhs);
454 const auto r = static_cast<const std::unique_ptr<scl::tree<PipelineResult>>*>(rhs);
455
456 ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs();
457 if (sortState == ImGuiSortDirection_Ascending)
458 {
459 return (*l)->GetData().result.statistics[selectBit] - (*r)->GetData().result.statistics[selectBit];
460 }
461 else
462 {
463 return (*r)->GetData().result.statistics[selectBit] - (*l)->GetData().result.statistics[selectBit];
464 }
465 };
466
470 static std::function<void(scl::tree<PipelineResult>*)> SortTimestampTree = [&](scl::tree<PipelineResult>* node) {
471
472 if (sortState == 0) return;
473
474 qsort((void*)node->GetChilds().data(), (size_t)node->GetChilds().size(), sizeof(node->GetChilds()[0]), SortTimestampTreeMethod);
475
476 for (auto& child : node->GetChilds())
477 {
478 SortTimestampTree(child.get());
479 }
480 };
481
485 static std::function<void(scl::tree<PipelineResult>*, uint32_t depth, scl::tree<PipelineResult>*)> DrawTimestampTree = [&](scl::tree<PipelineResult>* node, uint32_t depth, scl::tree<PipelineResult>* root) {
486
487 if (!node->GetData().result.valid) return;
488
489 ImGui::TableNextRow();
490 ImGui::TableNextColumn();
491
492 std::stringstream space;
493 for (uint32_t i = 0; i < depth; i++)
494 {
495 space << " ";
496 }
497
498 ImGui::Text(space.str().c_str());
499 ImGui::SameLine();
500
501 bool hasChild = node->GetChilds().size() > 0;
502 if (hasChild)
503 {
504 bool open = ImGui::TreeNodeEx(node->GetData().name.c_str(), tree_node_flags);
505 ImGui::TableNextColumn();
506
507 ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(0.0f, 0.8f, 0.0f, 1.0f));
508 ImGui::ProgressBar(root->GetData().result.statistics[bit] > 0 ? (node->GetData().result.statistics[bit] / float(root->GetData().result.statistics[bit])) : 0.0f, ImVec2(-FLT_MIN, 2.0f), "##");
509 ImGui::PopStyleColor();
510 ImGui::SameLine(0.05f);
511 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.8f, 0.8f, 0.8f, 1.0f));
512 ImGui::Text("%d", node->GetData().result.statistics[bit]);
513 ImGui::PopStyleColor();
514 if (open)
515 {
516 for (auto& child : node->GetChilds())
517 {
518 DrawTimestampTree(child.get(), depth + 1, root);
519 }
520 ImGui::TreePop();
521 }
522 }
523 else
524 {
525 ImGui::TreeNodeEx(node->GetData().name.c_str(), tree_node_flags | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen);
526 ImGui::TableNextColumn();
527
528 ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(0.0f, 0.8f, 0.0f, 1.0f));
529 ImGui::ProgressBar(root->GetData().result.statistics[bit] > 0 ? (node->GetData().result.statistics[bit] / float(root->GetData().result.statistics[bit])) : 0.0f, ImVec2(-FLT_MIN, 2.0f), "##");
530 ImGui::PopStyleColor();
531 ImGui::SameLine(0.05f);
532 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.8f, 0.8f, 0.8f, 1.0f));
533 ImGui::Text("%d", node->GetData().result.statistics[bit]);
534 ImGui::PopStyleColor();
535 }
536 };
537
538 ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, 0.0f);
539 ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
540 ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
541 ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
542 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
543
544 if (ImGui::BeginTable("pipelineTree", 2, flags))
545 {
546 // The first column will use the default _WidthStretch when ScrollX is Off and _WidthFixed when ScrollX is On
547 ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_NoHide);
548 ImGui::TableSetupColumn("Invocation Count", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_PreferSortDescending, ImGuiH::GetLineItemSize().x * 3.0f);
549 ImGui::TableSetupScrollFreeze(0, 1);
550 ImGui::TableHeadersRow();
551
552 // Sort our data if sort specs have been changed!
553 if (ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs())
554 {
555 // State changed since last frame.
556 if (sort_specs->SpecsDirty)
557 {
558 sortState = 0;
559
560 // Need sort this frame.
561 if (sort_specs->SpecsCount > 0)
562 {
563 sortState = sort_specs->Specs->SortDirection;
564 }
565
566 sort_specs->SpecsDirty = false;
567 }
568 }
569
570 SortTimestampTree(&totalResult);
571 DrawTimestampTree(&totalResult, 0, &totalResult);
572
573 ImGui::EndTable();
574 }
575 ImGui::PopStyleColor(4);
576 ImGui::PopStyleVar();
577 }
578 }
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
static ImVec2 GetLineItemSize()
Get Line Width's Square Size.
StatisticsBits
Statistics types.
Definition Querier.h:24
static void IterRenderer(T &&fn)
Iter all Renderer.
const std::vector< std::unique_ptr< tree > > & GetChilds() const
Get all this node children.
Definition Tree.h:63
T & GetData()
Definition Tree.h:69
tree * AddChild(Args &&... args)
Add a child to this tree.
Definition Tree.h:52
simple tree.
Definition Tree.h:18

Referenced by OnRender().