Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 21 +++++++++++++++++++-- libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index f03777a65..6462ce8fc 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -261,6 +261,21 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, s return type; }
+struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim) +{ + struct hlsl_type *type; + + if (!(type = vkd3d_calloc(1, sizeof(*type)))) + return NULL; + type->type = HLSL_CLASS_OBJECT; + type->base_type = HLSL_TYPE_TEXTURE; + type->dimx = 4; + type->dimy = 1; + type->sampler_dim = dim; + list_add_tail(&ctx->types, &type->entry); + return type; +} + struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive) { struct rb_entry *entry = rb_get(&scope->types, name); @@ -329,7 +344,8 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 return false; if (t1->base_type != t2->base_type) return false; - if (t1->base_type == HLSL_TYPE_SAMPLER && t1->sampler_dim != t2->sampler_dim) + if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) + && t1->sampler_dim != t2->sampler_dim) return false; if ((t1->modifiers & HLSL_MODIFIER_ROW_MAJOR) != (t2->modifiers & HLSL_MODIFIER_ROW_MAJOR)) @@ -734,7 +750,8 @@ static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hls } if (t1->base_type != t2->base_type) return t1->base_type - t2->base_type; - if (t1->base_type == HLSL_TYPE_SAMPLER && t1->sampler_dim != t2->sampler_dim) + if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) + && t1->sampler_dim != t2->sampler_dim) return t1->sampler_dim - t2->sampler_dim; if (t1->dimx != t2->dimx) return t1->dimx - t2->dimx; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 77b4ce928..65c6f34e0 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -655,6 +655,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned struct hlsl_ir_node *val, struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc); +struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim); struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location loc); struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 6f1794e79..b8149950d 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2451,6 +2451,26 @@ type: { $$ = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_3D]; } + | KW_TEXTURE + { + $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC); + } + | KW_TEXTURE1D + { + $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_1D); + } + | KW_TEXTURE2D + { + $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_2D); + } + | KW_TEXTURE3D + { + $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_3D); + } + | KW_TEXTURECUBE + { + $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_CUBE); + } | TYPE_IDENTIFIER { $$ = hlsl_get_type(ctx->cur_scope, $1, true);
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.l | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index f8ff28305..762a8a026 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -121,14 +121,18 @@ technique {return KW_TECHNIQUE; } technique10 {return KW_TECHNIQUE10; } texture {return KW_TEXTURE; } texture1D {return KW_TEXTURE1D; } +Texture1D {return KW_TEXTURE1D; } Texture1DArray {return KW_TEXTURE1DARRAY; } texture2D {return KW_TEXTURE2D; } +Texture2D {return KW_TEXTURE2D; } Texture2DArray {return KW_TEXTURE2DARRAY; } Texture2DMS {return KW_TEXTURE2DMS; } Texture2DMSArray {return KW_TEXTURE2DMSARRAY; } texture3D {return KW_TEXTURE3D; } +Texture3D {return KW_TEXTURE3D; } Texture3DArray {return KW_TEXTURE3DARRAY; } textureCUBE {return KW_TEXTURECUBE; } +TextureCube {return KW_TEXTURECUBE; } true {return KW_TRUE; } typedef {return KW_TYPEDEF; } uniform {return KW_UNIFORM; }
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 08/10/21 04:58, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.l | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index f8ff28305..762a8a026 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -121,14 +121,18 @@ technique {return KW_TECHNIQUE; } technique10 {return KW_TECHNIQUE10; } texture {return KW_TEXTURE; } texture1D {return KW_TEXTURE1D; } +Texture1D {return KW_TEXTURE1D; } Texture1DArray {return KW_TEXTURE1DARRAY; } texture2D {return KW_TEXTURE2D; } +Texture2D {return KW_TEXTURE2D; } Texture2DArray {return KW_TEXTURE2DARRAY; } Texture2DMS {return KW_TEXTURE2DMS; } Texture2DMSArray {return KW_TEXTURE2DMSARRAY; } texture3D {return KW_TEXTURE3D; } +Texture3D {return KW_TEXTURE3D; } Texture3DArray {return KW_TEXTURE3DARRAY; } textureCUBE {return KW_TEXTURECUBE; } +TextureCube {return KW_TEXTURECUBE; } true {return KW_TRUE; } typedef {return KW_TYPEDEF; } uniform {return KW_UNIFORM; }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v3: Check the format type in compare_param_hlsl_types() as well.
libs/vkd3d-shader/hlsl.c | 25 +++++++++++++++----- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl.y | 49 +++++++++++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 20 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6462ce8fc..aecc4a639 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -261,7 +261,7 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, s return type; }
-struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim) +struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format) { struct hlsl_type *type;
@@ -272,6 +272,7 @@ struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_ type->dimx = 4; type->dimy = 1; type->sampler_dim = dim; + type->e.resource_format = format; list_add_tail(&ctx->types, &type->entry); return type; } @@ -344,9 +345,14 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 return false; if (t1->base_type != t2->base_type) return false; - if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) - && t1->sampler_dim != t2->sampler_dim) - return false; + if (t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) + { + if (t1->sampler_dim != t2->sampler_dim) + return false; + if (t1->base_type == HLSL_TYPE_TEXTURE && t1->sampler_dim != HLSL_SAMPLER_DIM_GENERIC + && !hlsl_types_are_equal(t1->e.resource_format, t2->e.resource_format)) + return false; + } if ((t1->modifiers & HLSL_MODIFIER_ROW_MAJOR) != (t2->modifiers & HLSL_MODIFIER_ROW_MAJOR)) return false; @@ -742,6 +748,8 @@ void hlsl_pop_scope(struct hlsl_ctx *ctx)
static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) { + int r; + if (t1->type != t2->type) { if (!((t1->type == HLSL_CLASS_SCALAR && t2->type == HLSL_CLASS_VECTOR) @@ -752,7 +760,13 @@ static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hls return t1->base_type - t2->base_type; if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) && t1->sampler_dim != t2->sampler_dim) - return t1->sampler_dim - t2->sampler_dim; + { + if (t1->sampler_dim != t2->sampler_dim) + return t1->sampler_dim - t2->sampler_dim; + if (t1->base_type == HLSL_TYPE_TEXTURE && t1->sampler_dim != HLSL_SAMPLER_DIM_GENERIC + && (r = compare_param_hlsl_types(t1->e.resource_format, t2->e.resource_format))) + return r; + } if (t1->dimx != t2->dimx) return t1->dimx - t2->dimx; if (t1->dimy != t2->dimy) @@ -761,7 +775,6 @@ static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hls { struct list *t1cur, *t2cur; struct hlsl_struct_field *t1field, *t2field; - int r;
t1cur = list_head(t1->e.elements); t2cur = list_head(t2->e.elements); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 65c6f34e0..64a90ffdc 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -126,6 +126,7 @@ struct hlsl_type struct hlsl_type *type; unsigned int elements_count; } array; + struct hlsl_type *resource_format; } e;
unsigned int reg_size; @@ -655,7 +656,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned struct hlsl_ir_node *val, struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc); -struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim); +struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format); struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location loc); struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b8149950d..32dd418d1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1789,6 +1789,7 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type struct parse_colon_attribute colon_attribute; struct hlsl_semantic semantic; enum hlsl_buffer_type buffer_type; + enum hlsl_sampler_dim sampler_dim; }
%token KW_BLENDSTATE @@ -1963,6 +1964,8 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type
%type <reg_reservation> register_opt
+%type <sampler_dim> texture_type + %type <semantic> semantic
%type <type> field_type @@ -2376,6 +2379,24 @@ input_mod: $$ = HLSL_STORAGE_IN | HLSL_STORAGE_OUT; }
+texture_type: + KW_TEXTURE1D + { + $$ = HLSL_SAMPLER_DIM_1D; + } + | KW_TEXTURE2D + { + $$ = HLSL_SAMPLER_DIM_2D; + } + | KW_TEXTURE3D + { + $$ = HLSL_SAMPLER_DIM_3D; + } + | KW_TEXTURECUBE + { + $$ = HLSL_SAMPLER_DIM_CUBE; + } + type: KW_VECTOR '<' type ',' C_INTEGER '>' { @@ -2453,23 +2474,25 @@ type: } | KW_TEXTURE { - $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC); - } - | KW_TEXTURE1D - { - $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_1D); + $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC, NULL); } - | KW_TEXTURE2D + | texture_type { - $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_2D); + $$ = hlsl_new_texture_type(ctx, $1, ctx->builtin_types.vector[HLSL_TYPE_FLOAT][4 - 1]); } - | KW_TEXTURE3D + | texture_type '<' type '>' { - $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_3D); - } - | KW_TEXTURECUBE - { - $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_CUBE); + if ($3->type > HLSL_CLASS_VECTOR) + { + struct vkd3d_string_buffer *string; + + string = hlsl_type_to_string(ctx, $3); + if (string) + hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "Texture data type %s is not scalar or vector.\n", string->buffer); + hlsl_release_string_buffer(ctx, string); + } + $$ = hlsl_new_texture_type(ctx, $1, $3); } | TYPE_IDENTIFIER {
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 08/10/21 04:58, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
v3: Check the format type in compare_param_hlsl_types() as well.
libs/vkd3d-shader/hlsl.c | 25 +++++++++++++++----- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl.y | 49 +++++++++++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 20 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6462ce8fc..aecc4a639 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -261,7 +261,7 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, s return type; }
-struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim) +struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format) { struct hlsl_type *type;
@@ -272,6 +272,7 @@ struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_ type->dimx = 4; type->dimy = 1; type->sampler_dim = dim;
- type->e.resource_format = format; list_add_tail(&ctx->types, &type->entry); return type; }
@@ -344,9 +345,14 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 return false; if (t1->base_type != t2->base_type) return false;
- if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE)
&& t1->sampler_dim != t2->sampler_dim)
return false;
- if (t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE)
- {
if (t1->sampler_dim != t2->sampler_dim)
return false;
if (t1->base_type == HLSL_TYPE_TEXTURE && t1->sampler_dim != HLSL_SAMPLER_DIM_GENERIC
&& !hlsl_types_are_equal(t1->e.resource_format, t2->e.resource_format))
return false;
- } if ((t1->modifiers & HLSL_MODIFIER_ROW_MAJOR) != (t2->modifiers & HLSL_MODIFIER_ROW_MAJOR)) return false;
@@ -742,6 +748,8 @@ void hlsl_pop_scope(struct hlsl_ctx *ctx)
static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) {
- int r;
if (t1->type != t2->type) { if (!((t1->type == HLSL_CLASS_SCALAR && t2->type == HLSL_CLASS_VECTOR)
@@ -752,7 +760,13 @@ static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hls return t1->base_type - t2->base_type; if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) && t1->sampler_dim != t2->sampler_dim)
return t1->sampler_dim - t2->sampler_dim;
- {
if (t1->sampler_dim != t2->sampler_dim)
return t1->sampler_dim - t2->sampler_dim;
if (t1->base_type == HLSL_TYPE_TEXTURE && t1->sampler_dim != HLSL_SAMPLER_DIM_GENERIC
&& (r = compare_param_hlsl_types(t1->e.resource_format, t2->e.resource_format)))
return r;
- } if (t1->dimx != t2->dimx) return t1->dimx - t2->dimx; if (t1->dimy != t2->dimy)
@@ -761,7 +775,6 @@ static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hls { struct list *t1cur, *t2cur; struct hlsl_struct_field *t1field, *t2field;
int r; t1cur = list_head(t1->e.elements); t2cur = list_head(t2->e.elements);
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 65c6f34e0..64a90ffdc 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -126,6 +126,7 @@ struct hlsl_type struct hlsl_type *type; unsigned int elements_count; } array;
struct hlsl_type *resource_format; } e; unsigned int reg_size;
@@ -655,7 +656,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned struct hlsl_ir_node *val, struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc); -struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim); +struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format); struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location loc); struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b8149950d..32dd418d1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1789,6 +1789,7 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type struct parse_colon_attribute colon_attribute; struct hlsl_semantic semantic; enum hlsl_buffer_type buffer_type;
enum hlsl_sampler_dim sampler_dim; }
%token KW_BLENDSTATE
@@ -1963,6 +1964,8 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type
%type <reg_reservation> register_opt
+%type <sampler_dim> texture_type
%type <semantic> semantic
%type <type> field_type
@@ -2376,6 +2379,24 @@ input_mod: $$ = HLSL_STORAGE_IN | HLSL_STORAGE_OUT; }
+texture_type:
KW_TEXTURE1D
{
$$ = HLSL_SAMPLER_DIM_1D;
}
- | KW_TEXTURE2D
{
$$ = HLSL_SAMPLER_DIM_2D;
}
- | KW_TEXTURE3D
{
$$ = HLSL_SAMPLER_DIM_3D;
}
- | KW_TEXTURECUBE
{
$$ = HLSL_SAMPLER_DIM_CUBE;
}
- type: KW_VECTOR '<' type ',' C_INTEGER '>' {
@@ -2453,23 +2474,25 @@ type: } | KW_TEXTURE {
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC);
}
- | KW_TEXTURE1D
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_1D);
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC, NULL); }
- | KW_TEXTURE2D
- | texture_type {
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_2D);
$$ = hlsl_new_texture_type(ctx, $1, ctx->builtin_types.vector[HLSL_TYPE_FLOAT][4 - 1]); }
- | KW_TEXTURE3D
- | texture_type '<' type '>' {
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_3D);
}
- | KW_TEXTURECUBE
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_CUBE);
if ($3->type > HLSL_CLASS_VECTOR)
{
struct vkd3d_string_buffer *string;
string = hlsl_type_to_string(ctx, $3);
if (string)
hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Texture data type %s is not scalar or vector.\n", string->buffer);
hlsl_release_string_buffer(ctx, string);
}
$$ = hlsl_new_texture_type(ctx, $1, $3); } | TYPE_IDENTIFIER {
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v4: Add a couple of asserts.
libs/vkd3d-shader/hlsl.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index aecc4a639..e0f26c0fe 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -893,6 +893,37 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru vkd3d_string_buffer_printf(string, "<anonymous struct>"); return string;
+ case HLSL_CLASS_OBJECT: + { + static const char dimensions[5][HLSL_SAMPLER_DIM_MAX + 1] = + { + [HLSL_SAMPLER_DIM_1D] = "1D", + [HLSL_SAMPLER_DIM_2D] = "2D", + [HLSL_SAMPLER_DIM_3D] = "3D", + [HLSL_SAMPLER_DIM_CUBE] = "Cube" + }; + + switch (type->base_type) + { + case HLSL_TYPE_TEXTURE: + if (type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC) + { + vkd3d_string_buffer_printf(string, "Texture"); + return string; + } + + assert(type->sampler_dim < ARRAY_SIZE(dimensions)); + assert(type->e.resource_format->base_type < ARRAY_SIZE(base_types)); + vkd3d_string_buffer_printf(string, "Texture%s<%s%u>", dimensions[type->sampler_dim], + base_types[type->e.resource_format->base_type], type->e.resource_format->dimx); + return string; + + default: + vkd3d_string_buffer_printf(string, "<unexpected type>"); + return string; + } + } + default: vkd3d_string_buffer_printf(string, "<unexpected type>"); return string;
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 08/10/21 04:58, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
v4: Add a couple of asserts.
libs/vkd3d-shader/hlsl.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index aecc4a639..e0f26c0fe 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -893,6 +893,37 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru vkd3d_string_buffer_printf(string, "<anonymous struct>"); return string;
case HLSL_CLASS_OBJECT:
{
static const char dimensions[5][HLSL_SAMPLER_DIM_MAX + 1] =
{
[HLSL_SAMPLER_DIM_1D] = "1D",
[HLSL_SAMPLER_DIM_2D] = "2D",
[HLSL_SAMPLER_DIM_3D] = "3D",
[HLSL_SAMPLER_DIM_CUBE] = "Cube"
};
switch (type->base_type)
{
case HLSL_TYPE_TEXTURE:
if (type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC)
{
vkd3d_string_buffer_printf(string, "Texture");
return string;
}
assert(type->sampler_dim < ARRAY_SIZE(dimensions));
assert(type->e.resource_format->base_type < ARRAY_SIZE(base_types));
vkd3d_string_buffer_printf(string, "Texture%s<%s%u>", dimensions[type->sampler_dim],
base_types[type->e.resource_format->base_type], type->e.resource_format->dimx);
return string;
default:
vkd3d_string_buffer_printf(string, "<unexpected type>");
return string;
}
}
default: vkd3d_string_buffer_printf(string, "<unexpected type>"); return string;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v4: Pass a pointer to struct vkd3d_shader_location.
libs/vkd3d-shader/hlsl.c | 48 ++++++++++++++- libs/vkd3d-shader/hlsl.h | 26 +++++++- libs/vkd3d-shader/hlsl.y | 102 ++++++++++++++++++++++++++++++- libs/vkd3d-shader/hlsl_codegen.c | 14 +++++ libs/vkd3d-shader/hlsl_sm1.c | 5 ++ libs/vkd3d-shader/hlsl_sm4.c | 5 ++ 6 files changed, 196 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index e0f26c0fe..9bce6bebe 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -478,7 +478,7 @@ bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type) }
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type, - struct vkd3d_shader_location *loc) + const struct vkd3d_shader_location *loc) { struct hlsl_ir_node *cast;
@@ -626,6 +626,22 @@ struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var return hlsl_new_load(ctx, var, NULL, var->data_type, loc); }
+struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type, + enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *offset, + struct hlsl_ir_node *coords, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_resource_load *load; + + if (!(load = hlsl_alloc(ctx, sizeof(*load)))) + return NULL; + init_node(&load->node, HLSL_IR_RESOURCE_LOAD, data_type, *loc); + load->load_type = type; + load->resource.var = resource; + hlsl_src_from_node(&load->resource.offset, offset); + hlsl_src_from_node(&load->coords, coords); + return load; +} + struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components, struct hlsl_ir_node *val, struct vkd3d_shader_location *loc) { @@ -994,6 +1010,7 @@ const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) "HLSL_IR_LOAD", "HLSL_IR_LOOP", "HLSL_IR_JUMP", + "HLSL_IR_RESOURCE_LOAD", "HLSL_IR_STORE", "HLSL_IR_SWIZZLE", }; @@ -1216,6 +1233,20 @@ static void dump_ir_loop(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffe vkd3d_string_buffer_printf(buffer, "}\n"); }
+static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_resource_load *load) +{ + static const char *const type_names[] = + { + [HLSL_RESOURCE_LOAD] = "load_resource", + }; + + vkd3d_string_buffer_printf(buffer, "%s(resource = ", type_names[load->load_type]); + dump_deref(buffer, &load->resource); + vkd3d_string_buffer_printf(buffer, ", coords = "); + dump_src(buffer, &load->coords); + vkd3d_string_buffer_printf(buffer, ")"); +} + static void dump_ir_store(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_store *store) { vkd3d_string_buffer_printf(buffer, "= ("); @@ -1282,6 +1313,10 @@ static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, dump_ir_loop(ctx, buffer, hlsl_ir_loop(instr)); break;
+ case HLSL_IR_RESOURCE_LOAD: + dump_ir_resource_load(buffer, hlsl_ir_resource_load(instr)); + break; + case HLSL_IR_STORE: dump_ir_store(buffer, hlsl_ir_store(instr)); break; @@ -1380,6 +1415,13 @@ static void free_ir_loop(struct hlsl_ir_loop *loop) vkd3d_free(loop); }
+static void free_ir_resource_load(struct hlsl_ir_resource_load *load) +{ + hlsl_src_remove(&load->coords); + hlsl_src_remove(&load->resource.offset); + vkd3d_free(load); +} + static void free_ir_store(struct hlsl_ir_store *store) { hlsl_src_remove(&store->rhs); @@ -1423,6 +1465,10 @@ void hlsl_free_instr(struct hlsl_ir_node *node) free_ir_loop(hlsl_ir_loop(node)); break;
+ case HLSL_IR_RESOURCE_LOAD: + free_ir_resource_load(hlsl_ir_resource_load(node)); + break; + case HLSL_IR_STORE: free_ir_store(hlsl_ir_store(node)); break; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 64a90ffdc..e401971e1 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -166,6 +166,7 @@ enum hlsl_ir_node_type HLSL_IR_LOAD, HLSL_IR_LOOP, HLSL_IR_JUMP, + HLSL_IR_RESOURCE_LOAD, HLSL_IR_STORE, HLSL_IR_SWIZZLE, }; @@ -239,6 +240,7 @@ struct hlsl_ir_var uint32_t is_output_semantic : 1; uint32_t is_uniform : 1; uint32_t is_param : 1; + uint32_t has_resource_access : 1; };
struct hlsl_ir_function @@ -366,6 +368,19 @@ struct hlsl_ir_load struct hlsl_deref src; };
+enum hlsl_resource_load_type +{ + HLSL_RESOURCE_LOAD, +}; + +struct hlsl_ir_resource_load +{ + struct hlsl_ir_node node; + enum hlsl_resource_load_type load_type; + struct hlsl_deref resource; + struct hlsl_src coords; +}; + struct hlsl_ir_store { struct hlsl_ir_node node; @@ -521,6 +536,12 @@ static inline struct hlsl_ir_loop *hlsl_ir_loop(const struct hlsl_ir_node *node) return CONTAINING_RECORD(node, struct hlsl_ir_loop, node); }
+static inline struct hlsl_ir_resource_load *hlsl_ir_resource_load(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_RESOURCE_LOAD); + return CONTAINING_RECORD(node, struct hlsl_ir_resource_load, node); +} + static inline struct hlsl_ir_store *hlsl_ir_store(const struct hlsl_ir_node *node) { assert(node->type == HLSL_IR_STORE); @@ -639,7 +660,7 @@ struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_exp struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name, const struct hlsl_reg_reservation *reservation, struct vkd3d_shader_location loc); struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type, - struct vkd3d_shader_location *loc); + const struct vkd3d_shader_location *loc); struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node); struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type, struct list *parameters, const struct hlsl_semantic *semantic, struct vkd3d_shader_location loc); @@ -648,6 +669,9 @@ struct hlsl_ir_jump *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type struct hlsl_ir_load *hlsl_new_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset, struct hlsl_type *type, struct vkd3d_shader_location loc); struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc); +struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type, + enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *offset, + struct hlsl_ir_node *coords, const struct vkd3d_shader_location *loc); struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs); struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset, struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 32dd418d1..ae19cd1a7 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -258,7 +258,7 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ }
static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs, - struct hlsl_ir_node *node, struct hlsl_type *dst_type, struct vkd3d_shader_location *loc) + struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc) { struct hlsl_type *src_type = node->data_type; struct hlsl_ir_expr *cast; @@ -843,15 +843,21 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
case HLSL_IR_EXPR: case HLSL_IR_LOAD: + case HLSL_IR_RESOURCE_LOAD: case HLSL_IR_SWIZZLE: FIXME("Unhandled type %s.\n", hlsl_node_type_to_string(node->type)); return 0;
+ case HLSL_IR_IF: + case HLSL_IR_JUMP: + case HLSL_IR_LOOP: case HLSL_IR_STORE: - default: WARN("Invalid node type %s.\n", hlsl_node_type_to_string(node->type)); return 0; } + + assert(0); + return 0; }
static bool expr_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2) @@ -1513,6 +1519,23 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t return statements_list; }
+static unsigned int sampler_dim_count(enum hlsl_sampler_dim dim) +{ + switch (dim) + { + case HLSL_SAMPLER_DIM_1D: + return 1; + case HLSL_SAMPLER_DIM_2D: + return 2; + case HLSL_SAMPLER_DIM_3D: + case HLSL_SAMPLER_DIM_CUBE: + return 3; + default: + assert(0); + return 0; + } +} + struct find_function_call_args { const struct parse_initializer *params; @@ -1757,6 +1780,65 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type return params->instrs; }
+static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object, + const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) +{ + const struct hlsl_type *object_type = object->data_type; + struct hlsl_ir_load *object_load; + + if (object_type->type != HLSL_CLASS_OBJECT || object_type->base_type != HLSL_TYPE_TEXTURE + || object_type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC) + { + struct vkd3d_string_buffer *string; + + if ((string = hlsl_type_to_string(ctx, object_type))) + hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "Type '%s' does not have methods.", string->buffer); + hlsl_release_string_buffer(ctx, string); + return false; + } + + /* Only HLSL_IR_LOAD can return an object. */ + object_load = hlsl_ir_load(object); + + if (!strcmp(name, "Load")) + { + const unsigned int sampler_dim = sampler_dim_count(object_type->sampler_dim); + struct hlsl_ir_resource_load *load; + struct hlsl_ir_node *coords; + + if (params->args_count < 1 || params->args_count > 3) + { + hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT, + "Wrong number of arguments to method 'Load': expected 1, 2, or 3, but got %u.", params->args_count); + return false; + } + if (params->args_count >= 2) + FIXME("Ignoring index and/or offset parameter(s).\n"); + + /* -1 for zero-indexing; +1 for the mipmap level */ + if (!(coords = add_implicit_conversion(ctx, instrs, params->args[0], + ctx->builtin_types.vector[HLSL_TYPE_INT][sampler_dim - 1 + 1], loc))) + return false; + + if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format, HLSL_RESOURCE_LOAD, + object_load->src.var, object_load->src.offset.node, coords, loc))) + return false; + list_add_tail(instrs, &load->node.entry); + return true; + } + else + { + struct vkd3d_string_buffer *string; + + if ((string = hlsl_type_to_string(ctx, object_type))) + hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, + "Method '%s' is not defined on type '%s'.", name, string->buffer); + hlsl_release_string_buffer(ctx, string); + return false; + } +} + }
%locations @@ -3085,6 +3167,22 @@ postfix_expr: YYABORT; } } + | postfix_expr '.' any_identifier '(' func_arguments ')' + { + struct hlsl_ir_node *object = node_from_list($1); + + list_move_tail($1, $5.instrs); + vkd3d_free($5.instrs); + + if (!add_method_call(ctx, $1, object, $3, &$5, &@3)) + { + hlsl_free_instr_list($1); + vkd3d_free($5.args); + YYABORT; + } + vkd3d_free($5.args); + $$ = $1; + }
unary_expr: postfix_expr diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 9c9a38379..00fe76b2f 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -503,6 +503,7 @@ static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) case HLSL_IR_CONSTANT: case HLSL_IR_EXPR: case HLSL_IR_LOAD: + case HLSL_IR_RESOURCE_LOAD: case HLSL_IR_SWIZZLE: if (list_empty(&instr->uses)) { @@ -640,6 +641,16 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs loop_last ? loop_last : loop->next_index); break; } + case HLSL_IR_RESOURCE_LOAD: + { + struct hlsl_ir_resource_load *load = hlsl_ir_resource_load(instr); + + load->resource.var->has_resource_access = 1; + if (load->resource.offset.node) + load->resource.offset.node->last_read = instr->index; + load->coords.node->last_read = instr->index; + break; + } case HLSL_IR_SWIZZLE: { struct hlsl_ir_swizzle *swizzle = hlsl_ir_swizzle(instr); @@ -665,7 +676,10 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry) { LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry) + { var->first_write = var->last_read = 0; + var->has_resource_access = 0; + } }
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index ee2870eca..9fc1b2210 100644 --- a/libs/vkd3d-shader/hlsl_sm1.c +++ b/libs/vkd3d-shader/hlsl_sm1.c @@ -778,6 +778,11 @@ static void write_sm1_instructions(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b hlsl_fixme(ctx, instr->loc, "SM1 matrix expression."); continue; } + else if (instr->data_type->type == HLSL_CLASS_OBJECT) + { + hlsl_fixme(ctx, instr->loc, "Object copy.\n"); + break; + }
assert(instr->data_type->type == HLSL_CLASS_SCALAR || instr->data_type->type == HLSL_CLASS_VECTOR); } diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 328a8ba1b..b4fb8f2f7 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1286,6 +1286,11 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, FIXME("Matrix operations need to be lowered.\n"); break; } + else if (instr->data_type->type == HLSL_CLASS_OBJECT) + { + hlsl_fixme(ctx, instr->loc, "Object copy.\n"); + break; + }
assert(instr->data_type->type == HLSL_CLASS_SCALAR || instr->data_type->type == HLSL_CLASS_VECTOR); }
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 08/10/21 04:58, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
v4: Pass a pointer to struct vkd3d_shader_location.
libs/vkd3d-shader/hlsl.c | 48 ++++++++++++++- libs/vkd3d-shader/hlsl.h | 26 +++++++- libs/vkd3d-shader/hlsl.y | 102 ++++++++++++++++++++++++++++++- libs/vkd3d-shader/hlsl_codegen.c | 14 +++++ libs/vkd3d-shader/hlsl_sm1.c | 5 ++ libs/vkd3d-shader/hlsl_sm4.c | 5 ++ 6 files changed, 196 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index e0f26c0fe..9bce6bebe 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -478,7 +478,7 @@ bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type) }
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,
struct vkd3d_shader_location *loc)
{ struct hlsl_ir_node *cast;const struct vkd3d_shader_location *loc)
@@ -626,6 +626,22 @@ struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var return hlsl_new_load(ctx, var, NULL, var->data_type, loc); }
+struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *offset,
struct hlsl_ir_node *coords, const struct vkd3d_shader_location *loc)
+{
- struct hlsl_ir_resource_load *load;
- if (!(load = hlsl_alloc(ctx, sizeof(*load))))
return NULL;
- init_node(&load->node, HLSL_IR_RESOURCE_LOAD, data_type, *loc);
- load->load_type = type;
- load->resource.var = resource;
- hlsl_src_from_node(&load->resource.offset, offset);
- hlsl_src_from_node(&load->coords, coords);
- return load;
+}
- struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components, struct hlsl_ir_node *val, struct vkd3d_shader_location *loc) {
@@ -994,6 +1010,7 @@ const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) "HLSL_IR_LOAD", "HLSL_IR_LOOP", "HLSL_IR_JUMP",
"HLSL_IR_RESOURCE_LOAD", "HLSL_IR_STORE", "HLSL_IR_SWIZZLE", };
@@ -1216,6 +1233,20 @@ static void dump_ir_loop(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffe vkd3d_string_buffer_printf(buffer, "}\n"); }
+static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_resource_load *load) +{
- static const char *const type_names[] =
- {
[HLSL_RESOURCE_LOAD] = "load_resource",
- };
- vkd3d_string_buffer_printf(buffer, "%s(resource = ", type_names[load->load_type]);
- dump_deref(buffer, &load->resource);
- vkd3d_string_buffer_printf(buffer, ", coords = ");
- dump_src(buffer, &load->coords);
- vkd3d_string_buffer_printf(buffer, ")");
+}
- static void dump_ir_store(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_store *store) { vkd3d_string_buffer_printf(buffer, "= (");
@@ -1282,6 +1313,10 @@ static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, dump_ir_loop(ctx, buffer, hlsl_ir_loop(instr)); break;
case HLSL_IR_RESOURCE_LOAD:
dump_ir_resource_load(buffer, hlsl_ir_resource_load(instr));
break;
case HLSL_IR_STORE: dump_ir_store(buffer, hlsl_ir_store(instr)); break;
@@ -1380,6 +1415,13 @@ static void free_ir_loop(struct hlsl_ir_loop *loop) vkd3d_free(loop); }
+static void free_ir_resource_load(struct hlsl_ir_resource_load *load) +{
- hlsl_src_remove(&load->coords);
- hlsl_src_remove(&load->resource.offset);
- vkd3d_free(load);
+}
- static void free_ir_store(struct hlsl_ir_store *store) { hlsl_src_remove(&store->rhs);
@@ -1423,6 +1465,10 @@ void hlsl_free_instr(struct hlsl_ir_node *node) free_ir_loop(hlsl_ir_loop(node)); break;
case HLSL_IR_RESOURCE_LOAD:
free_ir_resource_load(hlsl_ir_resource_load(node));
break;
case HLSL_IR_STORE: free_ir_store(hlsl_ir_store(node)); break;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 64a90ffdc..e401971e1 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -166,6 +166,7 @@ enum hlsl_ir_node_type HLSL_IR_LOAD, HLSL_IR_LOOP, HLSL_IR_JUMP,
- HLSL_IR_RESOURCE_LOAD, HLSL_IR_STORE, HLSL_IR_SWIZZLE, };
@@ -239,6 +240,7 @@ struct hlsl_ir_var uint32_t is_output_semantic : 1; uint32_t is_uniform : 1; uint32_t is_param : 1;
uint32_t has_resource_access : 1; };
struct hlsl_ir_function
@@ -366,6 +368,19 @@ struct hlsl_ir_load struct hlsl_deref src; };
+enum hlsl_resource_load_type +{
- HLSL_RESOURCE_LOAD,
+};
+struct hlsl_ir_resource_load +{
- struct hlsl_ir_node node;
- enum hlsl_resource_load_type load_type;
- struct hlsl_deref resource;
- struct hlsl_src coords;
+};
- struct hlsl_ir_store { struct hlsl_ir_node node;
@@ -521,6 +536,12 @@ static inline struct hlsl_ir_loop *hlsl_ir_loop(const struct hlsl_ir_node *node) return CONTAINING_RECORD(node, struct hlsl_ir_loop, node); }
+static inline struct hlsl_ir_resource_load *hlsl_ir_resource_load(const struct hlsl_ir_node *node) +{
- assert(node->type == HLSL_IR_RESOURCE_LOAD);
- return CONTAINING_RECORD(node, struct hlsl_ir_resource_load, node);
+}
- static inline struct hlsl_ir_store *hlsl_ir_store(const struct hlsl_ir_node *node) { assert(node->type == HLSL_IR_STORE);
@@ -639,7 +660,7 @@ struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_exp struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name, const struct hlsl_reg_reservation *reservation, struct vkd3d_shader_location loc); struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,
struct vkd3d_shader_location *loc);
struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node); struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type, struct list *parameters, const struct hlsl_semantic *semantic, struct vkd3d_shader_location loc);const struct vkd3d_shader_location *loc);
@@ -648,6 +669,9 @@ struct hlsl_ir_jump *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type struct hlsl_ir_load *hlsl_new_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset, struct hlsl_type *type, struct vkd3d_shader_location loc); struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc); +struct hlsl_ir_resource_load *hlsl_new_resource_load(struct hlsl_ctx *ctx, struct hlsl_type *data_type,
enum hlsl_resource_load_type type, struct hlsl_ir_var *resource, struct hlsl_ir_node *offset,
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs); struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset, struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc);struct hlsl_ir_node *coords, const struct vkd3d_shader_location *loc);
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 32dd418d1..ae19cd1a7 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -258,7 +258,7 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ }
static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs,
struct hlsl_ir_node *node, struct hlsl_type *dst_type, struct vkd3d_shader_location *loc)
{ struct hlsl_type *src_type = node->data_type; struct hlsl_ir_expr *cast;struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
@@ -843,15 +843,21 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
case HLSL_IR_EXPR: case HLSL_IR_LOAD:
case HLSL_IR_RESOURCE_LOAD: case HLSL_IR_SWIZZLE: FIXME("Unhandled type %s.\n", hlsl_node_type_to_string(node->type)); return 0;
case HLSL_IR_IF:
case HLSL_IR_JUMP:
case HLSL_IR_LOOP: case HLSL_IR_STORE:
default: WARN("Invalid node type %s.\n", hlsl_node_type_to_string(node->type)); return 0; }
assert(0);
return 0; }
static bool expr_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t2)
@@ -1513,6 +1519,23 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t return statements_list; }
+static unsigned int sampler_dim_count(enum hlsl_sampler_dim dim) +{
- switch (dim)
- {
case HLSL_SAMPLER_DIM_1D:
return 1;
case HLSL_SAMPLER_DIM_2D:
return 2;
case HLSL_SAMPLER_DIM_3D:
case HLSL_SAMPLER_DIM_CUBE:
return 3;
default:
assert(0);
return 0;
- }
+}
- struct find_function_call_args { const struct parse_initializer *params;
@@ -1757,6 +1780,65 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type return params->instrs; }
+static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *object,
const char *name, const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
+{
- const struct hlsl_type *object_type = object->data_type;
- struct hlsl_ir_load *object_load;
- if (object_type->type != HLSL_CLASS_OBJECT || object_type->base_type != HLSL_TYPE_TEXTURE
|| object_type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC)
- {
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(ctx, object_type)))
hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
"Type '%s' does not have methods.", string->buffer);
hlsl_release_string_buffer(ctx, string);
return false;
- }
- /* Only HLSL_IR_LOAD can return an object. */
- object_load = hlsl_ir_load(object);
- if (!strcmp(name, "Load"))
- {
const unsigned int sampler_dim = sampler_dim_count(object_type->sampler_dim);
struct hlsl_ir_resource_load *load;
struct hlsl_ir_node *coords;
if (params->args_count < 1 || params->args_count > 3)
{
hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
"Wrong number of arguments to method 'Load': expected 1, 2, or 3, but got %u.", params->args_count);
return false;
}
if (params->args_count >= 2)
FIXME("Ignoring index and/or offset parameter(s).\n");
/* -1 for zero-indexing; +1 for the mipmap level */
if (!(coords = add_implicit_conversion(ctx, instrs, params->args[0],
ctx->builtin_types.vector[HLSL_TYPE_INT][sampler_dim - 1 + 1], loc)))
return false;
if (!(load = hlsl_new_resource_load(ctx, object_type->e.resource_format, HLSL_RESOURCE_LOAD,
object_load->src.var, object_load->src.offset.node, coords, loc)))
return false;
list_add_tail(instrs, &load->node.entry);
return true;
- }
- else
- {
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(ctx, object_type)))
hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED,
"Method '%s' is not defined on type '%s'.", name, string->buffer);
hlsl_release_string_buffer(ctx, string);
return false;
- }
+}
}
%locations
@@ -3085,6 +3167,22 @@ postfix_expr: YYABORT; } }
| postfix_expr '.' any_identifier '(' func_arguments ')'
{
struct hlsl_ir_node *object = node_from_list($1);
list_move_tail($1, $5.instrs);
vkd3d_free($5.instrs);
if (!add_method_call(ctx, $1, object, $3, &$5, &@3))
{
hlsl_free_instr_list($1);
vkd3d_free($5.args);
YYABORT;
}
vkd3d_free($5.args);
$$ = $1;
}
unary_expr: postfix_expr
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 9c9a38379..00fe76b2f 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -503,6 +503,7 @@ static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) case HLSL_IR_CONSTANT: case HLSL_IR_EXPR: case HLSL_IR_LOAD:
case HLSL_IR_RESOURCE_LOAD: case HLSL_IR_SWIZZLE: if (list_empty(&instr->uses)) {
@@ -640,6 +641,16 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs loop_last ? loop_last : loop->next_index); break; }
case HLSL_IR_RESOURCE_LOAD:
{
struct hlsl_ir_resource_load *load = hlsl_ir_resource_load(instr);
load->resource.var->has_resource_access = 1;
if (load->resource.offset.node)
load->resource.offset.node->last_read = instr->index;
load->coords.node->last_read = instr->index;
break;
} case HLSL_IR_SWIZZLE: { struct hlsl_ir_swizzle *swizzle = hlsl_ir_swizzle(instr);
@@ -665,7 +676,10 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry) { LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry)
{ var->first_write = var->last_read = 0;
var->has_resource_access = 0;
} } LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry)
diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index ee2870eca..9fc1b2210 100644 --- a/libs/vkd3d-shader/hlsl_sm1.c +++ b/libs/vkd3d-shader/hlsl_sm1.c @@ -778,6 +778,11 @@ static void write_sm1_instructions(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b hlsl_fixme(ctx, instr->loc, "SM1 matrix expression."); continue; }
else if (instr->data_type->type == HLSL_CLASS_OBJECT)
{
hlsl_fixme(ctx, instr->loc, "Object copy.\n");
break;
} assert(instr->data_type->type == HLSL_CLASS_SCALAR || instr->data_type->type == HLSL_CLASS_VECTOR); }
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 328a8ba1b..b4fb8f2f7 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1286,6 +1286,11 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, FIXME("Matrix operations need to be lowered.\n"); break; }
else if (instr->data_type->type == HLSL_CLASS_OBJECT)
{
hlsl_fixme(ctx, instr->loc, "Object copy.\n");
break;
} assert(instr->data_type->type == HLSL_CLASS_SCALAR || instr->data_type->type == HLSL_CLASS_VECTOR); }
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 08/10/21 04:58, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 21 +++++++++++++++++++-- libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index f03777a65..6462ce8fc 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -261,6 +261,21 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, s return type; }
+struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim) +{
- struct hlsl_type *type;
- if (!(type = vkd3d_calloc(1, sizeof(*type))))
return NULL;
- type->type = HLSL_CLASS_OBJECT;
- type->base_type = HLSL_TYPE_TEXTURE;
- type->dimx = 4;
- type->dimy = 1;
- type->sampler_dim = dim;
- list_add_tail(&ctx->types, &type->entry);
- return type;
+}
- struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive) { struct rb_entry *entry = rb_get(&scope->types, name);
@@ -329,7 +344,8 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 return false; if (t1->base_type != t2->base_type) return false;
- if (t1->base_type == HLSL_TYPE_SAMPLER && t1->sampler_dim != t2->sampler_dim)
- if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE)
&& t1->sampler_dim != t2->sampler_dim) return false; if ((t1->modifiers & HLSL_MODIFIER_ROW_MAJOR) != (t2->modifiers & HLSL_MODIFIER_ROW_MAJOR))
@@ -734,7 +750,8 @@ static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hls } if (t1->base_type != t2->base_type) return t1->base_type - t2->base_type;
- if (t1->base_type == HLSL_TYPE_SAMPLER && t1->sampler_dim != t2->sampler_dim)
- if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE)
&& t1->sampler_dim != t2->sampler_dim) return t1->sampler_dim - t2->sampler_dim; if (t1->dimx != t2->dimx) return t1->dimx - t2->dimx;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 77b4ce928..65c6f34e0 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -655,6 +655,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned struct hlsl_ir_node *val, struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc); +struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim); struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location loc); struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 6f1794e79..b8149950d 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2451,6 +2451,26 @@ type: { $$ = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_3D]; }
- | KW_TEXTURE
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC);
}
- | KW_TEXTURE1D
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_1D);
}
- | KW_TEXTURE2D
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_2D);
}
- | KW_TEXTURE3D
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_3D);
}
- | KW_TEXTURECUBE
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_CUBE);
} | TYPE_IDENTIFIER { $$ = hlsl_get_type(ctx->cur_scope, $1, true);