From cdc74a9377c7704f8923f349f2fdb4c0f1e1409c Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Wed, 12 Mar 2025 21:52:46 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Emit an error when min16uint is used in d3dbc target profiles. Fixes: 18ca7affadd21859a809168e258851e49a91fa2b --- libs/vkd3d-shader/hlsl.c | 22 ++++++++++++++++++++++ libs/vkd3d-shader/hlsl.h | 1 + libs/vkd3d-shader/hlsl.y | 4 ++-- libs/vkd3d-shader/hlsl_codegen.c | 21 +-------------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 36c79f4c0..cec8a7b1b 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -319,6 +319,28 @@ bool hlsl_type_is_shader(const struct hlsl_type *type) return false; } +bool hlsl_type_is_minimum_precision(const struct hlsl_type *type) +{ + if (!hlsl_is_numeric_type(type)) + return false; + + switch (type->e.numeric.type) + { + case HLSL_TYPE_BOOL: + case HLSL_TYPE_DOUBLE: + case HLSL_TYPE_FLOAT: + case HLSL_TYPE_HALF: + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + return false; + + case HLSL_TYPE_MIN16UINT: + return true; + } + + vkd3d_unreachable(); +} + bool hlsl_type_is_patch_array(const struct hlsl_type *type) { return type->class == HLSL_CLASS_ARRAY && (type->e.array.array_type == HLSL_ARRAY_PATCH_INPUT diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index c9ee90d4e..646ce3f7f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1775,6 +1775,7 @@ unsigned int hlsl_type_minor_size(const struct hlsl_type *type); unsigned int hlsl_type_major_size(const struct hlsl_type *type); unsigned int hlsl_type_element_count(const struct hlsl_type *type); bool hlsl_type_is_integer(const struct hlsl_type *type); +bool hlsl_type_is_minimum_precision(const struct hlsl_type *type); bool hlsl_type_is_resource(const struct hlsl_type *type); bool hlsl_type_is_shader(const struct hlsl_type *type); bool hlsl_type_is_patch_array(const struct hlsl_type *type); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 24c7ae6b0..166e1558b 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -8177,14 +8177,14 @@ type_no_void: | TYPE_IDENTIFIER { $$ = hlsl_get_type(ctx->cur_scope, $1, true, true); - if ($$->is_minimum_precision) + if ($$->is_minimum_precision || hlsl_type_is_minimum_precision($$)) { if (hlsl_version_lt(ctx, 4, 0)) { hlsl_error(ctx, &@1, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Target profile doesn't support minimum-precision types."); } - else + else if ($$->is_minimum_precision) { FIXME("Reinterpreting type %s.\n", $$->name); } diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 032ad025f..4e7ea6bf6 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -11838,25 +11838,6 @@ static void generate_vsir_scan_required_features(struct hlsl_ctx *ctx, struct vs * STENCIL_REF, and TYPED_UAV_LOAD_ADDITIONAL_FORMATS. */ } -static bool is_minimum_precision(enum hlsl_base_type type) -{ - switch (type) - { - case HLSL_TYPE_BOOL: - case HLSL_TYPE_DOUBLE: - case HLSL_TYPE_FLOAT: - case HLSL_TYPE_HALF: - case HLSL_TYPE_INT: - case HLSL_TYPE_UINT: - return false; - - case HLSL_TYPE_MIN16UINT: - return true; - } - - vkd3d_unreachable(); -} - static void generate_vsir_scan_global_flags(struct hlsl_ctx *ctx, struct vsir_program *program, const struct hlsl_ir_function_decl *entry_func) { @@ -11894,7 +11875,7 @@ static void generate_vsir_scan_global_flags(struct hlsl_ctx *ctx, /* Note that it doesn't matter if the semantic is unused or doesn't * generate a signature element (e.g. SV_DispatchThreadID). */ if ((var->is_input_semantic || var->is_output_semantic) - && (type->is_minimum_precision || is_minimum_precision(type->e.numeric.type))) + && (type->is_minimum_precision || hlsl_type_is_minimum_precision(type))) { program->global_flags |= VKD3DSGF_ENABLE_MINIMUM_PRECISION; break;