From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/asmshader.y | 4 +-- dlls/d3dcompiler_43/bytecodewriter.c | 6 +--- dlls/d3dcompiler_43/d3dcompiler_private.h | 38 +++++++++++------------ dlls/d3dcompiler_43/utils.c | 8 ++--- 4 files changed, 26 insertions(+), 30 deletions(-)
diff --git a/dlls/d3dcompiler_43/asmshader.y b/dlls/d3dcompiler_43/asmshader.y index 32b37d0885d..1b7a07313fc 100644 --- a/dlls/d3dcompiler_43/asmshader.y +++ b/dlls/d3dcompiler_43/asmshader.y @@ -1148,11 +1148,11 @@ swizzle: /* empty */ else { DWORD last, i;
- $$ = $2.swizzle << BWRITERVS_SWIZZLE_SHIFT; + $$ = $2.swizzle; /* Fill the swizzle by extending the last component */ last = ($2.swizzle >> 2 * ($2.idx - 1)) & 0x03; for(i = $2.idx; i < 4; i++){ - $$ |= last << (BWRITERVS_SWIZZLE_SHIFT + 2 * i); + $$ |= last << (2 * i); } TRACE("Got a swizzle: %08x\n", $$); } diff --git a/dlls/d3dcompiler_43/bytecodewriter.c b/dlls/d3dcompiler_43/bytecodewriter.c index 14162ab212b..42013dfba3f 100644 --- a/dlls/d3dcompiler_43/bytecodewriter.c +++ b/dlls/d3dcompiler_43/bytecodewriter.c @@ -342,8 +342,6 @@ static void put_dword(struct bytecode_buffer *buffer, DWORD value) { /* bwriter -> d3d9 conversion functions. */ static DWORD d3d9_swizzle(DWORD bwriter_swizzle) { - /* Currently a NOP, but this allows changing the internal definitions - * without side effects. */ DWORD ret = 0;
if ((bwriter_swizzle & BWRITERVS_X_X) == BWRITERVS_X_X) ret |= D3DVS_X_X; @@ -1270,9 +1268,7 @@ static void instr_ps_1_0123_texld(struct bc_writer *This, This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); } else if(instr->src[0].type == BWRITERSPR_TEMP) {
- swizzlemask = (3 << BWRITERVS_SWIZZLE_SHIFT) | - (3 << (BWRITERVS_SWIZZLE_SHIFT + 2)) | - (3 << (BWRITERVS_SWIZZLE_SHIFT + 4)); + swizzlemask = 3 | (3 << 2) | (3 << 4); if((instr->src[0].u.swizzle & swizzlemask) == (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z)) { TRACE("writing texreg2rgb\n"); This->funcs->opcode(This, instr, D3DSIO_TEXREG2RGB & D3DSI_OPCODE_MASK, buffer); diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 45dbff7225b..5fc3161f5f0 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -542,25 +542,25 @@ enum bwritershader_param_srcmod_type #define BWRITERVS_SWIZZLE_SHIFT 16 #define BWRITERVS_SWIZZLE_MASK (0xFF << BWRITERVS_SWIZZLE_SHIFT)
-#define BWRITERVS_X_X (0 << BWRITERVS_SWIZZLE_SHIFT) -#define BWRITERVS_X_Y (1 << BWRITERVS_SWIZZLE_SHIFT) -#define BWRITERVS_X_Z (2 << BWRITERVS_SWIZZLE_SHIFT) -#define BWRITERVS_X_W (3 << BWRITERVS_SWIZZLE_SHIFT) - -#define BWRITERVS_Y_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 2)) -#define BWRITERVS_Y_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 2)) -#define BWRITERVS_Y_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 2)) -#define BWRITERVS_Y_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 2)) - -#define BWRITERVS_Z_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 4)) -#define BWRITERVS_Z_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 4)) -#define BWRITERVS_Z_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 4)) -#define BWRITERVS_Z_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 4)) - -#define BWRITERVS_W_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 6)) -#define BWRITERVS_W_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 6)) -#define BWRITERVS_W_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 6)) -#define BWRITERVS_W_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 6)) +#define BWRITERVS_X_X (0) +#define BWRITERVS_X_Y (1) +#define BWRITERVS_X_Z (2) +#define BWRITERVS_X_W (3) + +#define BWRITERVS_Y_X (0 << 2) +#define BWRITERVS_Y_Y (1 << 2) +#define BWRITERVS_Y_Z (2 << 2) +#define BWRITERVS_Y_W (3 << 2) + +#define BWRITERVS_Z_X (0 << 4) +#define BWRITERVS_Z_Y (1 << 4) +#define BWRITERVS_Z_Z (2 << 4) +#define BWRITERVS_Z_W (3 << 4) + +#define BWRITERVS_W_X (0 << 6) +#define BWRITERVS_W_Y (1 << 6) +#define BWRITERVS_W_Z (2 << 6) +#define BWRITERVS_W_W (3 << 6)
#define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 1436ed6bf3e..b2b1e25bbdc 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -291,10 +291,10 @@ static const char *debug_print_swizzle(DWORD arg) return ".w"; }
- swizzle[0] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 0)) & 0x03; - swizzle[1] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 2)) & 0x03; - swizzle[2] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 4)) & 0x03; - swizzle[3] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 6)) & 0x03; + swizzle[0] = arg & 3; + swizzle[1] = (arg >> 2) & 3; + swizzle[2] = (arg >> 4) & 3; + swizzle[3] = (arg >> 6) & 3;
ret[0] = '.'; for (i = 0; i < 4; ++i)
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v2: don't drop all of the struct initializer elements on the floor v3: style tweak, clarify loop_condition()
dlls/d3dcompiler_43/d3dcompiler_private.h | 6 + dlls/d3dcompiler_43/hlsl.y | 287 ++++++++++++---------- dlls/d3dcompiler_43/utils.c | 46 +--- 3 files changed, 165 insertions(+), 174 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 5fc3161f5f0..9c58830ffe2 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -984,6 +984,7 @@ struct parse_initializer { struct hlsl_ir_node **args; unsigned int args_count; + struct list *instrs; };
struct parse_variable_def @@ -1120,6 +1121,11 @@ static inline struct hlsl_ir_loop *loop_from_node(const struct hlsl_ir_node *nod return CONTAINING_RECORD(node, struct hlsl_ir_loop, node); }
+static inline struct hlsl_ir_node *node_from_list(struct list *list) +{ + return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry); +} + BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN; struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN; void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index d81d6afa9cc..f72882187c8 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -255,32 +255,31 @@ static void declare_predefined_types(struct hlsl_scope *scope) add_type_to_scope(scope, type); }
-static struct hlsl_ir_if *loop_condition(struct list *cond_list) +static BOOL append_conditional_break(struct list *cond_list) { struct hlsl_ir_node *cond, *not_cond; struct hlsl_ir_if *out_cond; struct hlsl_ir_jump *jump; - unsigned int count = list_count(cond_list);
- if (!count) - return NULL; - if (count != 1) - ERR("Got multiple expressions in a for condition.\n"); + /* E.g. "for (i = 0; ; ++i)". */ + if (!list_count(cond_list)) + return TRUE;
- cond = LIST_ENTRY(list_head(cond_list), struct hlsl_ir_node, entry); + cond = node_from_list(cond_list); out_cond = d3dcompiler_alloc(sizeof(*out_cond)); if (!out_cond) { ERR("Out of memory.\n"); - return NULL; + return FALSE; } out_cond->node.type = HLSL_IR_IF; if (!(not_cond = new_unary_expr(HLSL_IR_UNOP_LOGIC_NOT, cond, cond->loc))) { ERR("Out of memory.\n"); d3dcompiler_free(out_cond); - return NULL; + return FALSE; } + list_add_tail(cond_list, ¬_cond->entry); out_cond->condition = not_cond; jump = d3dcompiler_alloc(sizeof(*jump)); if (!jump) @@ -288,7 +287,7 @@ static struct hlsl_ir_if *loop_condition(struct list *cond_list) ERR("Out of memory.\n"); d3dcompiler_free(out_cond); d3dcompiler_free(not_cond); - return NULL; + return FALSE; } jump->node.type = HLSL_IR_JUMP; jump->type = HLSL_IR_JUMP_BREAK; @@ -299,12 +298,12 @@ static struct hlsl_ir_if *loop_condition(struct list *cond_list) d3dcompiler_free(out_cond); d3dcompiler_free(not_cond); d3dcompiler_free(jump); - return NULL; + return FALSE; } list_init(out_cond->then_instrs); list_add_head(out_cond->then_instrs, &jump->node.entry);
- return out_cond; + return TRUE; }
enum loop_type @@ -315,7 +314,7 @@ enum loop_type };
static struct list *create_loop(enum loop_type type, struct list *init, struct list *cond, - struct hlsl_ir_node *iter, struct list *body, struct source_location *loc) + struct list *iter, struct list *body, struct source_location *loc) { struct list *list = NULL; struct hlsl_ir_loop *loop = NULL; @@ -340,20 +339,19 @@ static struct list *create_loop(enum loop_type type, struct list *init, struct l goto oom; list_init(loop->body);
- cond_jump = loop_condition(cond); - if (!cond_jump) + if (!append_conditional_break(cond)) goto oom;
if (type != LOOP_DO_WHILE) - list_add_tail(loop->body, &cond_jump->node.entry); + list_move_tail(loop->body, cond);
list_move_tail(loop->body, body);
if (iter) - list_add_tail(loop->body, &iter->entry); + list_move_tail(loop->body, iter);
if (type == LOOP_DO_WHILE) - list_add_tail(loop->body, &cond_jump->node.entry); + list_move_tail(loop->body, cond);
d3dcompiler_free(init); d3dcompiler_free(cond); @@ -369,7 +367,7 @@ oom: d3dcompiler_free(list); free_instr_list(init); free_instr_list(cond); - free_instr(iter); + free_instr_list(iter); free_instr_list(body); return NULL; } @@ -388,9 +386,7 @@ static unsigned int initializer_size(const struct parse_initializer *initializer
static void free_parse_initializer(struct parse_initializer *initializer) { - unsigned int i; - for (i = 0; i < initializer->args_count; ++i) - free_instr(initializer->args[i]); + free_instr_list(initializer->instrs); d3dcompiler_free(initializer->args); }
@@ -508,6 +504,9 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, return; }
+ list_move_tail(list, initializer->instrs); + d3dcompiler_free(initializer->instrs); + LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) { struct hlsl_ir_node *node = initializer->args[i]; @@ -526,6 +525,7 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, break; } deref->node.loc = node->loc; + list_add_tail(list, &deref->node.entry); assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, node); list_add_tail(list, &assignment->entry); } @@ -533,9 +533,6 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, FIXME("Initializing with "mismatched" fields is not supported yet.\n"); }
- /* Free initializer elements in excess. */ - for (; i < initializer->args_count; ++i) - free_instr(initializer->args[i]); d3dcompiler_free(initializer->args); }
@@ -609,6 +606,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, if (v->initializer.args_count) { unsigned int size = initializer_size(&v->initializer); + struct hlsl_ir_deref *deref;
TRACE("Variable with initializer.\n"); if (type->type <= HLSL_CLASS_LAST_NUMERIC @@ -661,7 +659,10 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, continue; }
- assignment = make_assignment(&new_var_deref(var)->node, ASSIGN_OP_ASSIGN, + deref = new_var_deref(var); + list_add_tail(statements_list, &deref->node.entry); + list_add_tail(statements_list, &v->initializer.args[0]->entry); + assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, v->initializer.args[0]); d3dcompiler_free(v->initializer.args); list_add_tail(statements_list, &assignment->entry); @@ -880,6 +881,35 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr return NULL; }
+static struct list *append_unop(struct list *list, struct hlsl_ir_node *node) +{ + list_add_tail(list, &node->entry); + return list; +} + +static struct list *append_binop(struct list *first, struct list *second, struct hlsl_ir_node *node) +{ + list_move_tail(first, second); + d3dcompiler_free(second); + list_add_tail(first, &node->entry); + return first; +} + +static struct list *make_list(struct hlsl_ir_node *node) +{ + struct list *list; + + if (!(list = d3dcompiler_alloc(sizeof(*list)))) + { + ERR("Out of memory.\n"); + free_instr(node); + return NULL; + } + list_init(list); + list_add_tail(list, &node->entry); + return list; +} + %}
%locations @@ -1024,12 +1054,12 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr %type <variable_def> type_spec %type <initializer> complex_initializer %type <initializer> initializer_expr_list -%type <instr> initializer_expr +%type <list> initializer_expr %type <modifiers> var_modifiers %type <list> field %type <list> parameters %type <list> param_list -%type <instr> expr +%type <list> expr %type <intval> array %type <list> statement %type <list> statement_list @@ -1048,21 +1078,21 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr %type <list> variables_def %type <list> variables_def_optional %type <if_body> if_body -%type <instr> primary_expr -%type <instr> postfix_expr -%type <instr> unary_expr -%type <instr> mul_expr -%type <instr> add_expr -%type <instr> shift_expr -%type <instr> relational_expr -%type <instr> equality_expr -%type <instr> bitand_expr -%type <instr> bitxor_expr -%type <instr> bitor_expr -%type <instr> logicand_expr -%type <instr> logicor_expr -%type <instr> conditional_expr -%type <instr> assignment_expr +%type <list> primary_expr +%type <list> postfix_expr +%type <list> unary_expr +%type <list> mul_expr +%type <list> add_expr +%type <list> shift_expr +%type <list> relational_expr +%type <list> equality_expr +%type <list> bitand_expr +%type <list> bitxor_expr +%type <list> bitor_expr +%type <list> logicand_expr +%type <list> logicor_expr +%type <list> conditional_expr +%type <list> assignment_expr %type <list> expr_statement %type <unary_op> unary_op %type <assign_op> assign_op @@ -1615,7 +1645,7 @@ array: /* Empty */ { FIXME("Array.\n"); $$ = 0; - free_instr($2); + free_instr_list($2); }
var_modifiers: /* Empty */ @@ -1672,7 +1702,8 @@ complex_initializer: initializer_expr $$.args_count = 1; if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) YYABORT; - $$.args[0] = $1; + $$.args[0] = node_from_list($1); + $$.instrs = $1; } | '{' initializer_expr_list '}' { @@ -1693,14 +1724,17 @@ initializer_expr_list: initializer_expr $$.args_count = 1; if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) YYABORT; - $$.args[0] = $1; + $$.args[0] = node_from_list($1); + $$.instrs = $1; } | initializer_expr_list ',' initializer_expr { $$ = $1; if (!($$.args = d3dcompiler_realloc($$.args, ($$.args_count + 1) * sizeof(*$$.args)))) YYABORT; - $$.args[$$.args_count++] = $3; + $$.args[$$.args_count++] = node_from_list($3); + list_move_tail($$.instrs, $3); + d3dcompiler_free($3); }
boolean: KW_TRUE @@ -1742,16 +1776,14 @@ jump_statement: KW_RETURN expr ';' jump->node.type = HLSL_IR_JUMP; set_location(&jump->node.loc, &@1); jump->type = HLSL_IR_JUMP_RETURN; - jump->node.data_type = $2->data_type; - jump->return_value = $2; + jump->node.data_type = node_from_list($2)->data_type; + jump->return_value = node_from_list($2);
FIXME("Check for valued return on void function.\n"); FIXME("Implicit conversion to the return type if needed, " "error out if conversion not possible.\n");
- $$ = d3dcompiler_alloc(sizeof(*$$)); - list_init($$); - list_add_tail($$, &jump->node.entry); + $$ = append_unop($2, &jump->node); }
selection_statement: KW_IF '(' expr ')' if_body @@ -1764,18 +1796,16 @@ selection_statement: KW_IF '(' expr ')' if_body } instr->node.type = HLSL_IR_IF; set_location(&instr->node.loc, &@1); - instr->condition = $3; + instr->condition = node_from_list($3); instr->then_instrs = $5.then_instrs; instr->else_instrs = $5.else_instrs; - if ($3->data_type->dimx > 1 || $3->data_type->dimy > 1) + if (instr->condition->data_type->dimx > 1 || instr->condition->data_type->dimy > 1) { hlsl_report_message(instr->node.loc.file, instr->node.loc.line, instr->node.loc.col, HLSL_LEVEL_ERROR, "if condition requires a scalar"); } - $$ = d3dcompiler_alloc(sizeof(*$$)); - list_init($$); - list_add_head($$, &instr->node.entry); + $$ = append_unop($3, &instr->node); }
if_body: statement @@ -1792,32 +1822,14 @@ if_body: statement loop_statement: KW_WHILE '(' expr ')' statement { struct source_location loc; - struct list *cond = d3dcompiler_alloc(sizeof(*cond)); - - if (!cond) - { - ERR("Out of memory.\n"); - YYABORT; - } - list_init(cond); - list_add_head(cond, &$3->entry); set_location(&loc, &@1); - $$ = create_loop(LOOP_WHILE, NULL, cond, NULL, $5, &loc); + $$ = create_loop(LOOP_WHILE, NULL, $3, NULL, $5, &loc); } | KW_DO statement KW_WHILE '(' expr ')' ';' { struct source_location loc; - struct list *cond = d3dcompiler_alloc(sizeof(*cond)); - - if (!cond) - { - ERR("Out of memory.\n"); - YYABORT; - } - list_init(cond); - list_add_head(cond, &$5->entry); set_location(&loc, &@1); - $$ = create_loop(LOOP_DO_WHILE, NULL, cond, NULL, $2, &loc); + $$ = create_loop(LOOP_DO_WHILE, NULL, $5, NULL, $2, &loc); } | KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement { @@ -1846,10 +1858,7 @@ expr_statement: ';' } | expr ';' { - $$ = d3dcompiler_alloc(sizeof(*$$)); - list_init($$); - if ($1) - list_add_head($$, &$1->entry); + $$ = $1; }
primary_expr: C_FLOAT @@ -1864,7 +1873,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("float"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); c->v.value.f[0] = $1; - $$ = &c->node; + if (!($$ = make_list(&c->node))) + YYABORT; } | C_INTEGER { @@ -1878,7 +1888,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("int"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); c->v.value.i[0] = $1; - $$ = &c->node; + if (!($$ = make_list(&c->node))) + YYABORT; } | boolean { @@ -1892,7 +1903,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("bool"), HLSL_CLASS_SCALAR, HLSL_TYPE_BOOL, 1, 1); c->v.value.b[0] = $1; - $$ = &c->node; + if (!($$ = make_list(&c->node))) + YYABORT; } | VAR_IDENTIFIER { @@ -1908,8 +1920,9 @@ primary_expr: C_FLOAT } if ((deref = new_var_deref(var))) { - $$ = &deref->node; - set_location(&$$->loc, &@1); + set_location(&deref->node.loc, &@1); + if (!($$ = make_list(&deref->node))) + YYABORT; } else $$ = NULL; @@ -1926,43 +1939,47 @@ postfix_expr: primary_expr | postfix_expr OP_INC { struct source_location loc; + struct hlsl_ir_node *inc;
set_location(&loc, &@2); - if ($1->data_type->modifiers & HLSL_MODIFIER_CONST) + if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; } - $$ = new_unary_expr(HLSL_IR_UNOP_POSTINC, $1, loc); + inc = new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */ - $$->data_type = clone_hlsl_type($$->data_type); - $$->data_type->modifiers |= HLSL_MODIFIER_CONST; + inc->data_type = clone_hlsl_type(inc->data_type); + inc->data_type->modifiers |= HLSL_MODIFIER_CONST; + $$ = append_unop($1, inc); } | postfix_expr OP_DEC { struct source_location loc; + struct hlsl_ir_node *inc;
set_location(&loc, &@2); - if ($1->data_type->modifiers & HLSL_MODIFIER_CONST) + if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; } - $$ = new_unary_expr(HLSL_IR_UNOP_POSTDEC, $1, loc); + inc = new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */ - $$->data_type = clone_hlsl_type($$->data_type); - $$->data_type->modifiers |= HLSL_MODIFIER_CONST; + inc->data_type = clone_hlsl_type(inc->data_type); + inc->data_type->modifiers |= HLSL_MODIFIER_CONST; + $$ = append_unop($1, inc); } | postfix_expr '.' any_identifier { struct source_location loc;
set_location(&loc, &@2); - if ($1->data_type->type == HLSL_CLASS_STRUCT) + if (node_from_list($1)->data_type->type == HLSL_CLASS_STRUCT) { - struct hlsl_type *type = $1->data_type; + struct hlsl_type *type = node_from_list($1)->data_type; struct hlsl_struct_field *field;
$$ = NULL; @@ -1970,7 +1987,7 @@ postfix_expr: primary_expr { if (!strcmp($3, field->name)) { - struct hlsl_ir_deref *deref = new_record_deref($1, field); + struct hlsl_ir_deref *deref = new_record_deref(node_from_list($1), field);
if (!deref) { @@ -1978,7 +1995,7 @@ postfix_expr: primary_expr YYABORT; } deref->node.loc = loc; - $$ = &deref->node; + $$ = append_unop($1, &deref->node); break; } } @@ -1989,18 +2006,18 @@ postfix_expr: primary_expr YYABORT; } } - else if ($1->data_type->type <= HLSL_CLASS_LAST_NUMERIC) + else if (node_from_list($1)->data_type->type <= HLSL_CLASS_LAST_NUMERIC) { struct hlsl_ir_swizzle *swizzle;
- swizzle = get_swizzle($1, $3, &loc); + swizzle = get_swizzle(node_from_list($1), $3, &loc); if (!swizzle) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "invalid swizzle %s", debugstr_a($3)); YYABORT; } - $$ = &swizzle->node; + $$ = append_unop($1, &swizzle->node); } else { @@ -2015,7 +2032,7 @@ postfix_expr: primary_expr * subcomponent access. * We store it as an array dereference in any case. */ struct hlsl_ir_deref *deref = d3dcompiler_alloc(sizeof(*deref)); - struct hlsl_type *expr_type = $1->data_type; + struct hlsl_type *expr_type = node_from_list($1)->data_type; struct source_location loc;
TRACE("Array dereference from type %s\n", debug_hlsl_type(expr_type)); @@ -2048,24 +2065,24 @@ postfix_expr: primary_expr hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "expression is not array-indexable"); d3dcompiler_free(deref); - free_instr($1); - free_instr($3); + free_instr_list($1); + free_instr_list($3); YYABORT; } - if ($3->data_type->type != HLSL_CLASS_SCALAR) + if (node_from_list($3)->data_type->type != HLSL_CLASS_SCALAR) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "array index is not scalar"); d3dcompiler_free(deref); - free_instr($1); - free_instr($3); + free_instr_list($1); + free_instr_list($3); YYABORT; } deref->type = HLSL_IR_DEREF_ARRAY; - deref->v.array.array = $1; - deref->v.array.index = $3; + deref->v.array.array = node_from_list($1); + deref->v.array.index = node_from_list($3);
- $$ = &deref->node; + $$ = append_binop($1, $3, &deref->node); } /* "var_modifiers" doesn't make sense in this case, but it's needed in the grammar to avoid shift/reduce conflicts. */ @@ -2104,7 +2121,7 @@ postfix_expr: primary_expr constructor->args_count = $4.args_count; memcpy(constructor->args, $4.args, $4.args_count * sizeof(*$4.args)); d3dcompiler_free($4.args); - $$ = &constructor->node; + $$ = append_unop($4.instrs, &constructor->node); }
unary_expr: postfix_expr @@ -2116,26 +2133,26 @@ unary_expr: postfix_expr struct source_location loc;
set_location(&loc, &@1); - if ($2->data_type->modifiers & HLSL_MODIFIER_CONST) + if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; } - $$ = new_unary_expr(HLSL_IR_UNOP_PREINC, $2, loc); + $$ = append_unop($2, new_unary_expr(HLSL_IR_UNOP_PREINC, node_from_list($2), loc)); } | OP_DEC unary_expr { struct source_location loc;
set_location(&loc, &@1); - if ($2->data_type->modifiers & HLSL_MODIFIER_CONST) + if (node_from_list($2)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; } - $$ = new_unary_expr(HLSL_IR_UNOP_PREDEC, $2, loc); + $$ = append_unop($2, new_unary_expr(HLSL_IR_UNOP_PREDEC, node_from_list($2), loc)); } | unary_op unary_expr { @@ -2150,14 +2167,13 @@ unary_expr: postfix_expr else { set_location(&loc, &@1); - $$ = new_unary_expr(ops[$1], $2, loc); + $$ = append_unop($2, new_unary_expr(ops[$1], node_from_list($2), loc)); } } /* var_modifiers just to avoid shift/reduce conflicts */ | '(' var_modifiers type array ')' unary_expr { - struct hlsl_ir_expr *expr; - struct hlsl_type *src_type = $6->data_type; + struct hlsl_type *src_type = node_from_list($6)->data_type; struct hlsl_type *dst_type; struct source_location loc;
@@ -2182,8 +2198,7 @@ unary_expr: postfix_expr YYABORT; }
- expr = new_cast($6, dst_type, &loc); - $$ = expr ? &expr->node : NULL; + $$ = append_unop($6, &new_cast(node_from_list($6), dst_type, &loc)->node); }
unary_op: '+' @@ -2212,21 +2227,21 @@ mul_expr: unary_expr struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_MUL, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_MUL, node_from_list($1), node_from_list($3), loc)); } | mul_expr '/' unary_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_DIV, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_DIV, node_from_list($1), node_from_list($3), loc)); } | mul_expr '%' unary_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_MOD, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_MOD, node_from_list($1), node_from_list($3), loc)); }
add_expr: mul_expr @@ -2238,14 +2253,14 @@ add_expr: mul_expr struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_ADD, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_ADD, node_from_list($1), node_from_list($3), loc)); } | add_expr '-' mul_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_SUB, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_SUB, node_from_list($1), node_from_list($3), loc)); }
shift_expr: add_expr @@ -2270,28 +2285,28 @@ relational_expr: shift_expr struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_LESS, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_LESS, node_from_list($1), node_from_list($3), loc)); } | relational_expr '>' shift_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_GREATER, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_GREATER, node_from_list($1), node_from_list($3), loc)); } | relational_expr OP_LE shift_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_LEQUAL, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_LEQUAL, node_from_list($1), node_from_list($3), loc)); } | relational_expr OP_GE shift_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_GEQUAL, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_GEQUAL, node_from_list($1), node_from_list($3), loc)); }
equality_expr: relational_expr @@ -2303,14 +2318,14 @@ equality_expr: relational_expr struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_EQUAL, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_EQUAL, node_from_list($1), node_from_list($3), loc)); } | equality_expr OP_NE relational_expr { struct source_location loc;
set_location(&loc, &@2); - $$ = new_binary_expr(HLSL_IR_BINOP_NEQUAL, $1, $3, loc); + $$ = append_binop($1, $3, new_binary_expr(HLSL_IR_BINOP_NEQUAL, node_from_list($1), node_from_list($3), loc)); }
bitand_expr: equality_expr @@ -2374,18 +2389,20 @@ assignment_expr: conditional_expr | unary_expr assign_op assignment_expr { struct source_location loc; + struct hlsl_ir_node *instr;
set_location(&loc, &@2); - if ($1->data_type->modifiers & HLSL_MODIFIER_CONST) + if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "l-value is const"); YYABORT; } - $$ = make_assignment($1, $2, BWRITERSP_WRITEMASK_ALL, $3); - if (!$$) + if (!(instr = make_assignment(node_from_list($1), $2, + BWRITERSP_WRITEMASK_ALL, node_from_list($3)))) YYABORT; - $$->loc = loc; + instr->loc = loc; + $$ = append_binop($3, $1, instr); }
assign_op: '=' diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index b2b1e25bbdc..4dc2e048808 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1278,10 +1278,14 @@ static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type static struct hlsl_ir_node *implicit_conversion(struct hlsl_ir_node *node, struct hlsl_type *type, struct source_location *loc) { + struct hlsl_ir_expr *cast; + if (compare_hlsl_types(node->data_type, type)) return node; TRACE("Implicit conversion of expression to %s\n", debug_hlsl_type(type)); - return &new_cast(node, type, loc)->node; + if ((cast = new_cast(node, type, loc))) + list_add_after(&node->entry, &cast->node.entry); + return &cast->node; }
struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands, @@ -1468,8 +1472,6 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assig hlsl_report_message(rhs->loc.file, rhs->loc.line, rhs->loc.col, HLSL_LEVEL_ERROR, "can't implicitly convert %s to %s", debug_hlsl_type(rhs->data_type), debug_hlsl_type(type)); - free_instr(lhs); - free_instr(rhs); d3dcompiler_free(assign); return NULL; } @@ -1481,8 +1483,6 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assig if (!converted_rhs) { ERR("Couldn't implicitly convert expression to %s.\n", debug_hlsl_type(type)); - free_instr(lhs); - free_instr(rhs); d3dcompiler_free(assign); return NULL; } @@ -1502,11 +1502,9 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assig } else { - struct hlsl_ir_deref *lhs_deref = deref_from_node(lhs), *new_deref; - TRACE("Adding an expression for the compound assignment.\n"); - new_deref = new_var_deref(lhs_deref->v.var); - expr = new_binary_expr(op, &new_deref->node, rhs, left->loc); + expr = new_binary_expr(op, lhs, rhs, lhs->loc); + list_add_after(&rhs->entry, &expr->entry); assign->rhs = expr; } } @@ -2156,60 +2154,32 @@ static void free_ir_constant(struct hlsl_ir_constant *constant)
static void free_ir_deref(struct hlsl_ir_deref *deref) { - switch (deref->type) - { - case HLSL_IR_DEREF_VAR: - /* Variables are shared among nodes in the tree. */ - break; - case HLSL_IR_DEREF_ARRAY: - free_instr(deref->v.array.array); - free_instr(deref->v.array.index); - break; - case HLSL_IR_DEREF_RECORD: - free_instr(deref->v.record.record); - break; - } d3dcompiler_free(deref); }
static void free_ir_swizzle(struct hlsl_ir_swizzle *swizzle) { - free_instr(swizzle->val); d3dcompiler_free(swizzle); }
static void free_ir_constructor(struct hlsl_ir_constructor *constructor) { - unsigned int i; - for (i = 0; i < constructor->args_count; ++i) - free_instr(constructor->args[i]); d3dcompiler_free(constructor); }
static void free_ir_expr(struct hlsl_ir_expr *expr) { - unsigned int i; - - for (i = 0; i < 3; ++i) - { - if (!expr->operands[i]) - break; - free_instr(expr->operands[i]); - } free_instr_list(expr->subexpressions); d3dcompiler_free(expr); }
static void free_ir_assignment(struct hlsl_ir_assignment *assignment) { - free_instr(assignment->lhs); - free_instr(assignment->rhs); d3dcompiler_free(assignment); }
static void free_ir_if(struct hlsl_ir_if *if_node) { - free_instr(if_node->condition); free_instr_list(if_node->then_instrs); free_instr_list(if_node->else_instrs); d3dcompiler_free(if_node); @@ -2217,8 +2187,6 @@ static void free_ir_if(struct hlsl_ir_if *if_node)
static void free_ir_jump(struct hlsl_ir_jump *jump) { - if (jump->type == HLSL_IR_JUMP_RETURN) - free_instr(jump->return_value); d3dcompiler_free(jump); }
On Wed, Feb 5, 2020 at 9:53 PM Zebediah Figura z.figura12@gmail.com wrote:
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
v2: don't drop all of the struct initializer elements on the floor v3: style tweak, clarify loop_condition()
dlls/d3dcompiler_43/d3dcompiler_private.h | 6 + dlls/d3dcompiler_43/hlsl.y | 287 ++++++++++++---------- dlls/d3dcompiler_43/utils.c | 46 +--- 3 files changed, 165 insertions(+), 174 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 5fc3161f5f0..9c58830ffe2 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -984,6 +984,7 @@ struct parse_initializer { struct hlsl_ir_node **args; unsigned int args_count;
- struct list *instrs;
};
struct parse_variable_def @@ -1120,6 +1121,11 @@ static inline struct hlsl_ir_loop *loop_from_node(const struct hlsl_ir_node *nod return CONTAINING_RECORD(node, struct hlsl_ir_loop, node); }
+static inline struct hlsl_ir_node *node_from_list(struct list *list) +{
- return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry);
+}
BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN; struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN; void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index d81d6afa9cc..f72882187c8 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -255,32 +255,31 @@ static void declare_predefined_types(struct hlsl_scope *scope) add_type_to_scope(scope, type); }
-static struct hlsl_ir_if *loop_condition(struct list *cond_list) +static BOOL append_conditional_break(struct list *cond_list) { struct hlsl_ir_node *cond, *not_cond; struct hlsl_ir_if *out_cond; struct hlsl_ir_jump *jump;
unsigned int count = list_count(cond_list);
if (!count)
return NULL;
if (count != 1)
ERR("Got multiple expressions in a for condition.\n");
- /* E.g. "for (i = 0; ; ++i)". */
- if (!list_count(cond_list))
return TRUE;
- cond = LIST_ENTRY(list_head(cond_list), struct hlsl_ir_node, entry);
- cond = node_from_list(cond_list); out_cond = d3dcompiler_alloc(sizeof(*out_cond)); if (!out_cond) { ERR("Out of memory.\n");
return NULL;
} out_cond->node.type = HLSL_IR_IF; if (!(not_cond = new_unary_expr(HLSL_IR_UNOP_LOGIC_NOT, cond, cond->loc))) { ERR("Out of memory.\n"); d3dcompiler_free(out_cond);return FALSE;
return NULL;
}return FALSE;
- list_add_tail(cond_list, ¬_cond->entry); out_cond->condition = not_cond; jump = d3dcompiler_alloc(sizeof(*jump)); if (!jump)
@@ -288,7 +287,7 @@ static struct hlsl_ir_if *loop_condition(struct list *cond_list) ERR("Out of memory.\n"); d3dcompiler_free(out_cond); d3dcompiler_free(not_cond);
return NULL;
}return FALSE;
You shouldn't free not_cond anymore in case of error since you appended it to cond_list already.
jump->node.type = HLSL_IR_JUMP; jump->type = HLSL_IR_JUMP_BREAK;
@@ -299,12 +298,12 @@ static struct hlsl_ir_if *loop_condition(struct list *cond_list) d3dcompiler_free(out_cond); d3dcompiler_free(not_cond); d3dcompiler_free(jump);
return NULL;
}return FALSE;
Same.
list_init(out_cond->then_instrs); list_add_head(out_cond->then_instrs, &jump->node.entry);
- return out_cond;
- return TRUE;
Shouldn't out_cond be inserted somewhere? Right now it looks to me like it's just leaked.
}
enum loop_type @@ -315,7 +314,7 @@ enum loop_type };
static struct list *create_loop(enum loop_type type, struct list *init, struct list *cond,
struct hlsl_ir_node *iter, struct list *body, struct source_location *loc)
struct list *iter, struct list *body, struct source_location *loc)
{ struct list *list = NULL; struct hlsl_ir_loop *loop = NULL; @@ -340,20 +339,19 @@ static struct list *create_loop(enum loop_type type, struct list *init, struct l goto oom; list_init(loop->body);
- cond_jump = loop_condition(cond);
- if (!cond_jump)
if (!append_conditional_break(cond)) goto oom;
if (type != LOOP_DO_WHILE)
list_add_tail(loop->body, &cond_jump->node.entry);
list_move_tail(loop->body, cond);
list_move_tail(loop->body, body);
if (iter)
list_add_tail(loop->body, &iter->entry);
list_move_tail(loop->body, iter);
if (type == LOOP_DO_WHILE)
list_add_tail(loop->body, &cond_jump->node.entry);
list_move_tail(loop->body, cond);
d3dcompiler_free(init); d3dcompiler_free(cond);
@@ -369,7 +367,7 @@ oom: d3dcompiler_free(list); free_instr_list(init); free_instr_list(cond);
- free_instr(iter);
- free_instr_list(iter); free_instr_list(body); return NULL;
} @@ -388,9 +386,7 @@ static unsigned int initializer_size(const struct parse_initializer *initializer
static void free_parse_initializer(struct parse_initializer *initializer) {
- unsigned int i;
- for (i = 0; i < initializer->args_count; ++i)
free_instr(initializer->args[i]);
- free_instr_list(initializer->instrs); d3dcompiler_free(initializer->args);
}
@@ -508,6 +504,9 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, return; }
- list_move_tail(list, initializer->instrs);
- d3dcompiler_free(initializer->instrs);
- LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) { struct hlsl_ir_node *node = initializer->args[i];
@@ -526,6 +525,7 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, break; } deref->node.loc = node->loc;
list_add_tail(list, &deref->node.entry); assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, node); list_add_tail(list, &assignment->entry); }
@@ -533,9 +533,6 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, FIXME("Initializing with "mismatched" fields is not supported yet.\n"); }
- /* Free initializer elements in excess. */
- for (; i < initializer->args_count; ++i)
d3dcompiler_free(initializer->args);free_instr(initializer->args[i]);
}
@@ -609,6 +606,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, if (v->initializer.args_count) { unsigned int size = initializer_size(&v->initializer);
struct hlsl_ir_deref *deref; TRACE("Variable with initializer.\n"); if (type->type <= HLSL_CLASS_LAST_NUMERIC
@@ -661,7 +659,10 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, continue; }
assignment = make_assignment(&new_var_deref(var)->node, ASSIGN_OP_ASSIGN,
deref = new_var_deref(var);
list_add_tail(statements_list, &deref->node.entry);
list_add_tail(statements_list, &v->initializer.args[0]->entry);
assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, v->initializer.args[0]); d3dcompiler_free(v->initializer.args); list_add_tail(statements_list, &assignment->entry);
@@ -880,6 +881,35 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr return NULL; }
+static struct list *append_unop(struct list *list, struct hlsl_ir_node *node) +{
- list_add_tail(list, &node->entry);
- return list;
+}
+static struct list *append_binop(struct list *first, struct list *second, struct hlsl_ir_node *node) +{
- list_move_tail(first, second);
- d3dcompiler_free(second);
- list_add_tail(first, &node->entry);
- return first;
+}
+static struct list *make_list(struct hlsl_ir_node *node) +{
- struct list *list;
- if (!(list = d3dcompiler_alloc(sizeof(*list))))
- {
ERR("Out of memory.\n");
free_instr(node);
return NULL;
- }
- list_init(list);
- list_add_tail(list, &node->entry);
- return list;
+}
%}
%locations @@ -1024,12 +1054,12 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr %type <variable_def> type_spec %type <initializer> complex_initializer %type <initializer> initializer_expr_list -%type <instr> initializer_expr +%type <list> initializer_expr %type <modifiers> var_modifiers %type <list> field %type <list> parameters %type <list> param_list -%type <instr> expr +%type <list> expr %type <intval> array %type <list> statement %type <list> statement_list @@ -1048,21 +1078,21 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr %type <list> variables_def %type <list> variables_def_optional %type <if_body> if_body -%type <instr> primary_expr -%type <instr> postfix_expr -%type <instr> unary_expr -%type <instr> mul_expr -%type <instr> add_expr -%type <instr> shift_expr -%type <instr> relational_expr -%type <instr> equality_expr -%type <instr> bitand_expr -%type <instr> bitxor_expr -%type <instr> bitor_expr -%type <instr> logicand_expr -%type <instr> logicor_expr -%type <instr> conditional_expr -%type <instr> assignment_expr +%type <list> primary_expr +%type <list> postfix_expr +%type <list> unary_expr +%type <list> mul_expr +%type <list> add_expr +%type <list> shift_expr +%type <list> relational_expr +%type <list> equality_expr +%type <list> bitand_expr +%type <list> bitxor_expr +%type <list> bitor_expr +%type <list> logicand_expr +%type <list> logicor_expr +%type <list> conditional_expr +%type <list> assignment_expr %type <list> expr_statement %type <unary_op> unary_op %type <assign_op> assign_op @@ -1615,7 +1645,7 @@ array: /* Empty */ { FIXME("Array.\n"); $$ = 0;
free_instr($2);
free_instr_list($2); }
var_modifiers: /* Empty */ @@ -1672,7 +1702,8 @@ complex_initializer: initializer_expr $$.args_count = 1; if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) YYABORT;
$$.args[0] = $1;
$$.args[0] = node_from_list($1);
$$.instrs = $1; } | '{' initializer_expr_list '}' {
@@ -1693,14 +1724,17 @@ initializer_expr_list: initializer_expr $$.args_count = 1; if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) YYABORT;
$$.args[0] = $1;
$$.args[0] = node_from_list($1);
$$.instrs = $1; } | initializer_expr_list ',' initializer_expr { $$ = $1; if (!($$.args = d3dcompiler_realloc($$.args, ($$.args_count + 1) * sizeof(*$$.args)))) YYABORT;
$$.args[$$.args_count++] = $3;
$$.args[$$.args_count++] = node_from_list($3);
list_move_tail($$.instrs, $3);
d3dcompiler_free($3); }
boolean: KW_TRUE @@ -1742,16 +1776,14 @@ jump_statement: KW_RETURN expr ';' jump->node.type = HLSL_IR_JUMP; set_location(&jump->node.loc, &@1); jump->type = HLSL_IR_JUMP_RETURN;
jump->node.data_type = $2->data_type;
jump->return_value = $2;
jump->node.data_type = node_from_list($2)->data_type;
jump->return_value = node_from_list($2); FIXME("Check for valued return on void function.\n"); FIXME("Implicit conversion to the return type if needed, " "error out if conversion not possible.\n");
$$ = d3dcompiler_alloc(sizeof(*$$));
list_init($$);
list_add_tail($$, &jump->node.entry);
$$ = append_unop($2, &jump->node);
I'm a bit thrown off by the use of append_unop() here (and for the "if" below): jump technically isn't a unary operator (expression). Maybe just do an explicit list_add_tail() like the previous code? I don't think you have to necessarily take this suggestion, I suspect I might not get the same uneasiness next time I read the patch...
}
selection_statement: KW_IF '(' expr ')' if_body @@ -1764,18 +1796,16 @@ selection_statement: KW_IF '(' expr ')' if_body } instr->node.type = HLSL_IR_IF; set_location(&instr->node.loc, &@1);
instr->condition = $3;
instr->condition = node_from_list($3); instr->then_instrs = $5.then_instrs; instr->else_instrs = $5.else_instrs;
if ($3->data_type->dimx > 1 || $3->data_type->dimy > 1)
if (instr->condition->data_type->dimx > 1 || instr->condition->data_type->dimy > 1) { hlsl_report_message(instr->node.loc.file, instr->node.loc.line, instr->node.loc.col, HLSL_LEVEL_ERROR, "if condition requires a scalar"); }
$$ = d3dcompiler_alloc(sizeof(*$$));
list_init($$);
list_add_head($$, &instr->node.entry);
$$ = append_unop($3, &instr->node); }
if_body: statement @@ -1792,32 +1822,14 @@ if_body: statement loop_statement: KW_WHILE '(' expr ')' statement { struct source_location loc;
struct list *cond = d3dcompiler_alloc(sizeof(*cond));
if (!cond)
{
ERR("Out of memory.\n");
YYABORT;
}
list_init(cond);
list_add_head(cond, &$3->entry); set_location(&loc, &@1);
$$ = create_loop(LOOP_WHILE, NULL, cond, NULL, $5, &loc);
$$ = create_loop(LOOP_WHILE, NULL, $3, NULL, $5, &loc); } | KW_DO statement KW_WHILE '(' expr ')' ';' { struct source_location loc;
struct list *cond = d3dcompiler_alloc(sizeof(*cond));
if (!cond)
{
ERR("Out of memory.\n");
YYABORT;
}
list_init(cond);
list_add_head(cond, &$5->entry); set_location(&loc, &@1);
$$ = create_loop(LOOP_DO_WHILE, NULL, cond, NULL, $2, &loc);
$$ = create_loop(LOOP_DO_WHILE, NULL, $5, NULL, $2, &loc); } | KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement {
@@ -1846,10 +1858,7 @@ expr_statement: ';' } | expr ';' {
$$ = d3dcompiler_alloc(sizeof(*$$));
list_init($$);
if ($1)
list_add_head($$, &$1->entry);
$$ = $1; }
primary_expr: C_FLOAT @@ -1864,7 +1873,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("float"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); c->v.value.f[0] = $1;
$$ = &c->node;
if (!($$ = make_list(&c->node)))
YYABORT; } | C_INTEGER {
@@ -1878,7 +1888,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("int"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); c->v.value.i[0] = $1;
$$ = &c->node;
if (!($$ = make_list(&c->node)))
YYABORT; } | boolean {
@@ -1892,7 +1903,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("bool"), HLSL_CLASS_SCALAR, HLSL_TYPE_BOOL, 1, 1); c->v.value.b[0] = $1;
$$ = &c->node;
if (!($$ = make_list(&c->node)))
YYABORT; } | VAR_IDENTIFIER {
@@ -1908,8 +1920,9 @@ primary_expr: C_FLOAT } if ((deref = new_var_deref(var))) {
$$ = &deref->node;
set_location(&$$->loc, &@1);
set_location(&deref->node.loc, &@1);
if (!($$ = make_list(&deref->node)))
YYABORT; } else $$ = NULL;
@@ -1926,43 +1939,47 @@ postfix_expr: primary_expr | postfix_expr OP_INC { struct source_location loc;
struct hlsl_ir_node *inc; set_location(&loc, &@2);
if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; }
$$ = new_unary_expr(HLSL_IR_UNOP_POSTINC, $1, loc);
inc = new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */
$$->data_type = clone_hlsl_type($$->data_type);
$$->data_type->modifiers |= HLSL_MODIFIER_CONST;
inc->data_type = clone_hlsl_type(inc->data_type);
inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
$$ = append_unop($1, inc); } | postfix_expr OP_DEC { struct source_location loc;
struct hlsl_ir_node *inc; set_location(&loc, &@2);
if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; }
$$ = new_unary_expr(HLSL_IR_UNOP_POSTDEC, $1, loc);
inc = new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */
$$->data_type = clone_hlsl_type($$->data_type);
$$->data_type->modifiers |= HLSL_MODIFIER_CONST;
inc->data_type = clone_hlsl_type(inc->data_type);
inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
$$ = append_unop($1, inc); } | postfix_expr '.' any_identifier { struct source_location loc; set_location(&loc, &@2);
if ($1->data_type->type == HLSL_CLASS_STRUCT)
if (node_from_list($1)->data_type->type == HLSL_CLASS_STRUCT) {
struct hlsl_type *type = $1->data_type;
struct hlsl_type *type = node_from_list($1)->data_type; struct hlsl_struct_field *field; $$ = NULL;
It might be nicer to store the result of node_from_list($1) in a local variable and use it through.
On 2/11/20 11:40 AM, Matteo Bruni wrote:
On Wed, Feb 5, 2020 at 9:53 PM Zebediah Figura z.figura12@gmail.com wrote:
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
v2: don't drop all of the struct initializer elements on the floor v3: style tweak, clarify loop_condition()
dlls/d3dcompiler_43/d3dcompiler_private.h | 6 + dlls/d3dcompiler_43/hlsl.y | 287 ++++++++++++---------- dlls/d3dcompiler_43/utils.c | 46 +--- 3 files changed, 165 insertions(+), 174 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 5fc3161f5f0..9c58830ffe2 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -984,6 +984,7 @@ struct parse_initializer { struct hlsl_ir_node **args; unsigned int args_count;
- struct list *instrs;
};
struct parse_variable_def @@ -1120,6 +1121,11 @@ static inline struct hlsl_ir_loop *loop_from_node(const struct hlsl_ir_node *nod return CONTAINING_RECORD(node, struct hlsl_ir_loop, node); }
+static inline struct hlsl_ir_node *node_from_list(struct list *list) +{
- return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry);
+}
BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN; struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN; void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index d81d6afa9cc..f72882187c8 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -255,32 +255,31 @@ static void declare_predefined_types(struct hlsl_scope *scope) add_type_to_scope(scope, type); }
-static struct hlsl_ir_if *loop_condition(struct list *cond_list) +static BOOL append_conditional_break(struct list *cond_list) { struct hlsl_ir_node *cond, *not_cond; struct hlsl_ir_if *out_cond; struct hlsl_ir_jump *jump;
unsigned int count = list_count(cond_list);
if (!count)
return NULL;
if (count != 1)
ERR("Got multiple expressions in a for condition.\n");
- /* E.g. "for (i = 0; ; ++i)". */
- if (!list_count(cond_list))
return TRUE;
- cond = LIST_ENTRY(list_head(cond_list), struct hlsl_ir_node, entry);
- cond = node_from_list(cond_list); out_cond = d3dcompiler_alloc(sizeof(*out_cond)); if (!out_cond) { ERR("Out of memory.\n");
return NULL;
} out_cond->node.type = HLSL_IR_IF; if (!(not_cond = new_unary_expr(HLSL_IR_UNOP_LOGIC_NOT, cond, cond->loc))) { ERR("Out of memory.\n"); d3dcompiler_free(out_cond);return FALSE;
return NULL;
}return FALSE;
- list_add_tail(cond_list, ¬_cond->entry); out_cond->condition = not_cond; jump = d3dcompiler_alloc(sizeof(*jump)); if (!jump)
@@ -288,7 +287,7 @@ static struct hlsl_ir_if *loop_condition(struct list *cond_list) ERR("Out of memory.\n"); d3dcompiler_free(out_cond); d3dcompiler_free(not_cond);
return NULL;
}return FALSE;
You shouldn't free not_cond anymore in case of error since you appended it to cond_list already.
jump->node.type = HLSL_IR_JUMP; jump->type = HLSL_IR_JUMP_BREAK;
@@ -299,12 +298,12 @@ static struct hlsl_ir_if *loop_condition(struct list *cond_list) d3dcompiler_free(out_cond); d3dcompiler_free(not_cond); d3dcompiler_free(jump);
return NULL;
}return FALSE;
Same.
list_init(out_cond->then_instrs); list_add_head(out_cond->then_instrs, &jump->node.entry);
- return out_cond;
- return TRUE;
Shouldn't out_cond be inserted somewhere? Right now it looks to me like it's just leaked.
Yes, you're right, this function needs more work...
}
enum loop_type @@ -315,7 +314,7 @@ enum loop_type };
static struct list *create_loop(enum loop_type type, struct list *init, struct list *cond,
struct hlsl_ir_node *iter, struct list *body, struct source_location *loc)
struct list *iter, struct list *body, struct source_location *loc)
{ struct list *list = NULL; struct hlsl_ir_loop *loop = NULL; @@ -340,20 +339,19 @@ static struct list *create_loop(enum loop_type type, struct list *init, struct l goto oom; list_init(loop->body);
- cond_jump = loop_condition(cond);
- if (!cond_jump)
if (!append_conditional_break(cond)) goto oom;
if (type != LOOP_DO_WHILE)
list_add_tail(loop->body, &cond_jump->node.entry);
list_move_tail(loop->body, cond);
list_move_tail(loop->body, body);
if (iter)
list_add_tail(loop->body, &iter->entry);
list_move_tail(loop->body, iter);
if (type == LOOP_DO_WHILE)
list_add_tail(loop->body, &cond_jump->node.entry);
list_move_tail(loop->body, cond);
d3dcompiler_free(init); d3dcompiler_free(cond);
@@ -369,7 +367,7 @@ oom: d3dcompiler_free(list); free_instr_list(init); free_instr_list(cond);
- free_instr(iter);
- free_instr_list(iter); free_instr_list(body); return NULL;
} @@ -388,9 +386,7 @@ static unsigned int initializer_size(const struct parse_initializer *initializer
static void free_parse_initializer(struct parse_initializer *initializer) {
- unsigned int i;
- for (i = 0; i < initializer->args_count; ++i)
free_instr(initializer->args[i]);
- free_instr_list(initializer->instrs); d3dcompiler_free(initializer->args);
}
@@ -508,6 +504,9 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, return; }
- list_move_tail(list, initializer->instrs);
- d3dcompiler_free(initializer->instrs);
- LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry) { struct hlsl_ir_node *node = initializer->args[i];
@@ -526,6 +525,7 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, break; } deref->node.loc = node->loc;
list_add_tail(list, &deref->node.entry); assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, node); list_add_tail(list, &assignment->entry); }
@@ -533,9 +533,6 @@ static void struct_var_initializer(struct list *list, struct hlsl_ir_var *var, FIXME("Initializing with "mismatched" fields is not supported yet.\n"); }
- /* Free initializer elements in excess. */
- for (; i < initializer->args_count; ++i)
d3dcompiler_free(initializer->args);free_instr(initializer->args[i]);
}
@@ -609,6 +606,7 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, if (v->initializer.args_count) { unsigned int size = initializer_size(&v->initializer);
struct hlsl_ir_deref *deref; TRACE("Variable with initializer.\n"); if (type->type <= HLSL_CLASS_LAST_NUMERIC
@@ -661,7 +659,10 @@ static struct list *declare_vars(struct hlsl_type *basic_type, DWORD modifiers, continue; }
assignment = make_assignment(&new_var_deref(var)->node, ASSIGN_OP_ASSIGN,
deref = new_var_deref(var);
list_add_tail(statements_list, &deref->node.entry);
list_add_tail(statements_list, &v->initializer.args[0]->entry);
assignment = make_assignment(&deref->node, ASSIGN_OP_ASSIGN, BWRITERSP_WRITEMASK_ALL, v->initializer.args[0]); d3dcompiler_free(v->initializer.args); list_add_tail(statements_list, &assignment->entry);
@@ -880,6 +881,35 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr return NULL; }
+static struct list *append_unop(struct list *list, struct hlsl_ir_node *node) +{
- list_add_tail(list, &node->entry);
- return list;
+}
+static struct list *append_binop(struct list *first, struct list *second, struct hlsl_ir_node *node) +{
- list_move_tail(first, second);
- d3dcompiler_free(second);
- list_add_tail(first, &node->entry);
- return first;
+}
+static struct list *make_list(struct hlsl_ir_node *node) +{
- struct list *list;
- if (!(list = d3dcompiler_alloc(sizeof(*list))))
- {
ERR("Out of memory.\n");
free_instr(node);
return NULL;
- }
- list_init(list);
- list_add_tail(list, &node->entry);
- return list;
+}
%}
%locations @@ -1024,12 +1054,12 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr %type <variable_def> type_spec %type <initializer> complex_initializer %type <initializer> initializer_expr_list -%type <instr> initializer_expr +%type <list> initializer_expr %type <modifiers> var_modifiers %type <list> field %type <list> parameters %type <list> param_list -%type <instr> expr +%type <list> expr %type <intval> array %type <list> statement %type <list> statement_list @@ -1048,21 +1078,21 @@ static const struct hlsl_ir_function_decl *get_overloaded_func(struct wine_rb_tr %type <list> variables_def %type <list> variables_def_optional %type <if_body> if_body -%type <instr> primary_expr -%type <instr> postfix_expr -%type <instr> unary_expr -%type <instr> mul_expr -%type <instr> add_expr -%type <instr> shift_expr -%type <instr> relational_expr -%type <instr> equality_expr -%type <instr> bitand_expr -%type <instr> bitxor_expr -%type <instr> bitor_expr -%type <instr> logicand_expr -%type <instr> logicor_expr -%type <instr> conditional_expr -%type <instr> assignment_expr +%type <list> primary_expr +%type <list> postfix_expr +%type <list> unary_expr +%type <list> mul_expr +%type <list> add_expr +%type <list> shift_expr +%type <list> relational_expr +%type <list> equality_expr +%type <list> bitand_expr +%type <list> bitxor_expr +%type <list> bitor_expr +%type <list> logicand_expr +%type <list> logicor_expr +%type <list> conditional_expr +%type <list> assignment_expr %type <list> expr_statement %type <unary_op> unary_op %type <assign_op> assign_op @@ -1615,7 +1645,7 @@ array: /* Empty */ { FIXME("Array.\n"); $$ = 0;
free_instr($2);
free_instr_list($2); }
var_modifiers: /* Empty */ @@ -1672,7 +1702,8 @@ complex_initializer: initializer_expr $$.args_count = 1; if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) YYABORT;
$$.args[0] = $1;
$$.args[0] = node_from_list($1);
$$.instrs = $1; } | '{' initializer_expr_list '}' {
@@ -1693,14 +1724,17 @@ initializer_expr_list: initializer_expr $$.args_count = 1; if (!($$.args = d3dcompiler_alloc(sizeof(*$$.args)))) YYABORT;
$$.args[0] = $1;
$$.args[0] = node_from_list($1);
$$.instrs = $1; } | initializer_expr_list ',' initializer_expr { $$ = $1; if (!($$.args = d3dcompiler_realloc($$.args, ($$.args_count + 1) * sizeof(*$$.args)))) YYABORT;
$$.args[$$.args_count++] = $3;
$$.args[$$.args_count++] = node_from_list($3);
list_move_tail($$.instrs, $3);
d3dcompiler_free($3); }
boolean: KW_TRUE @@ -1742,16 +1776,14 @@ jump_statement: KW_RETURN expr ';' jump->node.type = HLSL_IR_JUMP; set_location(&jump->node.loc, &@1); jump->type = HLSL_IR_JUMP_RETURN;
jump->node.data_type = $2->data_type;
jump->return_value = $2;
jump->node.data_type = node_from_list($2)->data_type;
jump->return_value = node_from_list($2); FIXME("Check for valued return on void function.\n"); FIXME("Implicit conversion to the return type if needed, " "error out if conversion not possible.\n");
$$ = d3dcompiler_alloc(sizeof(*$$));
list_init($$);
list_add_tail($$, &jump->node.entry);
$$ = append_unop($2, &jump->node);
I'm a bit thrown off by the use of append_unop() here (and for the "if" below): jump technically isn't a unary operator (expression). Maybe just do an explicit list_add_tail() like the previous code? I don't think you have to necessarily take this suggestion, I suspect I might not get the same uneasiness next time I read the patch...
Functionally it works the same way as e.g. "!", with the exception that it doesn't return a value. So, yeah, it's not particularly right to call it an operator, but we still want to return the list to the "statement" rule. I'd suggest renaming append_unop in that case, but I'm not really sure what to rename it to. Maybe just "append_unary"? Or maybe spelling out append_unop() is the best solution.
}
selection_statement: KW_IF '(' expr ')' if_body @@ -1764,18 +1796,16 @@ selection_statement: KW_IF '(' expr ')' if_body } instr->node.type = HLSL_IR_IF; set_location(&instr->node.loc, &@1);
instr->condition = $3;
instr->condition = node_from_list($3); instr->then_instrs = $5.then_instrs; instr->else_instrs = $5.else_instrs;
if ($3->data_type->dimx > 1 || $3->data_type->dimy > 1)
if (instr->condition->data_type->dimx > 1 || instr->condition->data_type->dimy > 1) { hlsl_report_message(instr->node.loc.file, instr->node.loc.line, instr->node.loc.col, HLSL_LEVEL_ERROR, "if condition requires a scalar"); }
$$ = d3dcompiler_alloc(sizeof(*$$));
list_init($$);
list_add_head($$, &instr->node.entry);
$$ = append_unop($3, &instr->node); }
if_body: statement @@ -1792,32 +1822,14 @@ if_body: statement loop_statement: KW_WHILE '(' expr ')' statement { struct source_location loc;
struct list *cond = d3dcompiler_alloc(sizeof(*cond));
if (!cond)
{
ERR("Out of memory.\n");
YYABORT;
}
list_init(cond);
list_add_head(cond, &$3->entry); set_location(&loc, &@1);
$$ = create_loop(LOOP_WHILE, NULL, cond, NULL, $5, &loc);
$$ = create_loop(LOOP_WHILE, NULL, $3, NULL, $5, &loc); } | KW_DO statement KW_WHILE '(' expr ')' ';' { struct source_location loc;
struct list *cond = d3dcompiler_alloc(sizeof(*cond));
if (!cond)
{
ERR("Out of memory.\n");
YYABORT;
}
list_init(cond);
list_add_head(cond, &$5->entry); set_location(&loc, &@1);
$$ = create_loop(LOOP_DO_WHILE, NULL, cond, NULL, $2, &loc);
$$ = create_loop(LOOP_DO_WHILE, NULL, $5, NULL, $2, &loc); } | KW_FOR '(' scope_start expr_statement expr_statement expr ')' statement {
@@ -1846,10 +1858,7 @@ expr_statement: ';' } | expr ';' {
$$ = d3dcompiler_alloc(sizeof(*$$));
list_init($$);
if ($1)
list_add_head($$, &$1->entry);
$$ = $1; }
primary_expr: C_FLOAT @@ -1864,7 +1873,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("float"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1); c->v.value.f[0] = $1;
$$ = &c->node;
if (!($$ = make_list(&c->node)))
YYABORT; } | C_INTEGER {
@@ -1878,7 +1888,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("int"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1); c->v.value.i[0] = $1;
$$ = &c->node;
if (!($$ = make_list(&c->node)))
YYABORT; } | boolean {
@@ -1892,7 +1903,8 @@ primary_expr: C_FLOAT set_location(&c->node.loc, &yylloc); c->node.data_type = new_hlsl_type(d3dcompiler_strdup("bool"), HLSL_CLASS_SCALAR, HLSL_TYPE_BOOL, 1, 1); c->v.value.b[0] = $1;
$$ = &c->node;
if (!($$ = make_list(&c->node)))
YYABORT; } | VAR_IDENTIFIER {
@@ -1908,8 +1920,9 @@ primary_expr: C_FLOAT } if ((deref = new_var_deref(var))) {
$$ = &deref->node;
set_location(&$$->loc, &@1);
set_location(&deref->node.loc, &@1);
if (!($$ = make_list(&deref->node)))
YYABORT; } else $$ = NULL;
@@ -1926,43 +1939,47 @@ postfix_expr: primary_expr | postfix_expr OP_INC { struct source_location loc;
struct hlsl_ir_node *inc; set_location(&loc, &@2);
if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; }
$$ = new_unary_expr(HLSL_IR_UNOP_POSTINC, $1, loc);
inc = new_unary_expr(HLSL_IR_UNOP_POSTINC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */
$$->data_type = clone_hlsl_type($$->data_type);
$$->data_type->modifiers |= HLSL_MODIFIER_CONST;
inc->data_type = clone_hlsl_type(inc->data_type);
inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
$$ = append_unop($1, inc); } | postfix_expr OP_DEC { struct source_location loc;
struct hlsl_ir_node *inc; set_location(&loc, &@2);
if ($1->data_type->modifiers & HLSL_MODIFIER_CONST)
if (node_from_list($1)->data_type->modifiers & HLSL_MODIFIER_CONST) { hlsl_report_message(loc.file, loc.line, loc.col, HLSL_LEVEL_ERROR, "modifying a const expression"); YYABORT; }
$$ = new_unary_expr(HLSL_IR_UNOP_POSTDEC, $1, loc);
inc = new_unary_expr(HLSL_IR_UNOP_POSTDEC, node_from_list($1), loc); /* Post increment/decrement expressions are considered const */
$$->data_type = clone_hlsl_type($$->data_type);
$$->data_type->modifiers |= HLSL_MODIFIER_CONST;
inc->data_type = clone_hlsl_type(inc->data_type);
inc->data_type->modifiers |= HLSL_MODIFIER_CONST;
$$ = append_unop($1, inc); } | postfix_expr '.' any_identifier { struct source_location loc; set_location(&loc, &@2);
if ($1->data_type->type == HLSL_CLASS_STRUCT)
if (node_from_list($1)->data_type->type == HLSL_CLASS_STRUCT) {
struct hlsl_type *type = $1->data_type;
struct hlsl_type *type = node_from_list($1)->data_type; struct hlsl_struct_field *field; $$ = NULL;
It might be nicer to store the result of node_from_list($1) in a local variable and use it through.
Agreed; will do.
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/utils.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 4dc2e048808..0a097138c69 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1787,6 +1787,11 @@ static void debug_dump_instr_list(const struct list *list) } }
+static void debug_dump_src(const struct hlsl_ir_node *node) +{ + TRACE("%p", node); +} + static void debug_dump_ir_var(const struct hlsl_ir_var *var) { if (var->modifiers) @@ -1806,13 +1811,13 @@ static void debug_dump_ir_deref(const struct hlsl_ir_deref *deref) TRACE(")"); break; case HLSL_IR_DEREF_ARRAY: - debug_dump_instr(deref->v.array.array); + debug_dump_src(deref->v.array.array); TRACE("["); - debug_dump_instr(deref->v.array.index); + debug_dump_src(deref->v.array.index); TRACE("]"); break; case HLSL_IR_DEREF_RECORD: - debug_dump_instr(deref->v.record.record); + debug_dump_src(deref->v.record.record); TRACE(".%s", debugstr_a(deref->v.record.field->name)); break; } @@ -1943,7 +1948,7 @@ static void debug_dump_ir_expr(const struct hlsl_ir_expr *expr) TRACE("%s (", debug_expr_op(expr)); for (i = 0; i < 3 && expr->operands[i]; ++i) { - debug_dump_instr(expr->operands[i]); + debug_dump_src(expr->operands[i]); TRACE(" "); } TRACE(")"); @@ -1956,7 +1961,7 @@ static void debug_dump_ir_constructor(const struct hlsl_ir_constructor *construc TRACE("%s (", debug_hlsl_type(constructor->node.data_type)); for (i = 0; i < constructor->args_count; ++i) { - debug_dump_instr(constructor->args[i]); + debug_dump_src(constructor->args[i]); TRACE(" "); } TRACE(")"); @@ -1984,11 +1989,11 @@ static const char *debug_writemask(DWORD writemask) static void debug_dump_ir_assignment(const struct hlsl_ir_assignment *assign) { TRACE("= ("); - debug_dump_instr(assign->lhs); + debug_dump_src(assign->lhs); if (assign->writemask != BWRITERSP_WRITEMASK_ALL) TRACE("%s", debug_writemask(assign->writemask)); TRACE(" "); - debug_dump_instr(assign->rhs); + debug_dump_src(assign->rhs); TRACE(")"); }
@@ -1996,7 +2001,7 @@ static void debug_dump_ir_swizzle(const struct hlsl_ir_swizzle *swizzle) { unsigned int i;
- debug_dump_instr(swizzle->val); + debug_dump_src(swizzle->val); TRACE("."); if (swizzle->val->data_type->dimy > 1) { @@ -2028,7 +2033,7 @@ static void debug_dump_ir_jump(const struct hlsl_ir_jump *jump) case HLSL_IR_JUMP_RETURN: TRACE("return "); if (jump->return_value) - debug_dump_instr(jump->return_value); + debug_dump_src(jump->return_value); TRACE(";"); break; } @@ -2037,7 +2042,7 @@ static void debug_dump_ir_jump(const struct hlsl_ir_jump *jump) static void debug_dump_ir_if(const struct hlsl_ir_if *if_node) { TRACE("if ("); - debug_dump_instr(if_node->condition); + debug_dump_src(if_node->condition); TRACE(")\n{\n"); debug_dump_instr_list(if_node->then_instrs); TRACE("}\n"); @@ -2051,6 +2056,7 @@ static void debug_dump_ir_if(const struct hlsl_ir_if *if_node)
static void debug_dump_instr(const struct hlsl_ir_node *instr) { + TRACE("%p: ", instr); switch (instr->type) { case HLSL_IR_EXPR:
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
From: Zebediah Figura zfigura@codeweavers.com
So that we don't print function names.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/utils.c | 92 ++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 46 deletions(-)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 0a097138c69..5239bf22b54 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1783,22 +1783,22 @@ static void debug_dump_instr_list(const struct list *list) LIST_FOR_EACH_ENTRY(instr, list, struct hlsl_ir_node, entry) { debug_dump_instr(instr); - TRACE("\n"); + wine_dbg_printf("\n"); } }
static void debug_dump_src(const struct hlsl_ir_node *node) { - TRACE("%p", node); + wine_dbg_printf("%p", node); }
static void debug_dump_ir_var(const struct hlsl_ir_var *var) { if (var->modifiers) - TRACE("%s ", debug_modifiers(var->modifiers)); - TRACE("%s %s", debug_hlsl_type(var->data_type), var->name); + wine_dbg_printf("%s ", debug_modifiers(var->modifiers)); + wine_dbg_printf("%s %s", debug_hlsl_type(var->data_type), var->name); if (var->semantic) - TRACE(" : %s", debugstr_a(var->semantic)); + wine_dbg_printf(" : %s", debugstr_a(var->semantic)); }
static void debug_dump_ir_deref(const struct hlsl_ir_deref *deref) @@ -1806,19 +1806,19 @@ static void debug_dump_ir_deref(const struct hlsl_ir_deref *deref) switch (deref->type) { case HLSL_IR_DEREF_VAR: - TRACE("deref("); + wine_dbg_printf("deref("); debug_dump_ir_var(deref->v.var); - TRACE(")"); + wine_dbg_printf(")"); break; case HLSL_IR_DEREF_ARRAY: debug_dump_src(deref->v.array.array); - TRACE("["); + wine_dbg_printf("["); debug_dump_src(deref->v.array.index); - TRACE("]"); + wine_dbg_printf("]"); break; case HLSL_IR_DEREF_RECORD: debug_dump_src(deref->v.record.record); - TRACE(".%s", debugstr_a(deref->v.record.field->name)); + wine_dbg_printf(".%s", debugstr_a(deref->v.record.field->name)); break; } } @@ -1829,39 +1829,39 @@ static void debug_dump_ir_constant(const struct hlsl_ir_constant *constant) unsigned int x, y;
if (type->dimy != 1) - TRACE("{"); + wine_dbg_printf("{"); for (y = 0; y < type->dimy; ++y) { if (type->dimx != 1) - TRACE("{"); + wine_dbg_printf("{"); for (x = 0; x < type->dimx; ++x) { switch (type->base_type) { case HLSL_TYPE_FLOAT: - TRACE("%g ", (double)constant->v.value.f[y * type->dimx + x]); + wine_dbg_printf("%g ", (double)constant->v.value.f[y * type->dimx + x]); break; case HLSL_TYPE_DOUBLE: - TRACE("%g ", constant->v.value.d[y * type->dimx + x]); + wine_dbg_printf("%g ", constant->v.value.d[y * type->dimx + x]); break; case HLSL_TYPE_INT: - TRACE("%d ", constant->v.value.i[y * type->dimx + x]); + wine_dbg_printf("%d ", constant->v.value.i[y * type->dimx + x]); break; case HLSL_TYPE_UINT: - TRACE("%u ", constant->v.value.u[y * type->dimx + x]); + wine_dbg_printf("%u ", constant->v.value.u[y * type->dimx + x]); break; case HLSL_TYPE_BOOL: - TRACE("%s ", constant->v.value.b[y * type->dimx + x] == FALSE ? "false" : "true"); + wine_dbg_printf("%s ", constant->v.value.b[y * type->dimx + x] == FALSE ? "false" : "true"); break; default: - TRACE("Constants of type %s not supported\n", debug_base_type(type)); + wine_dbg_printf("Constants of type %s not supported\n", debug_base_type(type)); } } if (type->dimx != 1) - TRACE("}"); + wine_dbg_printf("}"); } if (type->dimy != 1) - TRACE("}"); + wine_dbg_printf("}"); }
static const char *debug_expr_op(const struct hlsl_ir_expr *expr) @@ -1945,26 +1945,26 @@ static void debug_dump_ir_expr(const struct hlsl_ir_expr *expr) { unsigned int i;
- TRACE("%s (", debug_expr_op(expr)); + wine_dbg_printf("%s (", debug_expr_op(expr)); for (i = 0; i < 3 && expr->operands[i]; ++i) { debug_dump_src(expr->operands[i]); - TRACE(" "); + wine_dbg_printf(" "); } - TRACE(")"); + wine_dbg_printf(")"); }
static void debug_dump_ir_constructor(const struct hlsl_ir_constructor *constructor) { unsigned int i;
- TRACE("%s (", debug_hlsl_type(constructor->node.data_type)); + wine_dbg_printf("%s (", debug_hlsl_type(constructor->node.data_type)); for (i = 0; i < constructor->args_count; ++i) { debug_dump_src(constructor->args[i]); - TRACE(" "); + wine_dbg_printf(" "); } - TRACE(")"); + wine_dbg_printf(")"); }
static const char *debug_writemask(DWORD writemask) @@ -1988,13 +1988,13 @@ static const char *debug_writemask(DWORD writemask)
static void debug_dump_ir_assignment(const struct hlsl_ir_assignment *assign) { - TRACE("= ("); + wine_dbg_printf("= ("); debug_dump_src(assign->lhs); if (assign->writemask != BWRITERSP_WRITEMASK_ALL) - TRACE("%s", debug_writemask(assign->writemask)); - TRACE(" "); + wine_dbg_printf("%s", debug_writemask(assign->writemask)); + wine_dbg_printf(" "); debug_dump_src(assign->rhs); - TRACE(")"); + wine_dbg_printf(")"); }
static void debug_dump_ir_swizzle(const struct hlsl_ir_swizzle *swizzle) @@ -2002,18 +2002,18 @@ static void debug_dump_ir_swizzle(const struct hlsl_ir_swizzle *swizzle) unsigned int i;
debug_dump_src(swizzle->val); - TRACE("."); + wine_dbg_printf("."); if (swizzle->val->data_type->dimy > 1) { for (i = 0; i < swizzle->node.data_type->dimx; ++i) - TRACE("_m%u%u", (swizzle->swizzle >> i * 8) & 0xf, (swizzle->swizzle >> (i * 8 + 4)) & 0xf); + wine_dbg_printf("_m%u%u", (swizzle->swizzle >> i * 8) & 0xf, (swizzle->swizzle >> (i * 8 + 4)) & 0xf); } else { static const char c[] = {'x', 'y', 'z', 'w'};
for (i = 0; i < swizzle->node.data_type->dimx; ++i) - TRACE("%c", c[(swizzle->swizzle >> i * 2) & 0x3]); + wine_dbg_printf("%c", c[(swizzle->swizzle >> i * 2) & 0x3]); } }
@@ -2022,41 +2022,41 @@ static void debug_dump_ir_jump(const struct hlsl_ir_jump *jump) switch (jump->type) { case HLSL_IR_JUMP_BREAK: - TRACE("break"); + wine_dbg_printf("break"); break; case HLSL_IR_JUMP_CONTINUE: - TRACE("continue"); + wine_dbg_printf("continue"); break; case HLSL_IR_JUMP_DISCARD: - TRACE("discard"); + wine_dbg_printf("discard"); break; case HLSL_IR_JUMP_RETURN: - TRACE("return "); + wine_dbg_printf("return "); if (jump->return_value) debug_dump_src(jump->return_value); - TRACE(";"); + wine_dbg_printf(";"); break; } }
static void debug_dump_ir_if(const struct hlsl_ir_if *if_node) { - TRACE("if ("); + wine_dbg_printf("if ("); debug_dump_src(if_node->condition); - TRACE(")\n{\n"); + wine_dbg_printf(")\n{\n"); debug_dump_instr_list(if_node->then_instrs); - TRACE("}\n"); + wine_dbg_printf("}\n"); if (if_node->else_instrs) { - TRACE("else\n{\n"); + wine_dbg_printf("else\n{\n"); debug_dump_instr_list(if_node->else_instrs); - TRACE("}\n"); + wine_dbg_printf("}\n"); } }
static void debug_dump_instr(const struct hlsl_ir_node *instr) { - TRACE("%p: ", instr); + wine_dbg_printf("%p: ", instr); switch (instr->type) { case HLSL_IR_EXPR: @@ -2084,7 +2084,7 @@ static void debug_dump_instr(const struct hlsl_ir_node *instr) debug_dump_ir_if(if_from_node(instr)); break; default: - TRACE("<No dump function for %s>", debug_node_type(instr->type)); + wine_dbg_printf("<No dump function for %s>", debug_node_type(instr->type)); } }
@@ -2097,7 +2097,7 @@ void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl *func) LIST_FOR_EACH_ENTRY(param, func->parameters, struct hlsl_ir_var, param_entry) { debug_dump_ir_var(param); - TRACE("\n"); + wine_dbg_printf("\n"); } if (func->semantic) TRACE("Function semantic: %s\n", debugstr_a(func->semantic));
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/utils.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 5239bf22b54..3f5a57ffa40 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1765,6 +1765,7 @@ static const char *debug_node_type(enum hlsl_ir_node_type type) "HLSL_IR_DEREF", "HLSL_IR_EXPR", "HLSL_IR_IF", + "HLSL_IR_LOOP", "HLSL_IR_JUMP", "HLSL_IR_SWIZZLE", }; @@ -2054,6 +2055,13 @@ static void debug_dump_ir_if(const struct hlsl_ir_if *if_node) } }
+static void debug_dump_ir_loop(const struct hlsl_ir_loop *loop) +{ + wine_dbg_printf("for (;;)\n{\n"); + debug_dump_instr_list(loop->body); + wine_dbg_printf("}\n"); +} + static void debug_dump_instr(const struct hlsl_ir_node *instr) { wine_dbg_printf("%p: ", instr); @@ -2083,6 +2091,9 @@ static void debug_dump_instr(const struct hlsl_ir_node *instr) case HLSL_IR_IF: debug_dump_ir_if(if_from_node(instr)); break; + case HLSL_IR_LOOP: + debug_dump_ir_loop(loop_from_node(instr)); + break; default: wine_dbg_printf("<No dump function for %s>", debug_node_type(instr->type)); }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
On Wed, Feb 5, 2020 at 9:53 PM Zebediah Figura z.figura12@gmail.com wrote:
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/d3dcompiler_43/asmshader.y | 4 +-- dlls/d3dcompiler_43/bytecodewriter.c | 6 +--- dlls/d3dcompiler_43/d3dcompiler_private.h | 38 +++++++++++------------ dlls/d3dcompiler_43/utils.c | 8 ++--- 4 files changed, 26 insertions(+), 30 deletions(-)
diff --git a/dlls/d3dcompiler_43/asmshader.y b/dlls/d3dcompiler_43/asmshader.y index 32b37d0885d..1b7a07313fc 100644 --- a/dlls/d3dcompiler_43/asmshader.y +++ b/dlls/d3dcompiler_43/asmshader.y @@ -1148,11 +1148,11 @@ swizzle: /* empty */ else { DWORD last, i;
$$ = $2.swizzle << BWRITERVS_SWIZZLE_SHIFT;
$$ = $2.swizzle; /* Fill the swizzle by extending the last component */ last = ($2.swizzle >> 2 * ($2.idx - 1)) & 0x03; for(i = $2.idx; i < 4; i++){
$$ |= last << (BWRITERVS_SWIZZLE_SHIFT + 2 * i);
$$ |= last << (2 * i); } TRACE("Got a swizzle: %08x\n", $$); }
diff --git a/dlls/d3dcompiler_43/bytecodewriter.c b/dlls/d3dcompiler_43/bytecodewriter.c index 14162ab212b..42013dfba3f 100644 --- a/dlls/d3dcompiler_43/bytecodewriter.c +++ b/dlls/d3dcompiler_43/bytecodewriter.c @@ -342,8 +342,6 @@ static void put_dword(struct bytecode_buffer *buffer, DWORD value) { /* bwriter -> d3d9 conversion functions. */ static DWORD d3d9_swizzle(DWORD bwriter_swizzle) {
/* Currently a NOP, but this allows changing the internal definitions
* without side effects. */
DWORD ret = 0;
if ((bwriter_swizzle & BWRITERVS_X_X) == BWRITERVS_X_X) ret |= D3DVS_X_X;
@@ -1270,9 +1268,7 @@ static void instr_ps_1_0123_texld(struct bc_writer *This, This->funcs->dstreg(This, &instr->dst, buffer, instr->shift, instr->dstmod); } else if(instr->src[0].type == BWRITERSPR_TEMP) {
swizzlemask = (3 << BWRITERVS_SWIZZLE_SHIFT) |
(3 << (BWRITERVS_SWIZZLE_SHIFT + 2)) |
(3 << (BWRITERVS_SWIZZLE_SHIFT + 4));
swizzlemask = 3 | (3 << 2) | (3 << 4); if((instr->src[0].u.swizzle & swizzlemask) == (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z)) { TRACE("writing texreg2rgb\n"); This->funcs->opcode(This, instr, D3DSIO_TEXREG2RGB & D3DSI_OPCODE_MASK, buffer);
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 45dbff7225b..5fc3161f5f0 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -542,25 +542,25 @@ enum bwritershader_param_srcmod_type #define BWRITERVS_SWIZZLE_SHIFT 16 #define BWRITERVS_SWIZZLE_MASK (0xFF << BWRITERVS_SWIZZLE_SHIFT)
-#define BWRITERVS_X_X (0 << BWRITERVS_SWIZZLE_SHIFT) -#define BWRITERVS_X_Y (1 << BWRITERVS_SWIZZLE_SHIFT) -#define BWRITERVS_X_Z (2 << BWRITERVS_SWIZZLE_SHIFT) -#define BWRITERVS_X_W (3 << BWRITERVS_SWIZZLE_SHIFT)
-#define BWRITERVS_Y_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 2)) -#define BWRITERVS_Y_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 2)) -#define BWRITERVS_Y_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 2)) -#define BWRITERVS_Y_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
-#define BWRITERVS_Z_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 4)) -#define BWRITERVS_Z_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 4)) -#define BWRITERVS_Z_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 4)) -#define BWRITERVS_Z_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
-#define BWRITERVS_W_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 6)) -#define BWRITERVS_W_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 6)) -#define BWRITERVS_W_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 6)) -#define BWRITERVS_W_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 6)) +#define BWRITERVS_X_X (0) +#define BWRITERVS_X_Y (1) +#define BWRITERVS_X_Z (2) +#define BWRITERVS_X_W (3)
+#define BWRITERVS_Y_X (0 << 2) +#define BWRITERVS_Y_Y (1 << 2) +#define BWRITERVS_Y_Z (2 << 2) +#define BWRITERVS_Y_W (3 << 2)
+#define BWRITERVS_Z_X (0 << 4) +#define BWRITERVS_Z_Y (1 << 4) +#define BWRITERVS_Z_Z (2 << 4) +#define BWRITERVS_Z_W (3 << 4)
+#define BWRITERVS_W_X (0 << 6) +#define BWRITERVS_W_Y (1 << 6) +#define BWRITERVS_W_Z (2 << 6) +#define BWRITERVS_W_W (3 << 6)
#define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 1436ed6bf3e..b2b1e25bbdc 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -291,10 +291,10 @@ static const char *debug_print_swizzle(DWORD arg) return ".w"; }
- swizzle[0] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 0)) & 0x03;
- swizzle[1] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 2)) & 0x03;
- swizzle[2] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 4)) & 0x03;
- swizzle[3] = (arg >> (BWRITERVS_SWIZZLE_SHIFT + 6)) & 0x03;
swizzle[0] = arg & 3;
swizzle[1] = (arg >> 2) & 3;
swizzle[2] = (arg >> 4) & 3;
swizzle[3] = (arg >> 6) & 3;
ret[0] = '.'; for (i = 0; i < 4; ++i)
-- 2.25.0
Now BWRITERVS_SWIZZLE_SHIFT and BWRITERVS_SWIZZLE_MASK are unused. Are you going to need them in the future or can they just be dropped?
It was already the case before but this patch made it more obvious (at least to my simple script).
Both BWRITERVS_X_X and D3DVS_X_X are 0:
#define BWRITERVS_X_X (0) #define D3DVS_X_X (0 << D3DVS_SWIZZLE_SHIFT)
So this line in d3d9_swizzle() from dlls/d3dcompiler_43/bytecodewriter.c does nothing at all:
if ((bwriter_swizzle & BWRITERVS_X_X) == BWRITERVS_X_X) ret |= D3DVS_X_X;
Just to be sure, is this really what was intended? I guess having this line is nice for symmetry with the ones that follow but would it be better / less confusing to comment it out?
On Sat, Feb 15, 2020 at 1:12 PM Francois Gouget fgouget@free.fr wrote:
It was already the case before but this patch made it more obvious (at least to my simple script).
Both BWRITERVS_X_X and D3DVS_X_X are 0:
#define BWRITERVS_X_X (0) #define D3DVS_X_X (0 << D3DVS_SWIZZLE_SHIFT)
So this line in d3d9_swizzle() from dlls/d3dcompiler_43/bytecodewriter.c does nothing at all:
if ((bwriter_swizzle & BWRITERVS_X_X) == BWRITERVS_X_X) ret |= D3DVS_X_X;
Just to be sure, is this really what was intended? I guess having this line is nice for symmetry with the ones that follow but would it be better / less confusing to comment it out?
It looks like I haven't replied yet, better late than never I guess...
I don't think there is anything wrong with it. That it does nothing in practice is just an implementation detail caused by the fact that both defines are 0, but the user shouldn't need to know that. To me, commenting it out would be MORE confusing, in fact.
FWIW before this patch the whole function did exactly nothing at all. But since it was here in the first place we could now change those defines without having to update all the callers of the function.