Add tests for the ID3D10EffectScalarVariable and ID3D10EffectVectorVariable set/get functions.
Signed-off-by: Connor McAdams conmanx360@gmail.com --- v4: Add tests for Scalar/Vector array set/get offset arguments, instead of previously where it was just one of the two.
dlls/d3d10/tests/effect.c | 369 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 369 insertions(+)
diff --git a/dlls/d3d10/tests/effect.c b/dlls/d3d10/tests/effect.c index e2b27cf0c8..0848f34045 100644 --- a/dlls/d3d10/tests/effect.c +++ b/dlls/d3d10/tests/effect.c @@ -4273,6 +4273,373 @@ static void test_effect_state_group_defaults(void) ok(!refcount, "Device has %u references left.\n", refcount); }
+/* + * test_effect_scalar_variable + */ +#if 0 +cbuffer cb +{ + float f0, f_a[2]; + int i0, i_a[2]; + bool b0, b_a[2]; +}; +#endif +static DWORD fx_test_scalar_variable[] = +{ + 0x43425844, 0xe4da4aa6, 0x1380ddc5, 0x445edad5, + 0x08581666, 0x00000001, 0x0000020b, 0x00000001, + 0x00000024, 0x30315846, 0x000001df, 0xfeff1001, + 0x00000001, 0x00000006, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x000000d3, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x66006263, + 0x74616f6c, 0x00000700, 0x00000100, 0x00000000, + 0x00000400, 0x00001000, 0x00000400, 0x00090900, + 0x00306600, 0x00000007, 0x00000001, 0x00000002, + 0x00000014, 0x00000010, 0x00000008, 0x00000909, + 0x00615f66, 0x00746e69, 0x0000004c, 0x00000001, + 0x00000000, 0x00000004, 0x00000010, 0x00000004, + 0x00000911, 0x4c003069, 0x01000000, 0x02000000, + 0x14000000, 0x10000000, 0x08000000, 0x11000000, + 0x69000009, 0x6200615f, 0x006c6f6f, 0x0000008f, + 0x00000001, 0x00000000, 0x00000004, 0x00000010, + 0x00000004, 0x00000921, 0x8f003062, 0x01000000, + 0x02000000, 0x14000000, 0x10000000, 0x08000000, + 0x21000000, 0x62000009, 0x0400615f, 0x70000000, + 0x00000000, 0x06000000, 0xff000000, 0x00ffffff, + 0x29000000, 0x0d000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x48000000, + 0x2c000000, 0x00000000, 0x10000000, 0x00000000, + 0x00000000, 0x00000000, 0x6c000000, 0x50000000, + 0x00000000, 0x24000000, 0x00000000, 0x00000000, + 0x00000000, 0x8b000000, 0x6f000000, 0x00000000, + 0x30000000, 0x00000000, 0x00000000, 0x00000000, + 0xb0000000, 0x94000000, 0x00000000, 0x44000000, + 0x00000000, 0x00000000, 0x00000000, 0xcf000000, + 0xb3000000, 0x00000000, 0x50000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, +}; + +static void test_effect_scalar_variable(void) +{ + ID3D10Device *device; + ID3D10Effect *effect; + ID3D10EffectVariable *var; + ID3D10EffectType *type; + ID3D10EffectScalarVariable *f0, *f_a, *i0, *i_a, *b0, *b_a; + float f0_ret, f_a_ret[2], f_a_set[2]; + int i0_ret, i_a_ret[2], i_a_set[2]; + BOOL b0_ret, b_a_ret[2], b_a_set[2]; + D3D10_EFFECT_TYPE_DESC type_desc; + ULONG refcount; + HRESULT hr; + unsigned int i; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + + hr = create_effect(fx_test_scalar_variable, 0, device, NULL, &effect); + ok(SUCCEEDED(hr), "D3D10CreateEffectFromMemory failed (%x)\n", hr); + + /* Check each different scalar type, make sure the variable returned is + * valid, set it to a value, and make sure what we get back is the same + * as what we set it to. */ + + /* Scalar floating point variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "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); + f0 = var->lpVtbl->AsScalar(var); + + f0->lpVtbl->SetFloat(f0, 5.0f); + f0->lpVtbl->GetFloat(f0, &f0_ret); + ok(f0_ret == 5.0f, "f0 is %f, expected %f.\n", f0_ret, 5.0f); + + /* Scalar floating point array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "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); + f_a = var->lpVtbl->AsScalar(var); + + f_a_set[0] = 10.0f; f_a_set[1] = 20.0f; + f_a->lpVtbl->SetFloatArray(f_a, f_a_set, 0, 2); + f_a->lpVtbl->GetFloatArray(f_a, f_a_ret, 0, 2); + for (i = 0; i < 2; i++) + ok(f_a_ret[i] == f_a_set[i], "f_a_ret[%d] is %f, expected %f.\n", i, f_a_ret[i], f_a_set[i]); + + /* Scalar int variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "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); + i0 = var->lpVtbl->AsScalar(var); + + i0->lpVtbl->SetInt(i0, 2); + i0->lpVtbl->GetInt(i0, &i0_ret); + ok(i0_ret == 2, "i0 is %d, expected %d.\n", i0_ret, 2); + + /* Scalar int array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "i_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_INT, "Type is %x, expected %x\n", type_desc.Type, D3D10_SVT_INT); + i_a = var->lpVtbl->AsScalar(var); + + i_a_set[0] = 5; i_a_set[1] = 6; + i_a->lpVtbl->SetIntArray(i_a, i_a_set, 0, 2); + i_a->lpVtbl->GetIntArray(i_a, i_a_ret, 0, 2); + for (i = 0; i < 2; i++) + ok(i_a_ret[i] == i_a_set[i], "i_a_ret[%d] is %d, expected %d.\n", i, i_a_ret[i], i_a_set[i]); + + /* Scalar bool variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "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); + b0 = var->lpVtbl->AsScalar(var); + + b0->lpVtbl->SetBool(b0, TRUE); + b0->lpVtbl->GetBool(b0, &b0_ret); + ok(b0_ret == TRUE, "b0 is %d, expected %d.\n", b0_ret, TRUE); + + /* Scalar bool array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "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); + b_a = var->lpVtbl->AsScalar(var); + + b_a_set[0] = TRUE; b_a_set[1] = FALSE; + b_a->lpVtbl->SetBoolArray(b_a, b_a_set, 0, 2); + b_a->lpVtbl->GetBoolArray(b_a, b_a_ret, 0, 2); + for (i = 0; i < 2; i++) + ok(b_a_ret[i] == b_a_set[i], "b_a_ret[%d] is %d, expected %d.\n", i, b_a_ret[i], b_a_set[i]); + + /* According to MSDN, the offset argument goes unused. Test and make sure + * this is the case. */ + b_a->lpVtbl->SetBoolArray(b_a, b_a_set, 1, 1); + b_a->lpVtbl->GetBoolArray(b_a, b_a_ret, 0, 2); + /* If the offset argument actually worked, b_a_ret[1] should be set + * to TRUE instead of FALSE, having b_a's new values being { TRUE, TRUE }. */ + for (i = 0; i < 2; i++) + ok(b_a_ret[i] == b_a_set[i], "b_a_ret[%d] is %d, expected %d. Offset argument is being used in SetBoolArray.\n", i, b_a_ret[i], b_a_set[i]); + + /* In this case, if offset is used, b_a_ret[0] should be set to TRUE. */ + b_a_set[0] = FALSE; b_a_set[1] = TRUE; + b_a->lpVtbl->SetBoolArray(b_a, b_a_set, 0, 2); + b_a->lpVtbl->GetBoolArray(b_a, b_a_ret, 1, 1); + ok(!b_a_ret[0], "b_a_ret[0] is %d, expected 0. Offset argument is being used in GetBoolArray.\n", b_a_ret[0]); + + effect->lpVtbl->Release(effect); + + refcount = ID3D10Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +} + +/* + * test_effect_vector_variable + */ +#if 0 +cbuffer cb +{ + float4 v_f0, v_f_a[2]; + int3 v_i0, v_i_a[3]; + bool2 v_b0, v_b_a[4]; +}; +#endif +static DWORD fx_test_vector_variable[] = +{ + 0x43425844, 0x581ae0ae, 0xa906b020, 0x26bba03e, + 0x5d7dfba2, 0x00000001, 0x0000021a, 0x00000001, + 0x00000024, 0x30315846, 0x000001ee, 0xfeff1001, + 0x00000001, 0x00000006, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x000000e2, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x66006263, + 0x74616f6c, 0x00070034, 0x00010000, 0x00000000, + 0x00100000, 0x00100000, 0x00100000, 0x210a0000, + 0x5f760000, 0x07003066, 0x01000000, 0x02000000, + 0x20000000, 0x10000000, 0x20000000, 0x0a000000, + 0x76000021, 0x615f665f, 0x746e6900, 0x00510033, + 0x00010000, 0x00000000, 0x000c0000, 0x00100000, + 0x000c0000, 0x19120000, 0x5f760000, 0x51003069, + 0x01000000, 0x03000000, 0x2c000000, 0x10000000, + 0x24000000, 0x12000000, 0x76000019, 0x615f695f, + 0x6f6f6200, 0x9900326c, 0x01000000, 0x00000000, + 0x08000000, 0x10000000, 0x08000000, 0x22000000, + 0x76000011, 0x0030625f, 0x00000099, 0x00000001, + 0x00000004, 0x00000038, 0x00000010, 0x00000020, + 0x00001122, 0x5f625f76, 0x00040061, 0x00c00000, + 0x00000000, 0x00060000, 0xffff0000, 0x0000ffff, + 0x002a0000, 0x000e0000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x004b0000, + 0x002f0000, 0x00000000, 0x00100000, 0x00000000, + 0x00000000, 0x00000000, 0x00720000, 0x00560000, + 0x00000000, 0x00300000, 0x00000000, 0x00000000, + 0x00000000, 0x00930000, 0x00770000, 0x00000000, + 0x00400000, 0x00000000, 0x00000000, 0x00000000, + 0x00bb0000, 0x009f0000, 0x00000000, 0x00700000, + 0x00000000, 0x00000000, 0x00000000, 0x00dc0000, + 0x00c00000, 0x00000000, 0x00800000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, +}; + +static void test_effect_vector_variable(void) +{ + ID3D10Device *device; + ID3D10Effect *effect; + ID3D10EffectVariable *var; + ID3D10EffectType *type; + ID3D10EffectVectorVariable *v_f0, *v_f_a, *v_i0, *v_i_a, *v_b0, *v_b_a; + float v_f0_ret[4], v_f_a_ret[8], v_f0_set[4], v_f_a_set[8]; + int v_i0_ret[3], v_i_a_ret[9], v_i0_set[3], v_i_a_set[9]; + BOOL v_b0_ret[2], v_b_a_ret[8], v_b0_set[2], v_b_a_set[8]; + D3D10_EFFECT_TYPE_DESC type_desc; + ULONG refcount; + HRESULT hr; + unsigned int i; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + + hr = create_effect(fx_test_vector_variable, 0, device, NULL, &effect); + ok(SUCCEEDED(hr), "D3D10CreateEffectFromMemory failed (%x)\n", hr); + + /* Same as above test, except this time with vector variables. */ + + /* Vector floating point variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "v_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); + v_f0 = var->lpVtbl->AsVector(var); + + v_f0_set[0] = 1.0f; v_f0_set[1] = 3.0f; v_f0_set[2] = 5.0f; v_f0_set[3] = 7.0f; + v_f0->lpVtbl->SetFloatVector(v_f0, v_f0_set); + v_f0->lpVtbl->GetFloatVector(v_f0, v_f0_ret); + for (i = 0; i < 4; i++) + ok(v_f0_ret[i] == v_f0_set[i], "v_f0_ret[%d] is %f, expected %f.\n", i, v_f0_ret[i], v_f0_set[i]); + + /* Vector floating point array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "v_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); + v_f_a = var->lpVtbl->AsVector(var); + + v_f_a_set[0] = 5.0f; v_f_a_set[1] = 10.0f; v_f_a_set[2] = 15.0f; v_f_a_set[3] = 20.0f; + v_f_a_set[4] = 25.0f; v_f_a_set[5] = 30.0f; v_f_a_set[6] = 35.0f; v_f_a_set[7] = 40.0f; + v_f_a->lpVtbl->SetFloatVectorArray(v_f_a, v_f_a_set, 0, 2); + v_f_a->lpVtbl->GetFloatVectorArray(v_f_a, v_f_a_ret, 0, 2); + for (i = 0; i < 8; i++) + ok(v_f_a_ret[i] == v_f_a_set[i], "v_f_a_ret[%d] is %f, expected %f.\n", i, v_f_a_ret[i], v_f_a_set[i]); + + /* Vector int variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "v_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); + v_i0 = var->lpVtbl->AsVector(var); + + v_i0_set[0] = 1; v_i0_set[1] = 3; v_i0_set[2] = 5; + v_i0->lpVtbl->SetIntVector(v_i0, v_i0_set); + v_i0->lpVtbl->GetIntVector(v_i0, v_i0_ret); + for (i = 0; i < 3; i++) + ok(v_i0_ret[i] == v_i0_set[i], "v_i0_ret[%d] is %d, expected %d.\n", i, v_i0_ret[i], v_i0_set[i]); + + /* Vector int array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "v_i_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_INT, "Type is %x, expected %x\n", type_desc.Type, D3D10_SVT_INT); + v_i_a = var->lpVtbl->AsVector(var); + + v_i_a_set[0] = 1; v_i_a_set[1] = 3; v_i_a_set[2] = 5; + v_i_a_set[3] = 7; v_i_a_set[4] = 9; v_i_a_set[5] = 11; + v_i_a_set[6] = 13; v_i_a_set[7] = 15; v_i_a_set[8] = 17; + v_i_a->lpVtbl->SetIntVectorArray(v_i_a, v_i_a_set, 0, 3); + v_i_a->lpVtbl->GetIntVectorArray(v_i_a, v_i_a_ret, 0, 3); + for (i = 0; i < 9; i++) + ok(v_i_a_ret[i] == v_i_a_set[i], "v_i_a_ret[%d] is %d, expected %d.\n", i, v_i_a_ret[i], v_i_a_set[i]); + + /* Vector bool variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "v_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); + v_b0 = var->lpVtbl->AsVector(var); + + v_b0_set[0] = TRUE; v_b0_set[1] = FALSE; + v_b0->lpVtbl->SetBoolVector(v_b0, v_b0_set); + v_b0->lpVtbl->GetBoolVector(v_b0, v_b0_ret); + for (i = 0; i < 2; i++) + ok(v_b0_ret[i] == v_b0_set[i], "v_b0_ret[%d] is %d, expected %d.\n", i, v_b0_ret[i], v_b0_set[i]); + + /* Vector bool array variable. */ + var = effect->lpVtbl->GetVariableByName(effect, "v_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); + v_b_a = var->lpVtbl->AsVector(var); + + v_b_a_set[0] = TRUE; v_b_a_set[1] = FALSE; + v_b_a_set[2] = FALSE; v_b_a_set[3] = TRUE; + v_b_a_set[4] = TRUE; v_b_a_set[5] = FALSE; + v_b_a_set[6] = TRUE; v_b_a_set[7] = TRUE; + v_b_a->lpVtbl->SetBoolVectorArray(v_b_a, v_b_a_set, 0, 4); + v_b_a->lpVtbl->GetBoolVectorArray(v_b_a, v_b_a_ret, 0, 4); + for (i = 0; i < 8; i++) + ok(v_b_a_ret[i] == v_b_a_set[i], "v_b_a_ret[%d] is %d, expected %d.\n", i, v_b_a_ret[i], v_b_a_set[i]); + + /* According to MSDN, the offset argument goes unused for VectorArray + * methods, same as the ScalarArray methods. However, testing has shown + * this to not be the case. So, test for the correct behavior here. */ + v_b_a->lpVtbl->GetBoolVectorArray(v_b_a, v_b_a_ret, 2, 2); + + /* In this case, with the offset being two bool2 variables, v_b_a_ret[0] + * through v_b_a_ret[3] should be the same as v_b_a_set[4] through + * v_b_a_set[7]. */ + for (i = 0; i < 4; i++) + ok(v_b_a_ret[i] == v_b_a_set[i + 4], "v_b_a_ret[%d] is %d, expected %d.\n", i, v_b_a_ret[i], v_b_a_set[i + 4]); + + v_b_a_set[0] = FALSE; v_b_a_set[1] = FALSE; + v_b_a_set[2] = FALSE; v_b_a_set[3] = FALSE; + v_b_a->lpVtbl->SetBoolVectorArray(v_b_a, v_b_a_set, 2, 2); + v_b_a->lpVtbl->GetBoolVectorArray(v_b_a, v_b_a_ret, 0, 4); + + /* Similar to the GetBoolVectorArray test, v_b_a_ret[4] through + * v_b_a_ret[7] should be the same as v_b_a_set[0] through v_b_a_set[3]. */ + for (i = 0; i < 4; i++) + ok(v_b_a_ret[i + 4] == v_b_a_set[i], "v_b_a_ret[%d] is %d, expected %d.\n", i + 4, v_b_a_ret[i + 4], v_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(); @@ -4285,4 +4652,6 @@ START_TEST(effect) test_effect_get_variable_by(); test_effect_state_groups(); test_effect_state_group_defaults(); + test_effect_scalar_variable(); + test_effect_vector_variable(); }