From 874937dab48aedbef1fa99cb2fa60fdcc0d804ac Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 6 Feb 2024 17:33:26 -0600 Subject: [PATCH] vkd3d-shader/hlsl: Make HLSL_TYPE_VERTEXSHADER into a separate class. --- libs/vkd3d-shader/d3dbc.c | 6 ++++-- libs/vkd3d-shader/fx.c | 24 +++++++++++++++++------- libs/vkd3d-shader/hlsl.c | 7 ++++++- libs/vkd3d-shader/hlsl.h | 2 +- libs/vkd3d-shader/hlsl_codegen.c | 1 + libs/vkd3d-shader/tpf.c | 1 + 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index aa235844..145ebd85 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1518,6 +1518,7 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type) case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: + case HLSL_CLASS_VERTEX_SHADER: return D3DXPC_OBJECT; case HLSL_CLASS_DEPTH_STENCIL_VIEW: case HLSL_CLASS_EFFECT_GROUP: @@ -1605,8 +1606,6 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) { case HLSL_TYPE_PIXELSHADER: return D3DXPT_PIXELSHADER; - case HLSL_TYPE_VERTEXSHADER: - return D3DXPT_VERTEXSHADER; default: vkd3d_unreachable(); } @@ -1621,6 +1620,9 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type) case HLSL_CLASS_STRING: return D3DXPT_STRING; + case HLSL_CLASS_VERTEX_SHADER: + return D3DXPT_VERTEXSHADER; + case HLSL_CLASS_DEPTH_STENCIL_VIEW: case HLSL_CLASS_EFFECT_GROUP: case HLSL_CLASS_PASS: diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c index 168378e6..4f94f428 100644 --- a/libs/vkd3d-shader/fx.c +++ b/libs/vkd3d-shader/fx.c @@ -352,7 +352,6 @@ static const char * get_fx_4_type_name(const struct hlsl_type *type) static const char * const object_type_names[] = { [HLSL_TYPE_PIXELSHADER] = "PixelShader", - [HLSL_TYPE_VERTEXSHADER] = "VertexShader", }; static const char * const texture_type_names[] = { @@ -392,11 +391,13 @@ static const char * get_fx_4_type_name(const struct hlsl_type *type) case HLSL_CLASS_RENDER_TARGET_VIEW: return "RenderTargetView"; + case HLSL_CLASS_VERTEX_SHADER: + return "VertexShader"; + case HLSL_CLASS_OBJECT: switch (type->base_type) { case HLSL_TYPE_PIXELSHADER: - case HLSL_TYPE_VERTEXSHADER: return object_type_names[type->base_type]; default: return type->name; @@ -440,6 +441,7 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co case HLSL_CLASS_RENDER_TARGET_VIEW: case HLSL_CLASS_TEXTURE: case HLSL_CLASS_UAV: + case HLSL_CLASS_VERTEX_SHADER: put_u32_unaligned(buffer, 2); break; @@ -532,18 +534,20 @@ static uint32_t write_fx_4_type(const struct hlsl_type *type, struct fx_write_co { put_u32_unaligned(buffer, 19); } + else if (type->class == HLSL_CLASS_VERTEX_SHADER) + { + put_u32_unaligned(buffer, 6); + } else if (type->class == HLSL_CLASS_OBJECT) { static const uint32_t object_type[] = { [HLSL_TYPE_PIXELSHADER] = 5, - [HLSL_TYPE_VERTEXSHADER] = 6, }; switch (type->base_type) { case HLSL_TYPE_PIXELSHADER: - case HLSL_TYPE_VERTEXSHADER: put_u32_unaligned(buffer, object_type[type->base_type]); break; default: @@ -842,7 +846,6 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type switch (type->base_type) { case HLSL_TYPE_PIXELSHADER: - case HLSL_TYPE_VERTEXSHADER: hlsl_fixme(ctx, loc, "Write fx 2.0 parameter object type %#x.", type->base_type); return false; @@ -852,6 +855,7 @@ static bool is_type_supported_fx_2(struct hlsl_ctx *ctx, const struct hlsl_type case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: + case HLSL_CLASS_VERTEX_SHADER: hlsl_fixme(ctx, loc, "Write fx 2.0 parameter class %#x.", type->class); return false; @@ -1052,7 +1056,6 @@ static void write_fx_4_object_variable(struct hlsl_ir_var *var, struct fx_write_ switch (type->base_type) { case HLSL_TYPE_PIXELSHADER: - case HLSL_TYPE_VERTEXSHADER: /* FIXME: write shader blobs, once parser support works. */ for (i = 0; i < elements_count; ++i) put_u32(buffer, 0); @@ -1064,6 +1067,13 @@ static void write_fx_4_object_variable(struct hlsl_ir_var *var, struct fx_write_ } break; + case HLSL_CLASS_VERTEX_SHADER: + /* FIXME: write shader blobs, once parser support works. */ + for (i = 0; i < elements_count; ++i) + put_u32(buffer, 0); + ++fx->shader_variable_count; + break; + default: hlsl_fixme(ctx, &ctx->location, "Writing initializer for object type %u is not implemented.", type->base_type); @@ -1153,13 +1163,13 @@ static bool is_object_variable(const struct hlsl_ir_var *var) case HLSL_CLASS_SAMPLER: case HLSL_CLASS_TEXTURE: case HLSL_CLASS_UAV: + case HLSL_CLASS_VERTEX_SHADER: return true; case HLSL_CLASS_OBJECT: switch (type->base_type) { case HLSL_TYPE_PIXELSHADER: - case HLSL_TYPE_VERTEXSHADER: return true; default: return false; diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 0b48b17d..20ae3a64 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -370,6 +370,7 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type case HLSL_CLASS_RENDER_TARGET_VIEW: case HLSL_CLASS_STRING: case HLSL_CLASS_TECHNIQUE: + case HLSL_CLASS_VERTEX_SHADER: case HLSL_CLASS_VOID: break; } @@ -438,6 +439,7 @@ static bool type_is_single_component(const struct hlsl_type *type) case HLSL_CLASS_RENDER_TARGET_VIEW: case HLSL_CLASS_TEXTURE: case HLSL_CLASS_UAV: + case HLSL_CLASS_VERTEX_SHADER: return true; case HLSL_CLASS_VECTOR: @@ -578,6 +580,7 @@ unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_ty case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: case HLSL_CLASS_UAV: + case HLSL_CLASS_VERTEX_SHADER: assert(idx == 0); break; @@ -956,6 +959,7 @@ unsigned int hlsl_type_component_count(const struct hlsl_type *type) case HLSL_CLASS_STRING: case HLSL_CLASS_TEXTURE: case HLSL_CLASS_UAV: + case HLSL_CLASS_VERTEX_SHADER: return 1; case HLSL_CLASS_EFFECT_GROUP: @@ -2382,6 +2386,7 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru case HLSL_CLASS_SAMPLER: case HLSL_CLASS_STRING: case HLSL_CLASS_TECHNIQUE: + case HLSL_CLASS_VERTEX_SHADER: case HLSL_CLASS_VOID: break; } @@ -3558,7 +3563,6 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) {"vector", HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1}, {"matrix", HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4}, {"pixelshader", HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1}, - {"vertexshader", HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1}, }; static const struct @@ -3685,6 +3689,7 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "RenderTargetView", HLSL_CLASS_RENDER_TARGET_VIEW)); hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "STRING", HLSL_CLASS_STRING)); hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "texture", HLSL_CLASS_TEXTURE)); + hlsl_scope_add_type(ctx->globals, hlsl_new_simple_type(ctx, "vertexshader", HLSL_CLASS_VERTEX_SHADER)); for (i = 0; i < ARRAY_SIZE(effect_types); ++i) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index ec3f5826..ac8ccd61 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -88,6 +88,7 @@ enum hlsl_type_class HLSL_CLASS_TECHNIQUE, HLSL_CLASS_TEXTURE, HLSL_CLASS_UAV, + HLSL_CLASS_VERTEX_SHADER, HLSL_CLASS_VOID, }; @@ -101,7 +102,6 @@ enum hlsl_base_type HLSL_TYPE_BOOL, HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL, HLSL_TYPE_PIXELSHADER, - HLSL_TYPE_VERTEXSHADER, }; enum hlsl_sampler_dim diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 94acb70f..ff114c32 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1628,6 +1628,7 @@ static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, case HLSL_CLASS_SAMPLER: case HLSL_CLASS_TEXTURE: case HLSL_CLASS_UAV: + case HLSL_CLASS_VERTEX_SHADER: case HLSL_CLASS_OBJECT: break; diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index 708ab626..ffc0d9d5 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -3017,6 +3017,7 @@ static D3D_SHADER_VARIABLE_CLASS sm4_class(const struct hlsl_type *type) case HLSL_CLASS_TECHNIQUE: case HLSL_CLASS_TEXTURE: case HLSL_CLASS_UAV: + case HLSL_CLASS_VERTEX_SHADER: case HLSL_CLASS_VOID: break; }