d3dx9: CloneMesh test and improvements

Michael Mc Donnell michael at mcdonnell.dk
Fri Aug 19 07:04:59 CDT 2011

On Thu, Aug 18, 2011 at 8:05 PM, Stefan Dösinger <stefandoesinger at gmx.at> wrote:
> Hi,
> I noticed one small issue:
> On Saturday 13 August 2011 12:22:03 Michael Mc Donnell wrote:
>> +static HRESULT convert_vertex_buffer(ID3DXMesh *mesh_dst, ID3DXMesh
> *mesh_src)
>> ...
>> +    hr = mesh_dst->lpVtbl->LockVertexBuffer(mesh_dst, D3DLOCK_DISCARD,
> (void**)&vb_dst);
> On paper, D3DLOCK_DISCARD is only valid on D3DUSAGE_DYNAMIC buffers. Wine and
> Windows <= WinVista don't enforce this. Win7 does, and it broke some apps that
> way.

Ok I see that in dlls/d3d9/tests/buffers.c. So it will fail to lock on
Win7 if D3DLOCK_DISCARD is specified and the vertex buffer wasn't
created with D3DUSAGE_DYNAMIC?

Am I correct in D3DLOCK_DISCARD makes a copy of the vertex buffer so
that the video card can keep reading the old one, and the old vertex
buffer memory is released after the video card releases its lock [1]?

In that case it does not make sense to use D3DLOCK_DISCARD at all in
CloneMesh, as the video card has not begun to use the new vertex
buffer, and it will just add memory overhead. The easiest fix would be
to just pass 0 instead of D3DLOCK_DISCARD. I've done that in the
updated patch.

> I noticed a few more D3DLOCK_DISCARD locks in the mesh.c code.

I guess the other methods should check the mesh options for
before using D3DLOCK_DISCARD? I'll write patches for those.

[1] http://msdn.microsoft.com/en-us/library/bb147263(v=vs.85).aspx#Using_Dynamic_Vertex_and_Index_Buffers
[2] http://msdn.microsoft.com/en-us/library/bb205370(v=vs.85).aspx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-d3dx9-Implemented-non-equal-declaration-support-in-C.patch
Type: text/x-patch
Size: 18703 bytes
Desc: not available
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20110819/75ecbd11/attachment-0001.bin>

More information about the wine-devel mailing list