=?UTF-8?Q?Stefan=20D=C3=B6singer=20?=: ddraw: Don' t create a wastefully large index buffer.
Alexandre Julliard
julliard at winehq.org
Wed Nov 28 14:14:07 CST 2012
Module: wine
Branch: master
Commit: 4b95487bddd34f6dac3eb84f34110e0acc97470c
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4b95487bddd34f6dac3eb84f34110e0acc97470c
Author: Stefan Dösinger <stefan at codeweavers.com>
Date: Tue Nov 27 00:00:30 2012 +0100
ddraw: Don't create a wastefully large index buffer.
---
dlls/ddraw/ddraw_private.h | 1 +
dlls/ddraw/device.c | 29 ++++++-----------------------
2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 319fcab..a7fac29 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -276,6 +276,7 @@ struct d3d_device
struct wined3d_device *wined3d_device;
struct ddraw *ddraw;
struct wined3d_buffer *indexbuffer;
+ UINT indexbuffer_size;
struct ddraw_surface *target;
/* Viewport management */
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index ba7d011..dd7d3ee 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -240,7 +240,7 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface)
* care of that on uninit_3d(). */
/* Free the index buffer. */
- wined3d_buffer_decref(This->indexbuffer);
+ if (This->indexbuffer) wined3d_buffer_decref(This->indexbuffer);
/* Set the device up to render to the front buffer since the back
* buffer will vanish soon. */
@@ -4039,8 +4039,6 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
struct d3d_device *This = impl_from_IDirect3DDevice7(iface);
struct d3d_vertex_buffer *vb = unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf);
DWORD stride = get_flexible_vertex_size(vb->fvf);
- struct wined3d_resource *wined3d_resource;
- struct wined3d_resource_desc desc;
WORD *LockedIndices;
HRESULT hr;
@@ -4058,13 +4056,9 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
wined3d_device_set_vertex_declaration(This->wined3d_device, vb->wineD3DVertexDeclaration);
- /* check that the buffer is large enough to hold the indices,
- * reallocate if necessary. */
- wined3d_resource = wined3d_buffer_get_resource(This->indexbuffer);
- wined3d_resource_get_desc(wined3d_resource, &desc);
- if (desc.size < IndexCount * sizeof(WORD))
+ if (This->indexbuffer_size < IndexCount * sizeof(WORD))
{
- UINT size = max(desc.size * 2, IndexCount * sizeof(WORD));
+ UINT size = max(This->indexbuffer_size * 2, IndexCount * sizeof(WORD));
struct wined3d_buffer *buffer;
TRACE("Growing index buffer to %u bytes\n", size);
@@ -4073,13 +4067,14 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
WINED3D_POOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &buffer);
if (FAILED(hr))
{
- ERR("(%p) IWineD3DDevice::CreateIndexBuffer failed with hr = %08x\n", This, hr);
+ ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", This, hr);
wined3d_mutex_unlock();
return hr;
}
- wined3d_buffer_decref(This->indexbuffer);
+ if (This->indexbuffer) wined3d_buffer_decref(This->indexbuffer);
This->indexbuffer = buffer;
+ This->indexbuffer_size = size;
}
/* Copy the index stream into the index buffer. A new IWineD3DDevice
@@ -6529,17 +6524,6 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
device->legacy_projection = ident;
device->legacy_clipspace = ident;
- /* Create an index buffer, it's needed for indexed drawing */
- hr = wined3d_buffer_create_ib(ddraw->wined3d_device, 0x40000 /* Length. Don't know how long it should be */,
- WINED3DUSAGE_DYNAMIC /* Usage */, WINED3D_POOL_DEFAULT, NULL,
- &ddraw_null_wined3d_parent_ops, &device->indexbuffer);
- if (FAILED(hr))
- {
- ERR("Failed to create an index buffer, hr %#x.\n", hr);
- ddraw_handle_table_destroy(&device->handle_table);
- return hr;
- }
-
/* This is for convenience. */
device->wined3d_device = ddraw->wined3d_device;
wined3d_device_incref(ddraw->wined3d_device);
@@ -6549,7 +6533,6 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
if (FAILED(hr))
{
ERR("Failed to set render target, hr %#x.\n", hr);
- wined3d_buffer_decref(device->indexbuffer);
ddraw_handle_table_destroy(&device->handle_table);
return hr;
}
More information about the wine-cvs
mailing list