vkd3d-shader/hlsl: Parse explicitly typed texture types.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura
2021-10-07 21:58:55 -05:00
committed by Alexandre Julliard
parent a318f36e59
commit a56c294abe
3 changed files with 57 additions and 20 deletions

View File

@ -261,7 +261,7 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, s
return type; 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; 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->dimx = 4;
type->dimy = 1; type->dimy = 1;
type->sampler_dim = dim; type->sampler_dim = dim;
type->e.resource_format = format;
list_add_tail(&ctx->types, &type->entry); list_add_tail(&ctx->types, &type->entry);
return type; return type;
} }
@ -344,9 +345,14 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2
return false; return false;
if (t1->base_type != t2->base_type) if (t1->base_type != t2->base_type)
return false; return false;
if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) if (t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE)
&& t1->sampler_dim != t2->sampler_dim) {
if (t1->sampler_dim != t2->sampler_dim)
return false; 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) if ((t1->modifiers & HLSL_MODIFIER_ROW_MAJOR)
!= (t2->modifiers & HLSL_MODIFIER_ROW_MAJOR)) != (t2->modifiers & HLSL_MODIFIER_ROW_MAJOR))
return false; 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) 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 != t2->type)
{ {
if (!((t1->type == HLSL_CLASS_SCALAR && t2->type == HLSL_CLASS_VECTOR) 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; return t1->base_type - t2->base_type;
if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE) if ((t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE)
&& t1->sampler_dim != t2->sampler_dim) && t1->sampler_dim != t2->sampler_dim)
{
if (t1->sampler_dim != t2->sampler_dim)
return 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) if (t1->dimx != t2->dimx)
return t1->dimx - t2->dimx; return t1->dimx - t2->dimx;
if (t1->dimy != t2->dimy) 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 list *t1cur, *t2cur;
struct hlsl_struct_field *t1field, *t2field; struct hlsl_struct_field *t1field, *t2field;
int r;
t1cur = list_head(t1->e.elements); t1cur = list_head(t1->e.elements);
t2cur = list_head(t2->e.elements); t2cur = list_head(t2->e.elements);

View File

@ -126,6 +126,7 @@ struct hlsl_type
struct hlsl_type *type; struct hlsl_type *type;
unsigned int elements_count; unsigned int elements_count;
} array; } array;
struct hlsl_type *resource_format;
} e; } e;
unsigned int reg_size; 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_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, 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); 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, struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
const struct vkd3d_shader_location loc); 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, struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg,

View File

@ -1789,6 +1789,7 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type
struct parse_colon_attribute colon_attribute; struct parse_colon_attribute colon_attribute;
struct hlsl_semantic semantic; struct hlsl_semantic semantic;
enum hlsl_buffer_type buffer_type; enum hlsl_buffer_type buffer_type;
enum hlsl_sampler_dim sampler_dim;
} }
%token KW_BLENDSTATE %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 <reg_reservation> register_opt
%type <sampler_dim> texture_type
%type <semantic> semantic %type <semantic> semantic
%type <type> field_type %type <type> field_type
@ -2376,6 +2379,24 @@ input_mod:
$$ = HLSL_STORAGE_IN | HLSL_STORAGE_OUT; $$ = 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: type:
KW_VECTOR '<' type ',' C_INTEGER '>' KW_VECTOR '<' type ',' C_INTEGER '>'
{ {
@ -2453,23 +2474,25 @@ type:
} }
| KW_TEXTURE | KW_TEXTURE
{ {
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC); $$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_GENERIC, NULL);
} }
| KW_TEXTURE1D | texture_type
{ {
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_1D); $$ = hlsl_new_texture_type(ctx, $1, ctx->builtin_types.vector[HLSL_TYPE_FLOAT][4 - 1]);
} }
| KW_TEXTURE2D | texture_type '<' type '>'
{ {
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_2D); 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);
} }
| KW_TEXTURE3D $$ = hlsl_new_texture_type(ctx, $1, $3);
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_3D);
}
| KW_TEXTURECUBE
{
$$ = hlsl_new_texture_type(ctx, HLSL_SAMPLER_DIM_CUBE);
} }
| TYPE_IDENTIFIER | TYPE_IDENTIFIER
{ {