[PATCH 2/3] d3d8/tests/visual: Add Vertexbuffer locking tests, try 2
Patrick Rudolph
siro at das-labor.org
Mon Jul 11 11:13:02 CDT 2016
Port test from d3d9/tests/visual.
Signed-off-by: Patrick Rudolph <siro at das-labor.org>
---
dlls/d3d8/tests/visual.c | 229 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 229 insertions(+)
diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index cd28e82..76cc775 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -9352,6 +9352,234 @@ static void test_color_clamping(void)
DestroyWindow(window);
}
+static void test_vb_lock_flags(void)
+{
+ IDirect3DVertexBuffer8 *buffer;
+ IDirect3DDevice8 *device;
+ IDirect3D8 *d3d8;
+ DWORD i, j, tri, quads;
+ HWND window;
+ HRESULT hr;
+ ULONG size;
+ unsigned refcount;
+ D3DCOLOR color;
+ BOOL unsyncronized;
+ D3DCAPS8 caps;
+
+ static const struct
+ {
+ const char *flags_s;
+ unsigned int flags;
+ BOOL usage;
+ BOOL unsyncronized;
+ BOOL todo;
+ }
+ tests[] =
+ {
+ {
+ "0",
+ 0,
+ 0,
+ FALSE,
+ FALSE
+ },
+ {
+ "0",
+ 0,
+ D3DUSAGE_DYNAMIC,
+ FALSE,
+ FALSE
+ },
+ {
+ "D3DLOCK_NOOVERWRITE",
+ D3DLOCK_NOOVERWRITE,
+ 0,
+ TRUE,
+ TRUE
+ },
+ {
+ "D3DLOCK_NOOVERWRITE",
+ D3DLOCK_NOOVERWRITE,
+ D3DUSAGE_DYNAMIC,
+ TRUE,
+ FALSE
+ },
+ {
+ "D3DLOCK_DISCARD",
+ D3DLOCK_DISCARD,
+ 0,
+ FALSE,
+ FALSE
+ },
+ {
+ "D3DLOCK_DISCARD",
+ D3DLOCK_DISCARD,
+ D3DUSAGE_DYNAMIC,
+ FALSE,
+ FALSE
+ },
+ {
+ "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD",
+ D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD,
+ 0,
+ TRUE,
+ TRUE
+ },
+ {
+ "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD",
+ D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD,
+ D3DUSAGE_DYNAMIC,
+ TRUE,
+ TRUE
+ },
+ {
+ "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY",
+ D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY,
+ 0,
+ TRUE,
+ TRUE
+ },
+ {
+ "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY",
+ D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY,
+ D3DUSAGE_DYNAMIC,
+ TRUE,
+ TRUE
+ },
+ };
+
+ static struct
+ {
+ struct
+ {
+ struct vec3 position;
+ DWORD diffuse;
+ } strip[4];
+ }
+ *quad_strip_array, quad_strip1 =
+ {
+ {
+ {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
+ {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
+ {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
+ {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
+ }
+ },
+ quad_strip2 =
+ {
+ {
+ {{-1.0f, -1.0f, 0.0f}, 0xffffff00},
+ {{-1.0f, 1.0f, 0.0f}, 0xffffff00},
+ {{ 1.0f, -1.0f, 0.0f}, 0xffffff00},
+ {{ 1.0f, 1.0f, 0.0f}, 0xffffff00},
+ }
+ };
+
+ window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 0, 0, 640, 480, NULL, NULL, NULL, NULL);
+ ok(!!window, "Failed to create a window.\n");
+
+ d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
+ ok(!!d3d8, "Failed to create a D3D object.\n");
+ if (!(device = create_device(d3d8, window, window, TRUE)))
+ {
+ skip("Failed to create a D3D device, skipping tests.\n");
+ IDirect3D8_Release(d3d8);
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
+ ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+ ok(SUCCEEDED(hr), "IDirect3DDevice9_SetRenderState returned %08x\n", hr);
+
+ hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
+ ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShader failed with %08x\n", hr);
+
+ for (i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i)
+ {
+ unsyncronized = FALSE;
+
+ /* Increase triangle draw count for faster GPUs.
+ Limit size to 0x40000 as bigger values causes the Nvidia driver to crash. */
+ for (size = 0x1000; size <= 0x40000; size <<= 1)
+ {
+ /* calculate triangle count */
+ tri = (size / sizeof(quad_strip1.strip[0])) - 2;
+ if (tri > caps.MaxPrimitiveCount)
+ break;
+
+ quads = size / sizeof(quad_strip1);
+
+ hr = IDirect3DDevice8_CreateVertexBuffer(device, size, tests[i].usage, 0, D3DPOOL_DEFAULT, &buffer);
+ ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
+ if (!SUCCEEDED(hr))
+ continue;
+
+ /* place quads */
+ hr = IDirect3DVertexBuffer8_Lock(buffer, 0, size, (BYTE **)&quad_strip_array, 0);
+ ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
+
+ for (j = 0; j < quads; j++)
+ quad_strip_array[j] = quad_strip1;
+
+ hr = IDirect3DVertexBuffer8_Unlock(buffer);
+ ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(quad_strip1.strip[0]));
+ ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
+
+ /* draw a quad to make use of the bound buffer */
+ hr = IDirect3DDevice8_BeginScene(device);
+ ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
+ hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, tri);
+ ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
+ hr = IDirect3DDevice8_EndScene(device);
+ ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
+
+ /* Map the last quad while draw is in progress */
+ hr = IDirect3DVertexBuffer8_Lock(buffer, (quads - 1) * sizeof(quad_strip1),
+ sizeof(quad_strip1), (BYTE **)&quad_strip_array, tests[i].flags);
+ ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
+
+ /* Replace last quad with yellow quad */
+ quad_strip_array[0] = quad_strip2;
+
+ hr = IDirect3DVertexBuffer8_Unlock(buffer);
+ ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
+
+ /* Test if last triangle has different color */
+ color = getPixelColor(device, 160, 360);
+ unsyncronized |= color_match(color, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00), 1);
+
+ IDirect3DVertexBuffer8_Release(buffer);
+
+ hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
+ ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
+
+ if (tests[i].unsyncronized == unsyncronized)
+ break;
+ }
+ if (tests[i].todo)
+ {
+ todo_wine ok(tests[i].unsyncronized == unsyncronized, "Expected buffer mapped %s. Flags = %s. Usage = %d.\n",
+ tests[i].unsyncronized ? "unsyncronized" : "syncronized", tests[i].flags_s, tests[i].usage);
+ }
+ else
+ {
+ ok(tests[i].unsyncronized == unsyncronized, "Expected buffer mapped %s. Flags = %s. Usage = %d.\n",
+ tests[i].unsyncronized ? "unsyncronized" : "syncronized", tests[i].flags_s, tests[i].usage);
+ }
+ }
+
+ refcount = IDirect3DDevice8_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+ IDirect3D8_Release(d3d8);
+ DestroyWindow(window);
+}
+
START_TEST(visual)
{
D3DADAPTER_IDENTIFIER8 identifier;
@@ -9419,4 +9647,5 @@ START_TEST(visual)
test_multisample_init();
test_texture_blending();
test_color_clamping();
+ test_vb_lock_flags();
}
--
2.7.4
More information about the wine-patches
mailing list