rendercopy/bdw: Add AUB annotations for states
authorDamien Lespiau <damien.lespiau@intel.com>
Wed, 27 Feb 2013 14:51:48 +0000 (14:51 +0000)
committerBen Widawsky <benjamin.widawsky@intel.com>
Wed, 6 Nov 2013 17:39:41 +0000 (09:39 -0800)
This will hopefully help debugging things.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Ben Widawsky <benjamin.widawsky@intel.com>
lib/rendercopy_gen8.c

index 9dfcbaf..660ff03 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <assert.h>
 
+#include <intel_aub.h>
+
 #define ALIGN(x, y) (((x) + (y)-1) & ~((y)-1))
 #define VERTEX_SIZE (3*4)
 
@@ -51,6 +53,64 @@ static const uint32_t ps_kernel[][4] = {
 #endif
 };
 
+/* AUB annotation support */
+#define MAX_ANNOTATIONS        33
+struct annotations_context {
+       drm_intel_aub_annotation annotations[MAX_ANNOTATIONS];
+       int index;
+       uint32_t offset;
+} aub_annotations;
+
+static void annotation_init(struct annotations_context *ctx)
+{
+       /* ctx->annotations is an array keeping a list of annotations of the
+        * batch buffer ordered by offset. ctx->annotations[0] is thus left
+        * for the command stream and will be filled just before executing
+        * the batch buffer with annotations_add_batch() */
+       ctx->index = 1;
+}
+
+static void add_annotation(drm_intel_aub_annotation *a,
+                          uint32_t type, uint32_t subtype,
+                          uint32_t ending_offset)
+{
+       a->type = type;
+       a->subtype = subtype;
+       a->ending_offset = ending_offset;
+}
+
+static void annotation_add_batch(struct annotations_context *ctx, size_t size)
+{
+       add_annotation(&ctx->annotations[0], AUB_TRACE_TYPE_BATCH, 0, size);
+}
+
+static void annotation_add_state(struct annotations_context *ctx,
+                                uint32_t state_type,
+                                uint32_t start_offset,
+                                size_t   size)
+{
+       assert(ctx->index < MAX_ANNOTATIONS);
+
+       add_annotation(&ctx->annotations[ctx->index++],
+                      AUB_TRACE_TYPE_NOTYPE, 0,
+                      start_offset);
+       add_annotation(&ctx->annotations[ctx->index++],
+                      AUB_TRACE_TYPE(state_type),
+                      AUB_TRACE_SUBTYPE(state_type),
+                      start_offset + size);
+}
+
+static void annotation_flush(struct annotations_context *ctx,
+                            struct intel_batchbuffer *batch)
+{
+       if (!drmtest_dump_aub())
+               return;
+
+       drm_intel_bufmgr_gem_set_aub_annotations(batch->bo,
+                                                ctx->annotations,
+                                                ctx->index);
+}
+
 static uint32_t
 batch_used(struct intel_batchbuffer *batch)
 {
@@ -103,7 +163,7 @@ static uint32_t
 gen8_bind_buf(struct intel_batchbuffer *batch, struct scratch_buf *buf,
              uint32_t format, int is_dst) {
        struct gen8_surface_state *ss;
-       uint32_t write_domain, read_domain;
+       uint32_t write_domain, read_domain, offset;
        int ret;
 
        if (is_dst) {
@@ -114,6 +174,10 @@ gen8_bind_buf(struct intel_batchbuffer *batch, struct scratch_buf *buf,
        }
 
        ss = batch_alloc(batch, sizeof(*ss), 64);
+       offset = batch_offset(batch, ss);
+       annotation_add_state(&aub_annotations, AUB_TRACE_SURFACE_STATE,
+                            offset, sizeof(*ss));
+
        ss->ss0.surface_type = GEN6_SURFACE_2D;
        ss->ss0.surface_format = format;
        ss->ss0.render_cache_read_write = 1;
@@ -141,31 +205,39 @@ gen8_bind_buf(struct intel_batchbuffer *batch, struct scratch_buf *buf,
        ss->ss7.shader_chanel_select_b = 6;
        ss->ss7.shader_chanel_select_a = 7;
 
-       return batch_offset(batch, ss);
+       return offset;
 }
 
 static uint32_t
 gen8_bind_surfaces(struct intel_batchbuffer *batch,
                   struct scratch_buf *src,
-                  struct scratch_buf *dst) {
-       uint32_t *binding_table;
+                  struct scratch_buf *dst)
+{
+       uint32_t *binding_table, offset;
 
        binding_table = batch_alloc(batch, 8, 32);
+       offset = batch_offset(batch, binding_table);
+       annotation_add_state(&aub_annotations, AUB_TRACE_BINDING_TABLE,
+                            offset, 8);
 
        binding_table[0] =
                gen8_bind_buf(batch, dst, GEN6_SURFACEFORMAT_B8G8R8A8_UNORM, 1);
        binding_table[1] =
                gen8_bind_buf(batch, src, GEN6_SURFACEFORMAT_B8G8R8A8_UNORM, 0);
 
-       return batch_offset(batch, binding_table);
+       return offset;
 }
 
 /* Mostly copy+paste from gen6, except wrap modes moved */
 static uint32_t
 gen8_create_sampler(struct intel_batchbuffer *batch) {
        struct gen8_sampler_state *ss;
+       uint32_t offset;
 
-       ss = batch_alloc(batch, sizeof(*ss), 32);
+       ss = batch_alloc(batch, sizeof(*ss), 64);
+       offset = batch_offset(batch, ss);
+       annotation_add_state(&aub_annotations, AUB_TRACE_SAMPLER_STATE,
+                            offset, sizeof(*ss));
 
        ss->ss0.min_filter = GEN6_MAPFILTER_NEAREST;
        ss->ss0.mag_filter = GEN6_MAPFILTER_NEAREST;
@@ -177,7 +249,21 @@ gen8_create_sampler(struct intel_batchbuffer *batch) {
         * sampler fetch, but couldn't make it work. */
        ss->ss3.non_normalized_coord = 0;
 
-       return batch_offset(batch, ss);
+       return offset;
+}
+
+static uint32_t
+gen8_fill_ps(struct intel_batchbuffer *batch,
+            const uint32_t kernel[][4],
+            size_t size)
+{
+       uint32_t offset;
+
+       offset = batch_copy(batch, kernel, size, 64);
+       annotation_add_state(&aub_annotations, AUB_TRACE_KERNEL_INSTRUCTIONS,
+                            offset, size);
+
+       return offset;
 }
 
 /**
@@ -195,11 +281,13 @@ gen7_fill_vertex_buffer_data(struct intel_batchbuffer *batch,
                             struct scratch_buf *src,
                             uint32_t src_x, uint32_t src_y,
                             uint32_t dst_x, uint32_t dst_y,
-                            uint32_t width, uint32_t height) {
-       void *ret;
+                            uint32_t width, uint32_t height)
+{
+       void *start;
+       uint32_t offset;
 
        batch_align(batch, 8);
-       ret = batch->ptr;
+       start = batch->ptr;
 
        emit_vertex_2s(batch, dst_x + width, dst_y + height);
        emit_vertex_normalized(batch, src_x + width, buf_width(src));
@@ -213,7 +301,10 @@ gen7_fill_vertex_buffer_data(struct intel_batchbuffer *batch,
        emit_vertex_normalized(batch, src_x, buf_width(src));
        emit_vertex_normalized(batch, src_y, buf_height(src));
 
-       return batch_offset(batch, ret);
+       offset = batch_offset(batch, start);
+       annotation_add_state(&aub_annotations, AUB_TRACE_VERTEX_BUFFER,
+                            offset, 3 * VERTEX_SIZE);
+       return offset;
 }
 
 /**
@@ -294,8 +385,14 @@ static uint32_t
 gen6_create_cc_state(struct intel_batchbuffer *batch)
 {
        struct gen6_color_calc_state *cc_state;
+       uint32_t offset;
+
        cc_state = batch_alloc(batch, sizeof(*cc_state), 64);
-       return batch_offset(batch, cc_state);
+       offset = batch_offset(batch, cc_state);
+       annotation_add_state(&aub_annotations, AUB_TRACE_CC_STATE,
+                            offset, sizeof(*cc_state));
+
+       return offset;
 }
 
 static uint32_t
@@ -303,50 +400,74 @@ gen8_create_blend_state(struct intel_batchbuffer *batch)
 {
        struct gen8_blend_state *blend;
        int i;
+       uint32_t offset;
 
        blend = batch_alloc(batch, sizeof(*blend), 64);
+       offset = batch_offset(batch, blend);
+       annotation_add_state(&aub_annotations, AUB_TRACE_BLEND_STATE,
+                            offset, sizeof(*blend));
+
        for (i = 0; i < 16; i++) {
+               blend->bs[i].dest_blend_factor = GEN6_BLENDFACTOR_ZERO;
+               blend->bs[i].source_blend_factor = GEN6_BLENDFACTOR_ONE;
+               blend->bs[i].color_blend_func = GEN6_BLENDFUNCTION_ADD;
                blend->bs[i].pre_blend_color_clamp = 1;
                blend->bs[i].color_buffer_blend = 0;
        }
-       return batch_offset(batch, blend);
+
+       return offset;
 }
 
 static uint32_t
 gen6_create_cc_viewport(struct intel_batchbuffer *batch)
 {
        struct gen6_cc_viewport *vp;
+       uint32_t offset;
 
        vp = batch_alloc(batch, sizeof(*vp), 32);
+       offset = batch_offset(batch, vp);
+       annotation_add_state(&aub_annotations, AUB_TRACE_CC_VP_STATE,
+                            offset, sizeof(*vp));
+
        /* XXX I don't understand this */
        vp->min_depth = -1.e35;
        vp->max_depth = 1.e35;
-       return batch_offset(batch, vp);
+
+       return offset;
 }
 
 static uint32_t
 gen7_create_sf_clip_viewport(struct intel_batchbuffer *batch) {
        /* XXX these are likely not needed */
        struct gen7_sf_clip_viewport *scv_state;
+       uint32_t offset;
+
        scv_state = batch_alloc(batch, sizeof(*scv_state), 64);
+       offset = batch_offset(batch, scv_state);
+       annotation_add_state(&aub_annotations, AUB_TRACE_CLIP_VP_STATE,
+                            offset, sizeof(*scv_state));
+
        scv_state->guardband.xmin = 0;
        scv_state->guardband.xmax = 1.0f;
        scv_state->guardband.ymin = 0;
        scv_state->guardband.ymax = 1.0f;
-       return batch_offset(batch, scv_state);
+
+       return offset;
 }
 
 static uint32_t
 gen6_create_scissor_rect(struct intel_batchbuffer *batch)
 {
        struct gen6_scissor_rect *scissor;
-       scissor = batch_alloc(batch, sizeof(*scissor), 64);
-       return batch_offset(batch, scissor);
-}
-
-
+       uint32_t offset;
 
+       scissor = batch_alloc(batch, sizeof(*scissor), 64);
+       offset = batch_offset(batch, scissor);
+       annotation_add_state(&aub_annotations, AUB_TRACE_SCISSOR_STATE,
+                            offset, sizeof(*scissor));
 
+       return offset;
+}
 
 static void
 gen6_emit_sip(struct intel_batchbuffer *batch) {
@@ -725,6 +846,7 @@ static void gen8_emit_primitive(struct intel_batchbuffer *batch, uint32_t offset
  */
 
 #define BATCH_STATE_SPLIT 2048
+
 void gen8_render_copyfunc(struct intel_batchbuffer *batch,
                          struct scratch_buf *src, unsigned src_x, unsigned src_y,
                          unsigned width, unsigned height,
@@ -741,10 +863,15 @@ void gen8_render_copyfunc(struct intel_batchbuffer *batch,
 
        batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];
 
+       annotation_init(&aub_annotations);
+
        ps_binding_table  = gen8_bind_surfaces(batch, src, dst);
        ps_sampler_state  = gen8_create_sampler(batch);
-       ps_kernel_off = batch_copy(batch, ps_kernel, sizeof(ps_kernel), 64);
-       vertex_buffer = gen7_fill_vertex_buffer_data(batch, src, src_x, src_y, dst_x, dst_y, width, height);
+       ps_kernel_off = gen8_fill_ps(batch, ps_kernel, sizeof(ps_kernel));
+       vertex_buffer = gen7_fill_vertex_buffer_data(batch, src,
+                                                    src_x, src_y,
+                                                    dst_x, dst_y,
+                                                    width, height);
        cc.cc_state = gen6_create_cc_state(batch);
        cc.blend_state = gen8_create_blend_state(batch);
        viewport.cc_state = gen6_create_cc_viewport(batch);
@@ -814,9 +941,12 @@ void gen8_render_copyfunc(struct intel_batchbuffer *batch,
 
        batch_end = batch_align(batch, 8);
        assert(batch_end < BATCH_STATE_SPLIT);
+       annotation_add_batch(&aub_annotations, batch_end);
 
        dump_batch(batch);
 
+       annotation_flush(&aub_annotations, batch);
+
        gen6_render_flush(batch, batch_end);
        intel_batchbuffer_reset(batch);
 }