ChristianLa91 / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

Set/Get matrix variables in D3D10/11 shaders #780

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I'm working in a language that outputs to hlsl namely hlsl 2.0, 3.0, and 4.0. 
This language supports basic scalar types (bool, int and float), vector types 
(float2, float3 and float4) and matrix types (float2x2, float3x3 and float4x4). 
The vector and matrix types are custom defined. 

I support global variables in this language and thus it allows get/set 
operations in them. In my D3D9 ouput I'm using the SetValue<T> and GetValue<T> 
without any kind of problems, namely I'm able to get and set Matrix variables 
correctly. In my D3D10/11 output I'm having problems setting and obtaining the 
values from matrix variables (float2x2, float3x3 and float4x4). The problem is, 
I'm not getting the expected output. Everything works just fine with the scalar 
variables and the vector variables. The problem is the matrix variables. With 
D3D10 and D3D11 I'm using the GetRawValue method (I've compiled the latest 
version of SlimDX since the Get/SetRawValue method was not in the last official 
release)

To illustrate the problem I'm providing a code snippet in attachment which 
builds a Quad and obtains a matrix variable through the pixel shader. The 
program bellow also allows setting and getting global variables from the 
shader. It needs a custom compiled version of slimdx because it uses the 
Get/SetRawValue functions of D3D10. This problem also occurs in D3D11 and  I 
can provide a code snippet with the same issue. 

The problem is on the following lines:

bool test = prg.GetOutput<Float2x2>().Equals(new Float2x2(1.0f, 2.0f, 3.0f, 
4.0f)); //OK
test &= prg.GetVariable<Float2x2>("a").Equals(new Float2x2(1.0f, 2.0f, 3.0f, 
4.0f)); //Error, I'm getting Float2x2(1.0f, 3.0f, 0.0f, 0.0f)

Original issue reported on code.google.com by ivo.lei...@gmail.com on 21 Feb 2011 at 12:48

Attachments:

GoogleCodeExporter commented 9 years ago
You're getting some padding in there from the HLSL compiler. If you add an 
additional two float fields to your Float2x2 type, you'll see the other two 
values show up. They appear to be out of order because the HLSL compiler is 
storing the matrix in column-major format.

There might be a way to specify that you don't want any padding, but I'm not 
sure how to do it.

Original comment by Mike.Popoloski on 27 Feb 2011 at 2:39

GoogleCodeExporter commented 9 years ago
Tnks a lot for your answer. Meanwhile I've reach the same conclusion. In 
attachment is my methods to set/get Matrix's in DX10/11.

Original comment by ivo.lei...@gmail.com on 27 Feb 2011 at 1:06

Attachments:

GoogleCodeExporter commented 9 years ago
Ok then, closing this issue.

Original comment by Mike.Popoloski on 27 Feb 2011 at 6:56