[PATCH vkd3d v2 03/10] vkd3d-shader/hlsl: Set component count for objects to 1. --- Francisco, I left a test marked as todo because it still fails on master, because of missing object copy.

Giovanni Mascellani gmascellani at codeweavers.com
Tue May 10 08:31:06 CDT 2022


Hi,

sorry, I made a mess with the commit message and some of it remained in 
the subject line.

At any rate, I think this patch still requires some thought: changing 
hlsl_type_component_count(), while making sense in itself, impacts 
hlsl_compute_component_offset().

More in general, I think there are two different concepts that are still 
a bit too confused in the code:
  * the "logical" component count, i.e., how many things you have to put 
into an initializer;
  * the "physical" register count, i.e., how many register that type 
will require.

Most of base types take one component and one register, which is 
probably why we're confusing them right now. But objects don't (they 
take a component, but no registers, because they are pure entities, they 
don't have a value). I think doubles wouldn't either if we supported 
them (they take one component, but two registers).

Also, components are always packed (as far as I know), while registers 
have padding we have to take into account (for example, a matrix row is 
padded to a whole four registers; same for an array item; but these 
rules depend on the SM).

Therefore I think we should distinguish more clearly which of these two 
concept is used each time, and be sure that we're computing correctly 
both offsets and sizes based on either of them.

Consider for example:

struct foo
{
     Texture2D t;
     float x;
};

With this patch the field x would go to register offset 1, which doesn't 
look correct.

BTW, I just made up the words "component" and "register", and I think 
they're wrong already, because I guess that a register is technically 
four things of what I called "register" in this email. Maybe HLSL/DXBC 
gurus have better word proposals.

Giovanni.


Il 10/05/22 15:08, Giovanni Mascellani ha scritto:
> From: Francisco Casas <fcasas at codeweavers.com>
> 
> ---
>   libs/vkd3d-shader/hlsl.c                   | 17 ++++++++++-------
>   tests/hlsl-initializer-objects.shader_test | 10 +++++-----
>   2 files changed, 15 insertions(+), 12 deletions(-)
> 
> diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
> index 7239b183..4bdd770a 100644
> --- a/libs/vkd3d-shader/hlsl.c
> +++ b/libs/vkd3d-shader/hlsl.c
> @@ -412,17 +412,20 @@ unsigned int hlsl_type_component_count(struct hlsl_type *type)
>       {
>           return hlsl_type_component_count(type->e.array.type) * type->e.array.elements_count;
>       }
> -    if (type->type != HLSL_CLASS_STRUCT)
> +    if (type->type == HLSL_CLASS_OBJECT)
>       {
> -        ERR("Unexpected data type %#x.\n", type->type);
> -        return 0;
> +        return 1;
>       }
> -
> -    LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry)
> +    if (type->type == HLSL_CLASS_STRUCT)
>       {
> -        count += hlsl_type_component_count(field->type);
> +        LIST_FOR_EACH_ENTRY(field, type->e.elements, struct hlsl_struct_field, entry)
> +        {
> +            count += hlsl_type_component_count(field->type);
> +        }
> +        return count;
>       }
> -    return count;
> +    assert(0);
> +    return 0;
>   }
>   
>   bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2)
> diff --git a/tests/hlsl-initializer-objects.shader_test b/tests/hlsl-initializer-objects.shader_test
> index 2306d07f..5261aa05 100644
> --- a/tests/hlsl-initializer-objects.shader_test
> +++ b/tests/hlsl-initializer-objects.shader_test
> @@ -25,8 +25,8 @@ float4 main() : sv_target
>   }
>   
>   [test]
> -todo draw quad
> -todo probe all rgba (0.2, 0.2, 0.2, 0.1)
> +draw quad
> +probe all rgba (0.2, 0.2, 0.2, 0.1)
>   
>   
>   [pixel shader]
> @@ -49,7 +49,7 @@ float4 main() : sv_target
>   
>   [test]
>   todo draw quad
> -todo probe all rgba (31.1, 41.1, 51.1, 61.1) 1
> +probe all rgba (31.1, 41.1, 51.1, 61.1) 1
>   
>   
>   [pixel shader]
> @@ -71,7 +71,7 @@ float4 main() : sv_target
>   }
>   
>   
> -[pixel shader fail todo]
> +[pixel shader fail]
>   Texture2D tex;
>   
>   struct foo
> @@ -90,7 +90,7 @@ float4 main() : sv_target
>   }
>   
>   
> -[pixel shader fail todo]
> +[pixel shader fail]
>   Texture2D tex;
>   
>   struct foo



More information about the wine-devel mailing list