[PATCH 2/5] d3dx9_36: Improved constant table handle support (try 3)

Travis Athougies iammisc at gmail.com
Mon Jul 18 15:47:34 CDT 2011

On Mon, Jul 18, 2011 at 2:41 AM, Alexandre Julliard <julliard at winehq.org> wrote:
> Travis Athougies <iammisc at gmail.com> writes:
>> +static ctab_constant *is_valid_constant(ID3DXConstantTableImpl *This, D3DXHANDLE parameter)
>> +{
>> +    UINT i;
>> +
>> +    for (i = 0; i < This->desc.Constants; i++)
>> +        if ((ctab_constant *)parameter == &This->constants[i])
>> +            return (ctab_constant *)parameter;
> This doesn't look like an improvement.

While I understand that this is not the most efficient way to do
things, it is the same method used in the effects framework (see
is_valid_parameter in dlls/d3dx9_36/effect.c). Currently, in the
constant table implementation, we distinguish D3DXHANDLE's from char
pointers by forcing D3DXHANDLE's to be less than 65536, which is
rather arbitrary, and could be wrong. This, on the other hand, is
accurate, even though it may not necessarily offer the best

Native D3DX distinguishes D3DXHANDLEs from char pointers by negating
the address of all D3DXHANDLE's. Thus, if the most significant bit is
set, we know we are dealing with a D3DXHANDLE. Unfortunately, this
assumes that userspace ends at 2gb, which is not necessarily the case
on linux, so we can't make this assumption. Thus, we need a way to
distinguish d3dxhandles from char pointers, without using this trick.

Below, I've listed some ideas I've had. Which one(s) would be acceptable to you?

1. Using magic numbers to determine if a pointer is a D3DXHANDLE
2. Using a hash table to implement a set of D3DXHANDLEs and then
checking to see if a pointer is in this set
3. Allocating all handles in a contiguous block of memory and then
using range checking. (This could slow down loading somewhat, since
you might have to do a lot of HeapReAlloc's)

One final thing to note is that D3DXHANDLEs are not constant table
specific. If I get a D3DXHANDLE from constant table A, I can still use
it to set constants in constant table B. In this case, constant table
B will forward the call to constant table A. However, I don't think
any game makes use of this fact.


> --
> Alexandre Julliard
> julliard at winehq.org

Travis Athougies

More information about the wine-devel mailing list