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

Travis Athougies iammisc at gmail.com
Thu Sep 30 17:43:06 CDT 2010


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

diff --git a/dlls/d3dcompiler_43/tests/hlsl.c b/dlls/d3dcompiler_43/tests/hlsl.c
index 3658a86..42f7c3a 100644
--- a/dlls/d3dcompiler_43/tests/hlsl.c
+++ b/dlls/d3dcompiler_43/tests/hlsl.c
@@ -287,6 +287,44 @@ static void compute_shader_probe9(IDirect3DDevice9 *device, IDirect3DVertexShade
     IUnknown_Release(readback);
 }
 
+/* Repeatedly call a shader 32 times with linearly varying values and test the results against
+   an array of floats using the given epsilon */
+static void compute_shader_linear9(IDirect3DDevice9 *device, IDirect3DVertexShader9 *vshader,
+        IDirect3DPixelShader9 *pshader, IDirect3DVertexBuffer9 *quad_geometry,
+        ID3DXConstantTable *constants, const char *error, float *expected,
+        float epsilon, int samples)
+{
+    IDirect3DSurface9 *render_target;
+    IDirect3DSurface9 *readback;
+    int i;
+    float data;
+
+    HRESULT hr;
+    D3DLOCKED_RECT lr;
+
+    setup_device9(device, &render_target, &readback, D3DFMT_R32F, samples, 1, vshader, pshader);
+
+    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);
+        data = *(float *)lr.pBits;
+        ok(F_EQ(data, expected[i], epsilon), "At %d: %s: Expected %f, got %f\n", i, error,
+                expected[i], data);
+        hr = IDirect3DSurface9_UnlockRect(readback);
+        ok(hr == D3D_OK, "IDirect3DSurface9_UnlockRect returned: %08x\n", hr);
+    }
+
+    IUnknown_Release(render_target);
+    IUnknown_Release(readback);
+}
+
 /* Now the actual test functions */
 static void test_swizzle(IDirect3DDevice9 *device, IDirect3DVertexBuffer9 *quad_geometry,
         IDirect3DVertexShader9 *vshader_passthru)
@@ -496,6 +534,71 @@ 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;
+
+    pshader = compile_pixel_shader9(device, sin_shader, "ps_2_0", &constants);
+    if (pshader != NULL)
+    {
+        compute_shader_linear9(device, vshader_passthru, pshader, quad_geometry, constants,
+                "sin test failed", sin_expected, 0.0001f, 32);
+
+        IUnknown_Release(constants);
+        IUnknown_Release(pshader);
+    }
+
+    pshader = compile_pixel_shader9(device, cos_shader, "ps_2_0", &constants);
+    if (pshader != NULL)
+    {
+        compute_shader_linear9(device, vshader_passthru, pshader, quad_geometry, constants,
+                "cos test failed", cos_expected, 0.0001f, 32);
+
+        IUnknown_Release(constants);
+        IUnknown_Release(pshader);
+    }
+}
+
 START_TEST(hlsl)
 {
     D3DCAPS9 caps;
@@ -519,6 +622,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