From 1a6409cd5bc6836dcb7e232c863e69cf31edf07f Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 8 Nov 2024 16:15:32 +0100 Subject: [PATCH] vkd3d-shader/hlsl: Add parser support for stream-output object types. Signed-off-by: Nikolay Sivov --- libs/vkd3d-shader/d3dbc.c | 2 ++ libs/vkd3d-shader/fx.c | 2 ++ libs/vkd3d-shader/hlsl.c | 40 ++++++++++++++++++++++++++++++++ libs/vkd3d-shader/hlsl.h | 16 +++++++++++++ libs/vkd3d-shader/hlsl.l | 3 +++ libs/vkd3d-shader/hlsl.y | 24 +++++++++++++++++++ libs/vkd3d-shader/hlsl_codegen.c | 1 + libs/vkd3d-shader/tpf.c | 1 + 8 files changed, 89 insertions(+) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 9e2eacbc..bda9bc72 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1565,6 +1565,7 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type) case HLSL_CLASS_HULL_SHADER: case HLSL_CLASS_GEOMETRY_SHADER: case HLSL_CLASS_BLEND_STATE: + case HLSL_CLASS_STREAM_OUTPUT: case HLSL_CLASS_NULL: break; } @@ -1671,6 +1672,7 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) case HLSL_CLASS_HULL_SHADER: case HLSL_CLASS_GEOMETRY_SHADER: case HLSL_CLASS_BLEND_STATE: + case HLSL_CLASS_STREAM_OUTPUT: case HLSL_CLASS_NULL: break; } diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index e22177e1..cb42551e 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -762,6 +762,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co case HLSL_CLASS_TECHNIQUE: case HLSL_CLASS_CONSTANT_BUFFER: case HLSL_CLASS_NULL: + case HLSL_CLASS_STREAM_OUTPUT: vkd3d_unreachable(); case HLSL_CLASS_VOID: @@ -1298,6 +1299,7 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type case HLSL_CLASS_TECHNIQUE: case HLSL_CLASS_CONSTANT_BUFFER: case HLSL_CLASS_NULL: + case HLSL_CLASS_STREAM_OUTPUT: /* This cannot appear as an extern variable. */ break; } diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 96de18dc..3be9ba99 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -287,6 +287,7 @@ bool hlsl_type_is_shader(const struct hlsl_type *type) case HLSL_CLASS_UAV: case HLSL_CLASS_CONSTANT_BUFFER: case HLSL_CLASS_BLEND_STATE: + case HLSL_CLASS_STREAM_OUTPUT: case HLSL_CLASS_VOID: case HLSL_CLASS_NULL: return false; @@ -434,6 +435,7 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type case HLSL_CLASS_HULL_SHADER: case HLSL_CLASS_GEOMETRY_SHADER: case HLSL_CLASS_BLEND_STATE: + case HLSL_CLASS_STREAM_OUTPUT: case HLSL_CLASS_NULL: break; } @@ -525,6 +527,7 @@ static bool type_is_single_component(const struct hlsl_type *type) case HLSL_CLASS_PASS: case HLSL_CLASS_TECHNIQUE: case HLSL_CLASS_VOID: + case HLSL_CLASS_STREAM_OUTPUT: break; } vkd3d_unreachable(); @@ -680,6 +683,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty case HLSL_CLASS_SCALAR: case HLSL_CLASS_CONSTANT_BUFFER: case HLSL_CLASS_NULL: + case HLSL_CLASS_STREAM_OUTPUT: vkd3d_unreachable(); } type = next_type; @@ -898,6 +902,22 @@ struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *ba return type; } +struct hlsl_type *hlsl_new_stream_output_type(struct hlsl_ctx *ctx, + enum hlsl_so_object_type so_type, struct hlsl_type *data_type) +{ + struct hlsl_type *type; + + if (!(type = hlsl_alloc(ctx, sizeof(*type)))) + return NULL; + type->class = HLSL_CLASS_STREAM_OUTPUT; + type->e.so.so_type = so_type; + type->e.so.type = data_type; + + list_add_tail(&ctx->types, &type->entry); + + return type; +} + struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct hlsl_struct_field *fields, size_t field_count) { @@ -1086,6 +1106,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type) case HLSL_CLASS_PASS: case HLSL_CLASS_TECHNIQUE: case HLSL_CLASS_VOID: + case HLSL_CLASS_STREAM_OUTPUT: break; } @@ -1157,6 +1178,11 @@ bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2 case HLSL_CLASS_CONSTANT_BUFFER: return hlsl_types_are_equal(t1->e.resource.format, t2->e.resource.format); + case HLSL_CLASS_STREAM_OUTPUT: + if (t1->e.so.so_type != t2->e.so.so_type) + return false; + return hlsl_types_are_equal(t1->e.so.type, t2->e.so.type); + case HLSL_CLASS_DEPTH_STENCIL_STATE: case HLSL_CLASS_DEPTH_STENCIL_VIEW: case HLSL_CLASS_EFFECT_GROUP: @@ -2836,6 +2862,20 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru vkd3d_string_buffer_printf(string, ""); return string; + case HLSL_CLASS_STREAM_OUTPUT: + if (type->e.so.so_type == HLSL_STREAM_OUTPUT_POINT_STREAM) + vkd3d_string_buffer_printf(string, "PointStream"); + else if (type->e.so.so_type == HLSL_STREAM_OUTPUT_LINE_STREAM) + vkd3d_string_buffer_printf(string, "LineStream"); + else + vkd3d_string_buffer_printf(string, "TriangleStream"); + if ((inner_string = hlsl_type_to_string(ctx, type->e.so.type))) + { + vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer); + hlsl_release_string_buffer(ctx, inner_string); + } + return string; + case HLSL_CLASS_DEPTH_STENCIL_STATE: case HLSL_CLASS_DEPTH_STENCIL_VIEW: case HLSL_CLASS_EFFECT_GROUP: diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index be63e742..4dbc0413 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -104,6 +104,7 @@ enum hlsl_type_class HLSL_CLASS_GEOMETRY_SHADER, HLSL_CLASS_CONSTANT_BUFFER, HLSL_CLASS_BLEND_STATE, + HLSL_CLASS_STREAM_OUTPUT, HLSL_CLASS_VOID, HLSL_CLASS_NULL, HLSL_CLASS_ERROR, @@ -141,6 +142,13 @@ enum hlsl_sampler_dim /* NOTE: Remember to update object_methods[] in hlsl.y if this enum is modified. */ }; +enum hlsl_so_object_type +{ + HLSL_STREAM_OUTPUT_POINT_STREAM, + HLSL_STREAM_OUTPUT_LINE_STREAM, + HLSL_STREAM_OUTPUT_TRIANGLE_STREAM, +}; + enum hlsl_regset { HLSL_REGSET_SAMPLERS, @@ -219,6 +227,12 @@ struct hlsl_type } resource; /* Additional field to distinguish object types. Currently used only for technique types. */ unsigned int version; + /* Additional information if type is HLSL_CLASS_STREAM_OUTPUT. */ + struct + { + struct hlsl_type *type; + enum hlsl_so_object_type so_type; + } so; } e; /* Number of numeric register components used by one value of this type, for each regset. @@ -1518,6 +1532,8 @@ struct hlsl_ir_node *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *cond struct hlsl_ir_node *hlsl_new_int_constant(struct hlsl_ctx *ctx, int32_t n, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type, struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc); +struct hlsl_type *hlsl_new_stream_output_type(struct hlsl_ctx *ctx, + enum hlsl_so_object_type so_type, struct hlsl_type *type); struct hlsl_ir_node *hlsl_new_ternary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, struct hlsl_ir_node *arg3); diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l index 8dace119..31fb3052 100644 --- a/libs/vkd3d-shader/hlsl.l +++ b/libs/vkd3d-shader/hlsl.l @@ -104,6 +104,7 @@ if {return KW_IF; } in {return KW_IN; } inline {return KW_INLINE; } inout {return KW_INOUT; } +LineStream {return KW_LINESTREAM; } linear {return KW_LINEAR; } matrix {return KW_MATRIX; } namespace {return KW_NAMESPACE; } @@ -114,6 +115,7 @@ out {return KW_OUT; } packoffset {return KW_PACKOFFSET; } pass {return KW_PASS; } PixelShader {return KW_PIXELSHADER; } +PointStream {return KW_POINTSTREAM; } pixelshader {return KW_PIXELSHADER; } RasterizerOrderedBuffer {return KW_RASTERIZERORDEREDBUFFER; } RasterizerOrderedStructuredBuffer {return KW_RASTERIZERORDEREDSTRUCTUREDBUFFER; } @@ -170,6 +172,7 @@ texture3D {return KW_TEXTURE3D; } TextureCube {return KW_TEXTURECUBE; } textureCUBE {return KW_TEXTURECUBE; } TextureCubeArray {return KW_TEXTURECUBEARRAY; } +TriangleStream {return KW_TRIANGLESTREAM; } true {return KW_TRUE; } typedef {return KW_TYPEDEF; } unsigned {return KW_UNSIGNED; } diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 60aade73..03a2f38e 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -6553,6 +6553,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_semantic semantic; enum hlsl_buffer_type buffer_type; enum hlsl_sampler_dim sampler_dim; + enum hlsl_so_object_type so_type; struct hlsl_attribute *attr; struct parse_attribute_list attr_list; struct hlsl_ir_switch_case *switch_case; @@ -6596,6 +6597,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, %token KW_INLINE %token KW_INOUT %token KW_LINEAR +%token KW_LINESTREAM %token KW_MATRIX %token KW_NAMESPACE %token KW_NOINTERPOLATION @@ -6605,6 +6607,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, %token KW_PACKOFFSET %token KW_PASS %token KW_PIXELSHADER +%token KW_POINTSTREAM %token KW_RASTERIZERORDEREDBUFFER %token KW_RASTERIZERORDEREDSTRUCTUREDBUFFER %token KW_RASTERIZERORDEREDTEXTURE1D @@ -6654,6 +6657,7 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, %token KW_TEXTURE3D %token KW_TEXTURECUBE %token KW_TEXTURECUBEARRAY +%token KW_TRIANGLESTREAM %token KW_TRUE %token KW_TYPEDEF %token KW_UNSIGNED @@ -6784,6 +6788,8 @@ static void validate_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, %type semantic +%type so_type + %type state_block %type state_block_index_opt @@ -7805,6 +7811,20 @@ rov_type: $$ = HLSL_SAMPLER_DIM_3D; } +so_type: + KW_POINTSTREAM + { + $$ = HLSL_STREAM_OUTPUT_POINT_STREAM; + } + | KW_LINESTREAM + { + $$ = HLSL_STREAM_OUTPUT_LINE_STREAM; + } + | KW_TRIANGLESTREAM + { + $$ = HLSL_STREAM_OUTPUT_TRIANGLE_STREAM; + } + resource_format: var_modifiers type { @@ -7948,6 +7968,10 @@ type_no_void: validate_uav_type(ctx, $1, $3, &@4); $$ = hlsl_new_uav_type(ctx, $1, $3, true); } + | so_type '<' type '>' + { + $$ = hlsl_new_stream_output_type(ctx, $1, $3); + } | KW_RWBYTEADDRESSBUFFER { $$ = hlsl_new_uav_type(ctx, HLSL_SAMPLER_DIM_RAW_BUFFER, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), false); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index c3de9eb7..070b5875 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1679,6 +1679,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, case HLSL_CLASS_DEPTH_STENCIL_VIEW: case HLSL_CLASS_GEOMETRY_SHADER: case HLSL_CLASS_BLEND_STATE: + case HLSL_CLASS_STREAM_OUTPUT: case HLSL_CLASS_NULL: break; diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 8d363945..0c20981b 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3331,6 +3331,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type) case HLSL_CLASS_HULL_SHADER: case HLSL_CLASS_GEOMETRY_SHADER: case HLSL_CLASS_BLEND_STATE: + case HLSL_CLASS_STREAM_OUTPUT: case HLSL_CLASS_NULL: break; }