[PATCH vkd3d v7 3/6] vkd3d-shader/hlsl: Allow failure in hlsl_offset_from_deref.

Matteo Bruni matteo.mystral at gmail.com
Thu Nov 18 11:24:40 CST 2021


On Wed, Nov 17, 2021 at 9:47 AM Giovanni Mascellani
<gmascellani at codeweavers.com> wrote:
>
> Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> ---
>  libs/vkd3d-shader/hlsl.h         |  6 ++++--
>  libs/vkd3d-shader/hlsl_codegen.c | 33 +++++++++++++++++++++++---------
>  libs/vkd3d-shader/hlsl_sm1.c     |  4 ++--
>  libs/vkd3d-shader/hlsl_sm4.c     |  8 ++++----
>  4 files changed, 34 insertions(+), 17 deletions(-)

> diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
> index f5432d22..a0154e3b 100644
> --- a/libs/vkd3d-shader/hlsl_codegen.c
> +++ b/libs/vkd3d-shader/hlsl_codegen.c
> @@ -1286,31 +1286,46 @@ static bool type_is_single_reg(const struct hlsl_type *type)
>      return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR;
>  }
>
> -unsigned int hlsl_offset_from_deref(const struct hlsl_deref *deref)
> +bool hlsl_offset_from_deref(const struct hlsl_deref *deref, unsigned int *offset)
>  {
>      struct hlsl_ir_node *offset_node = deref->offset.node;
>
>      if (!offset_node)
> -        return 0;
> +    {
> +        *offset = 0;
> +        return true;
> +    }
>
>      /* We should always have generated a cast to UINT. */
>      assert(offset_node->data_type->type == HLSL_CLASS_SCALAR
>              && offset_node->data_type->base_type == HLSL_TYPE_UINT);
>
>      if (offset_node->type != HLSL_IR_CONSTANT)
> -    {
> -        FIXME("Dereference with non-constant offset of type %s.\n", hlsl_node_type_to_string(offset_node->type));
> -        return 0;
> -    }
> +        return false;
>
> -    return hlsl_ir_constant(offset_node)->value[0].u;
> +    *offset = hlsl_ir_constant(offset_node)->value[0].u;
> +    return true;
> +}

Mostly unrelated to the patch, a possible option would be to rename
the function to hlsl_constant_offset_from_deref(), or something to
that effect, and introduce a separate function for generic /
non-constant offset. I guess it depends on what will make more sense
once we get to handling dynamic offsets.



More information about the wine-devel mailing list