r600: use gallium list macros instead of making our own.

before this change, r600 glxinfo segfaulted in the list code, and I wasn't
debugging another linked list implementation, its 2010 after all.

So add the two missing list macros to the gallium header from X.org list header file (after fixing them), then port all r600 lists to the new header.

Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Dave Airlie
2010-07-02 15:27:17 +10:00
parent 44732103b2
commit 8556b77c56
8 changed files with 111 additions and 109 deletions

View File

@@ -98,5 +98,20 @@ struct list_head
#define LIST_IS_EMPTY(__list) \ #define LIST_IS_EMPTY(__list) \
((__list)->next == (__list)) ((__list)->next == (__list))
#ifndef container_of
#define container_of(ptr, sample, member) \
(void *)((char *)(ptr) \
- ((char *)&(sample)->member - (char *)(sample)))
#endif
#define LIST_FOR_EACH_ENTRY(pos, head, member) \
for (pos = container_of((head)->next, pos, member); \
&pos->member != (head); \
pos = container_of(pos->member.next, pos, member))
#define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member) \
for (pos = container_of((head)->next, pos, member), \
storage = container_of(pos->member.next, pos, member); \
&pos->member != (head); \
pos = storage, storage = container_of(storage->member.next, storage, member))
#endif /*_U_DOUBLE_LIST_H_*/ #endif /*_U_DOUBLE_LIST_H_*/

View File

