From: Evan Tang etang@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 3 +- libs/vkd3d-shader/hlsl.h | 7 ++- libs/vkd3d-shader/hlsl.l | 5 ++ libs/vkd3d-shader/hlsl.y | 112 ++++++++++++++++++++++++++------------- libs/vkd3d-shader/tpf.c | 5 ++ 5 files changed, 91 insertions(+), 41 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8b706e1e6..aa1726cd3 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -720,7 +720,7 @@ 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 *hlsl_new_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format, unsigned int modifiers) { struct hlsl_type *type;
@@ -731,6 +731,7 @@ struct hlsl_type *hlsl_new_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim type->dimx = format->dimx; type->dimy = 1; type->sampler_dim = dim; + type->modifiers = modifiers; type->e.resource_format = format; hlsl_type_calculate_reg_size(ctx, type); list_add_tail(&ctx->types, &type->entry); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 8bc72a8a2..919f2be62 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -357,10 +357,13 @@ struct hlsl_attribute #define HLSL_STORAGE_IN 0x00000800 #define HLSL_STORAGE_OUT 0x00001000 #define HLSL_MODIFIER_INLINE 0x00002000 +#define HLSL_MODIFIER_GLOBALLY_COHERENT 0x04000 +#define HLSL_MODIFIER_RASTERIZER_ORDERED 0x8000
#define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_MODIFIER_VOLATILE | \ HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \ - HLSL_MODIFIER_COLUMN_MAJOR) + HLSL_MODIFIER_COLUMN_MAJOR | HLSL_MODIFIER_GLOBALLY_COHERENT | \ + HLSL_MODIFIER_RASTERIZER_ORDERED)
#define HLSL_MODIFIERS_MAJORITY_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
@@ -1184,7 +1187,7 @@ struct hlsl_ir_var *hlsl_new_synthetic_var_named(struct hlsl_ctx *ctx, const cha struct hlsl_type *type, const struct vkd3d_shader_location *loc, bool dummy_scope); struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format, unsigned int sample_count); -struct hlsl_type *hlsl_new_uav_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, unsigned int modifiers); struct hlsl_ir_node *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.l b/libs/vkd3d-shader/hlsl.l index e9ae3ccf3..cb7d4f277 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -100,6 +100,11 @@ packoffset {return KW_PACKOFFSET; } pass {return KW_PASS; } PixelShader {return KW_PIXELSHADER; } precise {return KW_PRECISE; } +RasterizerOrderedBuffer {return KW_RASTERIZERORDEREDBUFFER; } +RasterizerOrderedStructuredBuffer {return KW_RASTERIZERORDEREDSTRUCTUREDBUFFER; } +RasterizerOrderedTexture1D {return KW_RASTERIZERORDEREDTEXTURE1D; } +RasterizerOrderedTexture2D {return KW_RASTERIZERORDEREDTEXTURE2D; } +RasterizerOrderedTexture3D {return KW_RASTERIZERORDEREDTEXTURE3D; } RasterizerState {return KW_RASTERIZERSTATE; } RenderTargetView {return KW_RENDERTARGETVIEW; } return {return KW_RETURN; } diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 43ea4b4d0..fceef364e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4568,6 +4568,45 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type } }
+static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format, const struct vkd3d_shader_location* loc) +{ + struct vkd3d_string_buffer *string = hlsl_type_to_string(ctx, format); + + if (!type_contains_only_numerics(format)) + { + if (string) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "UAV type %s is not numeric.", string->buffer); + } + + switch (dim) + { + case HLSL_SAMPLER_DIM_BUFFER: + case HLSL_SAMPLER_DIM_1D: + case HLSL_SAMPLER_DIM_2D: + case HLSL_SAMPLER_DIM_3D: + if (format->class == HLSL_CLASS_ARRAY) + { + if (string) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "This type of UAV does not support array type."); + } + else if (hlsl_type_component_count(format) > 4) + { + if (string) + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, + "UAV data type %s size exceeds maximum size.", string->buffer); + } + break; + case HLSL_SAMPLER_DIM_STRUCTURED_BUFFER: + break; + default: + vkd3d_unreachable(); + } + + hlsl_release_string_buffer(ctx, string); +} + }
%locations @@ -4639,6 +4678,11 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %token KW_PASS %token KW_PIXELSHADER %token KW_PRECISE +%token KW_RASTERIZERORDEREDBUFFER +%token KW_RASTERIZERORDEREDSTRUCTUREDBUFFER +%token KW_RASTERIZERORDEREDTEXTURE1D +%token KW_RASTERIZERORDEREDTEXTURE2D +%token KW_RASTERIZERORDEREDTEXTURE3D %token KW_RASTERIZERSTATE %token KW_RENDERTARGETVIEW %token KW_RETURN @@ -4795,7 +4839,7 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type <reg_reservation> register_opt %type <reg_reservation> packoffset_opt
-%type <sampler_dim> texture_type texture_ms_type uav_type +%type <sampler_dim> texture_type texture_ms_type uav_type rov_type
%type <semantic> semantic
@@ -5474,6 +5518,28 @@ uav_type: $$ = HLSL_SAMPLER_DIM_3D; }
+rov_type: + KW_RASTERIZERORDEREDBUFFER + { + $$ = HLSL_SAMPLER_DIM_BUFFER; + } + | KW_RASTERIZERORDEREDSTRUCTUREDBUFFER + { + $$ = HLSL_SAMPLER_DIM_STRUCTURED_BUFFER; + } + | KW_RASTERIZERORDEREDTEXTURE1D + { + $$ = HLSL_SAMPLER_DIM_1D; + } + | KW_RASTERIZERORDEREDTEXTURE2D + { + $$ = HLSL_SAMPLER_DIM_2D; + } + | KW_RASTERIZERORDEREDTEXTURE3D + { + $$ = HLSL_SAMPLER_DIM_3D; + } + type_no_void: KW_VECTOR '<' type ',' C_INTEGER '>' { @@ -5602,43 +5668,13 @@ type_no_void: } | uav_type '<' type '>' { - struct vkd3d_string_buffer *string = hlsl_type_to_string(ctx, $3); - - if (!type_contains_only_numerics($3)) - { - if (string) - hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, - "UAV type %s is not numeric.", string->buffer); - } - - switch ($1) - { - case HLSL_SAMPLER_DIM_BUFFER: - case HLSL_SAMPLER_DIM_1D: - case HLSL_SAMPLER_DIM_2D: - case HLSL_SAMPLER_DIM_3D: - if ($3->class == HLSL_CLASS_ARRAY) - { - if (string) - hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, - "This type of UAV does not support array type."); - } - else if (hlsl_type_component_count($3) > 4) - { - if (string) - hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, - "UAV data type %s size exceeds maximum size.", string->buffer); - } - break; - case HLSL_SAMPLER_DIM_STRUCTURED_BUFFER: - break; - default: - vkd3d_unreachable(); - } - - hlsl_release_string_buffer(ctx, string); - - $$ = hlsl_new_uav_type(ctx, $1, $3); + validate_uav_type(ctx, $1, $3, &@3); + $$ = hlsl_new_uav_type(ctx, $1, $3, 0); + } + | rov_type '<' type '>' + { + validate_uav_type(ctx, $1, $3, &@3); + $$ = hlsl_new_uav_type(ctx, $1, $3, HLSL_MODIFIER_RASTERIZER_ORDERED); } | TYPE_IDENTIFIER { diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 9142ed989..d21a8fc44 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4098,6 +4098,11 @@ static void write_sm4_dcl_textures(const struct tpf_writer *tpf, const struct ex instr.opcode |= component_type->sample_count << VKD3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT; }
+ if (resource->data_type->modifiers & HLSL_MODIFIER_RASTERIZER_ORDERED) + instr.opcode |= VKD3DSUF_RASTERISER_ORDERED_VIEW << VKD3D_SM5_UAV_FLAGS_SHIFT; + else if (resource->data_type->modifiers & HLSL_MODIFIER_GLOBALLY_COHERENT) + instr.opcode |= VKD3DSUF_GLOBALLY_COHERENT << VKD3D_SM5_UAV_FLAGS_SHIFT; + write_sm4_instruction(tpf, &instr); } }