Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/utils.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index ec0da2d4034..97e3cdf1a3f 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1294,6 +1294,8 @@ static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type } }
+ if (type == HLSL_CLASS_SCALAR) + return hlsl_ctx.builtin_types.scalar[base]; return new_hlsl_type(NULL, type, base, dimx, dimy); }
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 1 + dlls/d3dcompiler_43/hlsl.y | 1 + dlls/d3dcompiler_43/utils.c | 12 +++--------- 3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index a61b84d6b54..970150bbc5b 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -988,6 +988,7 @@ struct hlsl_parse_ctx struct { struct hlsl_type *scalar[HLSL_TYPE_LAST_SCALAR + 1]; + struct hlsl_type *vector[HLSL_TYPE_LAST_SCALAR + 1][4]; struct hlsl_type *sampler[HLSL_SAMPLER_DIM_MAX + 1]; struct hlsl_type *Void; } builtin_types; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 436b731fd16..83aa95b54fc 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -237,6 +237,7 @@ static void declare_predefined_types(struct hlsl_scope *scope) sprintf(name, "%s%u", names[bt], x); type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_VECTOR, bt, x, y); add_type_to_scope(scope, type); + hlsl_ctx.builtin_types.vector[bt][x - 1] = type;
if (x == 1) { diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 97e3cdf1a3f..bbce2aaca56 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1296,6 +1296,8 @@ static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type
if (type == HLSL_CLASS_SCALAR) return hlsl_ctx.builtin_types.scalar[base]; + else if (type == HLSL_CLASS_VECTOR) + return hlsl_ctx.builtin_types.vector[base][dimx - 1]; return new_hlsl_type(NULL, type, base, dimx, dimy); }
@@ -1495,15 +1497,7 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *lhs, enum parse_assign } assert(swizzle_type->type == HLSL_CLASS_VECTOR); if (swizzle_type->dimx != width) - { - struct hlsl_type *type; - if (!(type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, swizzle_type->base_type, width, 1))) - { - d3dcompiler_free(assign); - return NULL; - } - swizzle->node.data_type = type; - } + swizzle->node.data_type = hlsl_ctx.builtin_types.vector[swizzle_type->base_type][width - 1]; rhs = &swizzle->node; } else
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v3: use components_count_type(), and cast to the appropriate type
dlls/d3dcompiler_43/d3dcompiler_private.h | 14 --- dlls/d3dcompiler_43/hlsl.y | 112 ++++++++++++++-------- dlls/d3dcompiler_43/utils.c | 25 ----- 3 files changed, 70 insertions(+), 81 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 970150bbc5b..0002a070cca 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -648,7 +648,6 @@ enum hlsl_ir_node_type { HLSL_IR_ASSIGNMENT = 0, HLSL_IR_CONSTANT, - HLSL_IR_CONSTRUCTOR, HLSL_IR_EXPR, HLSL_IR_IF, HLSL_IR_LOAD, @@ -880,13 +879,6 @@ struct hlsl_ir_constant } v; };
-struct hlsl_ir_constructor -{ - struct hlsl_ir_node node; - struct hlsl_ir_node *args[16]; - unsigned int args_count; -}; - struct hlsl_scope { struct list entry; @@ -1043,12 +1035,6 @@ static inline struct hlsl_ir_swizzle *swizzle_from_node(const struct hlsl_ir_nod return CONTAINING_RECORD(node, struct hlsl_ir_swizzle, node); }
-static inline struct hlsl_ir_constructor *constructor_from_node(const struct hlsl_ir_node *node) -{ - assert(node->type == HLSL_IR_CONSTRUCTOR); - return CONTAINING_RECORD(node, struct hlsl_ir_constructor, node); -} - static inline struct hlsl_ir_if *if_from_node(const struct hlsl_ir_node *node) { assert(node->type == HLSL_IR_IF); diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 83aa95b54fc..d8e711795eb 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -1245,7 +1245,6 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node) return 0; } } - case HLSL_IR_CONSTRUCTOR: case HLSL_IR_EXPR: case HLSL_IR_LOAD: case HLSL_IR_SWIZZLE: @@ -2416,41 +2415,78 @@ postfix_expr: primary_expr } $$ = append_binop($1, $3, &load->node); } - /* "var_modifiers" doesn't make sense in this case, but it's needed - in the grammar to avoid shift/reduce conflicts. */ - | var_modifiers type '(' initializer_expr_list ')' - { - struct hlsl_ir_constructor *constructor;
- TRACE("%s constructor.\n", debug_hlsl_type($2)); - if ($1) - { - hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR, - "unexpected modifier on a constructor\n"); - YYABORT; - } - if ($2->type > HLSL_CLASS_LAST_NUMERIC) - { - hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR, - "constructors may only be used with numeric data types\n"); - YYABORT; - } - if ($2->dimx * $2->dimy != initializer_size(&$4)) - { - hlsl_report_message(get_location(&@4), HLSL_LEVEL_ERROR, - "expected %u components in constructor, but got %u\n", - $2->dimx * $2->dimy, initializer_size(&$4)); - YYABORT; - } - assert($4.args_count <= ARRAY_SIZE(constructor->args)); + /* "var_modifiers" doesn't make sense in this case, but it's needed + in the grammar to avoid shift/reduce conflicts. */ + | var_modifiers type '(' initializer_expr_list ')' + { + struct hlsl_ir_assignment *assignment; + unsigned int i, writemask_offset = 0; + static unsigned int counter; + struct hlsl_ir_load *load; + struct hlsl_ir_var *var; + char name[23];
- constructor = d3dcompiler_alloc(sizeof(*constructor)); - init_node(&constructor->node, HLSL_IR_CONSTRUCTOR, $2, get_location(&@3)); - constructor->args_count = $4.args_count; - memcpy(constructor->args, $4.args, $4.args_count * sizeof(*$4.args)); - d3dcompiler_free($4.args); - $$ = append_unop($4.instrs, &constructor->node); - } + if ($1) + { + hlsl_report_message(get_location(&@1), HLSL_LEVEL_ERROR, + "unexpected modifier on a constructor\n"); + YYABORT; + } + if ($2->type > HLSL_CLASS_LAST_NUMERIC) + { + hlsl_report_message(get_location(&@2), HLSL_LEVEL_ERROR, + "constructors may only be used with numeric data types\n"); + YYABORT; + } + if ($2->dimx * $2->dimy != initializer_size(&$4)) + { + hlsl_report_message(get_location(&@4), HLSL_LEVEL_ERROR, + "expected %u components in constructor, but got %u\n", + $2->dimx * $2->dimy, initializer_size(&$4)); + YYABORT; + } + + if ($2->type == HLSL_CLASS_MATRIX) + FIXME("Matrix constructors are not supported yet.\n"); + + sprintf(name, "<constructor-%x>", counter++); + if (!(var = new_synthetic_var(name, $2, get_location(&@2)))) + YYABORT; + for (i = 0; i < $4.args_count; ++i) + { + struct hlsl_ir_node *arg = $4.args[i]; + unsigned int width; + + if (arg->data_type->type == HLSL_CLASS_OBJECT) + { + hlsl_report_message(arg->loc, HLSL_LEVEL_ERROR, + "invalid constructor argument"); + continue; + } + width = components_count_type(arg->data_type); + + if (width > 4) + { + FIXME("Constructor argument with %u components.\n", width); + continue; + } + + if (!(arg = implicit_conversion(arg, + hlsl_ctx.builtin_types.vector[$2->base_type][width - 1], &arg->loc))) + continue; + + if (!(assignment = new_assignment(var, NULL, arg, + ((1 << width) - 1) << writemask_offset, arg->loc))) + YYABORT; + writemask_offset += width; + list_add_tail($4.instrs, &assignment->node.entry); + } + d3dcompiler_free($4.args); + if (!(load = new_var_load(var, get_location(&@2)))) + YYABORT; + $$ = append_unop($4.instrs, &load->node); + }
unary_expr: postfix_expr { @@ -2835,14 +2871,6 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs assignment->lhs.offset->last_read = instr->index; break; } - case HLSL_IR_CONSTRUCTOR: - { - struct hlsl_ir_constructor *constructor = constructor_from_node(instr); - unsigned int i; - for (i = 0; i < constructor->args_count; ++i) - constructor->args[i]->last_read = instr->index; - break; - } case HLSL_IR_EXPR: { struct hlsl_ir_expr *expr = expr_from_node(instr); diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index bbce2aaca56..63b1bccbd83 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1759,7 +1759,6 @@ const char *debug_node_type(enum hlsl_ir_node_type type) { "HLSL_IR_ASSIGNMENT", "HLSL_IR_CONSTANT", - "HLSL_IR_CONSTRUCTOR", "HLSL_IR_EXPR", "HLSL_IR_IF", "HLSL_IR_LOAD", @@ -1947,19 +1946,6 @@ static void debug_dump_ir_expr(const struct hlsl_ir_expr *expr) wine_dbg_printf(")"); }
-static void debug_dump_ir_constructor(const struct hlsl_ir_constructor *constructor) -{ - unsigned int i; - - 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]); - wine_dbg_printf(" "); - } - wine_dbg_printf(")"); -} - static const char *debug_writemask(DWORD writemask) { static const char components[] = {'x', 'y', 'z', 'w'}; @@ -2074,9 +2060,6 @@ static void debug_dump_instr(const struct hlsl_ir_node *instr) case HLSL_IR_SWIZZLE: debug_dump_ir_swizzle(swizzle_from_node(instr)); break; - case HLSL_IR_CONSTRUCTOR: - debug_dump_ir_constructor(constructor_from_node(instr)); - break; case HLSL_IR_JUMP: debug_dump_ir_jump(jump_from_node(instr)); break; @@ -2171,11 +2154,6 @@ static void free_ir_swizzle(struct hlsl_ir_swizzle *swizzle) d3dcompiler_free(swizzle); }
-static void free_ir_constructor(struct hlsl_ir_constructor *constructor) -{ - d3dcompiler_free(constructor); -} - static void free_ir_expr(struct hlsl_ir_expr *expr) { d3dcompiler_free(expr); @@ -2217,9 +2195,6 @@ void free_instr(struct hlsl_ir_node *node) case HLSL_IR_SWIZZLE: free_ir_swizzle(swizzle_from_node(node)); break; - case HLSL_IR_CONSTRUCTOR: - free_ir_constructor(constructor_from_node(node)); - break; case HLSL_IR_EXPR: free_ir_expr(expr_from_node(node)); break;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
On Mon, Jun 8, 2020 at 11:50 PM Zebediah Figura z.figura12@gmail.com wrote:
if ($2->type == HLSL_CLASS_MATRIX)
FIXME("Matrix constructors are not supported yet.\n");
sprintf(name, "<constructor-%x>", counter++);
if (!(var = new_synthetic_var(name, $2, get_location(&@2))))
YYABORT;
for (i = 0; i < $4.args_count; ++i)
{
struct hlsl_ir_node *arg = $4.args[i];
unsigned int width;
if (arg->data_type->type == HLSL_CLASS_OBJECT)
{
hlsl_report_message(arg->loc, HLSL_LEVEL_ERROR,
"invalid constructor argument");
continue;
}
width = components_count_type(arg->data_type);
if (width > 4)
{
FIXME("Constructor argument with %u components.\n", width);
continue;
}
if (!(arg = implicit_conversion(arg,
hlsl_ctx.builtin_types.vector[$2->base_type][width - 1], &arg->loc)))
continue;
if (!(assignment = new_assignment(var, NULL, arg,
((1 << width) - 1) << writemask_offset, arg->loc)))
YYABORT;
writemask_offset += width;
list_add_tail($4.instrs, &assignment->node.entry);
I'm still not sold on doing it like this. This generates nice code for vector constructors but it seems hard to extend to matrices in the future.
I'd do it component-by-component, generating swizzles as necessary. Any tidy up can be done by following passes, or not at all.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 17 +++++--------- dlls/d3dcompiler_43/hlsl.y | 18 +++++++-------- dlls/d3dcompiler_43/utils.c | 28 ++++------------------- 3 files changed, 20 insertions(+), 43 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 0002a070cca..9ac2f14041a 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -866,17 +866,12 @@ struct hlsl_ir_constant struct hlsl_ir_node node; union { - union - { - unsigned u[16]; - int i[16]; - float f[16]; - double d[16]; - BOOL b[16]; - } value; - struct hlsl_ir_constant *array_elements; - struct list *struct_elements; - } v; + unsigned u[16]; + int i[16]; + float f[16]; + double d[16]; + BOOL b[16]; + } value; };
struct hlsl_scope diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index d8e711795eb..79becca2578 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -590,7 +590,7 @@ static struct hlsl_ir_constant *new_uint_constant(unsigned int n, const struct s if (!(c = d3dcompiler_alloc(sizeof(*c)))) return NULL; init_node(&c->node, HLSL_IR_CONSTANT, hlsl_ctx.builtin_types.scalar[HLSL_TYPE_UINT], loc); - c->v.value.u[0] = n; + c->value.u[0] = n; return c; }
@@ -1231,15 +1231,15 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node) switch (constant->node.data_type->base_type) { case HLSL_TYPE_UINT: - return constant->v.value.u[0]; + return constant->value.u[0]; case HLSL_TYPE_INT: - return constant->v.value.i[0]; + return constant->value.i[0]; case HLSL_TYPE_FLOAT: - return constant->v.value.f[0]; + return constant->value.f[0]; case HLSL_TYPE_DOUBLE: - return constant->v.value.d[0]; + return constant->value.d[0]; case HLSL_TYPE_BOOL: - return constant->v.value.b[0]; + return constant->value.b[0]; default: WARN("Invalid type %s.\n", debug_base_type(constant->node.data_type)); return 0; @@ -2252,7 +2252,7 @@ primary_expr: C_FLOAT } init_node(&c->node, HLSL_IR_CONSTANT, hlsl_ctx.builtin_types.scalar[HLSL_TYPE_FLOAT], get_location(&@1)); - c->v.value.f[0] = $1; + c->value.f[0] = $1; if (!($$ = make_list(&c->node))) YYABORT; } @@ -2266,7 +2266,7 @@ primary_expr: C_FLOAT } init_node(&c->node, HLSL_IR_CONSTANT, hlsl_ctx.builtin_types.scalar[HLSL_TYPE_INT], get_location(&@1)); - c->v.value.i[0] = $1; + c->value.i[0] = $1; if (!($$ = make_list(&c->node))) YYABORT; } @@ -2280,7 +2280,7 @@ primary_expr: C_FLOAT } init_node(&c->node, HLSL_IR_CONSTANT, hlsl_ctx.builtin_types.scalar[HLSL_TYPE_BOOL], get_location(&@1)); - c->v.value.b[0] = $1; + c->value.b[0] = $1; if (!($$ = make_list(&c->node))) YYABORT; } diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 63b1bccbd83..9abdabbf2bc 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1831,19 +1831,19 @@ static void debug_dump_ir_constant(const struct hlsl_ir_constant *constant) switch (type->base_type) { case HLSL_TYPE_FLOAT: - wine_dbg_printf("%g ", (double)constant->v.value.f[y * type->dimx + x]); + wine_dbg_printf("%g ", (double)constant->value.f[y * type->dimx + x]); break; case HLSL_TYPE_DOUBLE: - wine_dbg_printf("%g ", constant->v.value.d[y * type->dimx + x]); + wine_dbg_printf("%g ", constant->value.d[y * type->dimx + x]); break; case HLSL_TYPE_INT: - wine_dbg_printf("%d ", constant->v.value.i[y * type->dimx + x]); + wine_dbg_printf("%d ", constant->value.i[y * type->dimx + x]); break; case HLSL_TYPE_UINT: - wine_dbg_printf("%u ", constant->v.value.u[y * type->dimx + x]); + wine_dbg_printf("%u ", constant->value.u[y * type->dimx + x]); break; case HLSL_TYPE_BOOL: - wine_dbg_printf("%s ", constant->v.value.b[y * type->dimx + x] == FALSE ? "false" : "true"); + wine_dbg_printf("%s ", constant->value.b[y * type->dimx + x] == FALSE ? "false" : "true"); break; default: wine_dbg_printf("Constants of type %s not supported\n", debug_base_type(type)); @@ -2123,24 +2123,6 @@ void free_instr_list(struct list *list)
static void free_ir_constant(struct hlsl_ir_constant *constant) { - struct hlsl_type *type = constant->node.data_type; - unsigned int i; - struct hlsl_ir_constant *field, *next_field; - - switch (type->type) - { - case HLSL_CLASS_ARRAY: - for (i = 0; i < type->e.array.elements_count; ++i) - free_ir_constant(&constant->v.array_elements[i]); - d3dcompiler_free(constant->v.array_elements); - break; - case HLSL_CLASS_STRUCT: - LIST_FOR_EACH_ENTRY_SAFE(field, next_field, constant->v.struct_elements, struct hlsl_ir_constant, node.entry) - free_ir_constant(field); - break; - default: - break; - } d3dcompiler_free(constant); }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v2: add another test
dlls/d3dcompiler_43/hlsl.y | 42 +++++++++++++++------------ dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 12 ++++++++ 2 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 79becca2578..b5057db8870 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -2971,24 +2971,6 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
hlsl_parse();
- TRACE("Compilation status = %d\n", hlsl_ctx.status); - if (messages) - { - if (hlsl_ctx.messages.size) - *messages = hlsl_ctx.messages.string; - else - *messages = NULL; - } - else - { - if (hlsl_ctx.messages.capacity) - d3dcompiler_free(hlsl_ctx.messages.string); - } - - for (i = 0; i < hlsl_ctx.source_files_count; ++i) - d3dcompiler_free((void *)hlsl_ctx.source_files[i]); - d3dcompiler_free(hlsl_ctx.source_files); - if (hlsl_ctx.status == PARSE_ERR) goto out;
@@ -2998,6 +2980,13 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino goto out; }
+ if (!type_is_void(entry_func->return_type) + && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic) + { + hlsl_report_message(entry_func->loc, HLSL_LEVEL_ERROR, + "entry point "%s" is missing a return value semantic", entry_func->func->name); + } + /* Index 0 means unused; index 1 means function entry, so start at 2. */ index_instructions(entry_func->body, 2);
@@ -3010,6 +2999,23 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino compute_liveness(entry_func);
out: + if (messages) + { + if (hlsl_ctx.messages.size) + *messages = hlsl_ctx.messages.string; + else + *messages = NULL; + } + else + { + if (hlsl_ctx.messages.capacity) + d3dcompiler_free(hlsl_ctx.messages.string); + } + + for (i = 0; i < hlsl_ctx.source_files_count; ++i) + d3dcompiler_free((void *)hlsl_ctx.source_files[i]); + d3dcompiler_free(hlsl_ctx.source_files); + TRACE("Freeing functions IR.\n"); wine_rb_destroy(&hlsl_ctx.functions, free_function_rb, NULL);
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index fba8a638b57..e82b466de23 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -1133,6 +1133,18 @@ static void test_fail(void) "{\n" " return float4(0, 0, 0, 0);\n" "}", + + /* 15 */ + "float4 test()\n" + "{\n" + " return float4(0, 0, 0, 0);\n" + "}", + + "float4 test(out float4 o : SV_TARGET)\n" + "{\n" + " o = float4(1, 1, 1, 1);\n" + " return float4(0, 0, 0, 0);\n" + "}", };
static const char *targets[] = {"ps_2_0", "ps_3_0", "ps_4_0"};
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/compiler.c | 49 ++++++----------------- dlls/d3dcompiler_43/d3dcompiler_private.h | 4 +- dlls/d3dcompiler_43/hlsl.l | 14 +++---- dlls/d3dcompiler_43/hlsl.y | 10 +++-- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 2 +- 5 files changed, 29 insertions(+), 50 deletions(-)
diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c index 9fc7c1d7734..78fb0c46cc0 100644 --- a/dlls/d3dcompiler_43/compiler.c +++ b/dlls/d3dcompiler_43/compiler.c @@ -752,12 +752,11 @@ static const struct target_info * get_target_info(const char *target) }
static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint, - ID3DBlob **shader_blob, ID3DBlob **error_messages) + ID3DBlob **shader, ID3DBlob **error_messages) { - struct bwriter_shader *shader; + DWORD size, major, minor; char *messages = NULL; HRESULT hr; - DWORD *res, size, major, minor; ID3DBlob *buffer; char *pos; enum shader_type shader_type; @@ -787,7 +786,7 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co } }
- shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages); + hr = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, shader, &messages);
if (messages) { @@ -800,14 +799,18 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co if (error_messages) { const char *preproc_messages = *error_messages ? ID3D10Blob_GetBufferPointer(*error_messages) : NULL; + HRESULT blob_hr;
size = strlen(messages) + (preproc_messages ? strlen(preproc_messages) : 0) + 1; - hr = D3DCreateBlob(size, &buffer); - if (FAILED(hr)) + if (FAILED(blob_hr = D3DCreateBlob(size, &buffer))) { HeapFree(GetProcessHeap(), 0, messages); - if (shader) SlDeleteShader(shader); - return hr; + if (*shader) + { + ID3D10Blob_Release(*shader); + *shader = NULL; + } + return blob_hr; } pos = ID3D10Blob_GetBufferPointer(buffer); if (preproc_messages) @@ -823,35 +826,7 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co HeapFree(GetProcessHeap(), 0, messages); }
- if (!shader) - { - ERR("HLSL shader parsing failed.\n"); - return D3DXERR_INVALIDDATA; - } - - hr = shader_write_bytecode(shader, &res, &size); - SlDeleteShader(shader); - if (FAILED(hr)) - { - ERR("Failed to write bytecode, hr %#x.\n", hr); - return D3DXERR_INVALIDDATA; - } - - if (shader_blob) - { - hr = D3DCreateBlob(size, &buffer); - if (FAILED(hr)) - { - HeapFree(GetProcessHeap(), 0, res); - return hr; - } - memcpy(ID3D10Blob_GetBufferPointer(buffer), res, size); - *shader_blob = buffer; - } - - HeapFree(GetProcessHeap(), 0, res); - - return S_OK; + return hr; }
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename, diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index 9ac2f14041a..9feaee0d8ac 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -1081,8 +1081,8 @@ BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN; void init_functions_tree(struct wine_rb_tree *funcs) DECLSPEC_HIDDEN; void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl, BOOL intrinsic) DECLSPEC_HIDDEN; -struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, - const char *entrypoint, char **messages) DECLSPEC_HIDDEN; +HRESULT parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, ID3D10Blob **shader, char **messages) DECLSPEC_HIDDEN;
const char *debug_base_type(const struct hlsl_type *type) DECLSPEC_HIDDEN; const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN; diff --git a/dlls/d3dcompiler_43/hlsl.l b/dlls/d3dcompiler_43/hlsl.l index 2994c7dea62..6ffd1375970 100644 --- a/dlls/d3dcompiler_43/hlsl.l +++ b/dlls/d3dcompiler_43/hlsl.l @@ -273,20 +273,20 @@ row_major {return KW_ROW_MAJOR; }
%%
-struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor, - const char *entrypoint, char **messages); +HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, ID3D10Blob **shader, char **messages);
-struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, - const char *entrypoint, char **messages) +HRESULT parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, ID3D10Blob **shader, char **messages) { - struct bwriter_shader *ret = NULL; YY_BUFFER_STATE buffer; + HRESULT hr;
buffer = hlsl__scan_string(text); hlsl__switch_to_buffer(buffer);
- ret = parse_hlsl(type, major, minor, entrypoint, messages); + hr = parse_hlsl(type, major, minor, entrypoint, shader, messages);
hlsl__delete_buffer(buffer); - return ret; + return hr; } diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index b5057db8870..28d4dd7f2c3 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -2942,13 +2942,14 @@ static void compute_liveness(struct hlsl_ir_function_decl *entry_func) compute_liveness_recurse(entry_func->body, 0, 0); }
-struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor, - const char *entrypoint, char **messages) +HRESULT parse_hlsl(enum shader_type type, DWORD major, DWORD minor, + const char *entrypoint, ID3D10Blob **shader_blob, char **messages) { struct hlsl_ir_function_decl *entry_func; struct hlsl_scope *scope, *next_scope; struct hlsl_type *hlsl_type, *next_type; struct hlsl_ir_var *var, *next_var; + HRESULT hr = E_FAIL; unsigned int i;
hlsl_ctx.status = PARSE_SUCCESS; @@ -2998,6 +2999,9 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
compute_liveness(entry_func);
+ if (hlsl_ctx.status != PARSE_ERR) + hr = E_NOTIMPL; + out: if (messages) { @@ -3036,5 +3040,5 @@ out: free_hlsl_type(hlsl_type); }
- return NULL; + return hr; } diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index e82b466de23..24829235a5b 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -1159,7 +1159,7 @@ static void test_fail(void) { compiled = errors = NULL; hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", targets[j], 0, 0, &compiled, &errors); - todo_wine ok(hr == E_FAIL, "Test %u, target %s, got unexpected hr %#x.\n", i, targets[j], hr); + ok(hr == E_FAIL, "Test %u, target %s, got unexpected hr %#x.\n", i, targets[j], hr); ok(!!errors, "Test %u, target %s, expected non-NULL error blob.\n", i, targets[j]); ok(!compiled, "Test %u, target %s, expected no compiled shader blob.\n", i, targets[j]); ID3D10Blob_Release(errors);
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- I think the most important part WRT externally visible behavior is that you're now returning the HRESULT (which is why you can remove the todo_wine). I'd use something like:
"d3dcompiler: Return an HRESULT from parse_hlsl()."
as commit subject. Not a huge deal though.
On 6/11/20 2:44 PM, Matteo Bruni wrote:
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
I think the most important part WRT externally visible behavior is that you're now returning the HRESULT (which is why you can remove the todo_wine). I'd use something like:
"d3dcompiler: Return an HRESULT from parse_hlsl()."
as commit subject. Not a huge deal though.
True enough, though it's not why I wrote the patch in the first or even second place—I wanted to be able to write the blob before freeing some data, and then I wanted to be able to write the blob without using the bytecodewriter layer.
On Thu, Jun 11, 2020 at 10:04 PM Zebediah Figura zfigura@codeweavers.com wrote:
On 6/11/20 2:44 PM, Matteo Bruni wrote:
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
I think the most important part WRT externally visible behavior is that you're now returning the HRESULT (which is why you can remove the todo_wine). I'd use something like:
"d3dcompiler: Return an HRESULT from parse_hlsl()."
as commit subject. Not a huge deal though.
True enough, though it's not why I wrote the patch in the first or even second place—I wanted to be able to write the blob before freeing some data, and then I wanted to be able to write the blob without using the bytecodewriter layer.
Yeah, I figured that the HRESULT part was "by chance".
On Mon, Jun 8, 2020 at 11:50 PM Zebediah Figura z.figura12@gmail.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/d3dcompiler_43/compiler.c | 49 ++++++----------------- dlls/d3dcompiler_43/d3dcompiler_private.h | 4 +- dlls/d3dcompiler_43/hlsl.l | 14 +++---- dlls/d3dcompiler_43/hlsl.y | 10 +++-- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 2 +- 5 files changed, 29 insertions(+), 50 deletions(-)
diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c index 9fc7c1d7734..78fb0c46cc0 100644 --- a/dlls/d3dcompiler_43/compiler.c +++ b/dlls/d3dcompiler_43/compiler.c @@ -752,12 +752,11 @@ static const struct target_info * get_target_info(const char *target) }
static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint,
ID3DBlob **shader_blob, ID3DBlob **error_messages)
ID3DBlob **shader, ID3DBlob **error_messages)
{
- struct bwriter_shader *shader;
- DWORD size, major, minor; char *messages = NULL; HRESULT hr;
- DWORD *res, size, major, minor; ID3DBlob *buffer; char *pos; enum shader_type shader_type;
@@ -787,7 +786,7 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co } }
- shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages);
- hr = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, shader, &messages);
Nothing really new, but it feels a bit awkward that parse_hlsl_shader() is supposed to generate the complete shader. I think it's just a matter of naming, replacing parse_hlsl_shader() and parse_hlsl() with e.g. compile_hlsl_shader() / compile_hlsl() is probably all there is to it.
On 6/11/20 3:04 PM, Matteo Bruni wrote:
On Mon, Jun 8, 2020 at 11:50 PM Zebediah Figura z.figura12@gmail.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
dlls/d3dcompiler_43/compiler.c | 49 ++++++----------------- dlls/d3dcompiler_43/d3dcompiler_private.h | 4 +- dlls/d3dcompiler_43/hlsl.l | 14 +++---- dlls/d3dcompiler_43/hlsl.y | 10 +++-- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 2 +- 5 files changed, 29 insertions(+), 50 deletions(-)
diff --git a/dlls/d3dcompiler_43/compiler.c b/dlls/d3dcompiler_43/compiler.c index 9fc7c1d7734..78fb0c46cc0 100644 --- a/dlls/d3dcompiler_43/compiler.c +++ b/dlls/d3dcompiler_43/compiler.c @@ -752,12 +752,11 @@ static const struct target_info * get_target_info(const char *target) }
static HRESULT compile_shader(const char *preproc_shader, const char *target, const char *entrypoint,
ID3DBlob **shader_blob, ID3DBlob **error_messages)
ID3DBlob **shader, ID3DBlob **error_messages)
{
- struct bwriter_shader *shader;
- DWORD size, major, minor; char *messages = NULL; HRESULT hr;
- DWORD *res, size, major, minor; ID3DBlob *buffer; char *pos; enum shader_type shader_type;
@@ -787,7 +786,7 @@ static HRESULT compile_shader(const char *preproc_shader, const char *target, co } }
- shader = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, &messages);
- hr = parse_hlsl_shader(preproc_shader, shader_type, major, minor, entrypoint, shader, &messages);
Nothing really new, but it feels a bit awkward that parse_hlsl_shader() is supposed to generate the complete shader. I think it's just a matter of naming, replacing parse_hlsl_shader() and parse_hlsl() with e.g. compile_hlsl_shader() / compile_hlsl() is probably all there is to it.
Agreed; I'll queue a follow-up patch for that.
From: Zebediah Figura z.figura12@gmail.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 1 + dlls/d3dcompiler_43/hlsl.y | 1 + dlls/d3dcompiler_43/utils.c | 12 +++--------- 3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index a61b84d6b546..970150bbc5be 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -988,6 +988,7 @@ struct hlsl_parse_ctx struct { struct hlsl_type *scalar[HLSL_TYPE_LAST_SCALAR + 1]; + struct hlsl_type *vector[HLSL_TYPE_LAST_SCALAR + 1][4]; struct hlsl_type *sampler[HLSL_SAMPLER_DIM_MAX + 1]; struct hlsl_type *Void; } builtin_types; diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index 436b731fd162..83aa95b54fc7 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -237,6 +237,7 @@ static void declare_predefined_types(struct hlsl_scope *scope) sprintf(name, "%s%u", names[bt], x); type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_VECTOR, bt, x, y); add_type_to_scope(scope, type); + hlsl_ctx.builtin_types.vector[bt][x - 1] = type;
if (x == 1) { diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c index 97e3cdf1a3f3..c3dbd505f2dc 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1296,6 +1296,8 @@ static struct hlsl_type *expr_common_type(struct hlsl_type *t1, struct hlsl_type
if (type == HLSL_CLASS_SCALAR) return hlsl_ctx.builtin_types.scalar[base]; + if (type == HLSL_CLASS_VECTOR) + return hlsl_ctx.builtin_types.vector[base][dimx - 1]; return new_hlsl_type(NULL, type, base, dimx, dimy); }
@@ -1495,15 +1497,7 @@ struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *lhs, enum parse_assign } assert(swizzle_type->type == HLSL_CLASS_VECTOR); if (swizzle_type->dimx != width) - { - struct hlsl_type *type; - if (!(type = new_hlsl_type(NULL, HLSL_CLASS_VECTOR, swizzle_type->base_type, width, 1))) - { - d3dcompiler_free(assign); - return NULL; - } - swizzle->node.data_type = type; - } + swizzle->node.data_type = hlsl_ctx.builtin_types.vector[swizzle_type->base_type][width - 1]; rhs = &swizzle->node; } else