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 06/10/21 16:45, 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: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 14 ++++++++---- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl.y | 49 +++++++++++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 18 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6462ce8fc..1f23a478c 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; 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 {
Hi,
Il 06/10/21 16:45, Zebediah Figura ha scritto:
@@ -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;
Shouldn't compare_param_hlsl_types be changed in a similar way?
More in general, do we really need both hlsl_types_are_equal and compare_param_hlsl_types? Couldn't hlsl_types_are_equal just cast to bool the result on compare_param_hlsl_types?
Thanks, Giovanni.
On 10/7/21 06:58, Giovanni Mascellani wrote:
Hi,
Il 06/10/21 16:45, Zebediah Figura ha scritto:
@@ -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;
Shouldn't compare_param_hlsl_types be changed in a similar way?
Indeed; thanks for catching that.
More in general, do we really need both hlsl_types_are_equal and compare_param_hlsl_types? Couldn't hlsl_types_are_equal just cast to bool the result on compare_param_hlsl_types?
They don't behave exactly the same, though. In particular, compare_param_hlsl_types() will count "float" as equal to "float1", and "row_major float4x4" as equal to "column_major float4x4".
Some brief testing suggests this is incorrect, though. Native will let you do this:
void func(float a) {}
void func(float1 a) {}
It will also accept "row_major float4x4" alongside "column_major 4x4". Even worse, though, it will accept "float4x4" alongside "column_major 4x4", "float" alongside "const float" alongside "volatile float", and even the following:
void func(float a) {}
typedef float myfloat; void func(myfloat a) {}
It won't accept "float" alongside "in float", though. That's too far. But it will accept "float" alongside "inout float" alongside "out float".
Of course, attempting to actually *call* func in any of these cases results in an "ambiguous function call" error. So it's not completely insane.
On 10/7/21 11:19, Zebediah Figura (she/her) wrote:
On 10/7/21 06:58, Giovanni Mascellani wrote:
Hi,
Il 06/10/21 16:45, Zebediah Figura ha scritto:
@@ -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;
Shouldn't compare_param_hlsl_types be changed in a similar way?
Indeed; thanks for catching that.
More in general, do we really need both hlsl_types_are_equal and compare_param_hlsl_types? Couldn't hlsl_types_are_equal just cast to bool the result on compare_param_hlsl_types?
They don't behave exactly the same, though. In particular, compare_param_hlsl_types() will count "float" as equal to "float1", and "row_major float4x4" as equal to "column_major float4x4".
Some brief testing suggests this is incorrect, though. Native will let you do this:
void func(float a) {}
void func(float1 a) {}
It will also accept "row_major float4x4" alongside "column_major 4x4". Even worse, though, it will accept "float4x4" alongside "column_major 4x4", "float" alongside "const float" alongside "volatile float", and even the following:
void func(float a) {}
typedef float myfloat; void func(myfloat a) {}
It won't accept "float" alongside "in float", though. That's too far. But it will accept "float" alongside "inout float" alongside "out float".
Of course, attempting to actually *call* func in any of these cases results in an "ambiguous function call" error. So it's not completely insane.
Anyway, what I was going to say is that we probably don't want that function (and if we do really need differences we may want to implement them with flags instead; cf. expr_compatible_data_types().) But it deserves some actual unit tests.
On Thu, Oct 7, 2021 at 6:34 PM Zebediah Figura (she/her) zfigura@codeweavers.com wrote:
On 10/7/21 11:19, Zebediah Figura (she/her) wrote:
On 10/7/21 06:58, Giovanni Mascellani wrote:
Hi,
Il 06/10/21 16:45, Zebediah Figura ha scritto:
@@ -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;
Shouldn't compare_param_hlsl_types be changed in a similar way?
Indeed; thanks for catching that.
More in general, do we really need both hlsl_types_are_equal and compare_param_hlsl_types? Couldn't hlsl_types_are_equal just cast to bool the result on compare_param_hlsl_types?
They don't behave exactly the same, though. In particular, compare_param_hlsl_types() will count "float" as equal to "float1", and "row_major float4x4" as equal to "column_major float4x4".
Some brief testing suggests this is incorrect, though. Native will let you do this:
void func(float a) {}
void func(float1 a) {}
It will also accept "row_major float4x4" alongside "column_major 4x4". Even worse, though, it will accept "float4x4" alongside "column_major 4x4", "float" alongside "const float" alongside "volatile float", and even the following:
void func(float a) {}
typedef float myfloat; void func(myfloat a) {}
It won't accept "float" alongside "in float", though. That's too far. But it will accept "float" alongside "inout float" alongside "out float".
Of course, attempting to actually *call* func in any of these cases results in an "ambiguous function call" error. So it's not completely insane.
Anyway, what I was going to say is that we probably don't want that function (and if we do really need differences we may want to implement them with flags instead; cf. expr_compatible_data_types().) But it deserves some actual unit tests.
That sounds like a good plan.
Hi,
Il 07/10/21 18:19, Zebediah Figura (she/her) ha scritto:
They don't behave exactly the same, though. In particular, compare_param_hlsl_types() will count "float" as equal to "float1", and "row_major float4x4" as equal to "column_major float4x4".
Ah, ok, didn't think of that. I am not sure that the compatibility of function overloads is regulated by an equivalence relation, so I am not sure this approach can really work, but I guess it's ok to postpone this problem until we want to really fix it (which probably means until we find a shader that depends on it).
Some brief testing suggests this is incorrect, though. Native will let you do this:
void func(float a) {}
void func(float1 a) {}
It will also accept "row_major float4x4" alongside "column_major 4x4". Even worse, though, it will accept "float4x4" alongside "column_major 4x4", "float" alongside "const float" alongside "volatile float", and even the following:
void func(float a) {}
typedef float myfloat; void func(myfloat a) {}
It won't accept "float" alongside "in float", though. That's too far. But it will accept "float" alongside "inout float" alongside "out float".
Of course, attempting to actually *call* func in any of these cases results in an "ambiguous function call" error. So it's not completely insane.
I think it is pretty insane anyway, especially given that even in the case of float vs float1 I don't think you have any mean at all to differentiate between the two. So, as soon as you define both of them, there is no way to call either, even with explicit casts.
Thanks, Giovanni.
On 10/8/21 03:41, Giovanni Mascellani wrote:
Hi,
Il 07/10/21 18:19, Zebediah Figura (she/her) ha scritto:
They don't behave exactly the same, though. In particular, compare_param_hlsl_types() will count "float" as equal to "float1", and "row_major float4x4" as equal to "column_major float4x4".
Ah, ok, didn't think of that. I am not sure that the compatibility of function overloads is regulated by an equivalence relation, so I am not sure this approach can really work, but I guess it's ok to postpone this problem until we want to really fix it (which probably means until we find a shader that depends on it).
I think the compatibility isn't, no, and I'm sure this code was written with the idea in mind that it could be used to look up the correct overloads for a call. Which it can't, really.
Frankly I'm not sure there's much reason to use an rbtree for function overloads, at least not given the way we implement intrinsics now. So maybe compare_param_hlsl_types() really doesn't need to exist, and hlsl_types_are_equal() is enough.
On Fri, Oct 8, 2021 at 6:44 PM Zebediah Figura (she/her) zfigura@codeweavers.com wrote:
On 10/8/21 03:41, Giovanni Mascellani wrote:
Hi,
Il 07/10/21 18:19, Zebediah Figura (she/her) ha scritto:
They don't behave exactly the same, though. In particular, compare_param_hlsl_types() will count "float" as equal to "float1", and "row_major float4x4" as equal to "column_major float4x4".
Ah, ok, didn't think of that. I am not sure that the compatibility of function overloads is regulated by an equivalence relation, so I am not sure this approach can really work, but I guess it's ok to postpone this problem until we want to really fix it (which probably means until we find a shader that depends on it).
I think the compatibility isn't, no, and I'm sure this code was written with the idea in mind that it could be used to look up the correct overloads for a call. Which it can't, really.
Yep, that's right. Unfortunate.
Frankly I'm not sure there's much reason to use an rbtree for function overloads, at least not given the way we implement intrinsics now. So maybe compare_param_hlsl_types() really doesn't need to exist, and hlsl_types_are_equal() is enough.
That sounds likely, given the above. Up to you to decide if (or when) to simplify function overloads storage.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1f23a478c..87841e0e4 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -886,6 +886,35 @@ 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; + } + + 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 06/10/21 16:45, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1f23a478c..87841e0e4 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -886,6 +886,35 @@ 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;
}
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
On Wed, Oct 6, 2021 at 4:45 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1f23a478c..87841e0e4 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -886,6 +886,35 @@ 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;
}
This made me curious about the casing of the generic "texture" (only lowercase?) so I ran a few tests. It looks like "texture" actually accepts all the casing variations. It is also still handled as a keyword rather than an identifier, somehow. Maybe you were already aware of this. At any rate, I don't think we should care until we find some application that depends on it.
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;
I guess this could use a couple of asserts for the array indices, if we're feeling paranoid.
On 10/7/21 13:46, Matteo Bruni wrote:
On Wed, Oct 6, 2021 at 4:45 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 1f23a478c..87841e0e4 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -886,6 +886,35 @@ 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;
}
This made me curious about the casing of the generic "texture" (only lowercase?) so I ran a few tests. It looks like "texture" actually accepts all the casing variations. It is also still handled as a keyword rather than an identifier, somehow. Maybe you were already aware of this. At any rate, I don't think we should care until we find some application that depends on it.
That's pretty easy to achieve with flex, actually, but I'll leave it alone regardless.
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;
I guess this could use a couple of asserts for the array indices, if we're feeling paranoid.
I wasn't feeling particularly paranoid, but I can add them anyway.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 46 ++++++++++++++ libs/vkd3d-shader/hlsl.h | 24 ++++++++ libs/vkd3d-shader/hlsl.y | 100 ++++++++++++++++++++++++++++++- libs/vkd3d-shader/hlsl_codegen.c | 14 +++++ libs/vkd3d-shader/hlsl_sm1.c | 5 ++ libs/vkd3d-shader/hlsl_sm4.c | 5 ++ 6 files changed, 193 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 87841e0e4..24caaf3c8 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -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, 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) { @@ -985,6 +1001,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", }; @@ -1207,6 +1224,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, "= ("); @@ -1273,6 +1304,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; @@ -1371,6 +1406,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); @@ -1414,6 +1456,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..80a8989c1 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); @@ -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, 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..3bf40563f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -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, 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 06/10/21 16:45, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 46 ++++++++++++++ libs/vkd3d-shader/hlsl.h | 24 ++++++++ libs/vkd3d-shader/hlsl.y | 100 ++++++++++++++++++++++++++++++- libs/vkd3d-shader/hlsl_codegen.c | 14 +++++ libs/vkd3d-shader/hlsl_sm1.c | 5 ++ libs/vkd3d-shader/hlsl_sm4.c | 5 ++ 6 files changed, 193 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 87841e0e4..24caaf3c8 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -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, 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) {
@@ -985,6 +1001,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", };
@@ -1207,6 +1224,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, "= (");
@@ -1273,6 +1304,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;
@@ -1371,6 +1406,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);
@@ -1414,6 +1456,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..80a8989c1 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);
@@ -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, struct vkd3d_shader_location loc);
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 32dd418d1..3bf40563f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -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, 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
On Wed, Oct 6, 2021 at 4:45 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 46 ++++++++++++++ libs/vkd3d-shader/hlsl.h | 24 ++++++++ libs/vkd3d-shader/hlsl.y | 100 ++++++++++++++++++++++++++++++- libs/vkd3d-shader/hlsl_codegen.c | 14 +++++ libs/vkd3d-shader/hlsl_sm1.c | 5 ++ libs/vkd3d-shader/hlsl_sm4.c | 5 ++ 6 files changed, 193 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 32dd418d1..3bf40563f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y
@@ -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, struct vkd3d_shader_location loc)
We have a mix of functions taking the location by value or by pointer. I think we want to consistently pass it by pointer, going forward.
On 10/7/21 13:47, Matteo Bruni wrote:
On Wed, Oct 6, 2021 at 4:45 PM Zebediah Figura zfigura@codeweavers.com wrote:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 46 ++++++++++++++ libs/vkd3d-shader/hlsl.h | 24 ++++++++ libs/vkd3d-shader/hlsl.y | 100 ++++++++++++++++++++++++++++++- libs/vkd3d-shader/hlsl_codegen.c | 14 +++++ libs/vkd3d-shader/hlsl_sm1.c | 5 ++ libs/vkd3d-shader/hlsl_sm4.c | 5 ++ 6 files changed, 193 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/xhlsl.y index 32dd418d1..3bf40563f 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y
@@ -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, struct vkd3d_shader_location loc)
We have a mix of functions taking the location by value or by pointer. I think we want to consistently pass it by pointer, going forward.
The main reason I wanted to pass it by value was to avoid the "&@" cluster, which is not particularly easy to read. I'll set that concern aside from now on, though.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 06/10/21 16:45, 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);