[PATCH vkd3d 5/5] vkd3d-shader/hlsl: Correctly calculate offsets for array elements.

Zebediah Figura (she/her) zfigura at codeweavers.com
Fri Feb 25 00:11:36 CST 2022


On 2/17/22 17:04, Francisco Casas wrote:
> Hi,
> 
> The failing tests aside, this padding rule for array elements is 
> an interesting find.
> 
> If this is correct, wouldn't that mean that we also have to use
> hlsl_type_get_array_element_reg_size() in hlsl_type_calculate_reg_size()?
> 
> In particular, here
> ---
>         case HLSL_CLASS_ARRAY:
>         {
>             unsigned int element_size = type->e.array.type->reg_size;
> 
>             assert(element_size);
>             if (is_sm4)
>                 type->reg_size = (type->e.array.elements_count - 1) * align(element_size, 4) + element_size;
>             else
>                 type->reg_size = type->e.array.elements_count * element_size;
>             break;
>         }
> ---
> 
> Also, it makes me wonder whether this rule only applies in sm4 and/or to uniform
> arrays (I don't know a quick way to test that).
> 
> If I am not mistaken and we indeed have to change hlsl_type_calculate_reg_size(), 
> then we would have to also take into account the padding in the
> HLSL_CLASS_STRUCT case, when the struct contains array fields.

Well, sort of. The "align(element_size, 4)" there is basically an
open-coded hlsl_type_get_array_element_reg_size(), and could I guess get
replaced with that.

Note that sm4 structs, unlike C structs, never have padding on the end.
We should have tests for that in d3dcompiler.

Note also that in sm1, *all* uniforms are aligned to the nearest whole
register, and we set reg_size accordingly. So the answer to "does this
apply to sm1" is basically "it's a moot point".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20220225/ce2c4be7/attachment.sig>


More information about the wine-devel mailing list