Module: wine Branch: master Commit: e6e0c2278359340594da7451654ef7c50d175e7c URL: http://source.winehq.org/git/wine.git/?a=commit;h=e6e0c2278359340594da745165...
Author: Henri Verbeet hverbeet@codeweavers.com Date: Tue Jan 5 15:04:55 2016 +0100
wined3d: Set WINED3D_BUFFER_DOUBLEBUFFER for managed buffers as well.
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/d3d8/tests/device.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ dlls/d3d9/tests/device.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ dlls/wined3d/buffer.c | 2 +- 3 files changed, 156 insertions(+), 1 deletion(-)
diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c index daf45b7..8b20d19 100644 --- a/dlls/d3d8/tests/device.c +++ b/dlls/d3d8/tests/device.c @@ -5577,6 +5577,82 @@ static void test_swvp_buffer(void) DestroyWindow(window); }
+static void test_managed_buffer(void) +{ + static const unsigned int vertex_count = 1024; + IDirect3DVertexBuffer8 *buffer; + D3DVERTEXBUFFER_DESC desc; + IDirect3DDevice8 *device; + struct vec3 *ptr, *ptr2; + IDirect3D8 *d3d8; + unsigned int i; + UINT refcount; + HWND window; + HRESULT hr; + + window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + d3d8 = Direct3DCreate8(D3D_SDK_VERSION); + ok(!!d3d8, "Failed to create a D3D object.\n"); + if (!(device = create_device(d3d8, window, NULL))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + IDirect3D8_Release(d3d8); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice8_CreateVertexBuffer(device, vertex_count * sizeof(*ptr), 0, 0, D3DPOOL_MANAGED, &buffer); + ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr); + hr = IDirect3DVertexBuffer8_GetDesc(buffer, &desc); + ok(SUCCEEDED(hr), "Failed to get desc, hr %#x.\n", hr); + ok(desc.Pool == D3DPOOL_MANAGED, "Got unexpected pool %#x.\n", desc.Pool); + ok(!desc.Usage, "Got unexpected usage %#x.\n", desc.Usage); + + hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr), (BYTE **)&ptr, D3DLOCK_DISCARD); + ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr); + for (i = 0; i < vertex_count; ++i) + { + ptr[i].x = i * 1.0f; + ptr[i].y = i * 2.0f; + ptr[i].z = i * 3.0f; + } + hr = IDirect3DVertexBuffer8_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ); + ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*ptr)); + ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr); + hr = IDirect3DDevice8_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2); + 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); + + hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr2), (BYTE **)&ptr2, D3DLOCK_DISCARD); + ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr); + ok(ptr2 == ptr, "Got unexpected ptr2 %p, expected %p.\n", ptr2, ptr); + for (i = 0; i < vertex_count; ++i) + { + if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f) + { + ok(FALSE, "Got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n", + i, ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f); + break; + } + } + hr = IDirect3DVertexBuffer8_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr); + + IDirect3DVertexBuffer8_Release(buffer); + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + IDirect3D8_Release(d3d8); + DestroyWindow(window); +} + static void test_npot_textures(void) { IDirect3DDevice8 *device = NULL; @@ -7530,6 +7606,7 @@ START_TEST(device) test_surface_blocks(); test_set_palette(); test_swvp_buffer(); + test_managed_buffer(); test_npot_textures(); test_volume_locking(); test_update_volumetexture(); diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 6cdb225..16723df 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -8102,6 +8102,83 @@ static void test_swvp_buffer(void) DestroyWindow(window); }
+static void test_managed_buffer(void) +{ + static const unsigned int vertex_count = 1024; + IDirect3DVertexBuffer9 *buffer; + D3DVERTEXBUFFER_DESC desc; + IDirect3DDevice9 *device; + struct vec3 *ptr, *ptr2; + IDirect3D9 *d3d9; + unsigned int i; + UINT refcount; + HWND window; + HRESULT hr; + + window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + d3d9 = Direct3DCreate9(D3D_SDK_VERSION); + ok(!!d3d9, "Failed to create a D3D object.\n"); + if (!(device = create_device(d3d9, window, NULL))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + IDirect3D9_Release(d3d9); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice9_CreateVertexBuffer(device, vertex_count * sizeof(*ptr), + 0, 0, D3DPOOL_MANAGED, &buffer, NULL); + ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr); + hr = IDirect3DVertexBuffer9_GetDesc(buffer, &desc); + ok(SUCCEEDED(hr), "Failed to get desc, hr %#x.\n", hr); + ok(desc.Pool == D3DPOOL_MANAGED, "Got unexpected pool %#x.\n", desc.Pool); + ok(!desc.Usage, "Got unexpected usage %#x.\n", desc.Usage); + + hr = IDirect3DVertexBuffer9_Lock(buffer, 0, vertex_count * sizeof(*ptr), (void **)&ptr, D3DLOCK_DISCARD); + ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr); + for (i = 0; i < vertex_count; ++i) + { + ptr[i].x = i * 1.0f; + ptr[i].y = i * 2.0f; + ptr[i].z = i * 3.0f; + } + hr = IDirect3DVertexBuffer9_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr); + + hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ); + ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetStreamSource(device, 0, buffer, 0, sizeof(*ptr)); + ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr); + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + hr = IDirect3DVertexBuffer9_Lock(buffer, 0, vertex_count * sizeof(*ptr2), (void **)&ptr2, D3DLOCK_DISCARD); + ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr); + ok(ptr2 == ptr, "Got unexpected ptr2 %p, expected %p.\n", ptr2, ptr); + for (i = 0; i < vertex_count; ++i) + { + if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f) + { + ok(FALSE, "Got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n", + i, ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f); + break; + } + } + hr = IDirect3DVertexBuffer9_Unlock(buffer); + ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr); + + IDirect3DVertexBuffer9_Release(buffer); + refcount = IDirect3DDevice9_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + IDirect3D9_Release(d3d9); + DestroyWindow(window); +} + static void test_npot_textures(void) { IDirect3DDevice9 *device = NULL; @@ -10446,6 +10523,7 @@ START_TEST(device) test_surface_blocks(); test_set_palette(); test_swvp_buffer(); + test_managed_buffer(); test_npot_textures(); test_vidmem_accounting(); test_volume_locking(); diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 444015f..1e66cae 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1230,7 +1230,7 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device TRACE("size %#x, usage %#x, format %s, memory @ %p, iface @ %p.\n", buffer->resource.size, buffer->resource.usage, debug_d3dformat(buffer->resource.format->id), buffer->resource.heap_memory, buffer);
- if (device->create_parms.flags & WINED3DCREATE_SOFTWARE_VERTEXPROCESSING) + if (device->create_parms.flags & WINED3DCREATE_SOFTWARE_VERTEXPROCESSING || pool == WINED3D_POOL_MANAGED) { /* SWvp always returns the same pointer in buffer maps and retains data in DISCARD maps. * Keep a system memory copy of the buffer to provide the same behavior to the application.