[PATCH 5/5] d3dx9_36/tests: Added tests for ID3DXConstantTable_Set* functions

Travis Athougies iammisc at gmail.com
Wed Jan 19 19:10:13 CST 2011


---
 dlls/d3dx9_36/tests/shader.c |  186 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 186 insertions(+), 0 deletions(-)

diff --git a/dlls/d3dx9_36/tests/shader.c b/dlls/d3dx9_36/tests/shader.c
index a4bbc22..a9c09d4 100644
--- a/dlls/d3dx9_36/tests/shader.c
+++ b/dlls/d3dx9_36/tests/shader.c
@@ -423,6 +423,191 @@ static void test_constant_tables(void)
             sizeof(ctab_arrays_expected)/sizeof(*ctab_arrays_expected));
 }
 
+static void test_setting_basic_table(IDirect3DDevice9 *device)
+{
+    static const D3DXMATRIX mvp = {
+        0.514f, 0.626f, 0.804f, 0.786f,
+        0.238f, 0.956f, 0.374f, 0.483f,
+        0.109f, 0.586f, 0.900f, 0.255f,
+        0.898f, 0.411f, 0.932f, 0.275f};
+    static const D3DXVECTOR4 f4 = {0.350f, 0.526f, 0.925f, 0.021f};
+    static const float f = 0.12543f;
+    static const int i = 321;
+
+    ID3DXConstantTable *ctable;
+
+    HRESULT res;
+    float out[16];
+
+    /* Get the constant table from the shader itself */
+    res = D3DXGetShaderConstantTable(ctab_basic, &ctable);
+    ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got 0x%08x\n", res);
+
+    /* Set constants */
+    res = ID3DXConstantTable_SetMatrix(ctable, device, "mvp", &mvp);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable mvp: got 0x%08x\n", res);
+
+    res = ID3DXConstantTable_SetInt(ctable, device, "i", i);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetInt failed on variable i: got 0x%08x\n", res);
+
+    res = ID3DXConstantTable_SetFloat(ctable, device, "f", f);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetFloat failed on variable f: got 0x%08x\n", res);
+
+    res = ID3DXConstantTable_SetVector(ctable, device, "f4", &f4);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetVector failed on variable f4: got 0x%08x\n", res);
+
+    /* Get constants back and validate */
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
+    ok(res == D3D_OK, "ID3DXConstantTable_GetVertexShaderConstantF failed: got 0x%08x\n", res);
+    ok(out[0] == mvp._11 && out[1] == mvp._12 && out[2] == mvp._13 && out[3] == mvp._14,
+            "The first row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
+            out[0], out[1], out[2], out[3], mvp._11, mvp._12, mvp._13, mvp._14);
+    ok(out[4] == mvp._21 && out[5] == mvp._22 && out[6] == mvp._23 && out[7] == mvp._24,
+            "The second row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
+            out[4], out[5], out[6], out[7], mvp._21, mvp._22, mvp._23, mvp._24);
+    ok(out[8] == mvp._31 && out[9] == mvp._32 && out[10] == mvp._33 && out[11] == mvp._34,
+            "The third row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
+            out[8], out[9], out[10], out[11], mvp._31, mvp._32, mvp._33, mvp._34);
+    ok(out[12] == mvp._41 && out[13] == mvp._42 && out[14] == mvp._43 && out[15] == mvp._44,
+            "The fourth row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
+            out[12], out[13], out[14], out[15], mvp._41, mvp._42, mvp._43, mvp._44);
+
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 4, out, 1);
+    ok(res == D3D_OK, "IDirect3DDevice9_GetVertexShaderConstantF failed: got 0x%08x\n", res);
+    ok(out[0] == (float)i && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
+            "The variable i was not set correctly, out={%f, %f, %f, %f}, should be {%d, 0.0, 0.0, 0.0}\n",
+            out[0], out[1], out[2], out[3], i);
+
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
+    ok(res == D3D_OK, "IDirect3DDevice9_GetVertexShaderConstantF failed: got 0x%08x\n", res);
+    ok(out[0] == f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
+            "The variable f was not set correctly, out={%f, %f, %f, %f}, should be {%f, 0.0, 0.0, 0.0}\n",
+            out[0], out[1], out[2], out[3], f);
+
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
+    ok(res == D3D_OK, "IDirect3DDevice9_GetVertexShaderConstantF failed: got 0x%08x\n", res);
+    ok(memcmp(out, (void*)&f4, sizeof(f4)) == 0,
+            "The variable f4 was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
+            out[0], out[1], out[2], out[3], f4.x, f4.y, f4.z, f4.w);
+
+    /* Finally test using a set* function for one type to set a variable of another type (should succeed) */
+    res = ID3DXConstantTable_SetVector(ctable, device, "f", &f4);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetVector failed on variable f: 0x%08x\n", res);
+
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
+    ok(res == D3D_OK, "IDirect3DDevice9_GetVertexShaderConstantF failed: got 0x%08x\n", res);
+    ok(out[0] == f4.x, "The variable f was not set correctly by ID3DXConstantTable_SetVector, got %f, should be %f\n",
+            out[0], f4.x);
+
+    ID3DXConstantTable_Release(ctable);
+}
+
+static void test_setting_arrays_table(IDirect3DDevice9 *device)
+{
+    /* The excess elements are because the out-of-bounds SetFloatArray call accesses all 8 elements in this list */
+    static const float farray[8] = {0.005f, 0.745f, 0.973f, 0.264f, 0.010f, 0.020f, 0.030f, 0.040f};
+    static const int iarray[4] = {1, 2, 3, 4};
+    static const D3DXVECTOR4 fvecarray[2] = {
+        {0.745f, 0.997f, 0.353f, 0.237f},
+        {0.060f, 0.455f, 0.333f, 0.983f}};
+
+    ID3DXConstantTable *ctable;
+
+    HRESULT res;
+    float out[16];
+
+    /* Get the constant table from the shader */
+    res = D3DXGetShaderConstantTable(ctab_arrays, &ctable);
+    ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got 0x%08x\n", res);
+
+    /* Set constants */
+
+    /* Make sure that we can set the variable even though we have too many elements */
+    res = ID3DXConstantTable_SetFloatArray(ctable, device, "farray", farray, 8);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetFloatArray failed: got 0x%08x\n", res);
+
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 12, out, 4);
+    ok(out[0] == farray[4] && out[4] == farray[5] && out[8] == farray[6] && out[12] == farray[7],
+            "The excess elements of the array were not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
+            out[0], out[4], out[8], out[12], farray[4], farray[5], farray[6], farray[7]);
+
+    /* Try setting an integer array to an array declared as a float array */
+    res = ID3DXConstantTable_SetIntArray(ctable, device, "farray", iarray, 4);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetIntArray failed: got 0x%08x\n", res);
+
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 4);
+    ok(out[0] == (float)iarray[0] && out[4] == (float)iarray[1] && out[8] == (float)iarray[2] &&
+            out[12] == (float)iarray[3], "SetIntArray did not properly set a float array: out={%f, %f, %f, %f}, should"
+            " be {%d, %d, %d, %d}\n", out[0], out[4], out[8], out[12], iarray[0], iarray[1], iarray[2], iarray[3]);
+
+    res = ID3DXConstantTable_SetFloatArray(ctable, device, "farray", farray, 4);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetFloatArray failed: got x0%08x\n", res);
+
+    res = ID3DXConstantTable_SetVectorArray(ctable, device, "fvecarray", fvecarray, 2);
+    ok(res == D3D_OK, "ID3DXConstantTable_SetVectorArray failed: got 0x%08x\n", res);
+
+    /* Read back constants */
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 4);
+    ok(out[0] == farray[0] && out[4] == farray[1] && out[8] == farray[2] && out[12] == farray[3],
+            "The variable farray was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
+            out[0], out[4], out[8], out[12], farray[0], farray[1], farray[2], farray[3]);
+
+    res = IDirect3DDevice9_GetVertexShaderConstantF(device, 12, out, 2);
+    ok(out[0] == fvecarray[0].x && out[1] == fvecarray[0].y && out[2] == fvecarray[0].z && out[3] == fvecarray[0].w &&
+            out[4] == fvecarray[1].x && out[5] == fvecarray[1].y && out[6] == fvecarray[1].z && out[7] == fvecarray[1].w,
+            "The variable fvecarray was not set correctly, out={{%f, %f, %f, %f}, {%f, %f, %f, %f}}, should be "
+            "{{%f, %f, %f, %f}, {%f, %f, %f, %f}}\n", out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
+            fvecarray[0].x, fvecarray[0].y, fvecarray[0].z, fvecarray[0].w, fvecarray[1].x, fvecarray[1].y,
+            fvecarray[1].z, fvecarray[1].w);
+
+    ID3DXConstantTable_Release(ctable);
+}
+
+static void test_setting_constants(void)
+{
+    HWND wnd;
+    IDirect3D9 *d3d;
+    IDirect3DDevice9 *device;
+    D3DPRESENT_PARAMETERS d3dpp;
+    HRESULT hr;
+
+    /* Create the device to use for our tests */
+    wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
+    d3d = Direct3DCreate9(D3D_SDK_VERSION);
+    if (!wnd)
+    {
+        skip("Couldn't create application window\n");
+        return;
+    }
+    if (!d3d)
+    {
+        skip("Couldn't create IDirect3D9 object\n");
+        DestroyWindow(wnd);
+        return;
+    }
+
+    ZeroMemory(&d3dpp, sizeof(d3dpp));
+    d3dpp.Windowed   = TRUE;
+    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
+    hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
+    if (FAILED(hr))
+    {
+        skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
+        IDirect3D9_Release(d3d);
+        DestroyWindow(wnd);
+        return;
+    }
+
+    test_setting_basic_table(device);
+    test_setting_arrays_table(device);
+
+    /* Release resources */
+    IDirect3DDevice9_Release(device);
+    IDirect3D9_Release(d3d);
+
+    if (wnd) DestroyWindow(wnd);
+}
+
 START_TEST(shader)
 {
     test_get_shader_size();
@@ -430,4 +615,5 @@ START_TEST(shader)
     test_find_shader_comment();
     test_get_shader_constant_table_ex();
     test_constant_tables();
+    test_setting_constants();
 }
-- 
1.7.0.4




More information about the wine-patches mailing list