[Mesa-dev] [PATCH v2 11/11] intel: aubinator_viewer: add urb view

Rafael Antognolli rafael.antognolli at intel.com
Wed Aug 8 21:09:45 UTC 2018


On Tue, Aug 07, 2018 at 06:35:22PM +0100, Lionel Landwerlin wrote:
> This is available through a "Show URB" button on the 3DPRIMITIVE
> instructions.
> 
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> ---
>  src/intel/tools/aubinator_viewer.cpp   | 75 ++++++++++++++++++++
>  src/intel/tools/aubinator_viewer_urb.h | 96 ++++++++++++++++++++++++++
>  2 files changed, 171 insertions(+)
>  create mode 100644 src/intel/tools/aubinator_viewer_urb.h
> 
> diff --git a/src/intel/tools/aubinator_viewer.cpp b/src/intel/tools/aubinator_viewer.cpp
> index f306f99bca5..5f2d50f6e46 100644
> --- a/src/intel/tools/aubinator_viewer.cpp
> +++ b/src/intel/tools/aubinator_viewer.cpp
> @@ -219,6 +219,7 @@ update_mem_for_exec(struct aub_mem *mem, struct aub_file *file, int exec_idx)
>  #include "imgui_impl_opengl3.h"
>  
>  #include "aubinator_viewer.h"
> +#include "aubinator_viewer_urb.h"
>  #include "imgui_memory_editor.h"
>  
>  struct window {
> @@ -267,6 +268,15 @@ struct shader_window {
>     size_t shader_size;
>  };
>  
> +struct urb_window {
> +   struct window base;
> +
> +   uint32_t end_urb_offset;
> +   struct aub_decode_urb_stage_state urb_stages[AUB_DECODE_N_STAGE];
> +
> +   AubinatorViewerUrb urb_view;
> +};
> +
>  struct batch_window {
>     struct window base;
>  
> @@ -389,6 +399,61 @@ new_shader_window(struct aub_mem *mem, uint64_t address, const char *desc)
>     return window;
>  }
>  
> +/* URB windows */
> +
> +static void
> +display_urb_window(struct window *win)
> +{
> +   struct urb_window *window = (struct urb_window *) win;
> +   static const char *stages[] = {
> +      [AUB_DECODE_STAGE_VS] = "VS",
> +      [AUB_DECODE_STAGE_HS] = "HS",
> +      [AUB_DECODE_STAGE_DS] = "DS",
> +      [AUB_DECODE_STAGE_GS] = "GS",
> +      [AUB_DECODE_STAGE_PS] = "PS",
> +      [AUB_DECODE_STAGE_CS] = "CS",
> +   };
> +
> +   ImGui::Text("URB allocation:");
> +   window->urb_view.DrawAllocation("##urb",
> +                                   ARRAY_SIZE(window->urb_stages),
> +                                   window->end_urb_offset,
> +                                   stages,
> +                                   &window->urb_stages[0]);
> +}
> +
> +static void
> +destroy_urb_window(struct window *win)
> +{
> +   struct urb_window *window = (struct urb_window *) win;
> +
> +   free(window);
> +}
> +
> +static struct urb_window *
> +new_urb_window(struct aub_viewer_decode_ctx *decode_ctx, uint64_t address)
> +{
> +   struct urb_window *window = xtzalloc(*window);
> +
> +   snprintf(window->base.name, sizeof(window->base.name),
> +            "URB view (0x%lx)##%p", address, window);
> +
> +   list_inithead(&window->base.parent_link);
> +   window->base.position = ImVec2(-1, -1);
> +   window->base.size = ImVec2(700, 300);
> +   window->base.opened = true;
> +   window->base.display = display_urb_window;
> +   window->base.destroy = destroy_urb_window;
> +
> +   window->end_urb_offset = decode_ctx->end_urb_offset;
> +   memcpy(window->urb_stages, decode_ctx->urb_stages, sizeof(window->urb_stages));
> +   window->urb_view = AubinatorViewerUrb();
> +
> +   list_addtail(&window->base.link, &context.windows);
> +
> +   return window;
> +}
> +
>  /* Memory editor windows */
>  
>  static uint8_t
> @@ -581,6 +646,15 @@ batch_display_shader(void *user_data, const char *shader_desc, uint64_t address)
>     list_add(&shader_window->base.parent_link, &window->base.children_windows);
>  }
>  
> +static void
> +batch_display_urb(void *user_data, const struct aub_decode_urb_stage_state *stages)
> +{
> +   struct batch_window *window = (struct batch_window *) user_data;
> +   struct urb_window *urb_window = new_urb_window(&window->decode_ctx, 0);
> +
> +   list_add(&urb_window->base.parent_link, &window->base.children_windows);
> +}
> +
>  static void
>  batch_edit_address(void *user_data, uint64_t address, uint32_t len)
>  {
> @@ -740,6 +814,7 @@ new_batch_window(int exec_idx)
>                                NULL,
>                                window);
>     window->decode_ctx.display_shader = batch_display_shader;
> +   window->decode_ctx.display_urb = batch_display_urb;
>     window->decode_ctx.edit_address = batch_edit_address;
>  
>     update_batch_window(window, false, exec_idx);
> diff --git a/src/intel/tools/aubinator_viewer_urb.h b/src/intel/tools/aubinator_viewer_urb.h
> new file mode 100644
> index 00000000000..6857bc20a8f
> --- /dev/null
> +++ b/src/intel/tools/aubinator_viewer_urb.h
> @@ -0,0 +1,96 @@
> +#ifndef AUBINATOR_VIEWER_URB_H
> +#define AUBINATOR_VIEWER_URB_H
> +
> +#include "aubinator_viewer.h"
> +
> +#include "imgui.h"
> +
> +struct AubinatorViewerUrb {
> +
> +   float RowHeight;
> +
> +   AubinatorViewerUrb() {
> +      RowHeight = 10.0f;
> +   }
> +
> +   bool _Hovered(const ImVec2& mouse, bool window_hovered,
> +                 const ImVec2& tl, const ImVec2& br) {
> +      return window_hovered &&
> +         tl.x <= mouse.x && tl.y <= mouse.y &&
> +         br.x > mouse.x && br.y > mouse.y;
> +   }
> +
> +   void DrawAllocation(const char *label,
> +                       int n_stages,
> +                       int end_urb_offset,
> +                       const char *stage_names[],
> +                       const struct aub_decode_urb_stage_state *stages) {
> +      const ImVec2 label_size = ImGui::CalcTextSize("VS entry:  ", NULL, true);
> +      ImVec2 graph_size(ImGui::CalcItemWidth(), 2 * n_stages * label_size.y);
> +
> +      ImGui::BeginChild(label, ImVec2(0, graph_size.y), false);
> +
> +      ImDrawList* draw_list = ImGui::GetWindowDrawList();
> +
> +      const float row_height = MAX2(RowHeight, label_size.y);
> +      const float width = ImGui::GetContentRegionAvailWidth() - label_size.x;
> +      const float alloc_delta = width / end_urb_offset;
> +      const ImVec2 window_pos = ImGui::GetWindowPos();
> +      const ImVec2 mouse_pos = ImGui::GetMousePos();
> +      const bool window_hovered = ImGui::IsWindowHovered();
> +
> +      int const_idx = 0;
> +      for (int s = 0; s < n_stages; s++) {
> +         const float x = window_pos.x + label_size.x;
> +         const float y = window_pos.y + s * row_height;
> +
> +         ImVec2 alloc_pos(window_pos.x, y);
> +         ImVec2 alloc_tl(x + stages[s].start * alloc_delta, y);
> +         ImVec2 alloc_br(x + (stages[s].start +
> +                              stages[s].n_entries * stages[s].size) * alloc_delta,
> +                         y + row_height);
> +         ImVec2 const_tl(x + const_idx * alloc_delta, y);
> +         ImVec2 const_br(x + (const_idx + stages[s].const_rd_length) * alloc_delta,
> +                         y + row_height);
> +
> +         char label[40];
> +         snprintf(label, sizeof(label), "%s: ", stage_names[s]);
> +         draw_list->AddText(alloc_pos, ImGui::GetColorU32(ImGuiCol_Text), label);
> +
> +         float r, g, b;
> +         bool hovered;
> +
> +         /* URB allocation */
> +         hovered = _Hovered(mouse_pos, window_hovered, alloc_tl, alloc_br);
> +         ImGui::ColorConvertHSVtoRGB((2 * s) * 1.0f / (2 * n_stages),
> +                                     1.0f, hovered ? 1.0f : 0.8f,
> +                                     r, g, b);
> +         draw_list->AddRectFilled(alloc_tl, alloc_br, ImColor(r, g, b));
> +         if (hovered) {
> +            ImGui::SetTooltip("%s: start=%u end=%u",
> +                              stage_names[s],
> +                              stages[s].start,
> +                              stages[s].n_entries * stages[s].size);

Maybe you should add stages[s].start to the "end" case? It seems
a little inconsistent right now.

Other than that, and taking into account how much I understand about
imgui, consider this:

Reviewed-by: Rafael Antognolli <rafael.antognolli at intel.com>

> +         }
> +
> +         /* Constant URB input */
> +         hovered = _Hovered(mouse_pos, window_hovered, const_tl, const_br);
> +         ImGui::ColorConvertHSVtoRGB((2 * s + 1) * 1.0f / (2 * n_stages),
> +                                     1.0f, hovered ? 1.0f : 0.8f,
> +                                     r, g, b);
> +         draw_list->AddRectFilled(const_tl, const_br, ImColor(r, g, b));
> +         if (hovered) {
> +            ImGui::SetTooltip("%s constant: start=%u end=%u",
> +                              stage_names[s],
> +                              stages[s].rd_offset,
> +                              stages[s].rd_offset + stages[s].rd_length);
> +         }
> +
> +         const_idx += stages[s].const_rd_length;
> +      }
> +
> +      ImGui::EndChild();
> +   }
> +};
> +
> +#endif /* AUBINATOR_VIEWER_URB_H */
> -- 
> 2.18.0
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list