Add tests for the ID3D10EffectMatrixVariable get/set.
Signed-off-by: Connor McAdams conmanx360@gmail.com --- dlls/d3d10/tests/effect.c | 207 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+)
diff --git a/dlls/d3d10/tests/effect.c b/dlls/d3d10/tests/effect.c index 24c20a51a5..339689557b 100644 --- a/dlls/d3d10/tests/effect.c +++ b/dlls/d3d10/tests/effect.c @@ -4626,6 +4626,212 @@ static void test_effect_vector_variable(void) ok(!refcount, "Device has %u references left.\n", refcount); }
+/* + * test_effect_matrix_variable + */ +#if 0 +cbuffer cb +{ + float4x4 m_f0; + float4x4 m_f_a[2]; + + row_major int2x3 m_i0; + + bool3x2 m_b0; + bool3x2 m_b_a[2]; +}; +#endif + +static DWORD fx_test_matrix_variable[] = +{ + 0x43425844, 0xc95a5c42, 0xa138d3cb, 0x8a4ef493, + 0x3515b7ee, 0x00000001, 0x000001e2, 0x00000001, + 0x00000024, 0x30315846, 0x000001b6, 0xfeff1001, + 0x00000001, 0x00000005, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x000000c6, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x66006263, + 0x74616f6c, 0x00347834, 0x00000007, 0x00000001, + 0x00000000, 0x00000040, 0x00000040, 0x00000040, + 0x0000640b, 0x30665f6d, 0x00000700, 0x00000100, + 0x00000200, 0x00008000, 0x00004000, 0x00008000, + 0x00640b00, 0x665f6d00, 0x6900615f, 0x7832746e, + 0x00530033, 0x00010000, 0x00000000, 0x001c0000, + 0x00200000, 0x00180000, 0x1a130000, 0x5f6d0000, + 0x62003069, 0x336c6f6f, 0x7b003278, 0x01000000, + 0x00000000, 0x1c000000, 0x20000000, 0x18000000, + 0x23000000, 0x6d000053, 0x0030625f, 0x0000007b, + 0x00000001, 0x00000002, 0x0000003c, 0x00000020, + 0x00000030, 0x00005323, 0x5f625f6d, 0x00040061, + 0x01400000, 0x00000000, 0x00050000, 0xffff0000, + 0x0000ffff, 0x002c0000, 0x00100000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x004d0000, 0x00310000, 0x00000000, 0x00400000, + 0x00000000, 0x00000000, 0x00000000, 0x00760000, + 0x005a0000, 0x00000000, 0x00c00000, 0x00000000, + 0x00000000, 0x00000000, 0x009f0000, 0x00830000, + 0x00000000, 0x00e00000, 0x00000000, 0x00000000, + 0x00000000, 0x00c00000, 0x00a40000, 0x00000000, + 0x01000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +}; + +static void test_effect_matrix_variable(void) +{ + ID3D10Device *device; + ID3D10Effect *effect; + ID3D10EffectVariable *var; + ID3D10EffectType *type; + ID3D10EffectMatrixVariable *m_f0, *m_f_a, *m_i0, *m_b0, *m_b_a; + float m_f0_ret[16], m_f_a_ret[32], m_f0_set[16], m_f_a_set[32]; + int m_i0_ret[16], m_i0_set[16]; + BOOL m_b0_ret[16], m_b_a_ret[32], m_b0_set[16], m_b_a_set[32]; + D3D10_EFFECT_TYPE_DESC type_desc; + ULONG refcount; + HRESULT hr; + unsigned int i; + float tmp; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + + hr = create_effect(fx_test_matrix_variable, 0, device, NULL, &effect); + ok(SUCCEEDED(hr), "D3D10CreateEffectFromMemory failed (%x)\n", hr); + + /* Matrix effect variables only have one set of methods for + * getting/setting, as opposed to the scalar and vector methods which have + * different methods for int, bool, and float. The input and output always + * expects a 4x4 matrix, regardless of the size of matrix within the + * shader. The input is also a float pointer, so we'll have to typecast + * int and bool types to floats for setting, and the reverse for reading + * back. */ + + /* Vector floating point variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "m_f0"); + type = var->lpVtbl->GetType(var); + hr = type->lpVtbl->GetDesc(type, &type_desc); + ok(SUCCEEDED(hr), "GetDesc failed (%x)\n", hr); + ok(type_desc.Type == D3D10_SVT_FLOAT, "Type is %x, expected %x\n", type_desc.Type, D3D10_SVT_FLOAT); + m_f0 = var->lpVtbl->AsMatrix(var); + + m_f0_set[0] = 1.0f; m_f0_set[1] = 2.0f; m_f0_set[2] = 3.0f; m_f0_set[3] = 4.0f; + m_f0_set[4] = 5.0f; m_f0_set[5] = 6.0f; m_f0_set[6] = 7.0f; m_f0_set[7] = 8.0f; + m_f0_set[8] = 9.0f; m_f0_set[9] = 10.0f; m_f0_set[10] = 11.0f; m_f0_set[11] = 12.0f; + m_f0_set[12] = 13.0f; m_f0_set[13] = 14.0f; m_f0_set[14] = 15.0f; m_f0_set[15] = 16.0f; + + m_f0->lpVtbl->SetMatrix(m_f0, m_f0_set); + m_f0->lpVtbl->GetMatrix(m_f0, m_f0_ret); + for (i = 0; i < 16; i++) + ok(m_f0_ret[i] == m_f0_set[i], "m_f0_ret[%d] is %f, expected %f.\n", i, m_f0_ret[i], m_f0_set[i]); + + /* Matrix floating point array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "m_f_a"); + type = var->lpVtbl->GetType(var); + hr = type->lpVtbl->GetDesc(type, &type_desc); + ok(SUCCEEDED(hr), "GetDesc failed (%x)\n", hr); + ok(type_desc.Type == D3D10_SVT_FLOAT, "Type is %x, expected %x\n", type_desc.Type, D3D10_SVT_FLOAT); + m_f_a = var->lpVtbl->AsMatrix(var); + + for (i = 0, tmp = 1.0f; i < 32; i++, tmp += 1.0f) + m_f_a_set[i] = tmp; + + m_f_a->lpVtbl->SetMatrixArray(m_f_a, m_f_a_set, 0, 2); + m_f_a->lpVtbl->GetMatrixArray(m_f_a, m_f_a_ret, 0, 2); + for (i = 0; i < 32; i++) + ok(m_f_a_ret[i] == m_f_a_set[i], "m_f_a_ret[%d] is %f, expected %f.\n", i, m_f_a_ret[i], m_f_a_set[i]); + + /* Matrix int variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "m_i0"); + type = var->lpVtbl->GetType(var); + hr = type->lpVtbl->GetDesc(type, &type_desc); + ok(SUCCEEDED(hr), "GetDesc failed (%x)\n", hr); + ok(type_desc.Type == D3D10_SVT_INT, "Type is %x, expected %x\n", type_desc.Type, D3D10_SVT_INT); + m_i0 = var->lpVtbl->AsMatrix(var); + + m_i0_set[0] = 1; m_i0_set[1] = 2; m_i0_set[2] = 3; m_i0_set[3] = 0; + m_i0_set[4] = 4; m_i0_set[5] = 5; m_i0_set[6] = 6; m_i0_set[7] = 0; + m_i0_set[8] = 0; m_i0_set[9] = 0; m_i0_set[10] = 0; m_i0_set[11] = 0; + m_i0_set[12] = 0; m_i0_set[13] = 0; m_i0_set[14] = 0; m_i0_set[15] = 0; + + memset(m_i0_ret, 0, sizeof(m_i0_ret)); + m_i0->lpVtbl->SetMatrix(m_i0, (float *)m_i0_set); + m_i0->lpVtbl->GetMatrix(m_i0, (float *)m_i0_ret); + for (i = 0; i < 16; i++) + ok(m_i0_ret[i] == m_i0_set[i], "m_i0_ret[%d] is %d, expected %d.\n", i, m_i0_ret[i], m_i0_set[i]); + + /* Test that transpose is working properly. */ + memset(m_i0_ret, 0, sizeof(m_i0_ret)); + m_i0->lpVtbl->SetMatrixTranspose(m_i0, (float *)m_i0_set); + m_i0->lpVtbl->GetMatrix(m_i0, (float *)m_i0_ret); + m_i0_set[0] = 1; m_i0_set[1] = 4; m_i0_set[2] = 0; m_i0_set[3] = 0; + m_i0_set[4] = 2; m_i0_set[5] = 5; m_i0_set[6] = 0; m_i0_set[7] = 0; + m_i0_set[8] = 0; m_i0_set[9] = 0; m_i0_set[10] = 0; m_i0_set[11] = 0; + m_i0_set[12] = 0; m_i0_set[13] = 0; m_i0_set[14] = 0; m_i0_set[15] = 0; + for (i = 0; i < 16; i++) + ok(m_i0_ret[i] == m_i0_set[i], "m_i0_ret[%d] is %d, expected %d. Transpose failure.\n", i, m_i0_ret[i], m_i0_set[i]); + + /* Matrix bool variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "m_b0"); + type = var->lpVtbl->GetType(var); + hr = type->lpVtbl->GetDesc(type, &type_desc); + ok(SUCCEEDED(hr), "GetDesc failed (%x)\n", hr); + ok(type_desc.Type == D3D10_SVT_BOOL, "Type is %x, expected %x\n", type_desc.Type, D3D10_SVT_BOOL); + m_b0 = var->lpVtbl->AsMatrix(var); + + m_b0_set[0] = TRUE; m_b0_set[1] = TRUE; m_b0_set[2] = FALSE; m_b0_set[3] = FALSE; + m_b0_set[4] = TRUE; m_b0_set[5] = FALSE; m_b0_set[6] = FALSE; m_b0_set[7] = FALSE; + m_b0_set[8] = FALSE; m_b0_set[9] = TRUE; m_b0_set[10] = FALSE; m_b0_set[11] = FALSE; + m_b0_set[12] = FALSE; m_b0_set[13] = FALSE; m_b0_set[14] = FALSE; m_b0_set[15] = FALSE; + + memset(m_b0_ret, 0, sizeof(m_b0_ret)); + m_b0->lpVtbl->SetMatrix(m_b0, (float *)m_b0_set); + m_b0->lpVtbl->GetMatrix(m_b0, (float *)m_b0_ret); + for (i = 0; i < 16; i++) + ok(m_b0_ret[i] == m_b0_set[i], "m_b0_ret[%d] is %d, expected %d.\n", i, m_b0_ret[i], m_b0_set[i]); + + /* Matrix bool array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "m_b_a"); + type = var->lpVtbl->GetType(var); + hr = type->lpVtbl->GetDesc(type, &type_desc); + ok(SUCCEEDED(hr), "GetDesc failed (%x)\n", hr); + ok(type_desc.Type == D3D10_SVT_BOOL, "Type is %x, expected %x\n", type_desc.Type, D3D10_SVT_BOOL); + m_b_a = var->lpVtbl->AsMatrix(var); + + /* First 3x2 matrix. */ + m_b_a_set[0] = TRUE; m_b_a_set[1] = TRUE; m_b_a_set[2] = FALSE; m_b_a_set[3] = FALSE; + m_b_a_set[4] = TRUE; m_b_a_set[5] = FALSE; m_b_a_set[6] = FALSE; m_b_a_set[7] = FALSE; + m_b_a_set[8] = FALSE; m_b_a_set[9] = TRUE; m_b_a_set[10] = FALSE; m_b_a_set[11] = FALSE; + m_b_a_set[12] = FALSE; m_b_a_set[13] = FALSE; m_b_a_set[14] = FALSE; m_b_a_set[15] = FALSE; + + /* Second 3x2 matrix. */ + m_b_a_set[16] = TRUE; m_b_a_set[17] = FALSE; m_b_a_set[18] = FALSE; m_b_a_set[19] = FALSE; + m_b_a_set[20] = FALSE; m_b_a_set[21] = TRUE; m_b_a_set[22] = FALSE; m_b_a_set[23] = FALSE; + m_b_a_set[24] = TRUE; m_b_a_set[25] = FALSE; m_b_a_set[26] = FALSE; m_b_a_set[27] = FALSE; + m_b_a_set[28] = FALSE; m_b_a_set[29] = FALSE; m_b_a_set[30] = FALSE; m_b_a_set[31] = FALSE; + + memset(m_b_a_ret, 0, sizeof(m_b_a_ret)); + m_b_a->lpVtbl->SetMatrixArray(m_b_a, (float *)m_b_a_set, 0, 2); + m_b_a->lpVtbl->GetMatrixArray(m_b_a, (float *)m_b_a_ret, 0, 2); + for (i = 0; i < 32; i++) + ok(m_b_a_ret[i] == m_b_a_set[i], "m_b_a_ret[%d] is %d, expected %d.\n", i, m_b_a_ret[i], m_b_a_set[i]); + + /* Test offset. */ + memset(m_b_a_ret, 0, sizeof(m_b_a_ret)); + m_b_a->lpVtbl->SetMatrixArray(m_b_a, (float *)m_b_a_set, 1, 1); + m_b_a->lpVtbl->GetMatrixArray(m_b_a, (float *)m_b_a_ret, 1, 1); + for (i = 0; i < 16; i++) + ok(m_b_a_ret[i] == m_b_a_set[i], "m_b_a_ret[%d] is %d, expected %d. Matrix offset failure.\n", i, m_b_a_ret[i], m_b_a_set[i]); + + effect->lpVtbl->Release(effect); + + refcount = ID3D10Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +} + START_TEST(effect) { test_effect_constant_buffer_type(); @@ -4640,4 +4846,5 @@ START_TEST(effect) test_effect_state_group_defaults(); test_effect_scalar_variable(); test_effect_vector_variable(); + test_effect_matrix_variable(); }