Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/d3dcompiler_private.h | 14 ---- dlls/d3dcompiler_43/hlsl.y | 94 +++++++++++++---------- dlls/d3dcompiler_43/utils.c | 25 ------ 3 files changed, 52 insertions(+), 81 deletions(-)
diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h index a61b84d6b54..c9bb6ced6c7 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; @@ -1042,12 +1034,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 436b731fd16..8fbb879778d 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -1244,7 +1244,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: @@ -2415,41 +2414,60 @@ 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) + { + const struct hlsl_type *arg_type = $4.args[i]->data_type; + unsigned int component_count = arg_type->dimx * arg_type->dimy; + + if (!(assignment = new_assignment(var, NULL, $4.args[i], + ((1 << component_count) - 1) << writemask_offset, $4.args[i]->loc))) + YYABORT; + writemask_offset += component_count; + 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 { @@ -2834,14 +2852,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 ec0da2d4034..4f156b678f2 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1763,7 +1763,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", @@ -1951,19 +1950,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'}; @@ -2078,9 +2064,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; @@ -2175,11 +2158,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); @@ -2221,9 +2199,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: 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 c9bb6ced6c7..b1719ec44f7 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 8fbb879778d..d5247d69b5c 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -589,7 +589,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; }
@@ -1230,15 +1230,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; @@ -2251,7 +2251,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; } @@ -2265,7 +2265,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; } @@ -2279,7 +2279,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 4f156b678f2..45dd52da590 100644 --- a/dlls/d3dcompiler_43/utils.c +++ b/dlls/d3dcompiler_43/utils.c @@ -1835,19 +1835,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)); @@ -2127,24 +2127,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: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/hlsl.y | 42 +++++++++++++++------------ dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 6 ++++ 2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y index d5247d69b5c..d3b50e3858d 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -2952,24 +2952,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;
@@ -2979,6 +2961,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);
@@ -2991,6 +2980,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 059f39e4c3e..16d1e6dda05 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -1092,6 +1092,12 @@ 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" + "}", };
static const char *targets[] = {"ps_2_0", "ps_3_0", "ps_4_0"};
On Sat, Jun 6, 2020 at 12:26 AM Zebediah Figura z.figura12@gmail.com wrote:
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index 059f39e4c3e..16d1e6dda05 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -1092,6 +1092,12 @@ 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"
"}",
Seems sensible, but, playing devil's advocate: does it fail if the function also has an out argument?
On 6/8/20 9:14 AM, Matteo Bruni wrote:
On Sat, Jun 6, 2020 at 12:26 AM Zebediah Figura z.figura12@gmail.com wrote:
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index 059f39e4c3e..16d1e6dda05 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -1092,6 +1092,12 @@ 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"
"}",
Seems sensible, but, playing devil's advocate: does it fail if the function also has an out argument?
Yes. I can add that as a test.
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 b1719ec44f7..b9e256c5754 100644 --- a/dlls/d3dcompiler_43/d3dcompiler_private.h +++ b/dlls/d3dcompiler_43/d3dcompiler_private.h @@ -1080,8 +1080,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 d3b50e3858d..e35ae7b71f0 100644 --- a/dlls/d3dcompiler_43/hlsl.y +++ b/dlls/d3dcompiler_43/hlsl.y @@ -2923,13 +2923,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; @@ -2979,6 +2980,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) { @@ -3017,5 +3021,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 16d1e6dda05..673fa36fc73 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -1112,7 +1112,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: Zebediah Figura zfigura@codeweavers.com --- dlls/d3dcompiler_43/tests/hlsl_d3d9.c | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c index 673fa36fc73..e2f66444d91 100644 --- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c +++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c @@ -859,6 +859,47 @@ static void test_majority(void) release_test_context(&test_context); }
+static void test_struct_assignment(void) +{ + struct test_context test_context; + ID3D10Blob *ps_code = NULL; + struct vec4 v; + + static const char ps_source[] = + "struct apple\n" + "{\n" + " struct\n" + " {\n" + " float4 a;\n" + " } m;\n" + " float4 b;\n" + "};\n" + "float4 main() : COLOR\n" + "{\n" + " struct apple q, r, s;\n" + " q.m.a = float4(0.1, 0.2, 0.3, 0.4);\n" + " q.b = float4(0.5, 0.1, 0.4, 0.5);\n" + " s = r = q;\n" + " return s.m.a + s.b;\n" + "}"; + + if (!init_test_context(&test_context)) + return; + + todo_wine ps_code = compile_shader(ps_source, "ps_2_0"); + if (ps_code) + { + draw_quad(test_context.device, ps_code); + + v = get_color_vec4(test_context.device, 0, 0); + ok(compare_vec4(&v, 0.6f, 0.3f, 0.7f, 0.9f, 1), + "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w); + + ID3D10Blob_Release(ps_code); + } + release_test_context(&test_context); +} + static void check_constant_desc(const char *prefix, const D3DXCONSTANT_DESC *desc, const D3DXCONSTANT_DESC *expect, BOOL nonzero_defaultvalue) { @@ -1160,6 +1201,7 @@ START_TEST(hlsl_d3d9) test_return(); test_array_dimensions(); test_majority(); + test_struct_assignment();
test_constant_table(); test_fail();
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
On Sat, Jun 6, 2020 at 12:20 AM Zebediah Figura z.figura12@gmail.com wrote:
@@ -2415,41 +2414,60 @@ 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. */
BTW there are 3 of those comments in hlsl.y, all different from each other... Good job me.
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)
{
const struct hlsl_type *arg_type = $4.args[i]->data_type;
unsigned int component_count = arg_type->dimx * arg_type->dimy;
if (!(assignment = new_assignment(var, NULL, $4.args[i],
((1 << component_count) - 1) << writemask_offset, $4.args[i]->loc)))
YYABORT;
writemask_offset += component_count;
Isn't this wrong for structs or arrays?
FWIW it seems it would be more easily extensible to matrix and other types if you generate a "full" assignment with a swizzle on the lhs and then delegate fixing it up to make_assignment() rather than directly computing the writemask here.
On 6/8/20 9:06 AM, Matteo Bruni wrote:
On Sat, Jun 6, 2020 at 12:20 AM Zebediah Figura z.figura12@gmail.com wrote:
@@ -2415,41 +2414,60 @@ 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. */
BTW there are 3 of those comments in hlsl.y, all different from each other... Good job me.
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)
{
const struct hlsl_type *arg_type = $4.args[i]->data_type;
unsigned int component_count = arg_type->dimx * arg_type->dimy;
if (!(assignment = new_assignment(var, NULL, $4.args[i],
((1 << component_count) - 1) << writemask_offset, $4.args[i]->loc)))
YYABORT;
writemask_offset += component_count;
Isn't this wrong for structs or arrays?
Ech, you're right; that should use components_count_type() instead.
FWIW it seems it would be more easily extensible to matrix and other types if you generate a "full" assignment with a swizzle on the lhs and then delegate fixing it up to make_assignment() rather than directly computing the writemask here.
It doesn't particularly feel like less work, when all we're missing here is implicit_conversion(), but we'd have to generate a load and swizzle instruction.