Commit 4d289c0c authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

ddraw: Upload only the used range of indices in d3d_device7_DrawIndexedPrimitive().

parent 498f0f11
...@@ -3582,9 +3582,11 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface, ...@@ -3582,9 +3582,11 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
WORD *indices, DWORD index_count, DWORD flags) WORD *indices, DWORD index_count, DWORD flags)
{ {
struct d3d_device *device = impl_from_IDirect3DDevice7(iface); struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
unsigned int idx_size = index_count * sizeof(*indices);
unsigned short min_index = USHRT_MAX, max_index = 0;
unsigned int i;
HRESULT hr; HRESULT hr;
UINT stride = get_flexible_vertex_size(fvf); UINT stride = get_flexible_vertex_size(fvf);
UINT vtx_size = stride * vertex_count, idx_size = index_count * sizeof(*indices);
UINT vb_pos, ib_pos; UINT vb_pos, ib_pos;
TRACE("iface %p, primitive_type %#x, fvf %#lx, vertices %p, vertex_count %lu, " TRACE("iface %p, primitive_type %#x, fvf %#lx, vertices %p, vertex_count %lu, "
...@@ -3597,11 +3599,19 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface, ...@@ -3597,11 +3599,19 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
return D3D_OK; return D3D_OK;
} }
/* Prince of Persia 3D creates large vertex buffers but only actually uses
* a few vertices from them. This improves performance dramatically. */
for (i = 0; i < index_count; ++i)
{
min_index = min(min_index, indices[i]);
max_index = max(max_index, indices[i]);
}
/* Set the D3DDevice's FVF */ /* Set the D3DDevice's FVF */
wined3d_mutex_lock(); wined3d_mutex_lock();
if (FAILED(hr = wined3d_streaming_buffer_upload(device->wined3d_device, if (FAILED(hr = wined3d_streaming_buffer_upload(device->wined3d_device, &device->vertex_buffer,
&device->vertex_buffer, vertices, vtx_size, stride, &vb_pos))) (char *)vertices + (min_index * stride), (max_index + 1 - min_index) * stride, stride, &vb_pos)))
goto done; goto done;
if (FAILED(hr = wined3d_streaming_buffer_upload(device->wined3d_device, if (FAILED(hr = wined3d_streaming_buffer_upload(device->wined3d_device,
...@@ -3618,7 +3628,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface, ...@@ -3618,7 +3628,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
wined3d_primitive_type_from_ddraw(primitive_type), 0); wined3d_primitive_type_from_ddraw(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state); wined3d_device_apply_stateblock(device->wined3d_device, device->state);
d3d_device_sync_surfaces(device); d3d_device_sync_surfaces(device);
wined3d_device_context_draw_indexed(device->immediate_context, vb_pos / stride, wined3d_device_context_draw_indexed(device->immediate_context, (int)(vb_pos / stride) - min_index,
ib_pos / sizeof(*indices), index_count, 0, 0); ib_pos / sizeof(*indices), index_count, 0, 0);
done: done:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment