• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef AUBINATOR_VIEWER_URB_H
2 #define AUBINATOR_VIEWER_URB_H
3 
4 #include "aubinator_viewer.h"
5 
6 #include "imgui/imgui.h"
7 
8 struct AubinatorViewerUrb {
9 
10    float RowHeight;
11 
AubinatorViewerUrbAubinatorViewerUrb12    AubinatorViewerUrb() {
13       RowHeight = 10.0f;
14    }
15 
_HoveredAubinatorViewerUrb16    bool _Hovered(const ImVec2& mouse, bool window_hovered,
17                  const ImVec2& tl, const ImVec2& br) {
18       return window_hovered &&
19          tl.x <= mouse.x && tl.y <= mouse.y &&
20          br.x > mouse.x && br.y > mouse.y;
21    }
22 
DrawAllocationAubinatorViewerUrb23    void DrawAllocation(const char *label,
24                        int n_stages,
25                        int end_urb_offset,
26                        const char *stage_names[],
27                        const struct aub_decode_urb_stage_state *stages) {
28       const ImVec2 label_size = ImGui::CalcTextSize("VS entry:  ", NULL, true);
29       ImVec2 graph_size(ImGui::CalcItemWidth(), 2 * n_stages * label_size.y);
30 
31       ImGui::BeginChild(label, ImVec2(0, graph_size.y), false);
32 
33       ImDrawList* draw_list = ImGui::GetWindowDrawList();
34 
35       const float row_height = MAX2(RowHeight, label_size.y);
36       const float width = ImGui::GetContentRegionAvailWidth() - label_size.x;
37       const float alloc_delta = width / end_urb_offset;
38       const ImVec2 window_pos = ImGui::GetWindowPos();
39       const ImVec2 mouse_pos = ImGui::GetMousePos();
40       const bool window_hovered = ImGui::IsWindowHovered();
41 
42       int const_idx = 0;
43       for (int s = 0; s < n_stages; s++) {
44          const float x = window_pos.x + label_size.x;
45          const float y = window_pos.y + s * row_height;
46 
47          ImVec2 alloc_pos(window_pos.x, y);
48          ImVec2 alloc_tl(x + stages[s].start * alloc_delta, y);
49          ImVec2 alloc_br(x + (stages[s].start +
50                               stages[s].n_entries * stages[s].size) * alloc_delta,
51                          y + row_height);
52          ImVec2 const_tl(x + const_idx * alloc_delta, y);
53          ImVec2 const_br(x + (const_idx + stages[s].const_rd_length) * alloc_delta,
54                          y + row_height);
55 
56          char label[40];
57          snprintf(label, sizeof(label), "%s: ", stage_names[s]);
58          draw_list->AddText(alloc_pos, ImGui::GetColorU32(ImGuiCol_Text), label);
59 
60          float r, g, b;
61          bool hovered;
62 
63          /* URB allocation */
64          hovered = _Hovered(mouse_pos, window_hovered, alloc_tl, alloc_br);
65          ImGui::ColorConvertHSVtoRGB((2 * s) * 1.0f / (2 * n_stages),
66                                      1.0f, hovered ? 1.0f : 0.8f,
67                                      r, g, b);
68          draw_list->AddRectFilled(alloc_tl, alloc_br, ImColor(r, g, b));
69          if (hovered) {
70             ImGui::SetTooltip("%s: start=%u end=%u",
71                               stage_names[s],
72                               stages[s].start,
73                               stages[s].start + stages[s].n_entries * stages[s].size);
74          }
75 
76          /* Constant URB input */
77          hovered = _Hovered(mouse_pos, window_hovered, const_tl, const_br);
78          ImGui::ColorConvertHSVtoRGB((2 * s + 1) * 1.0f / (2 * n_stages),
79                                      1.0f, hovered ? 1.0f : 0.8f,
80                                      r, g, b);
81          draw_list->AddRectFilled(const_tl, const_br, ImColor(r, g, b));
82          if (hovered) {
83             ImGui::SetTooltip("%s constant: start=%u end=%u",
84                               stage_names[s],
85                               stages[s].rd_offset,
86                               stages[s].rd_offset + stages[s].rd_length);
87          }
88 
89          const_idx += stages[s].const_rd_length;
90       }
91 
92       ImGui::EndChild();
93    }
94 };
95 
96 #endif /* AUBINATOR_VIEWER_URB_H */
97