tools/null_state_gen: terminate relocs with -1
PATCH 1/5 tools/null_state_gen: terminate relocs with -1
as this was already changed in kernel.
--- tools/null_state_gen/intel_null_state_gen.c | 1 + 1 file changed, 1 insertion(+)
tools/null_state_gen/intel_null_state_gen.c +1 -0
@@ -39,6 +39,7 @@ static int print_state(int gen, struct intel_batchbuffer *batch)for (i =0 ; i < batch->num_relocs; i++) {printf ("\t0x%08x,\n" , batch->relocs[i]); } +printf ("\t%d,\n" ,-1 );printf ("};\n\n" );printf ("static const u32 gen%d_null_state_batch[] = {\n" , gen);
Signature · 1 line
1.7.9.5
PATCH 2/5 lib/rendercopy: fix a typo in define
No functional changes
--- lib/gen6_render.h | 2 +- lib/rendercopy_gen8.c | 2 +- tools/null_state_gen/intel_renderstate_gen8.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
lib/gen6_render.h +1 -1
@@ -360,7 +360,7 @@#define GEN6_3DSTATE_WM GEN6_3D(3, 0, 0x14)/* DW2 */ -# define GEN6_3DSTATE_WM_SAMPLER_COUNT_SHITF 27 +# define GEN6_3DSTATE_WM_SAMPLER_COUNT_SHIFT 27# define GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT 18/* DW4 */ # define GEN6_3DSTATE_WM_DISPATCH_START_GRF_0_SHIFT 16
lib/rendercopy_gen8.c +1 -1
@@ -794,7 +794,7 @@ gen8_emit_ps(struct intel_batchbuffer *batch, uint32_t kernel) {OUT_BATCH (GEN7_3DSTATE_PS | (12 -2 ));OUT_BATCH (kernel);OUT_BATCH (0 );/* kernel hi */ -OUT_BATCH (1 <<GEN6_3DSTATE_WM_SAMPLER_COUNT_SHITF | +OUT_BATCH (1 <<GEN6_3DSTATE_WM_SAMPLER_COUNT_SHIFT |2 <<GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT );OUT_BATCH (0 );/* scratch space stuff */ OUT_BATCH (0 );/* scratch hi */
tools/null_state_gen/intel_renderstate_gen8.c +1 -1
@@ -598,7 +598,7 @@ gen8_emit_ps(struct intel_batchbuffer *batch, uint32_t kernel) {OUT_BATCH (GEN7_3DSTATE_PS | (12 -2 ));OUT_BATCH (kernel);OUT_BATCH (0 );/* kernel hi */ -OUT_BATCH (1 <<GEN6_3DSTATE_WM_SAMPLER_COUNT_SHITF | +OUT_BATCH (1 <<GEN6_3DSTATE_WM_SAMPLER_COUNT_SHIFT |2 <<GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT );OUT_BATCH (0 );/* scratch space stuff */ OUT_BATCH (0 );/* scratch hi */
Signature · 1 line
1.7.9.5
PATCH 3/5 lib/gen6_render: fix GEN6_3DSTATE_VF_STATISTICS define
In reply to Mika KuoppalaWe dont use this pre CTG and we will need it for gen8 golden state.
--- lib/gen6_render.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/gen6_render.h +1 -1
@@ -24,7 +24,7 @@#define GEN6_3DSTATE_VERTEX_BUFFERS GEN6_3D(3, 0, 8)#define GEN6_3DSTATE_VERTEX_ELEMENTS GEN6_3D(3, 0, 9)#define GEN6_3DSTATE_INDEX_BUFFER GEN6_3D(3, 0, 0xa) -#define GEN6_3DSTATE_VF_STATISTICS GEN6_3D(3, 0, 0xb) +#define GEN6_3DSTATE_VF_STATISTICS GEN6_3D(1, 0, 0xb)#define GEN6_3DSTATE_DRAWING_RECTANGLE GEN6_3D(3, 1, 0)#define GEN6_3DSTATE_CONSTANT_COLOR GEN6_3D(3, 1, 1)
Signature · 1 line
1.7.9.5
PATCH 4/5 lib: Add MI_LOAD_REGISTER_IMM
In reply to Mika Kuoppala--- lib/intel_reg.h | 1 + tests/gem_exec_parse.c | 1 - tests/gem_non_secure_batch.c | 4 +--- tests/gen7_forcewake_mt.c | 5 ++--- 4 files changed, 4 insertions(+), 7 deletions(-)
lib/intel_reg.h +1 -0
@@ -2545,6 +2545,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.#define MI_WAIT_FOR_PIPEA_SCAN_LINE_WINDOW (1<<1)#define MI_LOAD_SCAN_LINES_INCL (0x12<<23) +#define MI_LOAD_REGISTER_IMM ((0x22 << 23) | 1)/* Flush */ #define MI_FLUSH (0x04<<23)
tests/gem_exec_parse.c +0 -1
@@ -187,7 +187,6 @@ int fd;#define MI_ARB_ON_OFF (0x8 << 23)#define MI_DISPLAY_FLIP ((0x14 << 23) | 1) -#define MI_LOAD_REGISTER_IMM ((0x22 << 23) | 1)#define GFX_OP_PIPE_CONTROL ((0x3<<29)|(0x3<<27)|(0x2<<24)|2)#define PIPE_CONTROL_QW_WRITE (1<<14)
tests/gem_non_secure_batch.c +1 -3
@@ -52,8 +52,6 @@ struct intel_batchbuffer *batch;* should fail if the non-secure handling works correctly. */ -#define MI_LOAD_REGISTER_IMM (0x22<<23) -static int num_rings =1 ; static void
@@ -67,7 +65,7 @@ mi_lri_loop(void)int ring =random () % num_rings +1 ;BEGIN_BATCH (4 ); -OUT_BATCH (MI_LOAD_REGISTER_IMM |1 ); +OUT_BATCH (MI_LOAD_REGISTER_IMM );OUT_BATCH (0x203c );/* RENDER RING CTL */ OUT_BATCH (0 );/* try to stop the ring */ OUT_BATCH (MI_NOOP );
tests/gen7_forcewake_mt.c +2 -3
@@ -120,7 +120,6 @@ static void *thread(void *arg)return NULL ; } -#define MI_LOAD_REGISTER_IMM (0x22<<23)#define MI_STORE_REGISTER_MEM (0x24<<23) igt_simple_main
@@ -145,13 +144,13 @@ igt_simple_mainstruct drm_i915_gem_exec_object2 exec[2 ];struct drm_i915_gem_relocation_entry reloc[2 ];uint32_t b[] = { -MI_LOAD_REGISTER_IMM |1 , +MI_LOAD_REGISTER_IMM ,FORCEWAKE_MT ,2 <<16 |2 ,MI_STORE_REGISTER_MEM |1 ,FORCEWAKE_MT ,0 ,// to be patched -MI_LOAD_REGISTER_IMM |1 , +MI_LOAD_REGISTER_IMM ,FORCEWAKE_MT ,2 <<16 ,MI_STORE_REGISTER_MEM |1 ,
Signature · 1 line
1.7.9.5
PATCH 5/5 tools/null_state_gen: build cmd and state space separately
In reply to Mika KuoppalaInstead of building batch directly to memory, build into cmd and state arrays. This representation allows us more flexibility in batch state expression and batch generation/relocation.
As a bonus, we can also attach the line information that produced the batch data to help debugging.
There is no change in the output states produced. This can be considered as a preparatory patch to help introduce gen8 golden state.
--- tools/null_state_gen/intel_batchbuffer.c | 251 +++++++++++++++++-------- tools/null_state_gen/intel_batchbuffer.h | 86 +++++---- tools/null_state_gen/intel_null_state_gen.c | 100 +++------- tools/null_state_gen/intel_renderstate_gen6.c | 136 ++++++-------- tools/null_state_gen/intel_renderstate_gen7.c | 126 ++++--------- tools/null_state_gen/intel_renderstate_gen8.c | 167 ++++++---------- 6 files changed, 404 insertions(+), 462 deletions(-)
tools/null_state_gen/intel_batchbuffer.c +177 -74
@@ -29,145 +29,248 @@**************************************************************************/ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <errno.h> +#include <assert.h> #include "intel_batchbuffer.h" -int intel_batch_reset (struct intel_batchbuffer *batch, -void *p, -uint32_t size, -uint32_t off) +void bb_area_emit (struct bb_area *a,uint32_t dword,item_type type,const char *str) { - batch->err = -EINVAL ; - batch->base = batch->base_ptr = p; - batch->state_base = batch->state_ptr = p; +struct bb_item *item; +assert (a !=NULL ); +assert (a->num_items <MAX_ITEMS ); + item = &a->item[a->num_items]; -if (off >= size ||ALIGN (off,4 ) != off) -return -EINVAL ; + item->data = dword; + item->type = type; +strncpy (item->str, str,MAX_STRLEN ); + item->str[MAX_STRLEN -1 ] =0 ; - batch->size = size; + a->num_items++; +} - batch->state_base = batch->state_ptr = &batch->base[off]; +void bb_area_emit_offset (struct bb_area *a,unsigned offset,uint32_t dword,item_type type,const char *str) +{ +const unsigned i = offset /4 ; +struct bb_item *item; +assert (a !=NULL ); +assert (a->num_items <MAX_ITEMS ); +assert (i < a->num_items); + item = &a->item[i]; + + item->data = dword; + item->type = type; +strncpy (item->str, str,MAX_STRLEN ); + item->str[MAX_STRLEN -1 ] =0 ; +} - batch->num_relocs =0 ; - batch->err =0 ; +static struct bb_item *bb_area_get (struct bb_area *a,unsigned i) +{ +assert (i < a->num_items); +return &a->item[i]; +} -return batch->err; +static unsigned bb_area_items (struct bb_area *a) +{ +return a->num_items; } -uint32_t intel_batch_state_used (struct intel_batchbuffer *batch) +static unsigned long bb_area_used (struct bb_area *a) { -return batch->state_ptr - batch->state_base; +assert (a !=NULL ); +assert (a->num_items <=MAX_ITEMS ); + +return a->num_items *4 ; } -uint32_t intel_batch_state_offset (struct intel_batchbuffer *batch) +static unsigned long bb_area_room (struct bb_area *a) { -return batch->state_ptr - batch->base; +assert (a !=NULL ); +assert (a->num_items <=MAX_ITEMS ); + +return (MAX_ITEMS - a->num_items) *4 ; } -void *intel_batch_state_alloc (struct intel_batchbuffer *batch, -uint32_t size, -uint32_t align) +struct intel_batchbuffer *intel_batchbuffer_create (void ) { -uint32_t cur; -uint32_t offset; +struct intel_batchbuffer *batch; -if (batch->err) + batch =calloc (1 ,sizeof (*batch)); +if (batch ==NULL )return NULL ; - cur =intel_batch_state_offset (batch); - offset =ALIGN (cur, align); + batch->cmds =calloc (1 ,sizeof (struct bb_area )); +if (batch->cmds ==NULL ) { +free (batch); +return NULL ; + } -if (offset + size > batch->size) { - batch->err = -ENOSPC ; + batch->state =calloc (1 ,sizeof (struct bb_area )); +if (batch->state ==NULL ) { +free (batch->cmds); +free (batch);return NULL ; } - batch->state_ptr = batch->base + offset + size; + batch->state_start_offset =-1 ; + batch->cmds_end_offset =-1 ; -memset (batch->base + cur,0 , size); +return batch; +} -return batch->base + offset; +static void bb_area_align (struct bb_area *a,unsigned align) +{ +if (align ==0 ) +return ; + +assert ((align %4 ) ==0 ); + +while ((a->num_items *4 ) % align !=0 ) +bb_area_emit (a,0 ,PAD ,"align pad" ); } -int intel_batch_offset (struct intel_batchbuffer *batch,const void *ptr) +static int reloc_exists (struct intel_batchbuffer *batch,uint32_t offset) { -return (uint8_t *)ptr - batch->base; +int i; + +for (i =0 ; i < batch->cmds->num_items; i++) +if ((batch->cmds->item[i].type ==RELOC || + batch->cmds->item[i].type ==RELOC_STATE ) && + i *4 == offset) +return 1 ; + +return 0 ; } -int intel_batch_state_copy (struct intel_batchbuffer *batch, -const void *ptr, -const uint32_t size, -const uint32_t align) +int intel_batch_is_reloc (struct intel_batchbuffer *batch,unsigned i) { -void *const p =intel_batch_state_alloc (batch, size, align); +return reloc_exists (batch, i *4 ); +} -if (p ==NULL ) -return -1 ; +static void intel_batch_cmd_align (struct intel_batchbuffer *batch,unsigned align) +{ +bb_area_align (batch->cmds, align); +} -return intel_batch_offset (batch,memcpy (p, ptr, size)); +static void intel_batch_state_align (struct intel_batchbuffer *batch,unsigned align) +{ +bb_area_align (batch->state, align); } -uint32_t intel_batch_cmds_used (struct intel_batchbuffer *batch) +unsigned intel_batch_num_cmds (struct intel_batchbuffer *batch) { -return batch->base_ptr - batch->base; +return bb_area_items (batch->cmds); } -uint32_t intel_batch_total_used (struct intel_batchbuffer *batch) +static unsigned intel_batch_num_state (struct intel_batchbuffer *batch) { -return batch->state_ptr - batch->base; +return bb_area_items (batch->state); } -static uint32_t intel_batch_space (struct intel_batchbuffer *batch) +struct bb_item *intel_batch_cmd_get (struct intel_batchbuffer *batch,unsigned i) { -return batch->state_base - batch->base_ptr; +return bb_area_get (batch->cmds, i); } -int intel_batch_emit_dword (struct intel_batchbuffer *batch,uint32_t dword) +struct bb_item *intel_batch_state_get (struct intel_batchbuffer *batch,unsigned i) { -uint32_t offset; +return bb_area_get (batch->state, i); +} -if (batch->err) -return -1 ; +uint32_t intel_batch_state_offset (struct intel_batchbuffer *batch,unsigned align) +{ +intel_batch_state_align (batch, align); +return bb_area_used (batch->state); +} -if (intel_batch_space (batch) <4 ) { - batch->err = -ENOSPC ; -return -1 ; - } +uint32_t intel_batch_state_alloc (struct intel_batchbuffer *batch,unsigned bytes,unsigned align, +const char *str) +{ +unsigned offset; +unsigned dwords = bytes/4 ; +assert ((bytes %4 ) ==0 ); +assert (bb_area_room (batch->state) >= bytes); - offset =intel_batch_offset (batch, batch->base_ptr); + offset =intel_batch_state_offset (batch, align); - *(uint32_t *) (batch->base_ptr) = dword; - batch->base_ptr +=4 ; +while (dwords--) +bb_area_emit (batch->state,0 ,UNINITIALIZED , str);return offset; } -int intel_batch_emit_reloc (struct intel_batchbuffer *batch, -const uint32_t delta) +uint32_t intel_batch_state_copy (struct intel_batchbuffer *batch, +void *d,unsigned bytes, +unsigned align, +const char *str) { -uint32_t offset; +unsigned offset; +unsigned i; +unsigned dwords = bytes/4 ; +assert (d); +assert ((bytes %4 ) ==0 ); +assert (bb_area_room (batch->state) >= bytes); + + offset =intel_batch_state_offset (batch, align); -if (batch->err) -return -1 ; +for (i =0 ; i < dwords; i++) { +char offsetinside[80 ]; +sprintf (offsetinside,"%s: 0x%x" , str, i *4 ); -if (delta >= batch->size) { - batch->err = -EINVAL ; -return -1 ; +uint32_t *s = (uint32_t *)(uint8_t *)d + i; +bb_area_emit (batch->state, *s,STATE , offsetinside); } - offset =intel_batch_emit_dword (batch, delta); +return offset; +} + +void intel_batch_relocate_state (struct intel_batchbuffer *batch) +{ +unsigned int i; + +assert (batch->state_start_offset ==-1 ); -if (batch->err) -return -1 ; + batch->cmds_end_offset =bb_area_used (batch->cmds) -4 ; -if (batch->num_relocs >=MAX_RELOCS ) { - batch->err = -ENOSPC ; -return -1 ; +/* Hardcoded, could track max align done also */ +intel_batch_cmd_align (batch,64 ); + + batch->state_start_offset =bb_area_used (batch->cmds); + +for (i =0 ; i <bb_area_items (batch->state); i++) { +const struct bb_item *s =bb_area_get (batch->state, i); + +bb_area_emit (batch->cmds, s->data, s->type, s->str); } - batch->relocs[batch->num_relocs++] = offset; +for (i =0 ; i <bb_area_items (batch->cmds); i++) { +struct bb_item *s =bb_area_get (batch->cmds, i); -return offset; +if (s->type ==STATE_OFFSET || s->type ==RELOC_STATE ) + s->data += batch->state_start_offset; + } +} + +const char *intel_batch_type_as_str (const struct bb_item *item) +{ +switch (item->type) { +case UNINITIALIZED : +return "UNINITIALIZED" ; +case CMD : +return "CMD" ; +case STATE : +return "STATE" ; +case PAD : +return "PAD" ; +case RELOC : +return "RELOC" ; +case RELOC_STATE : +return "RELOC_STATE" ; +case STATE_OFFSET : +return "STATE_OFFSET" ; + } + +return "UNKNOWN" ; }
tools/null_state_gen/intel_batchbuffer.h +46 -40
104 lines not on this page · raw message
tools/null_state_gen/intel_null_state_gen.c +31 -69
160 lines not on this page · raw message
tools/null_state_gen/intel_renderstate_gen6.c +55 -81
261 lines not on this page · raw message
tools/null_state_gen/intel_renderstate_gen7.c +38 -88
220 lines not on this page · raw message
tools/null_state_gen/intel_renderstate_gen8.c +57 -110
304 lines not on this page · raw message
Signature · 1 line
1.7.9.5