[PATCH vkd3d 2/6] vkd3d-shader: Get rid of hlsl_base_type_to_string().

Matteo Bruni matteo.mystral at gmail.com
Thu Feb 18 17:48:35 CST 2021


On Wed, Feb 17, 2021 at 6:52 AM Zebediah Figura <zfigura at codeweavers.com> wrote:
>
> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> ---
>  libs/vkd3d-shader/hlsl.c | 47 ++++++++++++----------------------------
>  libs/vkd3d-shader/hlsl.h |  1 -
>  libs/vkd3d-shader/hlsl.y |  3 ++-
>  3 files changed, 16 insertions(+), 35 deletions(-)
>
> diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
> index 342fe6af..9e1eb7ee 100644
> --- a/libs/vkd3d-shader/hlsl.c
> +++ b/libs/vkd3d-shader/hlsl.c
> @@ -639,55 +639,37 @@ static int compare_function_decl_rb(const void *key, const struct rb_entry *entr
>      return 0;
>  }
>
> -const char *hlsl_base_type_to_string(const struct hlsl_type *type)
> -{
> -    const char *name = "(unknown)";
> -
> -    switch (type->base_type)
> -    {
> -        case HLSL_TYPE_FLOAT:        name = "float";         break;
> -        case HLSL_TYPE_HALF:         name = "half";          break;
> -        case HLSL_TYPE_DOUBLE:       name = "double";        break;
> -        case HLSL_TYPE_INT:          name = "int";           break;
> -        case HLSL_TYPE_UINT:         name = "uint";          break;
> -        case HLSL_TYPE_BOOL:         name = "bool";          break;
> -        case HLSL_TYPE_SAMPLER:
> -            switch (type->sampler_dim)
> -            {
> -                case HLSL_SAMPLER_DIM_GENERIC: name = "sampler";       break;
> -                case HLSL_SAMPLER_DIM_1D:      name = "sampler1D";     break;
> -                case HLSL_SAMPLER_DIM_2D:      name = "sampler2D";     break;
> -                case HLSL_SAMPLER_DIM_3D:      name = "sampler3D";     break;
> -                case HLSL_SAMPLER_DIM_CUBE:    name = "samplerCUBE";   break;
> -            }
> -            break;
> -        default:
> -            FIXME("Unhandled case %u.\n", type->base_type);
> -    }
> -    return name;
> -}
> -
>  char *hlsl_type_to_string(const struct hlsl_type *type)
>  {
>      const char *name;
>      char *string;
>
> +    static const char base_types[HLSL_TYPE_LAST_SCALAR + 1][7] =
> +    {
> +        "float",
> +        "half",
> +        "double",
> +        "int",
> +        "uint",
> +        "bool",
> +    };
> +
>      if (type->name)
>          return vkd3d_strdup(type->name);

Maybe it's overkill but I wouldn't mind an assert(type->base_type <
ARRAY_SIZE(base_types)) here.

> diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
> index b2b7daf0..56b8e2a8 100644
> --- a/libs/vkd3d-shader/hlsl.h
> +++ b/libs/vkd3d-shader/hlsl.h
> @@ -496,7 +496,6 @@ static inline void hlsl_src_remove(struct hlsl_src *src)
>
>  const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
>
> -const char *hlsl_base_type_to_string(const struct hlsl_type *type) DECLSPEC_HIDDEN;
>  char *hlsl_type_to_string(const struct hlsl_type *type) DECLSPEC_HIDDEN;
>  char *hlsl_modifiers_to_string(unsigned int modifiers) DECLSPEC_HIDDEN;
>  const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
> diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
> index 8b91ff5d..a3d4b4ed 100644
> --- a/libs/vkd3d-shader/hlsl.y
> +++ b/libs/vkd3d-shader/hlsl.y
> @@ -909,13 +909,14 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
>                  case HLSL_TYPE_INT:
>                      return constant->value.i[0];
>                  case HLSL_TYPE_FLOAT:
> +                case HLSL_TYPE_HALF:
>                      return constant->value.f[0];
>                  case HLSL_TYPE_DOUBLE:
>                      return constant->value.d[0];
>                  case HLSL_TYPE_BOOL:
>                      return constant->value.b[0];
>                  default:
> -                    WARN("Invalid type %s.\n", hlsl_base_type_to_string(constant->node.data_type));
> +                    assert(0);
>                      return 0;
>              }
>          }

The addition of the HLSL_TYPE_HALF case here is a bit sneaky.



More information about the wine-devel mailing list