lima/ppir: Fix branch codegen
authorVasily Khoruzhick <anarsoul@gmail.com>
Mon, 15 Jul 2019 01:22:36 +0000 (18:22 -0700)
committerVasily Khoruzhick <anarsoul@gmail.com>
Mon, 15 Jul 2019 02:49:14 +0000 (19:49 -0700)
"unknown_2" field is actually a size of instruction that branch
points to. If it's set to a smaller size than actual instruction
branch behavior is not defined (and it usually wedges the GPU).

Fix it by setting this field correctly.

Fixes: af0de6b91c0b ("lima/ppir: implement discard and discard_if")
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
src/gallium/drivers/lima/ir/pp/codegen.c
src/gallium/drivers/lima/ir/pp/codegen.h
src/gallium/drivers/lima/ir/pp/ppir.h

index 3b74f2c6afe3d02eeb6388ef44c0e62ab856d1ff..49e91a87a385eb952e83ba56f65fdf5370c77b73 100644 (file)
@@ -543,10 +543,10 @@ static void ppir_codegen_encode_branch(ppir_node *node, void *code)
    b->branch.cond_eq = branch->cond_eq;
    b->branch.cond_lt = branch->cond_lt;
    b->branch.unknown_1 = 0x0;
-   b->branch.unknown_2 = 0x3;
 
    target_instr = list_first_entry(&branch->target->instr_list, ppir_instr, list);
    b->branch.target = target_instr->offset - node->instr->offset;
+   b->branch.next_count = target_instr->encode_size;
 }
 
 typedef void (*ppir_codegen_instr_slot_encode_func)(ppir_node *, void *);
@@ -699,7 +699,8 @@ bool ppir_codegen_prog(ppir_compiler *comp)
    list_for_each_entry(ppir_block, block, &comp->block_list, list) {
       list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {
          instr->offset = size;
-         size += get_instr_encode_size(instr);
+         instr->encode_size = get_instr_encode_size(instr);
+         size += instr->encode_size;
       }
    }
 
index ab80d392dc2fce41236376c6c027f1515e2ed7be..3157566d91834090be37d4671872d462f287cb21 100644 (file)
@@ -345,7 +345,7 @@ typedef union __attribute__((__packed__)) {
       bool     cond_lt     :  1;
       unsigned unknown_1   : 22; /* = 0 0000 0000 0000 0000 0000 0 */
       signed   target      : 27;
-      unsigned unknown_2   :  5; /* = 0 0011 */
+      unsigned next_count  :  5;
    } branch;
    struct __attribute__((__packed__)) {
       unsigned word0 : 32;
index 2da4ea35a1dc5cf0da28666392eec9faba7c15ab..dafbd9425322ca66c13b5de5c6d9e3dddeb17434 100644 (file)
@@ -301,6 +301,7 @@ typedef struct ppir_instr {
    int parent_index;
    bool scheduled;
    int offset;
+   int encode_size;
 } ppir_instr;
 
 typedef struct ppir_block {