vkd3d-shader/hlsl: Parse UAV types.

This commit is contained in:
Zebediah Figura 2021-08-12 21:03:26 -05:00 committed by Alexandre Julliard
parent fea50d243c
commit 0ef04659c7
Notes: Alexandre Julliard 2022-10-19 22:07:47 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/30
5 changed files with 63 additions and 2 deletions

View File

@ -525,6 +525,23 @@ struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_
return type;
}
struct hlsl_type *hlsl_new_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format)
{
struct hlsl_type *type;
if (!(type = vkd3d_calloc(1, sizeof(*type))))
return NULL;
type->type = HLSL_CLASS_OBJECT;
type->base_type = HLSL_TYPE_UAV;
type->dimx = format->dimx;
type->dimy = 1;
type->sampler_dim = dim;
type->e.resource_format = format;
hlsl_type_calculate_reg_size(ctx, type);
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);
@ -596,7 +613,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->base_type == HLSL_TYPE_TEXTURE)
if (t1->base_type == HLSL_TYPE_SAMPLER || t1->base_type == HLSL_TYPE_TEXTURE
|| t1->base_type == HLSL_TYPE_UAV)
{
if (t1->sampler_dim != t2->sampler_dim)
return false;
@ -1411,6 +1429,11 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru
base_types[type->e.resource_format->base_type], type->e.resource_format->dimx);
return string;
case HLSL_TYPE_UAV:
vkd3d_string_buffer_printf(string, "RWTexture%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;

View File

@ -85,6 +85,7 @@ enum hlsl_base_type
HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL,
HLSL_TYPE_SAMPLER,
HLSL_TYPE_TEXTURE,
HLSL_TYPE_UAV,
HLSL_TYPE_PIXELSHADER,
HLSL_TYPE_VERTEXSHADER,
HLSL_TYPE_STRING,
@ -787,6 +788,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned
struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template,
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 *format);
struct hlsl_type *hlsl_new_uav_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,

View File

@ -102,6 +102,9 @@ RasterizerState {return KW_RASTERIZERSTATE; }
RenderTargetView {return KW_RENDERTARGETVIEW; }
return {return KW_RETURN; }
register {return KW_REGISTER; }
RWTexture1D {return KW_RWTEXTURE1D; }
RWTexture2D {return KW_RWTEXTURE2D; }
RWTexture3D {return KW_RWTEXTURE3D; }
sampler {return KW_SAMPLER; }
sampler1D {return KW_SAMPLER1D; }
sampler2D {return KW_SAMPLER2D; }

View File

@ -3031,6 +3031,9 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
%token KW_RETURN
%token KW_REGISTER
%token KW_ROW_MAJOR
%token KW_RWTEXTURE1D
%token KW_RWTEXTURE2D
%token KW_RWTEXTURE3D
%token KW_SAMPLER
%token KW_SAMPLER1D
%token KW_SAMPLER2D
@ -3168,7 +3171,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
%type <reg_reservation> register_opt
%type <sampler_dim> texture_type
%type <sampler_dim> texture_type uav_type
%type <semantic> semantic
@ -3592,6 +3595,20 @@ texture_type:
$$ = HLSL_SAMPLER_DIM_CUBEARRAY;
}
uav_type:
KW_RWTEXTURE1D
{
$$ = HLSL_SAMPLER_DIM_1D;
}
| KW_RWTEXTURE2D
{
$$ = HLSL_SAMPLER_DIM_2D;
}
| KW_RWTEXTURE3D
{
$$ = HLSL_SAMPLER_DIM_3D;
}
type:
KW_VECTOR '<' type ',' C_INTEGER '>'
{
@ -3697,6 +3714,20 @@ type:
}
$$ = hlsl_new_texture_type(ctx, $1, $3);
}
| uav_type '<' type '>'
{
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,
"UAV data type %s is not scalar or vector.", string->buffer);
hlsl_release_string_buffer(ctx, string);
}
$$ = hlsl_new_uav_type(ctx, $1, $3);
}
| TYPE_IDENTIFIER
{
$$ = hlsl_get_type(ctx->cur_scope, $1, true);

View File

@ -410,6 +410,8 @@ static D3D_SHADER_INPUT_TYPE sm4_resource_type(const struct hlsl_type *type)
return D3D_SIT_SAMPLER;
case HLSL_TYPE_TEXTURE:
return D3D_SIT_TEXTURE;
case HLSL_TYPE_UAV:
return D3D_SIT_UAV_RWTYPED;
default:
vkd3d_unreachable();
}