[PATCH 5/5] d3dcompiler_43/tests: Added trigonometric function tests to HLSL test suite

Travis Athougies iammisc at gmail.com
Sun Sep 26 12:51:32 CDT 2010


---
 dlls/d3dcompiler_43/tests/hlsl.c |  126 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/dlls/d3dcompiler_43/tests/hlsl.c b/dlls/d3dcompiler_43/tests/hlsl.c
index 4ac8f4d..82d2c4d 100644
--- a/dlls/d3dcompiler_43/tests/hlsl.c
+++ b/dlls/d3dcompiler_43/tests/hlsl.c
@@ -141,6 +141,17 @@ static void set_float4_d3d9(IDirect3DDevice9 *device, ID3DXConstantTable *consta
     ID3DXConstantTable_SetVector(constants, device, name, &vector);
 }
 
+/* Compare floating point arrays keeping a count of how many
+   erroneous values we have found */
+static int cmp_results_linear(int samples, float epsilon, float *expected, float *actual)
+{
+    int i, result = 0;
+    for (i = 0; i < samples; i++)
+        if (abs(expected[i] - actual[i]) > epsilon)
+            result++;
+    return result;
+}
+
 /* Compile our pixel shader and get back the compiled version and a constant
    table */
 static IDirect3DPixelShader9 *compile_pixel_shader9(IDirect3DDevice9 *device, const char *shader,
@@ -221,6 +232,43 @@ static void setup_device9(IDirect3DDevice9 *device, IDirect3DSurface9 **render_t
 /* For all compute_shader_* calls, this framework assumes that the data types are 4 bytes
    long. The two formats used here are D3DFMT_R32F and D3DFMT_A8R8G8B8 */
 
+/* Repeatedly call a shader with linearly varying values and collect the results */
+static void *compute_shader_linear9(IDirect3DDevice9 *device, IDirect3DVertexShader9 *vshader,
+        IDirect3DPixelShader9 *pshader, IDirect3DVertexBuffer9 *quad_geometry,
+        ID3DXConstantTable *constants, D3DFORMAT format, int samples)
+{
+    IDirect3DSurface9 *render_target;
+    IDirect3DSurface9 *readback;
+    int i;
+
+    HRESULT hr;
+    DWORD *ret;
+    D3DLOCKED_RECT lr;
+
+    setup_device9(device, &render_target, &readback, format, samples, 1, vshader, pshader);
+
+    ret = HeapAlloc(GetProcessHeap(), 0, 4 * samples);
+    for (i = 0; i < 32; i++)
+    {
+        ID3DXConstantTable_SetFloat(constants, device, "$x", ((float) i)/((float) samples));
+        draw_quad_with_shader9(device, quad_geometry);
+
+        hr = IDirect3DDevice9_GetRenderTargetData(device, render_target, readback);
+        ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTargetData returned: %08x\n", hr);
+
+        hr = IDirect3DSurface9_LockRect(readback, &lr, NULL, D3DLOCK_READONLY);
+        ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned: %08x\n", hr);
+        memcpy(ret + i, lr.pBits, 4);
+        hr = IDirect3DSurface9_UnlockRect(readback);
+        ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect returned: %08x\n", hr);
+    }
+
+    IUnknown_Release(render_target);
+    IUnknown_Release(readback);
+
+    return ret;
+}
+
 /* Compute a shader on a fullscreen quad and get the results back */
 static void *compute_shader_fullscreen9(IDirect3DDevice9 *device, IDirect3DVertexShader9 *vshader,
         IDirect3DPixelShader9 *pshader, IDirect3DVertexBuffer9 *quad_geometry, D3DFORMAT format,
@@ -463,6 +511,83 @@ static void test_float_vectors(IDirect3DDevice9 *device, IDirect3DVertexBuffer9
     }
 }
 
+static void test_trig(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
+        IDirect3DVertexShader9 *vshader_passthru)
+{
+    static float sin_expected[] = {
+        0.500000f, 0.597545f, 0.691341f, 0.777785f,
+        0.853553f, 0.915734f, 0.961939f, 0.990392f,
+        1.000000f, 0.990392f, 0.961939f, 0.915734f,
+        0.853553f, 0.777785f, 0.691341f, 0.597545f,
+        0.500000f, 0.402454f, 0.308658f, 0.222214f,
+        0.146446f, 0.084265f, 0.038060f, 0.009607f,
+        0.000000f, 0.009607f, 0.038060f, 0.084265f,
+        0.146446f, 0.222214f, 0.308658f, 0.402454f,
+    };
+
+    static float cos_expected[] = {
+        1.000000f, 0.990392f, 0.961939f, 0.915734f,
+        0.853553f, 0.777785f, 0.691341f, 0.597545f,
+        0.500000f, 0.402454f, 0.308658f, 0.222214f,
+        0.146446f, 0.084265f, 0.038060f, 0.009607f,
+        0.000000f, 0.009607f, 0.038060f, 0.084265f,
+        0.146446f, 0.222214f, 0.308658f, 0.402454f,
+        0.500000f, 0.597545f, 0.691341f, 0.777785f,
+        0.853553f, 0.915734f, 0.961939f, 0.990392f,
+    };
+
+    static const char *sin_shader =
+        "float4 test(uniform float x): COLOR    \
+         {                                      \
+            const float pi2 = 6.2831853;        \
+            float calcd = (sin(x * pi2) + 1)/2; \
+            return calcd;                       \
+         }";
+
+    static const char *cos_shader =
+        "float4 test(uniform float x): COLOR    \
+        {                                       \
+            const float pi2 = 6.2831853;        \
+            float calcd = (cos(x * pi2) + 1)/2; \
+            return calcd;                       \
+        }";
+
+    ID3DXConstantTable *constants;
+    IDirect3DPixelShader9 *pshader;
+    void *data;
+    int errors;
+
+    pshader = compile_pixel_shader9(device, sin_shader, "ps_2_0", &constants);
+    if (pshader != NULL)
+    {
+        data = compute_shader_linear9(device, vshader_passthru, pshader, quad_geometry, constants,
+                D3DFMT_R32F, 32);
+
+        errors = cmp_results_linear(32, 0.00001f, sin_expected, data);
+        ok(errors == 0, "sin: Got %d unexpected values\n", errors);
+
+        HeapFree(GetProcessHeap(), 0, data);
+
+        IUnknown_Release(constants);
+        IUnknown_Release(pshader);
+    }
+
+    pshader = compile_pixel_shader9(device, cos_shader, "ps_2_0", &constants);
+    if (pshader != NULL)
+    {
+        data = compute_shader_linear9(device, vshader_passthru, pshader, quad_geometry, constants,
+                D3DFMT_R32F, 32);
+
+        errors = cmp_results_linear(32, 0.00001f, cos_expected, data);
+        ok(errors == 0, "cos: Got %d unexpected values\n", errors);
+
+        HeapFree(GetProcessHeap(), 0, data);
+
+        IUnknown_Release(constants);
+        IUnknown_Release(pshader);
+    }
+}
+
 START_TEST(hlsl)
 {
     D3DCAPS9 caps;
@@ -486,6 +611,7 @@ START_TEST(hlsl)
             test_math(device, quad_geometry, vshader_passthru);
             test_conditionals(device, quad_geometry, vshader_passthru);
             test_float_vectors(device, quad_geometry, vshader_passthru);
+            test_trig(device, quad_geometry, vshader_passthru);
         }
     } else skip("no pixel shader support\n");
 
-- 
1.7.0.4




More information about the wine-patches mailing list