[PATCH vkd3d] vkd3d-shader/hlsl: Add cross() intrinsic function and test.

Giovanni Mascellani gmascellani at codeweavers.com
Tue Nov 16 10:22:12 CST 2021


Hi,

On 16/11/21 16:11, Francisco Casas wrote:
> +static bool intrinsic_cross(struct hlsl_ctx *ctx,
> +        const struct parse_initializer *params, struct vkd3d_shader_location loc) > +{
> +    struct hlsl_ir_node *v0 = params->args[0], *v1 = params->args[1];
> +    struct hlsl_ir_swizzle *v0_swzl1, *v0_swzl2, *v1_swzl1, *v1_swzl2;
> +    struct hlsl_ir_node *mul1_neg;
> +    struct hlsl_ir_expr *mul1, *mul2;
> +    int wrong_arg = -1;

Whenever possible, the declaration block is sorted by decreasing line 
length, sometimes with very funny results.

> +    if (v1->data_type->type != HLSL_CLASS_VECTOR)
> +        wrong_arg = 1;
> +    if (v0->data_type->type != HLSL_CLASS_VECTOR)
> +        wrong_arg = 0;
> +    if (wrong_arg != -1)
> +    {
> +        struct vkd3d_string_buffer *string;
> +        if ((string = hlsl_type_to_string(ctx, params->args[wrong_arg]->data_type)))
> +            hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
> +                    "Wrong type for argument %d of 'cross': expected 'vector' but got '%s'.",
> +                    wrong_arg, string->buffer);
> +        hlsl_release_string_buffer(ctx, string);
> +        return false;
> +    }

I think we need more checks on the types here (on the base type and on 
the vector length): from my experiments, it seems that cross() accepts 
vectors of length 3 or 4 (truncating them to 3 in that case, with a 
warning); it accepts whatever base type, but it casts non-floating point 
types to float. Implicitly, this means that it returns half3 when both 
its arguments have base type half, and float3 in every other case.

(BTW, "vector" is not a type name, use names like "float3")

En passant, I am a bit bothered by the fact that we don't have precise 
rules for typing in the IR, but that's not this patch's fault.

The actual cross vector computation looks fine.

Thanks, Giovanni.



More information about the wine-devel mailing list