[PATCH 4/5] d3dx9/tests: Add ID3DXConstantTable struct test.

Matteo Bruni matteo.mystral at gmail.com
Tue Jul 30 17:14:49 CDT 2013


2013/7/30 Rico Schüller <kgbricola at web.de>:
> Hi Matteo,
>
> please see the attached patch.
>
>
> On 25.07.2013 16:13, Matteo Bruni wrote:
>>
>> 2013/7/24 Rico Schüller <kgbricola at web.de>:
>>>
>>> ---
>>>   dlls/d3dx9_36/tests/shader.c | 308
>>> +++++++++++++++++++++++++++++++++++++++++++
>>>   1 file changed, 308 insertions(+)
>>>
>>
>> This is okay, but as a followup can you add some tests with mixed-type
>> structs? Something like:
>>
>> struct
>> {
>>      float f;
>>      int i;
>>      bool b;
>> };
>>
>> If you have already written tests of this kind, I'd like to know what
>> does the compiler do in this case :)
>>
> Single variables could only have the tested types (I was not able to
> generate other conversions than bool->bool, int->int, int->float,
> bool->float, float->float). But I found a way to do it with structs and
> there I found some issues. Hence this has to be fixed in wine, too. Thanks
> for the nice question. :-)
>
> Basically you got these for the struct:
> 1. D3DXRS_FLOAT4: if one variable is used as float or a float variable is
> used or an int variable is used as bool (the compiler may do some
> optimization), else #2
> 2. D3DXRS_BOOL: if a bool variable is used as bool (in an if clause), else
> #3
> 3. D3DXRS_INT4
>
> It looks like you could only do it that way with unused variables. I'm not
> sure if this makes sense at all. Why would someone set an unused variable?
> Maybe I missed something? Do you know anything else?
>

It does make some sense, although this is not what I expected. Also,
I'm getting different results...

If I understand correctly your test, all the fields of a structure
share the same registerset. Which is silly, since AFAIU each member of
the structure has a separate D3DXCONSTANT_DESC in the constant table,
both on disk and in memory, there is no point the compiler should
force the same registerset for all the struct members.

Under the constraint of forcing all the members in the same
registerset, the "conversion rules" you mention make sense. In SM3 an
if bool can be replaced by an if_comp with a float register and a
rep/loop, which is controlled by an integer constant, can be emulated
via loop unrolling (although I'm not sure how the compiler can
possibly do that for the shader in your testcase). These are also
pretty much the only use cases of bool and int constants and there are
no int or bool "non-constant" registers so essentially no other type
conversion is possible. You can check the plain text output from fxc
to see how those constants are used in the shader code and how did the
compiler manage to convert those constants from one type to another.

I tried to compile your HLSL shader myself (I had to disable
optimization though, otherwise compilation fails) and, assuming the
text output of fxc matches what actually ends up in the shader
bytecode, in general I'm getting different struct members in different
registersets. E.g. snbf gets allocated to c6-c9 and b8. FWIW, I used
fxc from the June 2010 DirectX SDK, on Windows 7.
I'm not sure why my results are different from yours. Or am I
misunderstanding the test?

BTW, what needs to be fixed in Wine? I couldn't see anything obvious
by reading the test.

Cheers,
Matteo.

> Cheers
> Rico



More information about the wine-devel mailing list