From: Evan Tang etang@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 3 +- libs/vkd3d-shader/hlsl.h | 39 +++--- libs/vkd3d-shader/hlsl.l | 5 + libs/vkd3d-shader/hlsl.y | 112 ++++++++++++------ libs/vkd3d-shader/tpf.c | 5 + .../hlsl/rasterizer-ordered-views.shader_test | 8 +- 6 files changed, 111 insertions(+), 61 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index b42e30888..af6586fe7 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -759,7 +759,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;
@@ -770,6 +770,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 9f1a3fe21..15674dbff 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -340,26 +340,29 @@ struct hlsl_attribute struct hlsl_src args[]; };
-#define HLSL_STORAGE_EXTERN 0x00000001 -#define HLSL_STORAGE_NOINTERPOLATION 0x00000002 -#define HLSL_MODIFIER_PRECISE 0x00000004 -#define HLSL_STORAGE_SHARED 0x00000008 -#define HLSL_STORAGE_GROUPSHARED 0x00000010 -#define HLSL_STORAGE_STATIC 0x00000020 -#define HLSL_STORAGE_UNIFORM 0x00000040 -#define HLSL_MODIFIER_VOLATILE 0x00000080 -#define HLSL_MODIFIER_CONST 0x00000100 -#define HLSL_MODIFIER_ROW_MAJOR 0x00000200 -#define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400 -#define HLSL_STORAGE_IN 0x00000800 -#define HLSL_STORAGE_OUT 0x00001000 -#define HLSL_MODIFIER_INLINE 0x00002000 -#define HLSL_STORAGE_CENTROID 0x00004000 -#define HLSL_STORAGE_NOPERSPECTIVE 0x00008000 +#define HLSL_STORAGE_EXTERN 0x00000001 +#define HLSL_STORAGE_NOINTERPOLATION 0x00000002 +#define HLSL_MODIFIER_PRECISE 0x00000004 +#define HLSL_STORAGE_SHARED 0x00000008 +#define HLSL_STORAGE_GROUPSHARED 0x00000010 +#define HLSL_STORAGE_STATIC 0x00000020 +#define HLSL_STORAGE_UNIFORM 0x00000040 +#define HLSL_MODIFIER_VOLATILE 0x00000080 +#define HLSL_MODIFIER_CONST 0x00000100 +#define HLSL_MODIFIER_ROW_MAJOR 0x00000200 +#define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400 +#define HLSL_STORAGE_IN 0x00000800 +#define HLSL_STORAGE_OUT 0x00001000 +#define HLSL_MODIFIER_INLINE 0x00002000 +#define HLSL_STORAGE_CENTROID 0x00004000 +#define HLSL_STORAGE_NOPERSPECTIVE 0x00008000 +#define HLSL_MODIFIER_GLOBALLY_COHERENT 0x00010000 +#define HLSL_MODIFIER_RASTERIZER_ORDERED 0x00020000
#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_INTERPOLATION_MODIFIERS_MASK (HLSL_STORAGE_NOINTERPOLATION | HLSL_STORAGE_CENTROID | \ HLSL_STORAGE_NOPERSPECTIVE) @@ -1203,7 +1206,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 90abd64a3..a98693f50 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -102,6 +102,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 ba738473f..198fc0b1c 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4641,6 +4641,45 @@ static struct hlsl_scope *get_loop_scope(struct hlsl_scope *scope) return scope->upper ? get_loop_scope(scope->upper) : NULL; }
+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 @@ -4714,6 +4753,11 @@ static struct hlsl_scope *get_loop_scope(struct hlsl_scope *scope) %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 @@ -4870,7 +4914,7 @@ static struct hlsl_scope *get_loop_scope(struct hlsl_scope *scope) %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
@@ -5556,6 +5600,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 '>' { @@ -5684,43 +5750,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 5e65f843c..c58609472 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4106,6 +4106,11 @@ static void write_sm4_dcl_textures(const struct tpf_writer *tpf, const struct ex instr.extra_bits |= 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); } } diff --git a/tests/hlsl/rasterizer-ordered-views.shader_test b/tests/hlsl/rasterizer-ordered-views.shader_test index d40be4314..6ab453c38 100644 --- a/tests/hlsl/rasterizer-ordered-views.shader_test +++ b/tests/hlsl/rasterizer-ordered-views.shader_test @@ -23,7 +23,7 @@ format r32g32b32a32 uint size (1, 1) 0 0 0 0
-[pixel shader todo] +[pixel shader] RasterizerOrderedTexture2D<uint4> tex : register(u1); Texture2D<uint4> spin : register(t0);
@@ -45,6 +45,6 @@ uint4 main(float4 pos : SV_Position, uint id : SV_PrimitiveID) : SV_Target return val; } [test] -todo draw triangle list 93 -probe uav 1 all rui ( 0x7fffffff ) -probe all rui ( 0x3fffffff ) +todo(sm>=6) draw triangle list 93 +todo probe uav 1 all rui ( 0x7fffffff ) +todo probe all rui ( 0x3fffffff )