ddraw: Don't discard buffers that haven't been used in draws.
This commit is contained in:
parent
5fd8529363
commit
d3520ef465
|
@ -535,6 +535,8 @@ struct d3d_vertex_buffer
|
||||||
DWORD fvf;
|
DWORD fvf;
|
||||||
DWORD size;
|
DWORD size;
|
||||||
BOOL dynamic;
|
BOOL dynamic;
|
||||||
|
|
||||||
|
BOOL read_since_last_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
HRESULT d3d_vertex_buffer_create(struct d3d_vertex_buffer **buffer, struct ddraw *ddraw,
|
HRESULT d3d_vertex_buffer_create(struct d3d_vertex_buffer **buffer, struct ddraw *ddraw,
|
||||||
|
|
|
@ -4113,6 +4113,10 @@ static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVE
|
||||||
/* Now draw the primitives */
|
/* Now draw the primitives */
|
||||||
wined3d_device_set_primitive_type(device->wined3d_device, PrimitiveType);
|
wined3d_device_set_primitive_type(device->wined3d_device, PrimitiveType);
|
||||||
hr = wined3d_device_draw_primitive(device->wined3d_device, StartVertex, NumVertices);
|
hr = wined3d_device_draw_primitive(device->wined3d_device, StartVertex, NumVertices);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
vb->read_since_last_map = TRUE;
|
||||||
|
|
||||||
wined3d_mutex_unlock();
|
wined3d_mutex_unlock();
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
@ -4236,6 +4240,9 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
|
||||||
wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
|
wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
|
||||||
hr = wined3d_device_draw_indexed_primitive(This->wined3d_device, ib_pos / sizeof(WORD), IndexCount);
|
hr = wined3d_device_draw_indexed_primitive(This->wined3d_device, ib_pos / sizeof(WORD), IndexCount);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
vb->read_since_last_map = TRUE;
|
||||||
|
|
||||||
wined3d_mutex_unlock();
|
wined3d_mutex_unlock();
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
|
|
@ -2856,6 +2856,85 @@ static void test_coop_level_surf_create(void)
|
||||||
IDirectDraw4_Release(ddraw);
|
IDirectDraw4_Release(ddraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_vb_discard(void)
|
||||||
|
{
|
||||||
|
static const struct vec4 quad[] =
|
||||||
|
{
|
||||||
|
{ 0.0f, 480.0f, 0.0f, 1.0f},
|
||||||
|
{ 0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
{640.0f, 480.0f, 0.0f, 1.0f},
|
||||||
|
{640.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
};
|
||||||
|
|
||||||
|
IDirect3DDevice3 *device;
|
||||||
|
IDirect3D3 *d3d;
|
||||||
|
IDirect3DVertexBuffer *buffer;
|
||||||
|
HWND window;
|
||||||
|
HRESULT hr;
|
||||||
|
D3DVERTEXBUFFERDESC desc;
|
||||||
|
BYTE *data;
|
||||||
|
static const unsigned int vbsize = 16;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
|
||||||
|
0, 0, 640, 480, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
if (!(device = create_device(window, DDSCL_NORMAL)))
|
||||||
|
{
|
||||||
|
skip("Failed to create D3D device, skipping test.\n");
|
||||||
|
DestroyWindow(window);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
memset(&desc, 0, sizeof(desc));
|
||||||
|
desc.dwSize = sizeof(desc);
|
||||||
|
desc.dwCaps = D3DVBCAPS_WRITEONLY;
|
||||||
|
desc.dwFVF = D3DFVF_XYZRHW;
|
||||||
|
desc.dwNumVertices = vbsize;
|
||||||
|
hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
|
||||||
|
memcpy(data, quad, sizeof(quad));
|
||||||
|
hr = IDirect3DVertexBuffer_Unlock(buffer);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DDevice3_BeginScene(device);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
|
||||||
|
hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
|
||||||
|
hr = IDirect3DDevice3_EndScene(device);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
|
||||||
|
memset(data, 0xaa, sizeof(struct vec4) * vbsize);
|
||||||
|
hr = IDirect3DVertexBuffer_Unlock(buffer);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
|
||||||
|
for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
|
||||||
|
{
|
||||||
|
if (data[i] != 0xaa)
|
||||||
|
{
|
||||||
|
ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hr = IDirect3DVertexBuffer_Unlock(buffer);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
IDirect3DVertexBuffer_Release(buffer);
|
||||||
|
IDirect3D3_Release(d3d);
|
||||||
|
IDirect3DDevice3_Release(device);
|
||||||
|
DestroyWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(ddraw4)
|
START_TEST(ddraw4)
|
||||||
{
|
{
|
||||||
test_process_vertices();
|
test_process_vertices();
|
||||||
|
@ -2879,4 +2958,5 @@ START_TEST(ddraw4)
|
||||||
test_coop_level_mode_set_multi();
|
test_coop_level_mode_set_multi();
|
||||||
test_initialize();
|
test_initialize();
|
||||||
test_coop_level_surf_create();
|
test_coop_level_surf_create();
|
||||||
|
test_vb_discard();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2665,6 +2665,85 @@ static void test_coop_level_surf_create(void)
|
||||||
IDirectDraw7_Release(ddraw);
|
IDirectDraw7_Release(ddraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_vb_discard(void)
|
||||||
|
{
|
||||||
|
static const struct vec4 quad[] =
|
||||||
|
{
|
||||||
|
{ 0.0f, 480.0f, 0.0f, 1.0f},
|
||||||
|
{ 0.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
{640.0f, 480.0f, 0.0f, 1.0f},
|
||||||
|
{640.0f, 0.0f, 0.0f, 1.0f},
|
||||||
|
};
|
||||||
|
|
||||||
|
IDirect3DDevice7 *device;
|
||||||
|
IDirect3D7 *d3d;
|
||||||
|
IDirect3DVertexBuffer7 *buffer;
|
||||||
|
HWND window;
|
||||||
|
HRESULT hr;
|
||||||
|
D3DVERTEXBUFFERDESC desc;
|
||||||
|
BYTE *data;
|
||||||
|
static const unsigned int vbsize = 16;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
|
||||||
|
0, 0, 640, 480, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
if (!(device = create_device(window, DDSCL_NORMAL)))
|
||||||
|
{
|
||||||
|
skip("Failed to create D3D device, skipping test.\n");
|
||||||
|
DestroyWindow(window);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
memset(&desc, 0, sizeof(desc));
|
||||||
|
desc.dwSize = sizeof(desc);
|
||||||
|
desc.dwCaps = D3DVBCAPS_WRITEONLY;
|
||||||
|
desc.dwFVF = D3DFVF_XYZRHW;
|
||||||
|
desc.dwNumVertices = vbsize;
|
||||||
|
hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
|
||||||
|
memcpy(data, quad, sizeof(quad));
|
||||||
|
hr = IDirect3DVertexBuffer7_Unlock(buffer);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DDevice7_BeginScene(device);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
|
||||||
|
hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
|
||||||
|
hr = IDirect3DDevice7_EndScene(device);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
|
||||||
|
memset(data, 0xaa, sizeof(struct vec4) * vbsize);
|
||||||
|
hr = IDirect3DVertexBuffer7_Unlock(buffer);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
|
||||||
|
for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
|
||||||
|
{
|
||||||
|
if (data[i] != 0xaa)
|
||||||
|
{
|
||||||
|
ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hr = IDirect3DVertexBuffer7_Unlock(buffer);
|
||||||
|
ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
|
||||||
|
|
||||||
|
IDirect3DVertexBuffer7_Release(buffer);
|
||||||
|
IDirect3D7_Release(d3d);
|
||||||
|
IDirect3DDevice7_Release(device);
|
||||||
|
DestroyWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(ddraw7)
|
START_TEST(ddraw7)
|
||||||
{
|
{
|
||||||
HMODULE module = GetModuleHandleA("ddraw.dll");
|
HMODULE module = GetModuleHandleA("ddraw.dll");
|
||||||
|
@ -2695,4 +2774,5 @@ START_TEST(ddraw7)
|
||||||
test_coop_level_mode_set_multi();
|
test_coop_level_mode_set_multi();
|
||||||
test_initialize();
|
test_initialize();
|
||||||
test_coop_level_surf_create();
|
test_coop_level_surf_create();
|
||||||
|
test_vb_discard();
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,7 +245,7 @@ static HRESULT WINAPI d3d_vertex_buffer7_Lock(IDirect3DVertexBuffer7 *iface,
|
||||||
wined3d_flags |= WINED3D_MAP_READONLY;
|
wined3d_flags |= WINED3D_MAP_READONLY;
|
||||||
if (flags & DDLOCK_NOOVERWRITE)
|
if (flags & DDLOCK_NOOVERWRITE)
|
||||||
wined3d_flags |= WINED3D_MAP_NOOVERWRITE;
|
wined3d_flags |= WINED3D_MAP_NOOVERWRITE;
|
||||||
if (flags & DDLOCK_DISCARDCONTENTS)
|
if (flags & DDLOCK_DISCARDCONTENTS && buffer->read_since_last_map)
|
||||||
{
|
{
|
||||||
wined3d_flags |= WINED3D_MAP_DISCARD;
|
wined3d_flags |= WINED3D_MAP_DISCARD;
|
||||||
|
|
||||||
|
@ -278,6 +278,10 @@ static HRESULT WINAPI d3d_vertex_buffer7_Lock(IDirect3DVertexBuffer7 *iface,
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = wined3d_buffer_map(buffer->wineD3DVertexBuffer, 0, 0, (BYTE **)data, wined3d_flags);
|
hr = wined3d_buffer_map(buffer->wineD3DVertexBuffer, 0, 0, (BYTE **)data, wined3d_flags);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
buffer->read_since_last_map = FALSE;
|
||||||
|
|
||||||
wined3d_mutex_unlock();
|
wined3d_mutex_unlock();
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
|
|
Loading…
Reference in New Issue