[PATCH 06/10] d3d10: Implement matrix effect variable set methods.

Matteo Bruni matteo.mystral at gmail.com
Wed Jan 22 09:41:03 CST 2020


On Sat, Dec 7, 2019 at 7:24 PM Connor McAdams <conmanx360 at gmail.com> wrote:
>
> Implement SetMatrix/SetMatrixArray and
> SetMatrixTranspose/SetMatrixTransposeArray methods for the matrix effect
> variable interface.
>
> Signed-off-by: Connor McAdams <conmanx360 at gmail.com>
> ---
>  dlls/d3d10/effect.c | 114 ++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 106 insertions(+), 8 deletions(-)
>
> diff --git a/dlls/d3d10/effect.c b/dlls/d3d10/effect.c
> index 4e51e43a01..0f08fb11e9 100644
> --- a/dlls/d3d10/effect.c
> +++ b/dlls/d3d10/effect.c
> @@ -19,6 +19,7 @@
>   */
>
>  #include "d3d10_private.h"
> +#include "d3d9types.h"

No, just define a local matrix struct.

>  #include <float.h>
>
> @@ -4942,6 +4943,89 @@ static const struct ID3D10EffectVectorVariableVtbl d3d10_effect_vector_variable_
>      d3d10_effect_vector_variable_GetFloatVectorArray,
>  };
>
> +static void transpose_matrix(D3DMATRIX *matrix)
> +{
> +    UINT row, col;
> +    D3DMATRIX tmp;
> +
> +    for (col = 0; col < 4; col++)
> +    {
> +        for (row = 0; row < 4; row++)
> +        {
> +            memcpy(&tmp.m[col][row], &matrix->m[row][col], sizeof(float));

No need to use an explicit memcpy here.

> +        }
> +    }
> +
> +    memcpy(matrix, &tmp, sizeof(D3DMATRIX));

Looking at the two users of the function, you probably want to
transpose the matrix in-place instead. The usual trick is to only loop
through half the matrix and swap elements.

Or, probably better, just use the "wrong" side of the branch in
write_matrix_to_cbuffer() below whenever you need to transpose.

> +}
> +
> +static void write_matrix_to_cbuffer(struct d3d10_effect_variable *variable, float *cbuf, D3DMATRIX *matrix)
> +{
> +    UINT row, col;
> +
> +    if (variable->type->type_class == D3D10_SVC_MATRIX_COLUMNS)
> +    {
> +        for (col = 0; col < variable->type->column_count; col++)
> +        {
> +            for (row = 0; row < variable->type->row_count; row++)
> +            {
> +                memcpy(cbuf + ((col * 4) + row), &matrix->m[row][col], sizeof(float));
> +            }
> +        }
> +    }
> +    else
> +    {
> +        for (col = 0; col < variable->type->column_count; col++)
> +        {
> +            for (row = 0; row < variable->type->row_count; row++)
> +            {
> +                memcpy(cbuf + ((row * 4) + col), &matrix->m[row][col], sizeof(float));
> +            }
> +        }

It maybe doesn't matter for a 4x4 matrix and the arguably rare case of
row-major storage but, generally, you want to go in row, column order
(i.e. move sequentially in memory).
Also mostly for general consistency, sizeof(*cbuf) would be preferred.



More information about the wine-devel mailing list