From: Connor McAdams Subject: [PATCH 06/10] d3d10: Implement matrix effect variable set methods. Message-Id: <20191207182300.3084-7-conmanx360@gmail.com> Date: Sat, 7 Dec 2019 13:22:56 -0500 In-Reply-To: <20191207182300.3084-1-conmanx360@gmail.com> References: <20191207182300.3084-1-conmanx360@gmail.com> Implement SetMatrix/SetMatrixArray and SetMatrixTranspose/SetMatrixTransposeArray methods for the matrix effect variable interface. Signed-off-by: Connor McAdams --- 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" #include @@ -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)); + } + } + + memcpy(matrix, &tmp, sizeof(D3DMATRIX)); +} + +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)); + } + } + } +} + +static void write_matrix_variable_to_cbuffer(struct d3d10_effect_variable *variable, void *data) +{ + char *cbuf = variable->buffer->u.buffer.local_buffer + variable->buffer_offset; + + write_matrix_to_cbuffer(variable, (float *)cbuf, data); + + variable->buffer->u.buffer.changed = 1; +} + +static void write_matrix_variable_array_to_cbuffer(struct d3d10_effect_variable *variable, void *data, UINT offset, + UINT count, BOOL transpose) +{ + char *cbuf = variable->buffer->u.buffer.local_buffer + variable->buffer_offset; + D3DMATRIX *input_data = data; + D3DMATRIX tmp; + UINT i; + + if (!variable->type->element_count) + { + write_matrix_variable_to_cbuffer(variable, data); + return; + } + + if (offset) + cbuf += variable->type->stride * offset; + + for (i = 0; i < count; i++) + { + tmp = input_data[i]; + + if (transpose) + transpose_matrix(&tmp); + + write_matrix_to_cbuffer(variable, (float *)cbuf, &tmp); + + cbuf += variable->type->stride; + } + + variable->buffer->u.buffer.changed = 1; +} + /* ID3D10EffectVariable methods */ static BOOL STDMETHODCALLTYPE d3d10_effect_matrix_variable_IsValid(ID3D10EffectMatrixVariable *iface) @@ -5100,9 +5184,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetRawValue(ID3D10 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrix(ID3D10EffectMatrixVariable *iface, float *data) { - FIXME("iface %p, data %p stub!\n", iface, data); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); - return E_NOTIMPL; + TRACE("iface %p, data %p.\n", iface, data); + write_matrix_variable_to_cbuffer(effect_var, data); + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrix(ID3D10EffectMatrixVariable *iface, @@ -5116,9 +5203,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrix(ID3D10Ef static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixArray(ID3D10EffectMatrixVariable *iface, float *data, UINT offset, UINT count) { - FIXME("iface %p, data %p, offset %u, count %u stub!\n", iface, data, offset, count); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); - return E_NOTIMPL; + TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count); + write_matrix_variable_array_to_cbuffer(effect_var, data, offset, count, FALSE); + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixArray(ID3D10EffectMatrixVariable *iface, @@ -5132,9 +5222,14 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixArray(ID3 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTranspose(ID3D10EffectMatrixVariable *iface, float *data) { - FIXME("iface %p, data %p stub!\n", iface, data); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); + D3DMATRIX tmp = *(D3DMATRIX *)data; - return E_NOTIMPL; + TRACE("iface %p, data %p.\n", iface, data); + transpose_matrix(&tmp); + write_matrix_variable_to_cbuffer(effect_var, &tmp); + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTranspose(ID3D10EffectMatrixVariable *iface, @@ -5148,9 +5243,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTranspose static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTransposeArray(ID3D10EffectMatrixVariable *iface, float *data, UINT offset, UINT count) { - FIXME("iface %p, data %p, offset %u, count %u stub!\n", iface, data, offset, count); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); - return E_NOTIMPL; + TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count); + write_matrix_variable_array_to_cbuffer(effect_var, data, offset, count, TRUE); + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTransposeArray(ID3D10EffectMatrixVariable *iface, -- 2.20.1