@@ -34,7 +34,7 @@ struct c_vector *c_vector_new(void)
if (v == NULL) { if (v == NULL) {
return NULL; return NULL;
} }
c_list_init(v); LIST_INITHEAD(&v->head);
return v; return v;
} }
@@ -184,10 +184,10 @@ static unsigned c_opcode_is_alu(unsigned opcode)
void c_node_init(struct c_node *node) void c_node_init(struct c_node *node)
{ {
memset(node, 0, sizeof(struct c_node)); memset(node, 0, sizeof(struct c_node));
c_list_init(&node->predecessors); LIST_INITHEAD(&node->predecessors);
c_list_init(&node->successors); LIST_INITHEAD(&node->successors);
c_list_init(&node->childs); LIST_INITHEAD(&node->childs);
c_list_init(&node->insts); LIST_INITHEAD(&node->insts);
node->parent = NULL; node->parent = NULL;
} }
@@ -198,7 +198,7 @@ static struct c_node_link *c_node_link_new(struct c_node *node)
link = calloc(1, sizeof(struct c_node_link)); link = calloc(1, sizeof(struct c_node_link));
if (link == NULL) if (link == NULL)
return NULL; return NULL;
c_list_init(link); LIST_INITHEAD(&link->head);
link->node = node; link->node = node;
return link; return link;
} }
@@ -214,30 +214,31 @@ int c_node_cfg_link(struct c_node *predecessor, struct c_node *successor)
free(pedge); free(pedge);
return -ENOMEM; return -ENOMEM;
} }
c_list_add_tail(pedge, &predecessor->successors); LIST_ADDTAIL(&pedge->head, &predecessor->successors);
c_list_add_tail(sedge, &successor->predecessors); LIST_ADDTAIL(&sedge->head, &successor->predecessors);
return 0; return 0;
} }
int c_node_add_new_instruction_head(struct c_node *node, struct c_instruction *instruction) int c_node_add_new_instruction_head(struct c_node *node, struct c_instruction *instruction)
{ {
struct c_instruction *inst = calloc(1, sizeof(struct c_instruction)); struct c_instruction *inst = malloc(sizeof(struct c_instruction));
if (inst == NULL) if (inst == NULL)
return -ENOMEM; return -ENOMEM;
memcpy(inst, instruction, sizeof(struct c_instruction)); memcpy(inst, instruction, sizeof(struct c_instruction));
c_list_add(inst, &node->insts); LIST_ADD(&inst->head, &node->insts);
return 0; return 0;
} }
int c_node_add_new_instruction(struct c_node *node, struct c_instruction *instruction) int c_node_add_new_instruction(struct c_node *node, struct c_instruction *instruction)
{ {
struct c_instruction *inst = calloc(1, sizeof(struct c_instruction)); struct c_instruction *inst = malloc(sizeof(struct c_instruction));
if (inst == NULL) if (inst == NULL)
return -ENOMEM; return -ENOMEM;
memcpy(inst, instruction, sizeof(struct c_instruction)); memcpy(inst, instruction, sizeof(struct c_instruction));
c_list_add_tail(inst, &node->insts); LIST_ADDTAIL(&inst->head, &node->insts);
return 0; return 0;
} }
@@ -252,7 +253,7 @@ struct c_node *c_shader_cfg_new_node_after(struct c_shader *shader, struct c_nod
free(node); free(node);
return NULL; return NULL;
} }
c_list_add_tail(node, &shader->nodes); LIST_ADDTAIL(&node->head, &shader->nodes);
return node; return node;
} }
@@ -264,9 +265,9 @@ int c_shader_init(struct c_shader *shader, unsigned type)
shader->type = type; shader->type = type;
for (i = 0; i < C_FILE_COUNT; i++) { for (i = 0; i < C_FILE_COUNT; i++) {
shader->files[i].nvectors = 0; shader->files[i].nvectors = 0;
c_list_init(&shader->files[i].vectors); LIST_INITHEAD(&shader->files[i].vectors);
} }
c_list_init(&shader->nodes); LIST_INITHEAD(&shader->nodes);
c_node_init(&shader->entry); c_node_init(&shader->entry);
c_node_init(&shader->end); c_node_init(&shader->end);
shader->entry.opcode = C_OPCODE_ENTRY; shader->entry.opcode = C_OPCODE_ENTRY;
@@ -297,7 +298,7 @@ struct c_vector *c_shader_vector_new(struct c_shader *shader, unsigned file, uns
v->sid = sid; v->sid = sid;
shader->files[v->file].nvectors++; shader->files[v->file].nvectors++;
v->id = shader->nvectors++; v->id = shader->nvectors++;
c_list_add_tail(v, &shader->files[v->file].vectors); LIST_ADDTAIL(&v->head, &shader->files[v->file].vectors);
return v; return v;
out_err: out_err:
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@@ -307,13 +308,13 @@ out_err:
return NULL; return NULL;
} }
static void c_node_remove_link(struct c_node_link *head, struct c_node *node) static void c_node_remove_link(struct list_head *head, struct c_node *node)
{ {
struct c_node_link *link, *tmp; struct c_node_link *link, *tmp;
c_list_for_each_safe(link, tmp, head) { LIST_FOR_EACH_ENTRY_SAFE(link, tmp, head, head) {
if (link->node == node) { if (link->node == node) {
c_list_del(link); LIST_DEL(&link->head);
free(link); free(link);
} }
} }
@@ -324,26 +325,26 @@ static void c_node_destroy(struct c_node *node)
struct c_instruction *i, *ni; struct c_instruction *i, *ni;
struct c_node_link *link, *tmp; struct c_node_link *link, *tmp;
c_list_for_each_safe(i, ni, &node->insts) { LIST_FOR_EACH_ENTRY_SAFE(i, ni, &node->insts, head) {
c_list_del(i); LIST_DEL(&i->head);
free(i); free(i);
} }
if (node->parent) if (node->parent)
c_node_remove_link(&node->parent->childs, node); c_node_remove_link(&node->parent->childs, node);
node->parent = NULL; node->parent = NULL;
c_list_for_each_safe(link, tmp, &node->predecessors) { LIST_FOR_EACH_ENTRY_SAFE(link, tmp, &node->predecessors, head) {
c_node_remove_link(&link->node->successors, node); c_node_remove_link(&link->node->successors, node);
c_list_del(link); LIST_DEL(&link->head);
free(link); free(link);
} }
c_list_for_each_safe(link, tmp, &node->successors) { LIST_FOR_EACH_ENTRY_SAFE(link, tmp, &node->successors, head) {
c_node_remove_link(&link->node->predecessors, node); c_node_remove_link(&link->node->predecessors, node);
c_list_del(link); LIST_DEL(&link->head);
free(link); free(link);
} }
c_list_for_each_safe(link, tmp, &node->childs) { LIST_FOR_EACH_ENTRY_SAFE(link, tmp, &node->childs, head) {
link->node->parent = NULL; link->node->parent = NULL;
c_list_del(link); LIST_DEL(&link->head);
free(link); free(link);
} }
} }
@@ -356,8 +357,8 @@ void c_shader_destroy(struct c_shader *shader)
for (i = 0; i < C_FILE_COUNT; i++) { for (i = 0; i < C_FILE_COUNT; i++) {
shader->files[i].nvectors = 0; shader->files[i].nvectors = 0;
c_list_for_each_safe(v, nv, &shader->files[i].vectors) { LIST_FOR_EACH_ENTRY_SAFE(v, nv, &shader->files[i].vectors, head) {
c_list_del(v); LIST_DEL(&v->head);
free(v->channel[0]); free(v->channel[0]);
free(v->channel[1]); free(v->channel[1]);
free(v->channel[2]); free(v->channel[2]);
@@ -365,8 +366,8 @@ void c_shader_destroy(struct c_shader *shader)
free(v); free(v);
} }
} }
c_list_for_each_safe(n, nn, &shader->nodes) { LIST_FOR_EACH_ENTRY_SAFE(n, nn, &shader->nodes, head) {
c_list_del(n); LIST_DEL(&n->head);
c_node_destroy(n); c_node_destroy(n);
} }
memset(shader, 0, sizeof(struct c_shader)); memset(shader, 0, sizeof(struct c_shader));
@@ -379,7 +380,7 @@ static void c_shader_dfs_without_rec(struct c_node *entry, struct c_node *node)
if (entry == node || entry->visited) if (entry == node || entry->visited)
return; return;
entry->visited = 1; entry->visited = 1;
c_list_for_each(link, &entry->successors) { LIST_FOR_EACH_ENTRY(link, &entry->successors, head) {
c_shader_dfs_without_rec(link->node, node); c_shader_dfs_without_rec(link->node, node);
} }
} }
@@ -390,7 +391,7 @@ static void c_shader_dfs_without(struct c_shader *shader, struct c_node *node)
shader->entry.visited = 0; shader->entry.visited = 0;
shader->end.visited = 0; shader->end.visited = 0;
c_list_for_each(n, &shader->nodes) { LIST_FOR_EACH_ENTRY(n, &shader->nodes, head) {
n->visited = 0; n->visited = 0;
} }
c_shader_dfs_without_rec(&shader->entry, node); c_shader_dfs_without_rec(&shader->entry, node);
@@ -405,7 +406,7 @@ static int c_shader_build_dominator_tree_rec(struct c_shader *shader, struct c_n
if (node->done) if (node->done)
return 0; return 0;
node->done = 1; node->done = 1;
c_list_for_each(link, &node->predecessors) { LIST_FOR_EACH_ENTRY(link, &node->predecessors, head) {
/* if we remove this predecessor can we reach the current node ? */ /* if we remove this predecessor can we reach the current node ? */
c_shader_dfs_without(shader, link->node); c_shader_dfs_without(shader, link->node);
if (node->visited == 0) { if (node->visited == 0) {
@@ -417,7 +418,7 @@ static int c_shader_build_dominator_tree_rec(struct c_shader *shader, struct c_n
nlink = c_node_link_new(node); nlink = c_node_link_new(node);
if (nlink == NULL) if (nlink == NULL)
return -ENOMEM; return -ENOMEM;
c_list_add_tail(nlink, &link->node->childs); LIST_ADDTAIL(&nlink->head, &link->node->childs);
found = 1; found = 1;
break; break;
} }
@@ -428,7 +429,7 @@ static int c_shader_build_dominator_tree_rec(struct c_shader *shader, struct c_n
node, node->opcode); node, node->opcode);
return -EINVAL; return -EINVAL;
} }
c_list_for_each(link, &node->predecessors) { LIST_FOR_EACH_ENTRY(link, &node->predecessors, head) {
r = c_shader_build_dominator_tree_rec(shader, link->node); r = c_shader_build_dominator_tree_rec(shader, link->node);
if (r) if (r)
return r; return r;
@@ -439,7 +440,7 @@ static int c_shader_build_dominator_tree_rec(struct c_shader *shader, struct c_n
int c_shader_build_dominator_tree(struct c_shader *shader) int c_shader_build_dominator_tree(struct c_shader *shader)
{ {
struct c_node *node; struct c_node *node;
c_list_for_each(node, &shader->nodes) { LIST_FOR_EACH_ENTRY(node, &shader->nodes, head) {
node->done = 0; node->done = 0;
} }
return c_shader_build_dominator_tree_rec(shader, &shader->end); return c_shader_build_dominator_tree_rec(shader, &shader->end);

View File

@@ -23,12 +23,13 @@
#ifndef R600_COMPILER_H #ifndef R600_COMPILER_H
#define R600_COMPILER_H #define R600_COMPILER_H
#include "util/u_double_list.h"
struct c_vector; struct c_vector;
/* operand are the basic source/destination of each operation */ /* operand are the basic source/destination of each operation */
struct c_channel { struct c_channel {
struct c_channel *next; struct list_head head;
struct c_channel *prev;
unsigned vindex; /**< index in vector X,Y,Z,W (0,1,2,3) */ unsigned vindex; /**< index in vector X,Y,Z,W (0,1,2,3) */
unsigned value; /**< immediate value 32bits */ unsigned value; /**< immediate value 32bits */
struct c_vector *vector; /**< vector to which it belongs */ struct c_vector *vector; /**< vector to which it belongs */
@@ -39,8 +40,7 @@ struct c_channel {
* operand into a same vector * operand into a same vector
*/ */
struct c_vector { struct c_vector {
struct c_vector *next; struct list_head head;
struct c_vector *prev;
unsigned id; /**< vector uniq id */ unsigned id; /**< vector uniq id */
unsigned name; /**< semantic name */ unsigned name; /**< semantic name */
unsigned file; /**< operand file C_FILE_* */ unsigned file; /**< operand file C_FILE_* */
@@ -48,16 +48,6 @@ struct c_vector {
struct c_channel *channel[4]; /**< operands */ struct c_channel *channel[4]; /**< operands */
}; };
#define c_list_init(e) do { (e)->next = e; (e)->prev = e; } while(0)
#define c_list_add(e, h) do { (e)->next = (h)->next; (e)->prev = h; (h)->next = e; (e)->next->prev = e; } while(0)
#define c_list_add_tail(e, h) do { (e)->next = h; (e)->prev = (h)->prev; (h)->prev = e; (e)->prev->next = e; } while(0)
#define c_list_del(e) do { (e)->next->prev = (e)->prev; (e)->prev->next = (e)->next; c_list_init(e); } while(0)
#define c_list_for_each(p, h) for (p = (h)->next; p != (h); p = p->next)
#define c_list_for_each_from(p, s, h) for (p = s; p != (h); p = p->next)
#define c_list_for_each_safe(p, n, h) for (p = (h)->next, n = p->next; p != (h); p = n, n = p->next)
#define c_list_empty(h) ((h)->next == h)
#define C_PROGRAM_TYPE_VS 0 #define C_PROGRAM_TYPE_VS 0
#define C_PROGRAM_TYPE_FS 1 #define C_PROGRAM_TYPE_FS 1
#define C_PROGRAM_TYPE_COUNT 2 #define C_PROGRAM_TYPE_COUNT 2
@@ -259,7 +249,7 @@ struct c_op {
}; };
struct c_instruction { struct c_instruction {
struct c_instruction *next, *prev; struct list_head head;
unsigned nop; unsigned nop;
struct c_op op[5]; struct c_op op[5];
}; };
@@ -267,8 +257,7 @@ struct c_instruction {
struct c_node; struct c_node;
struct c_node_link { struct c_node_link {
struct c_node_link *next; struct list_head head;
struct c_node_link *prev;
struct c_node *node; struct c_node *node;
}; };
@@ -285,12 +274,12 @@ struct c_node_link {
* @childs: child nodes in the depth first walk tree * @childs: child nodes in the depth first walk tree
*/ */
struct c_node { struct c_node {
struct c_node *next, *prev; struct list_head head;
struct c_node_link predecessors; struct list_head predecessors;
struct c_node_link successors; struct list_head successors;
struct list_head childs;
struct c_node *parent; struct c_node *parent;
struct c_node_link childs; struct list_head insts;
struct c_instruction insts;
unsigned opcode; unsigned opcode;
unsigned visited; unsigned visited;
unsigned done; unsigned done;
@@ -299,13 +288,13 @@ struct c_node {
struct c_file { struct c_file {
unsigned nvectors; unsigned nvectors;
struct c_vector vectors; struct list_head vectors;
}; };
struct c_shader { struct c_shader {
unsigned nvectors; unsigned nvectors;
struct c_file files[C_FILE_COUNT]; struct c_file files[C_FILE_COUNT];
struct c_node nodes; struct list_head nodes;
struct c_node entry; struct c_node entry;
struct c_node end; struct c_node end;
unsigned type; unsigned type;

View File

@@ -232,7 +232,7 @@ static void c_node_dump(struct c_node *node, unsigned indent)
unsigned j, k; unsigned j, k;
pindent(indent); fprintf(stderr, "# node %s\n", c_get_name(c_opcode_str, node->opcode)); pindent(indent); fprintf(stderr, "# node %s\n", c_get_name(c_opcode_str, node->opcode));
c_list_for_each(i, &node->insts) { LIST_FOR_EACH_ENTRY(i, &node->insts, head) {
for (k = 0; k < i->nop; k++) { for (k = 0; k < i->nop; k++) {
pindent(indent); pindent(indent);
fprintf(stderr, "%s", c_get_name(c_opcode_str, i->op[k].opcode)); fprintf(stderr, "%s", c_get_name(c_opcode_str, i->op[k].opcode));
@@ -256,7 +256,7 @@ static void c_shader_dump_rec(struct c_shader *shader, struct c_node *node, unsi
struct c_node_link *link; struct c_node_link *link;
c_node_dump(node, indent); c_node_dump(node, indent);
c_list_for_each(link, &node->childs) { LIST_FOR_EACH_ENTRY(link, &node->childs, head) {
c_shader_dump_rec(shader, link->node, indent + 1); c_shader_dump_rec(shader, link->node, indent + 1);
} }
} }

View File

@@ -53,7 +53,7 @@ int r600_shader_insert_fetch(struct c_shader *shader)
vi = c_shader_vector_new(shader, C_FILE_INPUT, C_SEMANTIC_VERTEXID, -1); vi = c_shader_vector_new(shader, C_FILE_INPUT, C_SEMANTIC_VERTEXID, -1);
if (vi == NULL) if (vi == NULL)
return -ENOMEM; return -ENOMEM;
c_list_for_each_safe(v, nv, &shader->files[C_FILE_INPUT].vectors) { LIST_FOR_EACH_ENTRY_SAFE(v, nv, &shader->files[C_FILE_INPUT].vectors, head) {
if (v == vi) if (v == vi)
continue; continue;
vr = c_shader_vector_new(shader, C_FILE_RESOURCE, C_SEMANTIC_GENERIC, -1); vr = c_shader_vector_new(shader, C_FILE_RESOURCE, C_SEMANTIC_GENERIC, -1);
@@ -88,9 +88,9 @@ int r600_shader_insert_fetch(struct c_shader *shader)
r = c_node_add_new_instruction_head(&shader->entry, &instruction); r = c_node_add_new_instruction_head(&shader->entry, &instruction);
if (r) if (r)
return r; return r;
c_list_del(v); LIST_DEL(&v->head);
shader->files[C_FILE_INPUT].nvectors--; shader->files[C_FILE_INPUT].nvectors--;
c_list_add_tail(v, &shader->files[C_FILE_TEMPORARY].vectors); LIST_ADDTAIL(&v->head, &shader->files[C_FILE_TEMPORARY].vectors);
shader->files[C_FILE_TEMPORARY].nvectors++; shader->files[C_FILE_TEMPORARY].nvectors++;
v->file = C_FILE_TEMPORARY; v->file = C_FILE_TEMPORARY;
} }
@@ -113,14 +113,14 @@ void r600_shader_cleanup(struct r600_shader *rshader)
free(rshader->gpr); free(rshader->gpr);
rshader->gpr = NULL; rshader->gpr = NULL;
} }
c_list_for_each_safe(n, nn, &rshader->nodes) { LIST_FOR_EACH_ENTRY_SAFE(n, nn, &rshader->nodes, head) {
c_list_del(n); LIST_DEL(&n->head);
c_list_for_each_safe(vf, nvf, &n->vfetch) { LIST_FOR_EACH_ENTRY_SAFE(vf, nvf, &n->vfetch, head) {
c_list_del(vf); LIST_DEL(&vf->head);
free(vf); free(vf);
} }
c_list_for_each_safe(alu, nalu, &n->alu) { LIST_FOR_EACH_ENTRY_SAFE(alu, nalu, &n->alu, head) {
c_list_del(alu); LIST_DEL(&alu->head);
free(alu); free(alu);
} }
free(n); free(n);
@@ -161,8 +161,8 @@ int r600_shader_update(struct r600_shader *rshader, enum pipe_format *resource_f
memcpy(rshader->resource_format, resource_format, memcpy(rshader->resource_format, resource_format,
rshader->nresource * sizeof(enum pipe_format)); rshader->nresource * sizeof(enum pipe_format));
c_list_for_each(rnode, &rshader->nodes) { LIST_FOR_EACH_ENTRY(rnode, &rshader->nodes, head) {
c_list_for_each(vfetch, &rnode->vfetch) { LIST_FOR_EACH_ENTRY(vfetch, &rnode->vfetch, head) {
const struct util_format_description *desc; const struct util_format_description *desc;
i = vfetch->cf_addr + 1; i = vfetch->cf_addr + 1;
rshader->bcode[i] &= C_SQ_VTX_WORD1_DST_SEL_X; rshader->bcode[i] &= C_SQ_VTX_WORD1_DST_SEL_X;
@@ -197,7 +197,7 @@ int r600_shader_register(struct r600_shader *rshader)
cid = 0; cid = 0;
rid = 0; rid = 0;
/* alloc input first */ /* alloc input first */
c_list_for_each(v, &rshader->cshader.files[C_FILE_INPUT].vectors) { LIST_FOR_EACH_ENTRY(v, &rshader->cshader.files[C_FILE_INPUT].vectors, head) {
nv = c_vector_new(); nv = c_vector_new();
if (nv == NULL) { if (nv == NULL) {
return -ENOMEM; return -ENOMEM;
@@ -209,7 +209,7 @@ int r600_shader_register(struct r600_shader *rshader)
for (i = 0; i < C_FILE_COUNT; i++) { for (i = 0; i < C_FILE_COUNT; i++) {
if (i == C_FILE_INPUT || i == C_FILE_IMMEDIATE) if (i == C_FILE_INPUT || i == C_FILE_IMMEDIATE)
continue; continue;
c_list_for_each(v, &rshader->cshader.files[i].vectors) { LIST_FOR_EACH_ENTRY(v, &rshader->cshader.files[i].vectors, head) {
switch (v->file) { switch (v->file) {
case C_FILE_OUTPUT: case C_FILE_OUTPUT:
case C_FILE_TEMPORARY: case C_FILE_TEMPORARY:
@@ -315,9 +315,9 @@ static struct r600_shader_node *r600_shader_new_node(struct r600_shader *rshader
if (rnode == NULL) if (rnode == NULL)
return NULL; return NULL;
rnode->node = node; rnode->node = node;
c_list_init(&rnode->vfetch); LIST_INITHEAD(&rnode->vfetch);
c_list_init(&rnode->alu); LIST_INITHEAD(&rnode->alu);
c_list_add_tail(rnode, &rshader->nodes); LIST_ADDTAIL(&rnode->head, &rshader->nodes);
return rnode; return rnode;
} }
@@ -333,7 +333,7 @@ static int r600_shader_add_vfetch(struct r600_shader *rshader,
return 0; return 0;
if (instruction->op[0].opcode != C_OPCODE_VFETCH) if (instruction->op[0].opcode != C_OPCODE_VFETCH)
return 0; return 0;
if (!c_list_empty(&node->alu)) { if (!LIST_IS_EMPTY(&node->alu)) {
rnode = r600_shader_new_node(rshader, node->node); rnode = r600_shader_new_node(rshader, node->node);
if (rnode == NULL) if (rnode == NULL)
return -ENOMEM; return -ENOMEM;
@@ -355,7 +355,7 @@ static int r600_shader_add_vfetch(struct r600_shader *rshader,
vfetch->dst[1].chan = C_SWIZZLE_Y; vfetch->dst[1].chan = C_SWIZZLE_Y;
vfetch->dst[2].chan = C_SWIZZLE_Z; vfetch->dst[2].chan = C_SWIZZLE_Z;
vfetch->dst[3].chan = C_SWIZZLE_W; vfetch->dst[3].chan = C_SWIZZLE_W;
c_list_add_tail(vfetch, &node->vfetch); LIST_ADDTAIL(&vfetch->head, &node->vfetch);
node->nslot += 2; node->nslot += 2;
return 0; return 0;
} }
@@ -369,7 +369,7 @@ static int r600_node_translate(struct r600_shader *rshader, struct c_node *node)
rnode = r600_shader_new_node(rshader, node); rnode = r600_shader_new_node(rshader, node);
if (rnode == NULL) if (rnode == NULL)
return -ENOMEM; return -ENOMEM;
c_list_for_each(instruction, &node->insts) { LIST_FOR_EACH_ENTRY(instruction, &node->insts, head) {
switch (instruction->op[0].opcode) { switch (instruction->op[0].opcode) {
case C_OPCODE_VFETCH: case C_OPCODE_VFETCH:
r = r600_shader_add_vfetch(rshader, rnode, instruction); r = r600_shader_add_vfetch(rshader, rnode, instruction);
@@ -400,7 +400,7 @@ int r600_shader_translate_rec(struct r600_shader *rshader, struct c_node *node)
r = r600_node_translate(rshader, node); r = r600_node_translate(rshader, node);
if (r) if (r)
return r; return r;
c_list_for_each(link, &node->childs) { LIST_FOR_EACH_ENTRY(link, &node->childs, head) {
r = r600_shader_translate_rec(rshader, link->node); r = r600_shader_translate_rec(rshader, link->node);
if (r) if (r)
return r; return r;
@@ -425,7 +425,7 @@ static struct r600_shader_alu *r600_shader_insert_alu(struct r600_shader *rshade
alu->alu[2].opcode = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP; alu->alu[2].opcode = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP;
alu->alu[3].opcode = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP; alu->alu[3].opcode = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP;
alu->alu[4].opcode = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP; alu->alu[4].opcode = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP;
c_list_add_tail(alu, &node->alu); LIST_ADDTAIL(&alu->head, &node->alu);
return alu; return alu;
} }
@@ -437,7 +437,7 @@ static int r600_shader_alu_translate(struct r600_shader *rshader,
struct r600_shader_alu *alu; struct r600_shader_alu *alu;
int i, j, r, comp, litteral_lastcomp = -1; int i, j, r, comp, litteral_lastcomp = -1;
if (!c_list_empty(&node->vfetch)) { if (!LIST_IS_EMPTY(&node->vfetch)) {
rnode = r600_shader_new_node(rshader, node->node); rnode = r600_shader_new_node(rshader, node->node);
if (rnode == NULL) { if (rnode == NULL) {
fprintf(stderr, "%s %d new node failed\n", __func__, __LINE__); fprintf(stderr, "%s %d new node failed\n", __func__, __LINE__);
@@ -541,17 +541,17 @@ void r600_shader_node_place(struct r600_shader *rshader)
rshader->ncf = 0; rshader->ncf = 0;
rshader->nslot = 0; rshader->nslot = 0;
c_list_for_each_safe(node, nnode, &rshader->nodes) { LIST_FOR_EACH_ENTRY_SAFE(node, nnode, &rshader->nodes, head) {
c_list_for_each_safe(alu, nalu, &node->alu) { LIST_FOR_EACH_ENTRY_SAFE(alu, nalu, &node->alu, head) {
node->nslot += alu->nalu; node->nslot += alu->nalu;
node->nslot += alu->nliteral >> 1; node->nslot += alu->nliteral >> 1;
} }
node->nfetch = 0; node->nfetch = 0;
c_list_for_each_safe(vfetch, nvfetch, &node->vfetch) { LIST_FOR_EACH_ENTRY_SAFE(vfetch, nvfetch, &node->vfetch, head) {
node->nslot += 2; node->nslot += 2;
node->nfetch += 1; node->nfetch += 1;
} }
if (!c_list_empty(&node->vfetch)) { if (!LIST_IS_EMPTY(&node->vfetch)) {
/* fetch node need to be 16 bytes aligned*/ /* fetch node need to be 16 bytes aligned*/
cf_addr += 1; cf_addr += 1;
cf_addr &= 0xFFFFFFFEUL; cf_addr &= 0xFFFFFFFEUL;
@@ -563,7 +563,7 @@ void r600_shader_node_place(struct r600_shader *rshader)
rshader->ncf++; rshader->ncf++;
} }
rshader->nslot = cf_addr; rshader->nslot = cf_addr;
c_list_for_each_safe(node, nnode, &rshader->nodes) { LIST_FOR_EACH_ENTRY_SAFE(node, nnode, &rshader->nodes, head) {
node->cf_addr += cf_id * 2; node->cf_addr += cf_id * 2;
} }
rshader->ncf += rshader->cshader.files[C_FILE_OUTPUT].nvectors; rshader->ncf += rshader->cshader.files[C_FILE_OUTPUT].nvectors;
@@ -584,7 +584,7 @@ static int r600_cshader_legalize_rec(struct c_shader *shader, struct c_node *nod
unsigned k; unsigned k;
int r; int r;
c_list_for_each(i, &node->insts) { LIST_FOR_EACH_ENTRY(i, &node->insts, head) {
for (k = 0; k < i->nop; k++) { for (k = 0; k < i->nop; k++) {
switch (i->op[k].opcode) { switch (i->op[k].opcode) {
case C_OPCODE_SLT: case C_OPCODE_SLT:
@@ -598,7 +598,7 @@ static int r600_cshader_legalize_rec(struct c_shader *shader, struct c_node *nod
} }
} }
} }
c_list_for_each(link, &node->childs) { LIST_FOR_EACH_ENTRY(link, &node->childs, head) {
r = r600_cshader_legalize_rec(shader, link->node); r = r600_cshader_legalize_rec(shader, link->node);
if (r) { if (r) {
return r; return r;

View File

@@ -172,14 +172,14 @@ int r700_shader_translate(struct r600_shader *rshader)
rshader->bcode = malloc(rshader->ndw * 4); rshader->bcode = malloc(rshader->ndw * 4);
if (rshader->bcode == NULL) if (rshader->bcode == NULL)
return -ENOMEM; return -ENOMEM;
c_list_for_each(rnode, &rshader->nodes) { LIST_FOR_EACH_ENTRY(rnode, &rshader->nodes, head) {
id = rnode->cf_addr; id = rnode->cf_addr;
c_list_for_each(vfetch, &rnode->vfetch) { LIST_FOR_EACH_ENTRY(vfetch, &rnode->vfetch, head) {
r = r600_shader_vfetch_bytecode(rshader, rnode, vfetch, &id); r = r600_shader_vfetch_bytecode(rshader, rnode, vfetch, &id);
if (r) if (r)
return r; return r;
} }
c_list_for_each(alu, &rnode->alu) { LIST_FOR_EACH_ENTRY(alu, &rnode->alu, head) {
for (i = 0; i < alu->nalu; i++) { for (i = 0; i < alu->nalu; i++) {
r = r700_shader_alu_bytecode(rshader, rnode, &alu->alu[i], &id); r = r700_shader_alu_bytecode(rshader, rnode, &alu->alu[i], &id);
if (r) if (r)
@@ -191,20 +191,20 @@ int r700_shader_translate(struct r600_shader *rshader)
} }
} }
id = 0; id = 0;
c_list_for_each(rnode, &rshader->nodes) { LIST_FOR_EACH_ENTRY(rnode, &rshader->nodes, head) {
r = r700_shader_cf_node_bytecode(rshader, rnode, &id); r = r700_shader_cf_node_bytecode(rshader, rnode, &id);
if (r) if (r)
return r; return r;
} }
c_list_for_each(v, &rshader->cshader.files[C_FILE_OUTPUT].vectors) { LIST_FOR_EACH_ENTRY(v, &rshader->cshader.files[C_FILE_OUTPUT].vectors, head) {
end = 0; end = 0;
if (v->next == &rshader->cshader.files[C_FILE_OUTPUT].vectors) if (v->head.next == &rshader->cshader.files[C_FILE_OUTPUT].vectors)
end = 1; end = 1;
r = r700_shader_cf_output_bytecode(rshader, v, &id, end); r = r700_shader_cf_output_bytecode(rshader, v, &id, end);
if (r) if (r)
return r; return r;
} }
c_list_for_each(v, &rshader->cshader.files[C_FILE_INPUT].vectors) { LIST_FOR_EACH_ENTRY(v, &rshader->cshader.files[C_FILE_INPUT].vectors, head) {
rshader->input[rshader->ninput].gpr = rshader->ninput; rshader->input[rshader->ninput].gpr = rshader->ninput;
rshader->input[rshader->ninput].sid = v->sid; rshader->input[rshader->ninput].sid = v->sid;
rshader->input[rshader->ninput].name = v->name; rshader->input[rshader->ninput].name = v->name;

View File

@@ -133,7 +133,7 @@ struct r600_pipe_shader *r600_pipe_shader_create(struct pipe_context *ctx, unsig
if (rpshader == NULL) if (rpshader == NULL)
return NULL; return NULL;
rpshader->type = type; rpshader->type = type;
c_list_init(&rshader->nodes); LIST_INITHEAD(&rshader->nodes);
fprintf(stderr, "<<\n"); fprintf(stderr, "<<\n");
tgsi_dump(tokens, 0); tgsi_dump(tokens, 0);
fprintf(stderr, "--------------------------------------------------------------\n"); fprintf(stderr, "--------------------------------------------------------------\n");

View File

@@ -35,8 +35,7 @@ struct r600_shader_operand {
}; };
struct r600_shader_vfetch { struct r600_shader_vfetch {
struct r600_shader_vfetch *next; struct list_head head;
struct r600_shader_vfetch *prev;
unsigned cf_addr; unsigned cf_addr;
struct r600_shader_operand src[2]; struct r600_shader_operand src[2];
struct r600_shader_operand dst[4]; struct r600_shader_operand dst[4];
@@ -52,8 +51,7 @@ struct r600_shader_inst {
}; };
struct r600_shader_alu { struct r600_shader_alu {
struct r600_shader_alu *next; struct list_head head;
struct r600_shader_alu *prev;
unsigned nalu; unsigned nalu;
unsigned nliteral; unsigned nliteral;
unsigned nconstant; unsigned nconstant;
@@ -62,15 +60,14 @@ struct r600_shader_alu {
}; };
struct r600_shader_node { struct r600_shader_node {
struct r600_shader_node *next; struct list_head head;
struct r600_shader_node *prev;
unsigned cf_id; /**< cf index (in dw) in byte code */ unsigned cf_id; /**< cf index (in dw) in byte code */
unsigned cf_addr; /**< instructions index (in dw) in byte code */ unsigned cf_addr; /**< instructions index (in dw) in byte code */
unsigned nslot; /**< number of slot (2 dw) needed by this node */ unsigned nslot; /**< number of slot (2 dw) needed by this node */
unsigned nfetch; unsigned nfetch;
struct c_node *node; /**< compiler node from which this node originate */ struct c_node *node; /**< compiler node from which this node originate */
struct r600_shader_vfetch vfetch; /**< list of vfetch instructions */ struct list_head vfetch; /**< list of vfetch instructions */
struct r600_shader_alu alu; /**< list of alu instructions */ struct list_head alu; /**< list of alu instructions */
}; };
struct r600_shader_io { struct r600_shader_io {
@@ -90,7 +87,7 @@ struct r600_shader {
unsigned ncf; /**< total number of cf clauses */ unsigned ncf; /**< total number of cf clauses */
unsigned nslot; /**< total number of slots (2 dw) */ unsigned nslot; /**< total number of slots (2 dw) */
unsigned flat_shade; /**< are we flat shading */ unsigned flat_shade; /**< are we flat shading */
struct r600_shader_node nodes; /**< list of node */ struct list_head nodes; /**< list of node */
struct r600_shader_io input[32]; struct r600_shader_io input[32];
struct r600_shader_io output[32]; struct r600_shader_io output[32];
/* TODO replace GPR by some better register allocator */ /* TODO replace GPR by some better register allocator */