Re: [Mesa-dev] [PATCH v2 10/11] intel: aubinator_viewer: store urb state during decoding

2018-08-08 Thread Lionel Landwerlin

On 08/08/18 21:55, Rafael Antognolli wrote:

t
@@ -790,6 +892,7 @@ aub_viewer_render_batch(struct aub_viewer_decode_ctx *ctx,
  
for (unsigned i = 0; i < ARRAY_SIZE(info_decoders); i++) {

   if (strcmp(inst_name, info_decoders[i].cmd_name) == 0) {
+ctx->stage = info_decoders[i].stage;
  info_decoders[i].decode(ctx, inst, p);
  break;

Looks like you run the info_decoders before the display decoders (even
though some of them decode the same type of instructions) because you
want to first do a pass storing all the information required for the
display_decoders, right?

And in this case, you also want to store the stage we are at, so when we
run the info_decoders that information is available.

Also, is there a chance we use these same info decoders for storing
other information than urb related stuff? If so, maybe we should just
call them handle_3ds_gs, handle_3ds_constant_vs, etc... Or something
along those lines. But of course we could just rename them in the
future.

The UI code (decode_* functions) run conditionally to the instruction 
having their fields visible (expanded by clicking on them).


info_decoders runs unconditionally so that we can have a consistent 
accumulated state that doesn't depend on the UI state.


For example, you might not want to display urb instructions & their 
content. Yet you still need to parse their content so that URB state can 
be displayed on a latter instruction (like 3DPRIMITIVE).



This is poorly named indeed and could be done more efficiently. This can 
be done later (once you get the hang of ImGui. It's really fun!).



-

Lionel

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2 10/11] intel: aubinator_viewer: store urb state during decoding

2018-08-08 Thread Rafael Antognolli
I'm not that familiar with this code yet, so take this review with a
grain of salt, but it looks good to me.

Reviewed-by: Rafael Antognolli 

Just a few comments below but nothing really important.

On Tue, Aug 07, 2018 at 06:35:21PM +0100, Lionel Landwerlin wrote:
> Signed-off-by: Lionel Landwerlin 
> ---
>  src/intel/tools/aubinator_viewer.h   |  26 
>  src/intel/tools/aubinator_viewer_decoder.cpp | 150 ---
>  2 files changed, 153 insertions(+), 23 deletions(-)
> 
> diff --git a/src/intel/tools/aubinator_viewer.h 
> b/src/intel/tools/aubinator_viewer.h
> index 2d89d9cf658..4a030efc0d0 100644
> --- a/src/intel/tools/aubinator_viewer.h
> +++ b/src/intel/tools/aubinator_viewer.h
> @@ -33,12 +33,35 @@ struct aub_viewer_decode_cfg {
>  show_dwords(true) {}
>  };
>  
> +enum aub_decode_stage {
> +   AUB_DECODE_STAGE_VS,
> +   AUB_DECODE_STAGE_HS,
> +   AUB_DECODE_STAGE_DS,
> +   AUB_DECODE_STAGE_GS,
> +   AUB_DECODE_STAGE_PS,
> +   AUB_DECODE_STAGE_CS,
> +   AUB_DECODE_N_STAGE,
> +};
> +
> +struct aub_decode_urb_stage_state {
> +   uint32_t start;
> +   uint32_t size;
> +   uint32_t n_entries;
> +
> +   uint32_t const_rd_length;
> +   uint32_t rd_offset;
> +   uint32_t rd_length;
> +   uint32_t wr_offset;
> +   uint32_t wr_length;
> +};
> +
>  struct aub_viewer_decode_ctx {
> struct gen_batch_decode_bo (*get_bo)(void *user_data, uint64_t address);
> unsigned (*get_state_size)(void *user_data,
>uint32_t offset_from_dynamic_state_base_addr);
>  
> void (*display_shader)(void *user_data, const char *shader_desc, uint64_t 
> address);
> +   void (*display_urb)(void *user_data, const struct 
> aub_decode_urb_stage_state *stages);
> void (*edit_address)(void *user_data, uint64_t address, uint32_t length);
>  
> void *user_data;
> @@ -53,6 +76,9 @@ struct aub_viewer_decode_ctx {
> uint64_t dynamic_base;
> uint64_t instruction_base;
>  
> +   enum aub_decode_stage stage;
> +   uint32_t end_urb_offset;
> +   struct aub_decode_urb_stage_state urb_stages[AUB_DECODE_N_STAGE];
>  };
>  
>  void aub_viewer_decode_ctx_init(struct aub_viewer_decode_ctx *ctx,
> diff --git a/src/intel/tools/aubinator_viewer_decoder.cpp 
> b/src/intel/tools/aubinator_viewer_decoder.cpp
> index a2ea3ba4a64..273bc2da376 100644
> --- a/src/intel/tools/aubinator_viewer_decoder.cpp
> +++ b/src/intel/tools/aubinator_viewer_decoder.cpp
> @@ -695,38 +695,125 @@ decode_load_register_imm(struct aub_viewer_decode_ctx 
> *ctx,
> }
>  }
>  
> +static void
> +decode_3dprimitive(struct aub_viewer_decode_ctx *ctx,
> +   struct gen_group *inst,
> +   const uint32_t *p)
> +{
> +   if (ctx->display_urb) {
> +  if (ImGui::Button("Show URB"))
> + ctx->display_urb(ctx->user_data, ctx->urb_stages);
> +   }
> +}
> +
> +static void
> +handle_urb(struct aub_viewer_decode_ctx *ctx,
> +   struct gen_group *inst,
> +   const uint32_t *p)
> +{
> +   struct gen_field_iterator iter;
> +   gen_field_iterator_init(, inst, p, 0, false);
> +   while (gen_field_iterator_next()) {
> +  if (strstr(iter.name, "URB Starting Address")) {
> + ctx->urb_stages[ctx->stage].start = iter.raw_value * 8192;
> +  } else if (strstr(iter.name, "URB Entry Allocation Size")) {
> + ctx->urb_stages[ctx->stage].size = (iter.raw_value + 1) * 64;
> +  } else if (strstr(iter.name, "Number of URB Entries")) {
> + ctx->urb_stages[ctx->stage].n_entries = iter.raw_value;
> +  }
> +   }
> +
> +   ctx->end_urb_offset = MAX2(ctx->urb_stages[ctx->stage].start +
> +  ctx->urb_stages[ctx->stage].n_entries *
> +  ctx->urb_stages[ctx->stage].size,
> +  ctx->end_urb_offset);
> +}
> +
> +static void
> +handle_urb_read(struct aub_viewer_decode_ctx *ctx,
> +struct gen_group *inst,
> +const uint32_t *p)
> +{
> +   struct gen_field_iterator iter;
> +   gen_field_iterator_init(, inst, p, 0, false);
> +   while (gen_field_iterator_next()) {
> +  /* Workaround the "Force * URB Entry Read Length" fields */
> +  if (iter.end_bit - iter.start_bit < 2)
> + continue;
> +
> +  if (strstr(iter.name, "URB Entry Read Offset")) {
> + ctx->urb_stages[ctx->stage].rd_offset = iter.raw_value * 32;
> +  } else if (strstr(iter.name, "URB Entry Read Length")) {
> + ctx->urb_stages[ctx->stage].rd_length = iter.raw_value * 32;
> +  } else if (strstr(iter.name, "URB Entry Output Read Offset")) {
> + ctx->urb_stages[ctx->stage].wr_offset = iter.raw_value * 32;
> +  } else if (strstr(iter.name, "URB Entry Output Length")) {
> + ctx->urb_stages[ctx->stage].wr_length = iter.raw_value * 32;
> +  }
> +   }
> +}
> +
> +static void
> +handle_urb_constant(struct aub_viewer_decode_ctx *ctx,
> +struct gen_group *inst,
> +const uint32_t *p)
> 

[Mesa-dev] [PATCH v2 10/11] intel: aubinator_viewer: store urb state during decoding

2018-08-07 Thread Lionel Landwerlin
Signed-off-by: Lionel Landwerlin 
---
 src/intel/tools/aubinator_viewer.h   |  26 
 src/intel/tools/aubinator_viewer_decoder.cpp | 150 ---
 2 files changed, 153 insertions(+), 23 deletions(-)

diff --git a/src/intel/tools/aubinator_viewer.h 
b/src/intel/tools/aubinator_viewer.h
index 2d89d9cf658..4a030efc0d0 100644
--- a/src/intel/tools/aubinator_viewer.h
+++ b/src/intel/tools/aubinator_viewer.h
@@ -33,12 +33,35 @@ struct aub_viewer_decode_cfg {
 show_dwords(true) {}
 };
 
+enum aub_decode_stage {
+   AUB_DECODE_STAGE_VS,
+   AUB_DECODE_STAGE_HS,
+   AUB_DECODE_STAGE_DS,
+   AUB_DECODE_STAGE_GS,
+   AUB_DECODE_STAGE_PS,
+   AUB_DECODE_STAGE_CS,
+   AUB_DECODE_N_STAGE,
+};
+
+struct aub_decode_urb_stage_state {
+   uint32_t start;
+   uint32_t size;
+   uint32_t n_entries;
+
+   uint32_t const_rd_length;
+   uint32_t rd_offset;
+   uint32_t rd_length;
+   uint32_t wr_offset;
+   uint32_t wr_length;
+};
+
 struct aub_viewer_decode_ctx {
struct gen_batch_decode_bo (*get_bo)(void *user_data, uint64_t address);
unsigned (*get_state_size)(void *user_data,
   uint32_t offset_from_dynamic_state_base_addr);
 
void (*display_shader)(void *user_data, const char *shader_desc, uint64_t 
address);
+   void (*display_urb)(void *user_data, const struct 
aub_decode_urb_stage_state *stages);
void (*edit_address)(void *user_data, uint64_t address, uint32_t length);
 
void *user_data;
@@ -53,6 +76,9 @@ struct aub_viewer_decode_ctx {
uint64_t dynamic_base;
uint64_t instruction_base;
 
+   enum aub_decode_stage stage;
+   uint32_t end_urb_offset;
+   struct aub_decode_urb_stage_state urb_stages[AUB_DECODE_N_STAGE];
 };
 
 void aub_viewer_decode_ctx_init(struct aub_viewer_decode_ctx *ctx,
diff --git a/src/intel/tools/aubinator_viewer_decoder.cpp 
b/src/intel/tools/aubinator_viewer_decoder.cpp
index a2ea3ba4a64..273bc2da376 100644
--- a/src/intel/tools/aubinator_viewer_decoder.cpp
+++ b/src/intel/tools/aubinator_viewer_decoder.cpp
@@ -695,38 +695,125 @@ decode_load_register_imm(struct aub_viewer_decode_ctx 
*ctx,
}
 }
 
+static void
+decode_3dprimitive(struct aub_viewer_decode_ctx *ctx,
+   struct gen_group *inst,
+   const uint32_t *p)
+{
+   if (ctx->display_urb) {
+  if (ImGui::Button("Show URB"))
+ ctx->display_urb(ctx->user_data, ctx->urb_stages);
+   }
+}
+
+static void
+handle_urb(struct aub_viewer_decode_ctx *ctx,
+   struct gen_group *inst,
+   const uint32_t *p)
+{
+   struct gen_field_iterator iter;
+   gen_field_iterator_init(, inst, p, 0, false);
+   while (gen_field_iterator_next()) {
+  if (strstr(iter.name, "URB Starting Address")) {
+ ctx->urb_stages[ctx->stage].start = iter.raw_value * 8192;
+  } else if (strstr(iter.name, "URB Entry Allocation Size")) {
+ ctx->urb_stages[ctx->stage].size = (iter.raw_value + 1) * 64;
+  } else if (strstr(iter.name, "Number of URB Entries")) {
+ ctx->urb_stages[ctx->stage].n_entries = iter.raw_value;
+  }
+   }
+
+   ctx->end_urb_offset = MAX2(ctx->urb_stages[ctx->stage].start +
+  ctx->urb_stages[ctx->stage].n_entries *
+  ctx->urb_stages[ctx->stage].size,
+  ctx->end_urb_offset);
+}
+
+static void
+handle_urb_read(struct aub_viewer_decode_ctx *ctx,
+struct gen_group *inst,
+const uint32_t *p)
+{
+   struct gen_field_iterator iter;
+   gen_field_iterator_init(, inst, p, 0, false);
+   while (gen_field_iterator_next()) {
+  /* Workaround the "Force * URB Entry Read Length" fields */
+  if (iter.end_bit - iter.start_bit < 2)
+ continue;
+
+  if (strstr(iter.name, "URB Entry Read Offset")) {
+ ctx->urb_stages[ctx->stage].rd_offset = iter.raw_value * 32;
+  } else if (strstr(iter.name, "URB Entry Read Length")) {
+ ctx->urb_stages[ctx->stage].rd_length = iter.raw_value * 32;
+  } else if (strstr(iter.name, "URB Entry Output Read Offset")) {
+ ctx->urb_stages[ctx->stage].wr_offset = iter.raw_value * 32;
+  } else if (strstr(iter.name, "URB Entry Output Length")) {
+ ctx->urb_stages[ctx->stage].wr_length = iter.raw_value * 32;
+  }
+   }
+}
+
+static void
+handle_urb_constant(struct aub_viewer_decode_ctx *ctx,
+struct gen_group *inst,
+const uint32_t *p)
+{
+   struct gen_group *body =
+  gen_spec_find_struct(ctx->spec, "3DSTATE_CONSTANT_BODY");
+
+   struct gen_field_iterator outer;
+   gen_field_iterator_init(, inst, p, 0, false);
+   while (gen_field_iterator_next()) {
+  if (outer.struct_desc != body)
+ continue;
+
+  struct gen_field_iterator iter;
+  gen_field_iterator_init(, body, [outer.start_bit / 32],
+  0, false);
+
+  ctx->urb_stages[ctx->stage].const_rd_length = 0;
+  while (gen_field_iterator_next()) {