1 #ifndef AUBINATOR_VIEWER_URB_H
2 #define AUBINATOR_VIEWER_URB_H
4 #include "aubinator_viewer.h"
6 #include "imgui/imgui.h"
8 struct AubinatorViewerUrb
{
12 AubinatorViewerUrb() {
16 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
;
23 void DrawAllocation(const char *label
,
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
);
31 ImGui::BeginChild(label
, ImVec2(0, graph_size
.y
), false);
33 ImDrawList
* draw_list
= ImGui::GetWindowDrawList();
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();
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
;
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
,
52 ImVec2
const_tl(x
+ const_idx
* alloc_delta
, y
);
53 ImVec2
const_br(x
+ (const_idx
+ stages
[s
].const_rd_length
) * alloc_delta
,
57 snprintf(label
, sizeof(label
), "%s: ", stage_names
[s
]);
58 draw_list
->AddText(alloc_pos
, ImGui::GetColorU32(ImGuiCol_Text
), label
);
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
,
68 draw_list
->AddRectFilled(alloc_tl
, alloc_br
, ImColor(r
, g
, b
));
70 ImGui::SetTooltip("%s: start=%u end=%u",
73 stages
[s
].start
+ stages
[s
].n_entries
* stages
[s
].size
);
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
,
81 draw_list
->AddRectFilled(const_tl
, const_br
, ImColor(r
, g
, b
));
83 ImGui::SetTooltip("%s constant: start=%u end=%u",
86 stages
[s
].rd_offset
+ stages
[s
].rd_length
);
89 const_idx
+= stages
[s
].const_rd_length
;
96 #endif /* AUBINATOR_VIEWER_URB_H */