d3dx9: Handle invalid byte code in D3DXFindShaderComment().
[wine] / dlls / d3dx9_36 / tests / shader.c
1 /*
2  * Copyright 2008 Luis Busquets
3  * Copyright 2011 Travis Athougies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "wine/test.h"
21 #include "d3dx9.h"
22
23 static const DWORD shader_zero[] = {0x0};
24
25 static const DWORD shader_invalid[] = {0xeeee0100};
26
27 static const DWORD shader_empty[] = {0xfffeffff, 0x0000ffff};
28
29 static const DWORD simple_vs[] = {
30     0xfffe0101,                                                             /* vs_1_1                       */
31     0x0000001f, 0x80000000, 0x900f0000,                                     /* dcl_position0 v0             */
32     0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000,                         /* dp4 oPos.x, v0, c0           */
33     0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001,                         /* dp4 oPos.y, v0, c1           */
34     0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002,                         /* dp4 oPos.z, v0, c2           */
35     0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003,                         /* dp4 oPos.w, v0, c3           */
36     0x0000ffff};                                                            /* END                          */
37
38 static const DWORD simple_ps[] = {
39     0xffff0101,                                                             /* ps_1_1                       */
40     0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0  */
41     0x00000042, 0xb00f0000,                                                 /* tex t0                       */
42     0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000,                         /* dp3 r0, c1, c0               */
43     0x00000005, 0x800f0000, 0x90e40000, 0x80e40000,                         /* mul r0, v0, r0               */
44     0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000,                         /* mul r0, t0, r0               */
45     0x0000ffff};                                                            /* END                          */
46
47 #define FCC_TEXT MAKEFOURCC('T','E','X','T')
48 #define FCC_CTAB MAKEFOURCC('C','T','A','B')
49
50 static const DWORD shader_with_ctab[] = {
51     0xfffe0300,                                                             /* vs_3_0                       */
52     0x0002fffe, FCC_TEXT,   0x00000000,                                     /* TEXT comment                 */
53     0x0008fffe, FCC_CTAB,   0x0000001c, 0x00000010, 0xfffe0300, 0x00000000, /* CTAB comment                 */
54                 0x00000000, 0x00000000, 0x00000000,
55     0x0004fffe, FCC_TEXT,   0x00000000, 0x00000000, 0x00000000,             /* TEXT comment                 */
56     0x0000ffff};                                                            /* END                          */
57
58 static const DWORD shader_with_invalid_ctab[] = {
59     0xfffe0300,                                                             /* vs_3_0                       */
60     0x0005fffe, FCC_CTAB,                                                   /* CTAB comment                 */
61                 0x0000001c, 0x000000a9, 0xfffe0300,
62                 0x00000000, 0x00000000,
63     0x0000ffff};                                                            /* END                          */
64
65 static const DWORD shader_with_ctab_constants[] = {
66     0xfffe0300,                                                             /* vs_3_0                       */
67     0x002efffe, FCC_CTAB,                                                   /* CTAB comment                 */
68     0x0000001c, 0x000000a4, 0xfffe0300, 0x00000003, 0x0000001c, 0x20008100, /* Header                       */
69     0x0000009c,
70     0x00000058, 0x00070002, 0x00000001, 0x00000064, 0x00000000,             /* Constant 1 desc              */
71     0x00000074, 0x00000002, 0x00000004, 0x00000080, 0x00000000,             /* Constant 2 desc              */
72     0x00000090, 0x00040002, 0x00000003, 0x00000080, 0x00000000,             /* Constant 3 desc              */
73     0x736e6f43, 0x746e6174, 0xabab0031,                                     /* Constant 1 name string       */
74     0x00030001, 0x00040001, 0x00000001, 0x00000000,                         /* Constant 1 type desc         */
75     0x736e6f43, 0x746e6174, 0xabab0032,                                     /* Constant 2 name string       */
76     0x00030003, 0x00040004, 0x00000001, 0x00000000,                         /* Constant 2 & 3 type desc     */
77     0x736e6f43, 0x746e6174, 0xabab0033,                                     /* Constant 3 name string       */
78     0x335f7376, 0xab00305f,                                                 /* Target name string           */
79     0x656e6957, 0x6f727020, 0x7463656a, 0xababab00,                         /* Creator name string          */
80     0x0000ffff};                                                            /* END                          */
81
82 static const DWORD ctab_basic[] = {
83     0xfffe0300,                                                             /* vs_3_0                       */
84     0x0040fffe, FCC_CTAB,                                                   /* CTAB comment                 */
85     0x0000001c, 0x000000ec, 0xfffe0300, 0x00000005, 0x0000001c, 0x20008100, /* Header                       */
86     0x000000e4,
87     0x00000080, 0x00060002, 0x00000001, 0x00000084, 0x00000000,             /* Constant 1 desc (f)          */
88     0x00000094, 0x00070002, 0x00000001, 0x00000098, 0x00000000,             /* Constant 2 desc (f4)         */
89     0x000000A8, 0x00040002, 0x00000001, 0x000000AC, 0x00000000,             /* Constant 3 desc (i)          */
90     0x000000BC, 0x00050002, 0x00000001, 0x000000C0, 0x00000000,             /* Constant 4 desc (i4)         */
91     0x000000D0, 0x00000002, 0x00000004, 0x000000D4, 0x00000000,             /* Constant 5 desc (mvp)        */
92     0xabab0066, 0x00030000, 0x00010001, 0x00000001, 0x00000000,             /* Constant 1 name/type desc    */
93     0xab003466, 0x00030001, 0x00040001, 0x00000001, 0x00000000,             /* Constant 2 name/type desc    */
94     0xabab0069, 0x00020000, 0x00010001, 0x00000001, 0x00000000,             /* Constant 3 name/type desc    */
95     0xab003469, 0x00020001, 0x00040001, 0x00000001, 0x00000000,             /* Constant 4 name/type desc    */
96     0x0070766d, 0x00030003, 0x00040004, 0x00000001, 0x00000000,             /* Constant 5 name/type desc    */
97     0x335f7376, 0xab00305f,                                                 /* Target name string           */
98     0x656e6957, 0x6f727020, 0x7463656a, 0xababab00,                         /* Creator name string          */
99     0x0000ffff};                                                            /* END                          */
100
101 static const D3DXCONSTANT_DESC ctab_basic_expected[] = {
102     {"mvp", D3DXRS_FLOAT4, 0, 4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4, 1, 0, 64, NULL},
103     {"i",   D3DXRS_FLOAT4, 4, 1, D3DXPC_SCALAR,         D3DXPT_INT,   1, 1, 1, 0,  4, NULL},
104     {"i4",  D3DXRS_FLOAT4, 5, 1, D3DXPC_VECTOR,         D3DXPT_INT,   1, 4, 1, 0, 16, NULL},
105     {"f",   D3DXRS_FLOAT4, 6, 1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1, 1, 1, 0,  4, NULL},
106     {"f4",  D3DXRS_FLOAT4, 7, 1, D3DXPC_VECTOR,         D3DXPT_FLOAT, 1, 4, 1, 0, 16, NULL}};
107
108 static const DWORD ctab_matrices[] = {
109     0xfffe0300,                                                             /* vs_3_0                       */
110     0x0032fffe, FCC_CTAB,                                                   /* CTAB comment                 */
111     0x0000001c, 0x000000b4, 0xfffe0300, 0x00000003, 0x0000001c, 0x20008100, /* Header                       */
112     0x000000ac,
113     0x00000058, 0x00070002, 0x00000001, 0x00000064, 0x00000000,             /* Constant 1 desc (fmatrix3x1) */
114     0x00000074, 0x00000002, 0x00000004, 0x00000080, 0x00000000,             /* Constant 2 desc (fmatrix4x4) */
115     0x00000090, 0x00040002, 0x00000003, 0x0000009c, 0x00000000,             /* Constant 3 desc (imatrix2x3) */
116     0x74616D66, 0x33786972, 0xab003178,                                     /* Constant 1 name              */
117     0x00030003, 0x00010003, 0x00000001, 0x00000000,                         /* Constant 1 type desc         */
118     0x74616D66, 0x34786972, 0xab003478,                                     /* Constant 2 name              */
119     0x00030003, 0x00040004, 0x00000001, 0x00000000,                         /* Constant 2 type desc         */
120     0x74616D69, 0x32786972, 0xab003378,                                     /* Constant 3 name              */
121     0x00020002, 0x00030002, 0x00000001, 0x00000000,                         /* Constant 3 type desc         */
122     0x335f7376, 0xab00305f,                                                 /* Target name string           */
123     0x656e6957, 0x6f727020, 0x7463656a, 0xababab00,                         /* Creator name string          */
124     0x0000ffff};                                                            /* END                          */
125
126 static const D3DXCONSTANT_DESC ctab_matrices_expected[] = {
127     {"fmatrix4x4", D3DXRS_FLOAT4, 0, 4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4, 1, 0, 64, NULL},
128     {"imatrix2x3", D3DXRS_FLOAT4, 4, 3, D3DXPC_MATRIX_ROWS,    D3DXPT_INT,   2, 3, 1, 0, 24, NULL},
129     {"fmatrix3x1", D3DXRS_FLOAT4, 7, 1, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 1, 1, 0, 12, NULL}};
130
131 static const DWORD ctab_matrices2[] = {
132     0xfffe0200,                                                             /* vs_2_0                        */
133     0x0058fffe, FCC_CTAB,                                                   /* CTAB comment                  */
134     0x0000001c, 0x0000012b, 0xfffe0200, 0x00000006, 0x0000001c, 0x00000100, /* Header                        */
135     0x00000124,
136     0x00000094, 0x00070002, 0x00000003, 0x0000009c, 0x00000000,             /* Constant 1 desc (c2x3)        */
137     0x000000ac, 0x000d0002, 0x00000002, 0x000000b4, 0x00000000,             /* Constant 2 desc (c3x2)        */
138     0x000000c4, 0x000a0002, 0x00000003, 0x000000cc, 0x00000000,             /* Constant 3 desc (c3x3)        */
139     0x000000dc, 0x000f0002, 0x00000002, 0x000000e4, 0x00000000,             /* Constant 4 desc (r2x3)        */
140     0x000000f4, 0x00040002, 0x00000003, 0x000000fc, 0x00000000,             /* Constant 5 desc (r3x2)        */
141     0x0000010c, 0x00000002, 0x00000004, 0x00000114, 0x00000000,             /* Constant 6 desc (r4x4)        */
142     0x33783263, 0xababab00,                                                 /* Constant 1 name               */
143     0x00030003, 0x00030002, 0x00000001, 0x00000000,                         /* Constant 1 type desc          */
144     0x32783363, 0xababab00,                                                 /* Constant 2 name               */
145     0x00030003, 0x00020003, 0x00000001, 0x00000000,                         /* Constant 2 type desc          */
146     0x33783363, 0xababab00,                                                 /* Constant 3 name               */
147     0x00030003, 0x00030003, 0x00000001, 0x00000000,                         /* Constant 3 type desc          */
148     0x33783272, 0xababab00,                                                 /* Constant 4 name               */
149     0x00030002, 0x00030002, 0x00000001, 0x00000000,                         /* Constant 4 type desc          */
150     0x32783372, 0xababab00,                                                 /* Constant 5 name               */
151     0x00030002, 0x00020003, 0x00000001, 0x00000000,                         /* Constant 5 type desc          */
152     0x34783472, 0xababab00,                                                 /* Constant 6 name               */
153     0x00030002, 0x00040004, 0x00000001, 0x00000000,                         /* Constant 6 type desc          */
154     0x325f7376, 0x4100305f, 0x41414141, 0x00414141,                         /* Target and Creator name       */
155     0x0000ffff};                                                            /* END                           */
156
157 static const D3DXCONSTANT_DESC ctab_matrices2_expected[] = {
158     {"c2x3", D3DXRS_FLOAT4,  7, 3, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 2, 3, 1, 0, 24, NULL},
159     {"c3x2", D3DXRS_FLOAT4, 13, 2, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 2, 1, 0, 24, NULL},
160     {"c3x3", D3DXRS_FLOAT4, 10, 3, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 3, 1, 0, 36, NULL},
161     {"r2x3", D3DXRS_FLOAT4, 15, 2, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 2, 3, 1, 0, 24, NULL},
162     {"r3x2", D3DXRS_FLOAT4,  4, 3, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3, 2, 1, 0, 24, NULL},
163     {"r4x4", D3DXRS_FLOAT4,  0, 4, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 4, 4, 1, 0, 64, NULL}};
164
165 static const DWORD ctab_arrays[] = {
166     0xfffe0300,                                                             /* vs_3_0                       */
167     0x0052fffe, FCC_CTAB,                                                   /* CTAB comment                 */
168     0x0000001c, 0x0000013c, 0xfffe0300, 0x00000006, 0x0000001c, 0x20008100, /* Header                       */
169     0x00000134,
170     0x00000094, 0x000E0002, 0x00000002, 0x0000009c, 0x00000000,             /* Constant 1 desc (barray)     */
171     0x000000ac, 0x00100002, 0x00000002, 0x000000b8, 0x00000000,             /* Constant 2 desc (bvecarray)  */
172     0x000000c8, 0x00080002, 0x00000004, 0x000000d0, 0x00000000,             /* Constant 3 desc (farray)     */
173     0x000000e0, 0x00000002, 0x00000008, 0x000000ec, 0x00000000,             /* Constant 4 desc (fmtxarray)  */
174     0x000000fc, 0x000C0002, 0x00000002, 0x00000108, 0x00000000,             /* Constant 5 desc (fvecarray)  */
175     0x00000118, 0x00120002, 0x00000001, 0x00000124, 0x00000000,             /* Constant 6 desc (ivecarray)  */
176     0x72726162, 0xab007961,                                                 /* Constant 1 name              */
177     0x00010000, 0x00010001, 0x00000002, 0x00000000,                         /* Constant 1 type desc         */
178     0x63657662, 0x61727261, 0xabab0079,                                     /* Constant 2 name              */
179     0x00010001, 0x00030001, 0x00000003, 0x00000000,                         /* Constant 2 type desc         */
180     0x72726166, 0xab007961,                                                 /* Constant 3 name              */
181     0x00030000, 0x00010001, 0x00000004, 0x00000000,                         /* constant 3 type desc         */
182     0x78746d66, 0x61727261, 0xabab0079,                                     /* Constant 4 name              */
183     0x00030002, 0x00040004, 0x00000002, 0x00000000,                         /* Constant 4 type desc         */
184     0x63657666, 0x61727261, 0xabab0079,                                     /* Constant 5 name              */
185     0x00030001, 0x00040001, 0x00000002, 0x00000000,                         /* Constant 5 type desc         */
186     0x63657669, 0x61727261, 0xabab0079,                                     /* Constant 6 name              */
187     0x00020001, 0x00040001, 0x00000001, 0x00000000,                         /* Constant 6 type desc         */
188     0x335f7376, 0xab00305f,                                                 /* Target name string           */
189     0x656e6957, 0x6f727020, 0x7463656a, 0xababab00,                         /* Creator name string          */
190     0x0000ffff};                                                            /* END                          */
191
192 static const D3DXCONSTANT_DESC ctab_arrays_expected[] = {
193     {"fmtxarray", D3DXRS_FLOAT4,  0, 8, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 4, 4, 2, 0, 128, NULL},
194     {"farray",    D3DXRS_FLOAT4,  8, 4, D3DXPC_SCALAR,      D3DXPT_FLOAT, 1, 1, 4, 0,  16, NULL},
195     {"fvecarray", D3DXRS_FLOAT4, 12, 2, D3DXPC_VECTOR,      D3DXPT_FLOAT, 1, 4, 2, 0,  32, NULL},
196     {"barray",    D3DXRS_FLOAT4, 14, 2, D3DXPC_SCALAR,      D3DXPT_BOOL,  1, 1, 2, 0,   8, NULL},
197     {"bvecarray", D3DXRS_FLOAT4, 16, 2, D3DXPC_VECTOR,      D3DXPT_BOOL,  1, 3, 3, 0,  36, NULL},
198     {"ivecarray", D3DXRS_FLOAT4, 18, 1, D3DXPC_VECTOR,      D3DXPT_INT,   1, 4, 1, 0,  16, NULL}};
199
200 static const DWORD ctab_with_default_values[] = {
201     0xfffe0200,                                                 /* vs_2_0 */
202     0x007bfffe, FCC_CTAB,                                       /* CTAB comment */
203     0x0000001c, 0x000001b7, 0xfffe0200, 0x00000005, 0x0000001c, /* header */
204     0x00000100, 0x000001b0,
205     0x00000080, 0x00080002, 0x00000003, 0x00000084, 0x00000094, /* constant 1 desc (arr) */
206     0x000000c4, 0x000c0002, 0x00000001, 0x000000c8, 0x000000d8, /* constant 2 desc (flt) */
207     0x000000e8, 0x00040002, 0x00000004, 0x000000f0, 0x00000100, /* constant 3 desc (mat3) */
208     0x00000140, 0x00000002, 0x00000004, 0x000000f0, 0x00000148, /* constant 4 desc (mat4) */
209     0x00000188, 0x000b0002, 0x00000001, 0x00000190, 0x000001a0, /* constant 5 desc (vec4) */
210     0x00727261,                                                 /* constant 1 name */
211     0x00030000, 0x00010001, 0x00000003, 0x00000000,             /* constant 1 type desc */
212     0x42c80000, 0x00000000, 0x00000000, 0x00000000,             /* constant 1 default value */
213     0x43480000, 0x00000000, 0x00000000, 0x00000000,
214     0x43960000, 0x00000000, 0x00000000, 0x00000000,
215     0x00746c66,                                                 /* constant 2 name */
216     0x00030000, 0x00010001, 0x00000001, 0x00000000,             /* constant 2 type desc */
217     0x411fd70a, 0x00000000, 0x00000000, 0x00000000,             /* constant 2 default value */
218     0x3374616d,                                                 /* constant 3 name */
219     0xababab00,
220     0x00030003, 0x00040004, 0x00000001, 0x00000000,             /* constant 3 & 4 type desc */
221     0x41300000, 0x425c0000, 0x42c60000, 0x44a42000,             /* constat 3 default value */
222     0x41b00000, 0x42840000, 0x447c8000, 0x44b0c000,
223     0x42040000, 0x429a0000, 0x448ae000, 0x44bd6000,
224     0x42300000, 0x42b00000, 0x44978000, 0x44ca0000,
225     0x3474616d,                                                 /* constant 4 name */
226     0xababab00,
227     0x3f800000, 0x40a00000, 0x41100000, 0x41500000,             /* constant 4 default value */
228     0x40000000, 0x40c00000, 0x41200000, 0x41600000,
229     0x40400000, 0x40e00000, 0x41300000, 0x41700000,
230     0x40800000, 0x41000000, 0x41400000, 0x41800000,
231     0x34636576,                                                 /* constant 5 name */
232     0xababab00,
233     0x00030001, 0x00040001, 0x00000001, 0x00000000,             /* constant 5 type desc */
234     0x41200000, 0x41a00000, 0x41f00000, 0x42200000,             /* constant 5 default value */
235     0x325f7376, 0x4d004141, 0x41414141, 0x00000000,             /* target & creator string */
236     0x0000ffff};                                                /* END */
237
238 static const float mat4_default_value[] = {1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16};
239 static const float mat3_default_value[] = {11, 55, 99, 1313, 22, 66, 1010, 1414, 33, 77, 1111, 1515, 44, 88, 1212, 1616};
240 static const float arr_default_value[] = {100, 0, 0, 0, 200, 0, 0, 0, 300, 0, 0, 0};
241 static const float vec4_default_value[] = {10, 20, 30, 40};
242 static const float flt_default_value[] = {9.99, 0, 0, 0};
243
244 static const D3DXCONSTANT_DESC ctab_with_default_values_expected[] = {
245     {"mat4", D3DXRS_FLOAT4,  0, 4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4, 1, 0, 64, mat4_default_value},
246     {"mat3", D3DXRS_FLOAT4,  4, 4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4, 1, 0, 64, mat3_default_value},
247     {"arr",  D3DXRS_FLOAT4,  8, 3, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1, 1, 3, 0, 12, arr_default_value},
248     {"vec4", D3DXRS_FLOAT4, 11, 1, D3DXPC_VECTOR,         D3DXPT_FLOAT, 1, 4, 1, 0, 16, vec4_default_value},
249     {"flt",  D3DXRS_FLOAT4, 12, 1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1, 1, 1, 0,  4, flt_default_value}};
250
251 static const DWORD ctab_samplers[] = {
252     0xfffe0300,                                                             /* vs_3_0                        */
253     0x0032fffe, FCC_CTAB,                                                   /* CTAB comment                  */
254     0x0000001c, 0x000000b4, 0xfffe0300, 0x00000003, 0x0000001c, 0x20008100, /* Header                        */
255     0x000000ac,
256     0x00000058, 0x00020002, 0x00000001, 0x00000064, 0x00000000,             /* Constant 1 desc (notsampler)  */
257     0x00000074, 0x00000003, 0x00000001, 0x00000080, 0x00000000,             /* Constant 2 desc (sampler1)    */
258     0x00000090, 0x00030003, 0x00000001, 0x0000009c, 0x00000000,             /* Constant 3 desc (sampler2)    */
259     0x73746f6e, 0x6c706d61, 0xab007265,                                     /* Constant 1 name               */
260     0x00030001, 0x00040001, 0x00000001, 0x00000000,                         /* Constant 1 type desc          */
261     0x706d6173, 0x3172656c, 0xababab00,                                     /* Constant 2 name               */
262     0x000c0004, 0x00010001, 0x00000001, 0x00000000,                         /* Constant 2 type desc          */
263     0x706d6173, 0x3272656c, 0xababab00,                                     /* Constant 3 name               */
264     0x000d0004, 0x00010001, 0x00000001, 0x00000000,                         /* Constant 3 type desc          */
265     0x335f7376, 0xab00305f,                                                 /* Target name string            */
266     0x656e6957, 0x6f727020, 0x7463656a, 0xababab00,                         /* Creator name string           */
267     0x0000ffff};                                                            /* END                           */
268
269 static const D3DXCONSTANT_DESC ctab_samplers_expected[] = {
270     {"sampler1",   D3DXRS_SAMPLER, 0, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER2D, 1, 1, 1, 0, 4,  NULL},
271     {"sampler2",   D3DXRS_SAMPLER, 3, 1, D3DXPC_OBJECT, D3DXPT_SAMPLER3D, 1, 1, 1, 0, 4,  NULL},
272     {"notsampler", D3DXRS_FLOAT4,  2, 1, D3DXPC_VECTOR, D3DXPT_FLOAT,     1, 4, 1, 0, 16, NULL}};
273
274 static void test_get_shader_size(void)
275 {
276     UINT shader_size, expected;
277
278     shader_size = D3DXGetShaderSize(simple_vs);
279     expected = sizeof(simple_vs);
280     ok(shader_size == expected, "Got shader size %u, expected %u\n", shader_size, expected);
281
282     shader_size = D3DXGetShaderSize(simple_ps);
283     expected = sizeof(simple_ps);
284     ok(shader_size == expected, "Got shader size %u, expected %u\n", shader_size, expected);
285
286     shader_size = D3DXGetShaderSize(NULL);
287     ok(shader_size == 0, "Got shader size %u, expected 0\n", shader_size);
288 }
289
290 static void test_get_shader_version(void)
291 {
292     DWORD shader_version;
293
294     shader_version = D3DXGetShaderVersion(simple_vs);
295     ok(shader_version == D3DVS_VERSION(1, 1), "Got shader version 0x%08x, expected 0x%08x\n",
296             shader_version, D3DVS_VERSION(1, 1));
297
298     shader_version = D3DXGetShaderVersion(simple_ps);
299     ok(shader_version == D3DPS_VERSION(1, 1), "Got shader version 0x%08x, expected 0x%08x\n",
300             shader_version, D3DPS_VERSION(1, 1));
301
302     shader_version = D3DXGetShaderVersion(NULL);
303     ok(shader_version == 0, "Got shader version 0x%08x, expected 0\n", shader_version);
304 }
305
306 static void test_find_shader_comment(void)
307 {
308     HRESULT hr;
309     LPCVOID data = (LPVOID)0xdeadbeef;
310     UINT size = 100;
311
312     hr = D3DXFindShaderComment(NULL, MAKEFOURCC('C','T','A','B'), &data, &size);
313     ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
314     ok(!data, "Got %p, expected NULL\n", data);
315     ok(!size, "Got %u, expected 0\n", size);
316
317     hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), NULL, &size);
318     ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
319     ok(size == 28, "Got %u, expected 28\n", size);
320
321     hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), &data, NULL);
322     ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
323     ok(data == (LPCVOID)(shader_with_ctab + 6), "Got result %p, expected %p\n", data, shader_with_ctab + 6);
324
325     hr = D3DXFindShaderComment(shader_with_ctab, 0, &data, &size);
326     ok(hr == S_FALSE, "Got result %x, expected 1 (S_FALSE)\n", hr);
327     ok(!data, "Got %p, expected NULL\n", data);
328     ok(!size, "Got %u, expected 0\n", size);
329
330     hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('X','X','X','X'), &data, &size);
331     ok(hr == S_FALSE, "Got result %x, expected 1 (S_FALSE)\n", hr);
332     ok(!data, "Got %p, expected NULL\n", data);
333     ok(!size, "Got %u, expected 0\n", size);
334
335     hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), &data, &size);
336     ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
337     ok(data == (LPCVOID)(shader_with_ctab + 6), "Got result %p, expected %p\n", data, shader_with_ctab + 6);
338     ok(size == 28, "Got result %d, expected 28\n", size);
339
340     hr = D3DXFindShaderComment(shader_zero, MAKEFOURCC('C','T','A','B'), &data, &size);
341     ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
342     ok(!data, "Got %p, expected NULL\n", data);
343     ok(!size, "Got %u, expected 0\n", size);
344
345     hr = D3DXFindShaderComment(shader_invalid, MAKEFOURCC('C','T','A','B'), &data, &size);
346     ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
347     ok(!data, "Got %p, expected NULL\n", data);
348     ok(!size, "Got %u, expected 0\n", size);
349
350     hr = D3DXFindShaderComment(shader_empty, MAKEFOURCC('C','T','A','B'), &data, &size);
351     ok(hr == S_FALSE, "Got result %x, expected %x (S_FALSE)\n", hr, S_FALSE);
352     ok(!data, "Got %p, expected NULL\n", data);
353     ok(!size, "Got %u, expected 0\n", size);
354 }
355
356 static void test_get_shader_constant_table_ex(void)
357 {
358     ID3DXConstantTable *constant_table = NULL;
359     HRESULT hr;
360     LPVOID data;
361     DWORD size;
362     D3DXCONSTANTTABLE_DESC desc;
363
364     hr = D3DXGetShaderConstantTableEx(NULL, 0, &constant_table);
365     ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
366
367     /* No CTAB data */
368     hr = D3DXGetShaderConstantTableEx(simple_ps, 0, &constant_table);
369     ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
370
371     /* With invalid CTAB data */
372     hr = D3DXGetShaderConstantTableEx(shader_with_invalid_ctab, 0, &constant_table);
373     ok(hr == D3DXERR_INVALIDDATA || broken(hr == D3D_OK), /* winxp 64-bit, w2k3 64-bit */
374        "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
375     if (constant_table) ID3DXConstantTable_Release(constant_table);
376
377     hr = D3DXGetShaderConstantTableEx(shader_with_ctab, 0, &constant_table);
378     ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
379
380     if (constant_table)
381     {
382         size = ID3DXConstantTable_GetBufferSize(constant_table);
383         ok(size == 28, "Got result %x, expected 28\n", size);
384
385         data = ID3DXConstantTable_GetBufferPointer(constant_table);
386         ok(!memcmp(data, shader_with_ctab + 6, size), "Retrieved wrong CTAB data\n");
387
388         hr = ID3DXConstantTable_GetDesc(constant_table, NULL);
389         ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
390
391         hr = ID3DXConstantTable_GetDesc(constant_table, &desc);
392         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
393         ok(desc.Creator == (LPCSTR)data + 0x10, "Got result %p, expected %p\n", desc.Creator, (LPCSTR)data + 0x10);
394         ok(desc.Version == D3DVS_VERSION(3, 0), "Got result %x, expected %x\n", desc.Version, D3DVS_VERSION(3, 0));
395         ok(desc.Constants == 0, "Got result %x, expected 0\n", desc.Constants);
396
397         ID3DXConstantTable_Release(constant_table);
398     }
399
400     hr = D3DXGetShaderConstantTableEx(shader_with_ctab_constants, 0, &constant_table);
401     ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
402
403     if (SUCCEEDED(hr))
404     {
405         D3DXHANDLE constant;
406         D3DXCONSTANT_DESC constant_desc;
407         D3DXCONSTANT_DESC constant_desc_save;
408         UINT nb;
409
410         /* Test GetDesc */
411         hr = ID3DXConstantTable_GetDesc(constant_table, &desc);
412         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
413         ok(!strcmp(desc.Creator, "Wine project"), "Got result '%s', expected 'Wine project'\n", desc.Creator);
414         ok(desc.Version == D3DVS_VERSION(3, 0), "Got result %x, expected %x\n", desc.Version, D3DVS_VERSION(3, 0));
415         ok(desc.Constants == 3, "Got result %x, expected 3\n", desc.Constants);
416
417         /* Test GetConstant */
418         constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 0);
419         ok(constant != NULL, "No constant found\n");
420         hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
421         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
422         ok(!strcmp(constant_desc.Name, "Constant1"), "Got result '%s', expected 'Constant1'\n",
423             constant_desc.Name);
424         ok(constant_desc.Class == D3DXPC_VECTOR, "Got result %x, expected %u (D3DXPC_VECTOR)\n",
425             constant_desc.Class, D3DXPC_VECTOR);
426         ok(constant_desc.Type == D3DXPT_FLOAT, "Got result %x, expected %u (D3DXPT_FLOAT)\n",
427             constant_desc.Type, D3DXPT_FLOAT);
428         ok(constant_desc.Rows == 1, "Got result %x, expected 1\n", constant_desc.Rows);
429         ok(constant_desc.Columns == 4, "Got result %x, expected 4\n", constant_desc.Columns);
430
431         constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 1);
432         ok(constant != NULL, "No constant found\n");
433         hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
434         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
435         ok(!strcmp(constant_desc.Name, "Constant2"), "Got result '%s', expected 'Constant2'\n",
436             constant_desc.Name);
437         ok(constant_desc.Class == D3DXPC_MATRIX_COLUMNS, "Got result %x, expected %u (D3DXPC_MATRIX_COLUMNS)\n",
438             constant_desc.Class, D3DXPC_MATRIX_COLUMNS);
439         ok(constant_desc.Type == D3DXPT_FLOAT, "Got result %x, expected %u (D3DXPT_FLOAT)\n",
440             constant_desc.Type, D3DXPT_FLOAT);
441         ok(constant_desc.Rows == 4, "Got result %x, expected 1\n", constant_desc.Rows);
442         ok(constant_desc.Columns == 4, "Got result %x, expected 4\n", constant_desc.Columns);
443
444         constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 2);
445         ok(constant != NULL, "No constant found\n");
446         hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
447         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
448         ok(!strcmp(constant_desc.Name, "Constant3"), "Got result '%s', expected 'Constant3'\n",
449             constant_desc.Name);
450         ok(constant_desc.Class == D3DXPC_MATRIX_COLUMNS, "Got result %x, expected %u (D3DXPC_MATRIX_COLUMNS)\n",
451             constant_desc.Class, D3DXPC_MATRIX_COLUMNS);
452         ok(constant_desc.Type == D3DXPT_FLOAT, "Got result %x, expected %u (D3DXPT_FLOAT)\n",
453             constant_desc.Type, D3DXPT_FLOAT);
454         ok(constant_desc.Rows == 4, "Got result %x, expected 1\n", constant_desc.Rows);
455         ok(constant_desc.Columns == 4, "Got result %x, expected 4\n", constant_desc.Columns);
456         constant_desc_save = constant_desc; /* For GetConstantDesc test */
457
458         constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 3);
459         ok(constant == NULL, "Got result %p, expected NULL\n", constant);
460
461         /* Test GetConstantByName */
462         constant = ID3DXConstantTable_GetConstantByName(constant_table, NULL, "Constant unknown");
463         ok(constant == NULL, "Got result %p, expected NULL\n", constant);
464         constant = ID3DXConstantTable_GetConstantByName(constant_table, NULL, "Constant3");
465         ok(constant != NULL, "No constant found\n");
466         hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
467         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
468         ok(!memcmp(&constant_desc, &constant_desc_save, sizeof(D3DXCONSTANT_DESC)), "Got different constant data\n");
469
470         /* Test GetConstantDesc */
471         constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 0);
472         ok(constant != NULL, "No constant found\n");
473         hr = ID3DXConstantTable_GetConstantDesc(constant_table, NULL, &constant_desc, &nb);
474         ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
475         hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, NULL, &nb);
476         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
477         hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, NULL);
478         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
479         hr = ID3DXConstantTable_GetConstantDesc(constant_table, "Constant unknow", &constant_desc, &nb);
480         ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
481         hr = ID3DXConstantTable_GetConstantDesc(constant_table, "Constant3", &constant_desc, &nb);
482         ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
483         ok(!memcmp(&constant_desc, &constant_desc_save, sizeof(D3DXCONSTANT_DESC)), "Got different constant data\n");
484
485         ID3DXConstantTable_Release(constant_table);
486     }
487 }
488
489 static void test_constant_table(const char *test_name, const DWORD *ctable_fn,
490         const D3DXCONSTANT_DESC *expecteds, UINT count)
491 {
492     UINT i;
493     ID3DXConstantTable *ctable;
494
495     HRESULT res;
496
497     /* Get the constant table from the shader itself */
498     res = D3DXGetShaderConstantTable(ctable_fn, &ctable);
499     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed on %s: got %08x\n", test_name, res);
500
501     for (i = 0; i < count; i++)
502     {
503         const D3DXCONSTANT_DESC *expected = &expecteds[i];
504         D3DXHANDLE const_handle;
505         D3DXCONSTANT_DESC actual;
506         UINT pCount = 1;
507
508         const_handle = ID3DXConstantTable_GetConstantByName(ctable, NULL, expected->Name);
509
510         res = ID3DXConstantTable_GetConstantDesc(ctable, const_handle, &actual, &pCount);
511         ok(SUCCEEDED(res), "%s in %s: ID3DXConstantTable_GetConstantDesc returned %08x\n", expected->Name,
512                 test_name, res);
513         ok(pCount == 1, "%s in %s: Got more or less descriptions: %d\n", expected->Name, test_name, pCount);
514
515         ok(strcmp(actual.Name, expected->Name) == 0,
516            "%s in %s: Got different names: Got %s, expected %s\n", expected->Name,
517            test_name, actual.Name, expected->Name);
518         ok(actual.RegisterSet == expected->RegisterSet,
519            "%s in %s: Got different register sets: Got %d, expected %d\n",
520            expected->Name, test_name, actual.RegisterSet, expected->RegisterSet);
521         ok(actual.RegisterIndex == expected->RegisterIndex,
522            "%s in %s: Got different register indices: Got %d, expected %d\n",
523            expected->Name, test_name, actual.RegisterIndex, expected->RegisterIndex);
524         ok(actual.RegisterCount == expected->RegisterCount,
525            "%s in %s: Got different register counts: Got %d, expected %d\n",
526            expected->Name, test_name, actual.RegisterCount, expected->RegisterCount);
527         ok(actual.Class == expected->Class,
528            "%s in %s: Got different classes: Got %d, expected %d\n", expected->Name,
529            test_name, actual.Class, expected->Class);
530         ok(actual.Type == expected->Type,
531            "%s in %s: Got different types: Got %d, expected %d\n", expected->Name,
532            test_name, actual.Type, expected->Type);
533         ok(actual.Rows == expected->Rows && actual.Columns == expected->Columns,
534            "%s in %s: Got different dimensions: Got (%d, %d), expected (%d, %d)\n",
535            expected->Name, test_name, actual.Rows, actual.Columns, expected->Rows,
536            expected->Columns);
537         ok(actual.Elements == expected->Elements,
538            "%s in %s: Got different element count: Got %d, expected %d\n",
539            expected->Name, test_name, actual.Elements, expected->Elements);
540         ok(actual.StructMembers == expected->StructMembers,
541            "%s in %s: Got different struct member count: Got %d, expected %d\n",
542            expected->Name, test_name, actual.StructMembers, expected->StructMembers);
543         ok(actual.Bytes == expected->Bytes,
544            "%s in %s: Got different byte count: Got %d, expected %d\n",
545            expected->Name, test_name, actual.Bytes, expected->Bytes);
546
547         if (!expected->DefaultValue)
548         {
549             ok(actual.DefaultValue == NULL,
550                 "%s in %s: Got different default value: expected NULL\n",
551                 expected->Name, test_name);
552         }
553         else
554         {
555             ok(actual.DefaultValue != NULL,
556                 "%s in %s: Got different default value: expected non-NULL\n",
557                 expected->Name, test_name);
558             ok(memcmp(actual.DefaultValue, expected->DefaultValue, expected->Bytes) == 0,
559                 "%s in %s: Got different default value\n", expected->Name, test_name);
560         }
561     }
562
563     /* Finally, release the constant table */
564     ID3DXConstantTable_Release(ctable);
565 }
566
567 static void test_constant_tables(void)
568 {
569     test_constant_table("test_basic", ctab_basic, ctab_basic_expected,
570             sizeof(ctab_basic_expected)/sizeof(*ctab_basic_expected));
571     test_constant_table("test_matrices", ctab_matrices, ctab_matrices_expected,
572             sizeof(ctab_matrices_expected)/sizeof(*ctab_matrices_expected));
573     test_constant_table("test_matrices2", ctab_matrices2, ctab_matrices2_expected,
574             sizeof(ctab_matrices2_expected)/sizeof(*ctab_matrices2_expected));
575     test_constant_table("test_arrays", ctab_arrays, ctab_arrays_expected,
576             sizeof(ctab_arrays_expected)/sizeof(*ctab_arrays_expected));
577     test_constant_table("test_default_values", ctab_with_default_values, ctab_with_default_values_expected,
578             sizeof(ctab_with_default_values_expected)/sizeof(*ctab_with_default_values_expected));
579     test_constant_table("test_samplers", ctab_samplers, ctab_samplers_expected,
580             sizeof(ctab_samplers_expected)/sizeof(*ctab_samplers_expected));
581 }
582
583 static void test_setting_basic_table(IDirect3DDevice9 *device)
584 {
585     static const D3DXMATRIX mvp = {{{
586         0.514f, 0.626f, 0.804f, 0.786f,
587         0.238f, 0.956f, 0.374f, 0.483f,
588         0.109f, 0.586f, 0.900f, 0.255f,
589         0.898f, 0.411f, 0.932f, 0.275f}}};
590     static const D3DXVECTOR4 f4 = {0.350f, 0.526f, 0.925f, 0.021f};
591     static const float f = 0.12543f;
592     static const int i = 321;
593     static const D3DXMATRIX *matrix_pointer[] = {&mvp};
594
595     ID3DXConstantTable *ctable;
596
597     HRESULT res;
598     float out[16];
599     ULONG refcnt;
600
601     /* Get the constant table from the shader itself */
602     res = D3DXGetShaderConstantTable(ctab_basic, &ctable);
603     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got 0x%08x\n", res);
604
605     /* Set constants */
606     res = ID3DXConstantTable_SetMatrix(ctable, device, "mvp", &mvp);
607     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable mvp: got 0x%08x\n", res);
608
609     res = ID3DXConstantTable_SetInt(ctable, device, "i", i + 1);
610     ok(res == D3D_OK, "ID3DXConstantTable_SetInt failed on variable i: got 0x%08x\n", res);
611
612     /* Check that setting i again will overwrite the previous value */
613     res = ID3DXConstantTable_SetInt(ctable, device, "i", i);
614     ok(res == D3D_OK, "ID3DXConstantTable_SetInt failed on variable i: got 0x%08x\n", res);
615
616     res = ID3DXConstantTable_SetFloat(ctable, device, "f", f);
617     ok(res == D3D_OK, "ID3DXConstantTable_SetFloat failed on variable f: got 0x%08x\n", res);
618
619     res = ID3DXConstantTable_SetVector(ctable, device, "f4", &f4);
620     ok(res == D3D_OK, "ID3DXConstantTable_SetVector failed on variable f4: got 0x%08x\n", res);
621
622     /* Get constants back and validate */
623     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
624     ok(out[0] == S(U(mvp))._11 && out[4] == S(U(mvp))._12 && out[8] == S(U(mvp))._13 && out[12] == S(U(mvp))._14,
625             "The first row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
626             out[0], out[4], out[8], out[12], S(U(mvp))._11, S(U(mvp))._12, S(U(mvp))._13, S(U(mvp))._14);
627     ok(out[1] == S(U(mvp))._21 && out[5] == S(U(mvp))._22 && out[9] == S(U(mvp))._23 && out[13] == S(U(mvp))._24,
628             "The second row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
629             out[1], out[5], out[9], out[13], S(U(mvp))._21, S(U(mvp))._22, S(U(mvp))._23, S(U(mvp))._24);
630     ok(out[2] == S(U(mvp))._31 && out[6] == S(U(mvp))._32 && out[10] == S(U(mvp))._33 && out[14] == S(U(mvp))._34,
631             "The third row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
632             out[2], out[6], out[10], out[14], S(U(mvp))._31, S(U(mvp))._32, S(U(mvp))._33, S(U(mvp))._34);
633     ok(out[3] == S(U(mvp))._41 && out[7] == S(U(mvp))._42 && out[11] == S(U(mvp))._43 && out[15] == S(U(mvp))._44,
634             "The fourth row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
635             out[3], out[7], out[11], out[15], S(U(mvp))._41, S(U(mvp))._42, S(U(mvp))._43, S(U(mvp))._44);
636
637     IDirect3DDevice9_GetVertexShaderConstantF(device, 4, out, 1);
638     ok(out[0] == (float)i && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
639             "The variable i was not set correctly, out={%f, %f, %f, %f}, should be {%d, 0.0, 0.0, 0.0}\n",
640             out[0], out[1], out[2], out[3], i);
641
642     IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
643     ok(out[0] == f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
644             "The variable f was not set correctly, out={%f, %f, %f, %f}, should be {%f, 0.0, 0.0, 0.0}\n",
645             out[0], out[1], out[2], out[3], f);
646
647     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
648     ok(memcmp(out, &f4, sizeof(f4)) == 0,
649             "The variable f4 was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
650             out[0], out[1], out[2], out[3], f4.x, f4.y, f4.z, f4.w);
651
652     /* Finally test using a set* function for one type to set a variable of another type (should succeed) */
653     res = ID3DXConstantTable_SetVector(ctable, device, "f", &f4);
654     ok(res == D3D_OK, "ID3DXConstantTable_SetVector failed on variable f: 0x%08x\n", res);
655
656     IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
657     ok(out[0] == f4.x && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
658             "The variable f was not set correctly by ID3DXConstantTable_SetVector, got %f, should be %f\n",
659             out[0], f4.x);
660
661     memset(out, 0, sizeof(out));
662     IDirect3DDevice9_SetVertexShaderConstantF(device, 6, out, 1);
663     res = ID3DXConstantTable_SetMatrix(ctable, device, "f", &mvp);
664     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable f: 0x%08x\n", res);
665
666     IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
667     ok(out[0] == S(U(mvp))._11 && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
668             "The variable f was not set correctly by ID3DXConstantTable_SetMatrix, got %f, should be %f\n",
669             out[0], S(U(mvp))._11);
670
671     /* Clear registers */
672     memset(out, 0, sizeof(out));
673     IDirect3DDevice9_SetVertexShaderConstantF(device, 0, out, 4);
674     IDirect3DDevice9_SetVertexShaderConstantF(device, 6, out, 1);
675     IDirect3DDevice9_SetVertexShaderConstantF(device, 7, out, 1);
676
677     /* SetVector shouldn't change the value of a matrix constant */
678     res = ID3DXConstantTable_SetVector(ctable, device, "mvp", &f4);
679     ok(res == D3D_OK, "ID3DXConstantTable_SetVector failed on variable f: 0x%08x\n", res);
680
681     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
682     ok(out[0] == 0.0f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f
683             && out[4] == 0.0f && out[5] == 0.0f && out[6] == 0.0f && out[7] == 0.0f
684             && out[8] == 0.0f && out[9] == 0.0f && out[10] == 0.0f && out[11] == 0.0f
685             && out[12] == 0.0f && out[13] == 0.0f && out[14] == 0.0f && out[15] == 0.0f,
686             "The variable mvp was not set correctly by ID3DXConstantTable_SetVector, "
687             "got {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f %f; %f, %f, %f, %f}, "
688             "should be all 0.0f\n",
689             out[0], out[1], out[2], out[3],
690             out[4], out[5], out[6], out[7],
691             out[8], out[9], out[10], out[11],
692             out[12], out[13], out[14], out[15]);
693
694     res = ID3DXConstantTable_SetFloat(ctable, device, "mvp", f);
695     ok(res == D3D_OK, "ID3DXConstantTable_SetFloat failed on variable mvp: 0x%08x\n", res);
696
697     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
698     ok(out[0] == 0.0f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f
699             && out[4] == 0.0f && out[5] == 0.0f && out[6] == 0.0f && out[7] == 0.0f
700             && out[8] == 0.0f && out[9] == 0.0f && out[10] == 0.0f && out[11] == 0.0f
701             && out[12] == 0.0f && out[13] == 0.0f && out[14] == 0.0f && out[15] == 0.0f,
702             "The variable mvp was not set correctly by ID3DXConstantTable_SetFloat, "
703             "got {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f %f; %f, %f, %f, %f}, "
704             "should be all 0.0f\n",
705             out[0], out[1], out[2], out[3],
706             out[4], out[5], out[6], out[7],
707             out[8], out[9], out[10], out[11],
708             out[12], out[13], out[14], out[15]);
709
710     res = ID3DXConstantTable_SetFloat(ctable, device, "f4", f);
711     ok(res == D3D_OK, "ID3DXConstantTable_SetFloat failed on variable f4: 0x%08x\n", res);
712
713     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
714     ok(out[0] == 0.0f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
715             "The variable f4 was not set correctly by ID3DXConstantTable_SetFloat, "
716             "got {%f, %f, %f, %f}, should be all 0.0f\n",
717             out[0], out[1], out[2], out[3]);
718
719     res = ID3DXConstantTable_SetMatrixTranspose(ctable, device, "f", &mvp);
720     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTranspose failed on variable f: 0x%08x\n", res);
721
722     IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
723     ok(out[0] == S(U(mvp))._11 && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
724             "The variable f was not set correctly by ID3DXConstantTable_SetMatrixTranspose, got %f, should be %f\n",
725             out[0], S(U(mvp))._11);
726
727     res = ID3DXConstantTable_SetMatrixTranspose(ctable, device, "f4", &mvp);
728     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTranspose failed on variable f4: 0x%08x\n", res);
729
730     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
731     ok(out[0] == S(U(mvp))._11 && out[1] == S(U(mvp))._21 && out[2] == S(U(mvp))._31 && out[3] == S(U(mvp))._41,
732             "The variable f4 was not set correctly by ID3DXConstantTable_SetMatrixTranspose, "
733             "got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
734             out[0], out[1], out[2], out[3],
735             S(U(mvp))._11, S(U(mvp))._21, S(U(mvp))._31, S(U(mvp))._41);
736
737     memset(out, 0, sizeof(out));
738     IDirect3DDevice9_SetVertexShaderConstantF(device, 6, out, 1);
739     res = ID3DXConstantTable_SetMatrixPointerArray(ctable, device, "f", matrix_pointer, 1);
740     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixPointerArray failed on variable f: got %#x\n", res);
741
742     IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
743     ok(out[0] == S(U(mvp))._11 && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
744             "The variable f was not set correctly by ID3DXConstantTable_SetMatrixPointerArray, "
745             "got %f, should be %f\n",
746             out[0], S(U(mvp))._11);
747
748     res = ID3DXConstantTable_SetMatrixPointerArray(ctable, device, "f4", matrix_pointer, 1);
749     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixPointerArray failed on variable f4: got %#x\n", res);
750
751     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
752     ok(out[0] == S(U(mvp))._11 && out[1] == S(U(mvp))._12 && out[2] == S(U(mvp))._13 && out[3] == S(U(mvp))._14,
753             "The variable f4 was not set correctly by ID3DXConstantTable_SetMatrixPointerArray, "
754             "got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
755             out[0], out[1], out[2], out[3],
756             S(U(mvp))._11, S(U(mvp))._12, S(U(mvp))._13, S(U(mvp))._14);
757
758     memset(out, 0, sizeof(out));
759     IDirect3DDevice9_SetVertexShaderConstantF(device, 6, out, 1);
760     res = ID3DXConstantTable_SetMatrixTransposePointerArray(ctable, device, "f", matrix_pointer, 1);
761     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTransposePointerArray failed on variable f: got %#x\n", res);
762
763     IDirect3DDevice9_GetVertexShaderConstantF(device, 6, out, 1);
764     ok(out[0] == S(U(mvp))._11 && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
765             "The variable f was not set correctly by ID3DXConstantTable_SetMatrixTransposePointerArray, "
766             "got %f, should be %f\n",
767             out[0], S(U(mvp))._11);
768
769     res = ID3DXConstantTable_SetMatrixTransposePointerArray(ctable, device, "f4", matrix_pointer, 1);
770     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTransposePointerArray failed on variable f4: got %#x\n", res);
771
772     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
773     ok(out[0] == S(U(mvp))._11 && out[1] == S(U(mvp))._21 && out[2] == S(U(mvp))._31 && out[3] == S(U(mvp))._41,
774             "The variable f4 was not set correctly by ID3DXConstantTable_SetMatrixTransposePointerArray, "
775             "got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
776             out[0], out[1], out[2], out[3],
777             S(U(mvp))._11, S(U(mvp))._21, S(U(mvp))._31, S(U(mvp))._41);
778
779     refcnt = ID3DXConstantTable_Release(ctable);
780     ok(refcnt == 0, "The constant table reference count was %u, should be 0\n", refcnt);
781 }
782
783 static void test_setting_matrices_table(IDirect3DDevice9 *device)
784 {
785     static const D3DXMATRIX fmatrix =
786         {{{2.001f, 1.502f, 9.003f, 1.004f,
787            5.005f, 3.006f, 3.007f, 6.008f,
788            9.009f, 5.010f, 7.011f, 1.012f,
789            5.013f, 5.014f, 5.015f, 9.016f}}};
790     static const D3DXMATRIX *matrix_pointer[] = {&fmatrix};
791
792     ID3DXConstantTable *ctable;
793
794     HRESULT res;
795     float out[32];
796
797     res = D3DXGetShaderConstantTable(ctab_matrices, &ctable);
798     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %#x\n", res);
799
800     res = ID3DXConstantTable_SetMatrix(ctable, device, "imatrix2x3", &fmatrix);
801     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable imatrix2x3: got %#x\n", res);
802
803     res = ID3DXConstantTable_SetMatrix(ctable, device, "fmatrix3x1", &fmatrix);
804     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable fmatrix3x1: got %#x\n", res);
805
806     IDirect3DDevice9_GetVertexShaderConstantF(device, 4, out, 2);
807     todo_wine ok(out[0] == (int)S(U(fmatrix))._11 && out[1] == (int)S(U(fmatrix))._12 && out[2] == (int)S(U(fmatrix))._13
808             && out[3] == 0
809             && out[4] == (int)S(U(fmatrix))._21 && out[5] == (int)S(U(fmatrix))._22 && out[6] == (int)S(U(fmatrix))._23
810             && out[7] == 0,
811             "The variable imatrix2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f}, "
812             "should be {%d, %d, %d, %d; %d, %d, %d, %d}\n",
813             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
814             (int)S(U(fmatrix))._11, (int)S(U(fmatrix))._12, (int)S(U(fmatrix))._13, 0,
815             (int)S(U(fmatrix))._21, (int)S(U(fmatrix))._22, (int)S(U(fmatrix))._23, 0);
816
817     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
818     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._21 && out[2] == S(U(fmatrix))._31 && out[3] == 0.0f,
819             "The variable fmatrix3x1 was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
820             out[0], out[1], out[2], out[3],
821             S(U(fmatrix))._11, S(U(fmatrix))._21, S(U(fmatrix))._31, 0.0f);
822
823     ID3DXConstantTable_Release(ctable);
824
825     res = D3DXGetShaderConstantTable(ctab_matrices2, &ctable);
826     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %#x\n", res);
827
828     /* SetMatrix */
829     res = ID3DXConstantTable_SetMatrix(ctable, device, "c2x3", &fmatrix);
830     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable c2x3: got %#x\n", res);
831
832     res = ID3DXConstantTable_SetMatrix(ctable, device, "r2x3", &fmatrix);
833     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable r2x3: got %#x\n", res);
834
835     res = ID3DXConstantTable_SetMatrix(ctable, device, "c3x2", &fmatrix);
836     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable c3x2: got %#x\n", res);
837
838     res = ID3DXConstantTable_SetMatrix(ctable, device, "r3x2", &fmatrix);
839     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable r3x2: got %#x\n", res);
840
841     res = ID3DXConstantTable_SetMatrix(ctable, device, "c3x3", &fmatrix);
842     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable c3x3: got %#x\n", res);
843
844     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 3);
845     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._21 && out[2] == 0.0f && out[3] == 0.0f
846             && out[4] == S(U(fmatrix))._12 && out[5] == S(U(fmatrix))._22 && out[6] == 0.0f && out[7] == 0.0f
847             && out[8] == S(U(fmatrix))._13 && out[9] == S(U(fmatrix))._23 && out[10] == 0.0f && out[11] == 0.0f,
848             "The variable c2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
849             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
850             out[0], out[1], out[2], out[3],
851             out[4], out[5], out[6], out[7],
852             out[8], out[9], out[10], out[11],
853             S(U(fmatrix))._11, S(U(fmatrix))._21, 0.0f, 0.0f,
854             S(U(fmatrix))._12, S(U(fmatrix))._22, 0.0f, 0.0f,
855             S(U(fmatrix))._13, S(U(fmatrix))._23, 0.0f, 0.0f);
856
857     res = ID3DXConstantTable_SetMatrix(ctable, device, "r4x4", &fmatrix);
858     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed on variable r4x4: got %#x\n", res);
859
860     IDirect3DDevice9_GetVertexShaderConstantF(device, 15, out, 2);
861     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._12 && out[2] == S(U(fmatrix))._13 && out[3] == 0.0f
862             && out[4] == S(U(fmatrix))._21 && out[5] == S(U(fmatrix))._22 && out[6] == S(U(fmatrix))._23 && out[7] == 0.0f,
863             "The variable r2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f}, "
864             "should be {%f, %f, %f, %f; %f, %f, %f, %f}\n",
865             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
866             S(U(fmatrix))._11, S(U(fmatrix))._12, S(U(fmatrix))._13, 0.0f,
867             S(U(fmatrix))._21, S(U(fmatrix))._22, S(U(fmatrix))._23, 0.0f);
868
869     IDirect3DDevice9_GetVertexShaderConstantF(device, 13, out, 2);
870     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._21 && out[2] == S(U(fmatrix))._31 && out[3] == 0.0f
871             && out[4] == S(U(fmatrix))._12 && out[5] == S(U(fmatrix))._22 && out[6] == S(U(fmatrix))._32 && out[7] == 0.0f,
872             "The variable c3x2 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f}, "
873             "should be {%f, %f, %f, %f; %f, %f, %f, %f}\n",
874             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
875             S(U(fmatrix))._11, S(U(fmatrix))._21, S(U(fmatrix))._31, 0.0f,
876             S(U(fmatrix))._12, S(U(fmatrix))._22, S(U(fmatrix))._32, 0.0f);
877
878     IDirect3DDevice9_GetVertexShaderConstantF(device, 4, out, 3);
879     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._12 && out[2] == 0.0f && out[3] == 0.0f
880             && out[4] == S(U(fmatrix))._21 && out[5] == S(U(fmatrix))._22 && out[6] == 0.0f && out[7] == 0.0f
881             && out[8] == S(U(fmatrix))._31 && out[9] == S(U(fmatrix))._32 && out[10] == 0.0f && out[11] == 0.0f,
882             "The variable r3x2 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
883             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
884             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], out[8], out[9], out[10], out[11],
885             S(U(fmatrix))._11, S(U(fmatrix))._12, 0.0f, 0.0f,
886             S(U(fmatrix))._21, S(U(fmatrix))._22, 0.0f, 0.0f,
887             S(U(fmatrix))._31, S(U(fmatrix))._32, 0.0f, 0.0f);
888
889     IDirect3DDevice9_GetVertexShaderConstantF(device, 10, out, 3);
890     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._21 && out[2] == S(U(fmatrix))._31 && out[3] == 0.0f
891             && out[4] == S(U(fmatrix))._12 && out[5] == S(U(fmatrix))._22 && out[6] == S(U(fmatrix))._32 && out[7] == 0.0f
892             && out[8] == S(U(fmatrix))._13 && out[9] == S(U(fmatrix))._23 && out[10] == S(U(fmatrix))._33 && out[11] == 0.0f,
893             "The variable c3x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
894             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
895             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], out[8], out[9], out[10], out[11],
896             S(U(fmatrix))._11, S(U(fmatrix))._21, S(U(fmatrix))._31, 0.0f,
897             S(U(fmatrix))._12, S(U(fmatrix))._22, S(U(fmatrix))._32, 0.0f,
898             S(U(fmatrix))._13, S(U(fmatrix))._23, S(U(fmatrix))._33, 0.0f);
899
900     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
901     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._12 && out[2] == S(U(fmatrix))._13 && out[3] == S(U(fmatrix))._14
902             && out[4] == S(U(fmatrix))._21 && out[5] == S(U(fmatrix))._22 && out[6] == S(U(fmatrix))._23 && out[7] == S(U(fmatrix))._24
903             && out[8] == S(U(fmatrix))._31 && out[9] == S(U(fmatrix))._32 && out[10] == S(U(fmatrix))._33 && out[11] == S(U(fmatrix))._34
904             && out[12] == S(U(fmatrix))._41 && out[13] == S(U(fmatrix))._42 && out[14] == S(U(fmatrix))._43 && out[15] == S(U(fmatrix))._44,
905             "The variable r4x4 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
906             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
907             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
908             out[8], out[9], out[10], out[11], out[12], out[13], out[14], out[15],
909             S(U(fmatrix))._11, S(U(fmatrix))._12, S(U(fmatrix))._13, S(U(fmatrix))._14,
910             S(U(fmatrix))._21, S(U(fmatrix))._22, S(U(fmatrix))._23, S(U(fmatrix))._24,
911             S(U(fmatrix))._31, S(U(fmatrix))._32, S(U(fmatrix))._33, S(U(fmatrix))._34,
912             S(U(fmatrix))._41, S(U(fmatrix))._42, S(U(fmatrix))._43, S(U(fmatrix))._44);
913
914     /* SetMatrixTranspose */
915     res = ID3DXConstantTable_SetMatrixTranspose(ctable, device, "c2x3", &fmatrix);
916     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTranspose failed on variable c2x3: got %#x\n", res);
917
918     res = ID3DXConstantTable_SetMatrixTranspose(ctable, device, "r2x3", &fmatrix);
919     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTranspose failed on variable r2x3: got %#x\n", res);
920
921     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 3);
922     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._12 && out[2] == 0.0f && out[3] == 0.0f
923             && out[4] == S(U(fmatrix))._21 && out[5] == S(U(fmatrix))._22 && out[6] == 0.0f && out[7] == 0.0f
924             && out[8] == S(U(fmatrix))._31 && out[9] == S(U(fmatrix))._32 && out[10] == 0.0f && out[11] == 0.0f,
925             "The variable c2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
926             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
927             out[0], out[1], out[2], out[3],
928             out[4], out[5], out[6], out[7],
929             out[8], out[9], out[10], out[11],
930             S(U(fmatrix))._11, S(U(fmatrix))._12, 0.0f, 0.0f,
931             S(U(fmatrix))._21, S(U(fmatrix))._22, 0.0f, 0.0f,
932             S(U(fmatrix))._31, S(U(fmatrix))._32, 0.0f, 0.0f);
933
934     IDirect3DDevice9_GetVertexShaderConstantF(device, 15, out, 2);
935     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._21 && out[2] == S(U(fmatrix))._31 && out[3] == 0.0f
936             && out[4] == S(U(fmatrix))._12 && out[5] == S(U(fmatrix))._22 && out[6] == S(U(fmatrix))._32 && out[7] == 0.0f,
937             "The variable r2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f}, "
938             "should be {%f, %f, %f, %f; %f, %f, %f, %f}\n",
939             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
940             S(U(fmatrix))._11, S(U(fmatrix))._21, S(U(fmatrix))._31, 0.0f,
941             S(U(fmatrix))._12, S(U(fmatrix))._22, S(U(fmatrix))._32, 0.0f);
942
943     /* SetMatrixPointerArray */
944     res = ID3DXConstantTable_SetMatrixPointerArray(ctable, device, "c2x3", matrix_pointer, 1);
945     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixPointerArray failed on variable c2x3: got %#x\n", res);
946
947     res = ID3DXConstantTable_SetMatrixPointerArray(ctable, device, "r2x3", matrix_pointer, 1);
948     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixPointerArray failed on variable r2x3: got %#x\n", res);
949
950     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 3);
951     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._21 && out[2] == 0.0f && out[3] == 0.0f
952             && out[4] == S(U(fmatrix))._12 && out[5] == S(U(fmatrix))._22 && out[6] == 0.0f && out[7] == 0.0f
953             && out[8] == S(U(fmatrix))._13 && out[9] == S(U(fmatrix))._23 && out[10] == 0.0f && out[11] == 0.0f,
954             "The variable c2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
955             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
956             out[0], out[1], out[2], out[3],
957             out[4], out[5], out[6], out[7],
958             out[8], out[9], out[10], out[11],
959             S(U(fmatrix))._11, S(U(fmatrix))._21, 0.0f, 0.0f,
960             S(U(fmatrix))._12, S(U(fmatrix))._22, 0.0f, 0.0f,
961             S(U(fmatrix))._13, S(U(fmatrix))._23, 0.0f, 0.0f);
962
963     IDirect3DDevice9_GetVertexShaderConstantF(device, 15, out, 2);
964     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._12 && out[2] == S(U(fmatrix))._13 && out[3] == 0.0f
965             && out[4] == S(U(fmatrix))._21 && out[5] == S(U(fmatrix))._22 && out[6] == S(U(fmatrix))._23 && out[7] == 0.0f,
966             "The variable r2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f}, "
967             "should be {%f, %f, %f, %f; %f, %f, %f, %f}\n",
968             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
969             S(U(fmatrix))._11, S(U(fmatrix))._12, S(U(fmatrix))._13, 0.0f,
970             S(U(fmatrix))._21, S(U(fmatrix))._22, S(U(fmatrix))._23, 0.0f);
971
972     /* SetMatrixTransposePointerArray */
973     res = ID3DXConstantTable_SetMatrixTransposePointerArray(ctable, device, "c2x3", matrix_pointer, 1);
974     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTransposePointerArray failed on variable c2x3: got %#x\n", res);
975
976     res = ID3DXConstantTable_SetMatrixTransposePointerArray(ctable, device, "r2x3", matrix_pointer, 1);
977     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixTransposePointerArray failed on variable r2x3: got %#x\n", res);
978
979     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 3);
980     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._12 && out[2] == 0.0f && out[3] == 0.0f
981             && out[4] == S(U(fmatrix))._21 && out[5] == S(U(fmatrix))._22 && out[6] == 0.0f && out[7] == 0.0f
982             && out[8] == S(U(fmatrix))._31 && out[9] == S(U(fmatrix))._32 && out[10] == 0.0f && out[11] == 0.0f,
983             "The variable c2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
984             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
985             out[0], out[1], out[2], out[3],
986             out[4], out[5], out[6], out[7],
987             out[8], out[9], out[10], out[11],
988             S(U(fmatrix))._11, S(U(fmatrix))._12, 0.0f, 0.0f,
989             S(U(fmatrix))._21, S(U(fmatrix))._22, 0.0f, 0.0f,
990             S(U(fmatrix))._31, S(U(fmatrix))._32, 0.0f, 0.0f);
991
992     IDirect3DDevice9_GetVertexShaderConstantF(device, 15, out, 2);
993     ok(out[0] == S(U(fmatrix))._11 && out[1] == S(U(fmatrix))._21 && out[2] == S(U(fmatrix))._31 && out[3] == 0.0f
994             && out[4] == S(U(fmatrix))._12 && out[5] == S(U(fmatrix))._22 && out[6] == S(U(fmatrix))._32 && out[7] == 0.0f,
995             "The variable r2x3 was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f}, "
996             "should be {%f, %f, %f, %f; %f, %f, %f, %f}\n",
997             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
998             S(U(fmatrix))._11, S(U(fmatrix))._21, S(U(fmatrix))._31, 0.0f,
999             S(U(fmatrix))._12, S(U(fmatrix))._22, S(U(fmatrix))._32, 0.0f);
1000
1001     ID3DXConstantTable_Release(ctable);
1002 }
1003
1004 static void test_setting_arrays_table(IDirect3DDevice9 *device)
1005 {
1006     static const float farray[8] = {
1007         0.005f, 0.745f, 0.973f, 0.264f,
1008         0.010f, 0.020f, 0.030f, 0.040f};
1009     static const D3DXMATRIX fmtxarray[2] = {
1010         {{{0.001f, 0.002f, 0.003f, 0.004f,
1011            0.005f, 0.006f, 0.007f, 0.008f,
1012            0.009f, 0.010f, 0.011f, 0.012f,
1013            0.013f, 0.014f, 0.015f, 0.016f}}},
1014         {{{0.010f, 0.020f, 0.030f, 0.040f,
1015            0.050f, 0.060f, 0.070f, 0.080f,
1016            0.090f, 0.100f, 0.110f, 0.120f,
1017            0.130f, 0.140f, 0.150f, 0.160f}}}};
1018     static const int iarray[4] = {1, 2, 3, 4};
1019     static const D3DXVECTOR4 fvecarray[2] = {
1020         {0.745f, 0.997f, 0.353f, 0.237f},
1021         {0.060f, 0.455f, 0.333f, 0.983f}};
1022     static BOOL barray[4] = {FALSE, 100, TRUE, TRUE};
1023
1024     ID3DXConstantTable *ctable;
1025
1026     HRESULT res;
1027     float out[32];
1028     ULONG refcnt;
1029
1030     /* Clear registers */
1031     memset(out, 0, sizeof(out));
1032     IDirect3DDevice9_SetVertexShaderConstantF(device,  8, out, 4);
1033     IDirect3DDevice9_SetVertexShaderConstantF(device, 12, out, 4);
1034
1035     /* Get the constant table from the shader */
1036     res = D3DXGetShaderConstantTable(ctab_arrays, &ctable);
1037     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got 0x%08x\n", res);
1038
1039     /* Set constants */
1040
1041     /* Make sure that we cannot set registers that do not belong to this constant */
1042     res = ID3DXConstantTable_SetFloatArray(ctable, device, "farray", farray, 8);
1043     ok(res == D3D_OK, "ID3DXConstantTable_SetFloatArray failed: got 0x%08x\n", res);
1044
1045     IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 8);
1046     ok(out[0] == farray[0] && out[4] == farray[1] && out[8] == farray[2] && out[12] == farray[3],
1047             "The in-bounds elements of the array were not set, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1048             out[0], out[4], out[8], out[12], farray[0], farray[1], farray[2], farray[3]);
1049     ok(out[16] == 0.0f && out[20] == 0.0f && out[24] == 0.0f && out[28] == 0.0f,
1050             "The excess elements of the array were set, out={%f, %f, %f, %f}, should be all 0.0f\n",
1051             out[16], out[20], out[24], out[28]);
1052
1053     /* ivecarray takes up only 1 register, but a matrix takes up 4, so no elements should be set */
1054     res = ID3DXConstantTable_SetMatrix(ctable, device, "ivecarray", &fmtxarray[0]);
1055     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed: got 0x%08x\n", res);
1056
1057     IDirect3DDevice9_GetVertexShaderConstantF(device, 18, out, 4);
1058     ok(out[0] == 0.0f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f,
1059        "The array was set, out={%f, %f, %f, %f}, should be all 0.0f\n", out[0], out[1], out[2], out[3]);
1060
1061     /* Try setting an integer array to an array declared as a float array */
1062     res = ID3DXConstantTable_SetIntArray(ctable, device, "farray", iarray, 4);
1063     ok(res == D3D_OK, "ID3DXConstantTable_SetIntArray failed: got 0x%08x\n", res);
1064
1065     IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 4);
1066     ok(out[0] == iarray[0] && out[4] == iarray[1] && out[8] == iarray[2] && out[12] == iarray[3],
1067            "SetIntArray did not properly set a float array: out={%f, %f, %f, %f}, should be {%d, %d, %d, %d}\n",
1068             out[0], out[4], out[8], out[12], iarray[0], iarray[1], iarray[2], iarray[3]);
1069
1070     res = ID3DXConstantTable_SetFloatArray(ctable, device, "farray", farray, 4);
1071     ok(res == D3D_OK, "ID3DXConstantTable_SetFloatArray failed: got x0%08x\n", res);
1072
1073     res = ID3DXConstantTable_SetVectorArray(ctable, device, "fvecarray", fvecarray, 2);
1074     ok(res == D3D_OK, "ID3DXConstantTable_SetVectorArray failed: got 0x%08x\n", res);
1075
1076     res = ID3DXConstantTable_SetMatrixArray(ctable, device, "fmtxarray", fmtxarray, 2);
1077     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrixArray failed: got 0x%08x\n", res);
1078
1079     res = ID3DXConstantTable_SetBoolArray(ctable, device, "barray", barray, 2);
1080     ok(res == D3D_OK, "ID3DXConstantTable_SetBoolArray failed: got 0x%08x\n", res);
1081
1082     /* Read back constants */
1083     IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 4);
1084     ok(out[0] == farray[0] && out[4] == farray[1] && out[8] == farray[2] && out[12] == farray[3],
1085             "The variable farray was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1086             out[0], out[4], out[8], out[12], farray[0], farray[1], farray[2], farray[3]);
1087
1088     IDirect3DDevice9_GetVertexShaderConstantF(device, 12, out, 2);
1089     ok(out[0] == fvecarray[0].x && out[1] == fvecarray[0].y && out[2] == fvecarray[0].z && out[3] == fvecarray[0].w &&
1090             out[4] == fvecarray[1].x && out[5] == fvecarray[1].y && out[6] == fvecarray[1].z && out[7] == fvecarray[1].w,
1091             "The variable fvecarray was not set correctly, out={{%f, %f, %f, %f}, {%f, %f, %f, %f}}, should be "
1092             "{{%f, %f, %f, %f}, {%f, %f, %f, %f}}\n", out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
1093             fvecarray[0].x, fvecarray[0].y, fvecarray[0].z, fvecarray[0].w, fvecarray[1].x, fvecarray[1].y,
1094             fvecarray[1].z, fvecarray[1].w);
1095
1096     IDirect3DDevice9_GetVertexShaderConstantF(device, 14, out, 2);
1097     ok(out[0] == 0.0f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f
1098             && out[4] == 1.0f && out[5] == 0.0f && out[6] == 0.0f && out[7] == 0.0f,
1099             "The variable barray was not set correctly, out={%f, %f %f, %f; %f, %f, %f, %f}, should be {%f, %f, %f, %f; %f, %f, %f, %f}\n",
1100             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
1101             0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
1102
1103     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 8);
1104     /* Just check a few elements in each matrix to make sure fmtxarray was set row-major */
1105     ok(out[0] == S(U(fmtxarray[0]))._11 && out[1] == S(U(fmtxarray[0]))._12 && out[2] == S(U(fmtxarray[0]))._13 && out[3] == S(U(fmtxarray[0]))._14,
1106            "The variable fmtxarray was not set row-major, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1107            out[0], out[1], out[2], out[3], S(U(fmtxarray[0]))._11, S(U(fmtxarray[0]))._12, S(U(fmtxarray[0]))._13, S(U(fmtxarray[0]))._14);
1108     ok(out[16] == S(U(fmtxarray[1]))._11 && out[17] == S(U(fmtxarray[1]))._12 && out[18] == S(U(fmtxarray[1]))._13 && out[19] == S(U(fmtxarray[1]))._14,
1109            "The variable fmtxarray was not set row-major, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1110            out[16], out[17], out[18], out[19], S(U(fmtxarray[1]))._11, S(U(fmtxarray[1]))._12, S(U(fmtxarray[1]))._13, S(U(fmtxarray[1]))._14);
1111
1112     refcnt = ID3DXConstantTable_Release(ctable);
1113     ok(refcnt == 0, "The constant table reference count was %u, should be 0\n", refcnt);
1114 }
1115
1116 static void test_SetDefaults(IDirect3DDevice9 *device)
1117 {
1118     static const D3DXMATRIX mvp = {{{
1119         0.51f, 0.62f, 0.80f, 0.78f,
1120         0.23f, 0.95f, 0.37f, 0.48f,
1121         0.10f, 0.58f, 0.90f, 0.25f,
1122         0.89f, 0.41f, 0.93f, 0.27f}}};
1123     static const D3DXVECTOR4 f4 = {0.2f, 0.4f, 0.8f, 1.2f};
1124
1125     float out[16];
1126
1127     HRESULT res;
1128     ID3DXConstantTable *ctable;
1129
1130     res = D3DXGetShaderConstantTable(ctab_basic, &ctable);
1131     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %08x\n", res);
1132
1133     res = ID3DXConstantTable_SetVector(ctable, device, "f4", &f4);
1134     ok(res == D3D_OK, "ID3DXConstantTable_SetVector failed: got %08x\n", res);
1135
1136     res = ID3DXConstantTable_SetMatrix(ctable, device, "mvp", &mvp);
1137     ok(res == D3D_OK, "ID3DXConstantTable_SetMatrix failed: got %08x\n", res);
1138
1139     res = ID3DXConstantTable_SetDefaults(ctable, device);
1140     ok(res == D3D_OK, "ID3dXConstantTable_SetDefaults failed: got %08x\n", res);
1141
1142     /* SetDefaults doesn't change constants without default values */
1143     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
1144     ok(out[0] == S(U(mvp))._11 && out[4] == S(U(mvp))._12 && out[8] == S(U(mvp))._13 && out[12] == S(U(mvp))._14,
1145             "The first row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1146             out[0], out[4], out[8], out[12], S(U(mvp))._11, S(U(mvp))._12, S(U(mvp))._13, S(U(mvp))._14);
1147     ok(out[1] == S(U(mvp))._21 && out[5] == S(U(mvp))._22 && out[9] == S(U(mvp))._23 && out[13] == S(U(mvp))._24,
1148             "The second row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1149             out[1], out[5], out[9], out[13], S(U(mvp))._21, S(U(mvp))._22, S(U(mvp))._23, S(U(mvp))._24);
1150     ok(out[2] == S(U(mvp))._31 && out[6] == S(U(mvp))._32 && out[10] == S(U(mvp))._33 && out[14] == S(U(mvp))._34,
1151             "The third row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1152             out[2], out[6], out[10], out[14], S(U(mvp))._31, S(U(mvp))._32, S(U(mvp))._33, S(U(mvp))._34);
1153     ok(out[3] == S(U(mvp))._41 && out[7] == S(U(mvp))._42 && out[11] == S(U(mvp))._43 && out[15] == S(U(mvp))._44,
1154             "The fourth row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1155             out[3], out[7], out[11], out[15], S(U(mvp))._41, S(U(mvp))._42, S(U(mvp))._43, S(U(mvp))._44);
1156
1157     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
1158     ok(memcmp(out, &f4, sizeof(f4)) == 0,
1159             "The variable f4 was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1160             out[0], out[1], out[2], out[3], f4.x, f4.y, f4.z, f4.w);
1161
1162     ID3DXConstantTable_Release(ctable);
1163
1164     res = D3DXGetShaderConstantTable(ctab_with_default_values, &ctable);
1165     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %08x\n", res);
1166
1167     res = ID3DXConstantTable_SetDefaults(ctable, device);
1168     ok(res == D3D_OK, "ID3DXConstantTable_SetDefaults failed: got %08x\n", res);
1169
1170     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
1171     ok(memcmp(out, mat4_default_value, sizeof(mat4_default_value)) == 0,
1172             "The variable mat4 was not set correctly to default value\n");
1173
1174     IDirect3DDevice9_GetVertexShaderConstantF(device, 4, out, 4);
1175     ok(memcmp(out, mat3_default_value, sizeof(mat3_default_value)) == 0,
1176             "The variable mat3 was not set correctly to default value\n");
1177
1178     IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 3);
1179     ok(memcmp(out, arr_default_value, sizeof(arr_default_value)) == 0,
1180         "The variable array was not set correctly to default value\n");
1181
1182     IDirect3DDevice9_GetVertexShaderConstantF(device, 11, out, 1);
1183     ok(memcmp(out, vec4_default_value, sizeof(vec4_default_value)) == 0,
1184         "The variable vec4 was not set correctly to default value\n");
1185
1186     IDirect3DDevice9_GetVertexShaderConstantF(device, 12, out, 1);
1187     ok(memcmp(out, flt_default_value, sizeof(flt_default_value)) == 0,
1188         "The variable flt was not set correctly to default value\n");
1189
1190     ID3DXConstantTable_Release(ctable);
1191 }
1192
1193 static void test_SetValue(IDirect3DDevice9 *device)
1194 {
1195     static const D3DXMATRIX mvp = {{{
1196         0.51f, 0.62f, 0.80f, 0.78f,
1197         0.23f, 0.95f, 0.37f, 0.48f,
1198         0.10f, 0.58f, 0.90f, 0.25f,
1199         0.89f, 0.41f, 0.93f, 0.27f}}};
1200     static const D3DXVECTOR4 f4 = {0.2f, 0.4f, 0.8f, 1.2f};
1201     static const FLOAT arr[] = {0.33f, 0.55f, 0.96f, 1.00f,
1202                                 1.00f, 1.00f, 1.00f, 1.00f,
1203                                 1.00f, 1.00f, 1.00f, 1.00f};
1204     static int imatrix[] = {1, 2, 3, 4, 5, 6};
1205     static float fmatrix[] = {1.1f, 2.2f, 3.3f, 4.4f};
1206     static BOOL barray[] = {TRUE, FALSE};
1207     static float fvecarray[] = {9.1f, 9.2f, 9.3f, 9.4f, 9.5f, 9.6f, 9.7f, 9.8f};
1208     static float farray[] = {2.2f, 3.3f};
1209
1210     static const float def[16] = {5.5f, 5.5f, 5.5f, 5.5f,
1211                                   5.5f, 5.5f, 5.5f, 5.5f,
1212                                   5.5f, 5.5f, 5.5f, 5.5f,
1213                                   5.5f, 5.5f, 5.5f, 5.5f};
1214     float out[16];
1215
1216     HRESULT res;
1217     ID3DXConstantTable *ctable;
1218
1219     res = D3DXGetShaderConstantTable(ctab_basic, &ctable);
1220     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %08x\n", res);
1221
1222     IDirect3DDevice9_SetVertexShaderConstantF(device, 7, def, 1);
1223
1224     /* SetValue called with 0 bytes size doesn't change value */
1225     res = ID3DXConstantTable_SetValue(ctable, device, "f4", &f4, 0);
1226     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1227
1228     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
1229     ok(memcmp(out, def, sizeof(f4)) == 0,
1230             "The variable f4 was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1231             out[0], out[1], out[2], out[3], def[0], def[1], def[2], def[3]);
1232
1233     res = ID3DXConstantTable_SetValue(ctable, device, "f4", &f4, sizeof(f4));
1234     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1235
1236     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 1);
1237     ok(memcmp(out, &f4, sizeof(f4)) == 0,
1238             "The variable f4 was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1239             out[0], out[1], out[2], out[3], f4.x, f4.y, f4.z, f4.w);
1240
1241     IDirect3DDevice9_SetVertexShaderConstantF(device, 0, def, 4);
1242
1243     /* SetValue called with size smaller than constant size doesn't change value */
1244     res = ID3DXConstantTable_SetValue(ctable, device, "mvp", &mvp, sizeof(mvp) / 2);
1245     ok(res == D3D_OK, "ID3DXConstantTable_SetValue returned %08x\n", res);
1246
1247     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
1248     ok(memcmp(out, def, sizeof(def)) == 0,
1249             "The variable mvp was not set correctly, out={%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
1250             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
1251             out[0], out[4], out[ 8], out[12],
1252             out[1], out[5], out[ 9], out[13],
1253             out[2], out[6], out[10], out[14],
1254             out[3], out[7], out[11], out[15],
1255             def[0], def[4], def[ 8], def[12],
1256             def[1], def[5], def[ 9], def[13],
1257             def[2], def[6], def[10], def[14],
1258             def[3], def[7], def[11], def[15]);
1259
1260     res = ID3DXConstantTable_SetValue(ctable, device, "mvp", &mvp, sizeof(mvp));
1261     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1262
1263     IDirect3DDevice9_GetVertexShaderConstantF(device, 0, out, 4);
1264     ok(out[0] == S(U(mvp))._11 && out[4] == S(U(mvp))._12 && out[8] == S(U(mvp))._13 && out[12] == S(U(mvp))._14,
1265             "The first row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1266             out[0], out[4], out[8], out[12], S(U(mvp))._11, S(U(mvp))._12, S(U(mvp))._13, S(U(mvp))._14);
1267     ok(out[1] == S(U(mvp))._21 && out[5] == S(U(mvp))._22 && out[9] == S(U(mvp))._23 && out[13] == S(U(mvp))._24,
1268             "The second row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1269             out[1], out[5], out[9], out[13], S(U(mvp))._21, S(U(mvp))._22, S(U(mvp))._23, S(U(mvp))._24);
1270     ok(out[2] == S(U(mvp))._31 && out[6] == S(U(mvp))._32 && out[10] == S(U(mvp))._33 && out[14] == S(U(mvp))._34,
1271             "The third row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1272             out[2], out[6], out[10], out[14], S(U(mvp))._31, S(U(mvp))._32, S(U(mvp))._33, S(U(mvp))._34);
1273     ok(out[3] == S(U(mvp))._41 && out[7] == S(U(mvp))._42 && out[11] == S(U(mvp))._43 && out[15] == S(U(mvp))._44,
1274             "The fourth row of mvp was not set correctly, got {%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1275             out[3], out[7], out[11], out[15], S(U(mvp))._41, S(U(mvp))._42, S(U(mvp))._43, S(U(mvp))._44);
1276
1277     ID3DXConstantTable_Release(ctable);
1278
1279     res = D3DXGetShaderConstantTable(ctab_with_default_values, &ctable);
1280     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %08x\n", res);
1281
1282     res = ID3DXConstantTable_SetValue(ctable, device, "arr", arr, sizeof(arr));
1283     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1284
1285     IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 3);
1286     ok(out[0] == arr[0] && out[4] == arr[1] && out[8] == arr[2]
1287             && out[1] == 0 &&  out[2] == 0 && out[3] == 0 && out[5] == 0 && out[6] == 0 && out[7] == 0
1288             && out[9] == 0 && out[10] == 0 && out[11] == 0,
1289             "The variable arr was not set correctly, out={%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f}, "
1290             "should be {0.33, 0, 0, 0, 0.55, 0, 0, 0, 0.96, 0, 0, 0}\n",
1291             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], out[8], out[9], out[10], out[11]);
1292
1293     ID3DXConstantTable_Release(ctable);
1294
1295     res = D3DXGetShaderConstantTable(ctab_matrices, &ctable);
1296     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %08x\n", res);
1297
1298     res = ID3DXConstantTable_SetValue(ctable, device, "fmatrix3x1", fmatrix, sizeof(fmatrix));
1299     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1300
1301     res = ID3DXConstantTable_SetValue(ctable, device, "imatrix2x3", imatrix, sizeof(imatrix));
1302     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1303
1304     IDirect3DDevice9_GetVertexShaderConstantF(device, 4, out, 2);
1305     ok(out[0] == imatrix[0] && out[1] == imatrix[1] && out[2] == imatrix[2] && out[3] == 0.0f
1306             && out[4] == imatrix[3] && out[5] == imatrix[4] && out[6] == imatrix[5] && out[7] == 0.0f,
1307             "The variable imatrix2x3 was not set correctly, out={%f, %f, %f, %f, %f, %f, %f, %f}, "
1308             "should be {%d, %d, %d, 0, %d, %d, %d, 0}\n",
1309             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
1310             imatrix[0], imatrix[1], imatrix[2], imatrix[3], imatrix[4], imatrix[5]);
1311
1312     IDirect3DDevice9_GetVertexShaderConstantF(device, 7, out, 2);
1313     ok(out[0] == fmatrix[0] && out[1] == fmatrix[1] && out[2] == fmatrix[2] && out[3] == 0.0f,
1314             "The variable fmatrix3x1 was not set correctly, out={%f, %f, %f, %f}, should be {%f, %f, %f, %f}\n",
1315             out[0], out[1] ,out[2], out[4],
1316             fmatrix[0], fmatrix[1], fmatrix[2], 0.0f);
1317
1318     ID3DXConstantTable_Release(ctable);
1319
1320     res = D3DXGetShaderConstantTable(ctab_arrays, &ctable);
1321     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed: got %08x\n", res);
1322
1323     res = ID3DXConstantTable_SetValue(ctable, device, "barray", barray, sizeof(barray));
1324     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1325
1326     res = ID3DXConstantTable_SetValue(ctable, device, "fvecarray", fvecarray, sizeof(fvecarray));
1327     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1328
1329     IDirect3DDevice9_SetVertexShaderConstantF(device, 8, def, 4);
1330     res = ID3DXConstantTable_SetValue(ctable, device, "farray", farray, sizeof(farray));
1331     ok(res == D3D_OK, "ID3DXConstantTable_SetValue failed: got %08x\n", res);
1332
1333     /* 2 elements of farray were set */
1334     IDirect3DDevice9_GetVertexShaderConstantF(device, 8, out, 4);
1335     ok(out[0] == farray[0] && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f
1336             && out[4] == farray[1] && out[5] == 0.0f && out[6] == 0.0f && out[7] == 0.0f
1337             && out[8] == def[8] && out[9] == def[9] && out[10] == def[10] && out[11] == def[11]
1338             && out[12] == def[12] && out[13] == def[13] && out[14] == def[14] && out[15] == def[15],
1339             "The variable farray was not set correctly, should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}, "
1340             "should be {%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f}\n",
1341             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
1342             out[8], out[9], out[10], out[11], out[12], out[13], out[14], out[15],
1343             farray[0], 0.0f, 0.0f, 0.0f,
1344             farray[1], 0.0f, 0.0f, 0.0f,
1345             def[8], def[9], def[10], def[11],
1346             def[12], def[13], def[14], def[15]);
1347
1348     IDirect3DDevice9_GetVertexShaderConstantF(device, 12, out, 2);
1349     ok(out[0] == fvecarray[0] && out[1] == fvecarray[1] && out[2] == fvecarray[2] && out[3] == fvecarray[3]
1350             && out[4] == fvecarray[4] && out[5] == fvecarray[5] && out[6] == fvecarray[6] && out[7] == fvecarray[7],
1351             "The variable fvecarray was not set correctly, out ={%f, %f, %f, %f, %f, %f, %f, %f}, "
1352             "should be {%f, %f, %f, %f, %f, %f, %f, %f}\n",
1353             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
1354             fvecarray[0], fvecarray[1], fvecarray[2], fvecarray[3], fvecarray[4], fvecarray[5], fvecarray[6], fvecarray[7]);
1355
1356     IDirect3DDevice9_GetVertexShaderConstantF(device, 14, out, 2);
1357     ok(out[0] == 1.0f && out[1] == 0.0f && out[2] == 0.0f && out[3] == 0.0f
1358             && out[4] == 0.0f && out[5] == 0.0f && out[6] == 0.0f && out[7] == 0.0f,
1359             "The variable barray was not set correctly, out={%f, %f, %f, %f, %f, %f, %f, %f}, "
1360             "should be {%f, %f, %f, %f, %f, %f, %f, %f}\n",
1361             out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
1362             1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
1363
1364     ID3DXConstantTable_Release(ctable);
1365 }
1366
1367 static void test_setting_constants(void)
1368 {
1369     HWND wnd;
1370     IDirect3D9 *d3d;
1371     IDirect3DDevice9 *device;
1372     D3DPRESENT_PARAMETERS d3dpp;
1373     HRESULT hr;
1374     ULONG refcnt;
1375
1376     /* Create the device to use for our tests */
1377     wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1378     d3d = Direct3DCreate9(D3D_SDK_VERSION);
1379     if (!wnd)
1380     {
1381         skip("Couldn't create application window\n");
1382         return;
1383     }
1384     if (!d3d)
1385     {
1386         skip("Couldn't create IDirect3D9 object\n");
1387         DestroyWindow(wnd);
1388         return;
1389     }
1390
1391     ZeroMemory(&d3dpp, sizeof(d3dpp));
1392     d3dpp.Windowed   = TRUE;
1393     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1394     hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1395     if (FAILED(hr))
1396     {
1397         skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1398         IDirect3D9_Release(d3d);
1399         DestroyWindow(wnd);
1400         return;
1401     }
1402
1403     test_setting_basic_table(device);
1404     test_setting_matrices_table(device);
1405     test_setting_arrays_table(device);
1406     test_SetDefaults(device);
1407     test_SetValue(device);
1408
1409     /* Release resources */
1410     refcnt = IDirect3DDevice9_Release(device);
1411     ok(refcnt == 0, "The Direct3D device reference count was %u, should be 0\n", refcnt);
1412
1413     refcnt = IDirect3D9_Release(d3d);
1414     ok(refcnt == 0, "The Direct3D object referenct count was %u, should be 0\n", refcnt);
1415
1416     if (wnd) DestroyWindow(wnd);
1417 }
1418
1419 static void test_get_sampler_index(void)
1420 {
1421     ID3DXConstantTable *ctable;
1422
1423     HRESULT res;
1424     UINT index;
1425
1426     ULONG refcnt;
1427
1428     res = D3DXGetShaderConstantTable(ctab_samplers, &ctable);
1429     ok(res == D3D_OK, "D3DXGetShaderConstantTable failed on ctab_samplers: got %08x\n", res);
1430
1431     index = ID3DXConstantTable_GetSamplerIndex(ctable, "sampler1");
1432     ok(index == 0, "ID3DXConstantTable_GetSamplerIndex returned wrong index: Got %d, expected 0\n", index);
1433
1434     index = ID3DXConstantTable_GetSamplerIndex(ctable, "sampler2");
1435     ok(index == 3, "ID3DXConstantTable_GetSamplerIndex returned wrong index: Got %d, expected 3\n", index);
1436
1437     index = ID3DXConstantTable_GetSamplerIndex(ctable, "nonexistent");
1438     ok(index == -1, "ID3DXConstantTable_GetSamplerIndex found nonexistent sampler: Got %d\n",
1439             index);
1440
1441     index = ID3DXConstantTable_GetSamplerIndex(ctable, "notsampler");
1442     ok(index == -1, "ID3DXConstantTable_GetSamplerIndex succeeded on non-sampler constant: Got %d\n",
1443             index);
1444
1445     refcnt = ID3DXConstantTable_Release(ctable);
1446     ok(refcnt == 0, "The ID3DXConstantTable reference count was %u, should be 0\n", refcnt);
1447 }
1448
1449 /*
1450  * fxc.exe /Tps_3_0
1451  */
1452 #if 0
1453 sampler s;
1454 sampler1D s1D;
1455 sampler2D s2D;
1456 sampler3D s3D;
1457 samplerCUBE scube;
1458 float4 init;
1459 float4 main(float3 tex : TEXCOORD0) : COLOR
1460 {
1461     float4 tmp = init;
1462     tmp = tmp + tex1D(s1D, tex.x);
1463     tmp = tmp + tex1D(s1D, tex.y);
1464     tmp = tmp + tex3D(s3D, tex.xyz);
1465     tmp = tmp + tex1D(s, tex.x);
1466     tmp = tmp + tex2D(s2D, tex.xy);
1467     tmp = tmp + texCUBE(scube, tex.xyz);
1468     return tmp;
1469 }
1470 #endif
1471 static const DWORD get_shader_samplers_blob[] =
1472 {
1473     0xffff0300,                                                             /* ps_3_0                        */
1474     0x0054fffe, FCC_CTAB,                                                   /* CTAB comment                  */
1475     0x0000001c, 0x0000011b, 0xffff0300, 0x00000006, 0x0000001c, 0x00000100, /* Header                        */
1476     0x00000114,
1477     0x00000094, 0x00000002, 0x00000001, 0x0000009c, 0x00000000,             /* Constant 1 desc (init)        */
1478     0x000000ac, 0x00040003, 0x00000001, 0x000000b0, 0x00000000,             /* Constant 2 desc (s)           */
1479     0x000000c0, 0x00000003, 0x00000001, 0x000000c4, 0x00000000,             /* Constant 3 desc (s1D)         */
1480     0x000000d4, 0x00010003, 0x00000001, 0x000000d8, 0x00000000,             /* Constant 4 desc (s2D)         */
1481     0x000000e8, 0x00030003, 0x00000001, 0x000000ec, 0x00000000,             /* Constant 5 desc (s3D)         */
1482     0x000000fc, 0x00020003, 0x00000001, 0x00000104, 0x00000000,             /* Constant 6 desc (scube)       */
1483     0x74696e69, 0xababab00,                                                 /* Constant 1 name               */
1484     0x00030001, 0x00040001, 0x00000001, 0x00000000,                         /* Constant 1 type desc          */
1485     0xabab0073,                                                             /* Constant 2 name               */
1486     0x000c0004, 0x00010001, 0x00000001, 0x00000000,                         /* Constant 2 type desc          */
1487     0x00443173,                                                             /* Constant 3 name               */
1488     0x000b0004, 0x00010001, 0x00000001, 0x00000000,                         /* Constant 3 type desc          */
1489     0x00443273,                                                             /* Constant 4 name               */
1490     0x000c0004, 0x00010001, 0x00000001, 0x00000000,                         /* Constant 4 type desc          */
1491     0x00443373,                                                             /* Constant 5 name               */
1492     0x000d0004, 0x00010001, 0x00000001, 0x00000000,                         /* Constant 5 type desc          */
1493     0x62756373, 0xabab0065,                                                 /* Constant 6 name               */
1494     0x000e0004, 0x00010001, 0x00000001, 0x00000000,                         /* Constant 6 type desc          */
1495     0x335f7370, 0x4d00305f, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, /* Target/Creator name string    */
1496     0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072, 0x392e3932,
1497     0x332e3235, 0x00313131,
1498     0x0200001f, 0x80000005, 0x90070000, 0x0200001f, 0x90000000, 0xa00f0800, /* shader                        */
1499     0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, 0x98000000, 0xa00f0802,
1500     0x0200001f, 0xa0000000, 0xa00f0803, 0x0200001f, 0x90000000, 0xa00f0804,
1501     0x03000042, 0x800f0000, 0x90e40000, 0xa0e40800, 0x03000002, 0x800f0000,
1502     0x80e40000, 0xa0e40000, 0x03000042, 0x800f0001, 0x90550000, 0xa0e40800,
1503     0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x03000042, 0x800f0001,
1504     0x90e40000, 0xa0e40803, 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001,
1505     0x03000042, 0x800f0001, 0x90e40000, 0xa0e40804, 0x03000002, 0x800f0000,
1506     0x80e40000, 0x80e40001, 0x03000042, 0x800f0001, 0x90e40000, 0xa0e40801,
1507     0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x03000042, 0x800f0001,
1508     0x90e40000, 0xa0e40802, 0x03000002, 0x800f0800, 0x80e40000, 0x80e40001,
1509     0x0000ffff,                                                             /* END                           */
1510 };
1511
1512 static void test_get_shader_samplers(void)
1513 {
1514     LPCSTR samplers[16] = {NULL}; /* maximum number of sampler registers v/ps 3.0 = 16 */
1515     LPCSTR sampler_orig;
1516     UINT count = 2;
1517     HRESULT hr;
1518
1519 #if 0
1520     /* crashes if bytecode is NULL */
1521     hr = D3DXGetShaderSamplers(NULL, NULL, &count);
1522     ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
1523 #endif
1524
1525     hr = D3DXGetShaderSamplers(get_shader_samplers_blob, NULL, NULL);
1526     ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
1527
1528     samplers[5] = "dummy";
1529
1530     hr = D3DXGetShaderSamplers(get_shader_samplers_blob, samplers, NULL);
1531     ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
1532
1533     /* check that sampler points to shader blob */
1534     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x2E];
1535     ok(sampler_orig == samplers[0], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[0], sampler_orig);
1536
1537     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x33];
1538     ok(sampler_orig == samplers[1], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[1], sampler_orig);
1539
1540     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x38];
1541     ok(sampler_orig == samplers[2], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[2], sampler_orig);
1542
1543     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x3D];
1544     ok(sampler_orig == samplers[3], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[3], sampler_orig);
1545
1546     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x42];
1547     ok(sampler_orig == samplers[4], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[4], sampler_orig);
1548
1549     ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy");
1550
1551     /* reset samplers */
1552     memset(samplers, 0, sizeof(samplers));
1553     samplers[5] = "dummy";
1554
1555     hr = D3DXGetShaderSamplers(get_shader_samplers_blob, NULL, &count);
1556     ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
1557     ok(count == 5, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 5);
1558
1559     hr = D3DXGetShaderSamplers(get_shader_samplers_blob, samplers, &count);
1560     ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
1561     ok(count == 5, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 5);
1562
1563     /* check that sampler points to shader blob */
1564     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x2E];
1565     ok(sampler_orig == samplers[0], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[0], sampler_orig);
1566
1567     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x33];
1568     ok(sampler_orig == samplers[1], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[1], sampler_orig);
1569
1570     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x38];
1571     ok(sampler_orig == samplers[2], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[2], sampler_orig);
1572
1573     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x3D];
1574     ok(sampler_orig == samplers[3], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[3], sampler_orig);
1575
1576     sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x42];
1577     ok(sampler_orig == samplers[4], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[4], sampler_orig);
1578
1579     ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy");
1580
1581     /* check without ctab */
1582     hr = D3DXGetShaderSamplers(simple_vs, samplers, &count);
1583     ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
1584     ok(count == 0, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 0);
1585
1586     /* check invalid ctab */
1587     hr = D3DXGetShaderSamplers(shader_with_invalid_ctab, samplers, &count);
1588     ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
1589     ok(count == 0, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 0);
1590 }
1591
1592 /*
1593  * fxc.exe /Tvs_3_0
1594  */
1595 #if 0
1596 float f = {1.1f}, f_2[2] = {2.1f, 2.2f};
1597 struct {float f; int i;} s = {3.1f, 31},
1598 s_2[2] = {{4.1f, 41}, {4.2f, 42}},
1599 s_3[3] = {{5.1f, 51}, {5.2f, 52}, {5.3f, 53}};
1600 struct {int i1; int i2; float2 f_2; row_major float3x1 r[2];}
1601 p[2] = {{11, 12, {13.1, 14.1}, {{3.11, 3.21, 3.31}, {3.41, 3.51, 3.61}}},
1602         {15, 16, {17.1, 18.1}, {{4.11, 4.21, 4.31}, {4.41, 4.51, 4.61}}}};
1603 int i[1] = {6};
1604 float2x3 f23[2] = {{0.11, 0.21, 0.31, 0.41, 0.51, 0.61}, {0.12, 0.22, 0.32, 0.42, 0.52, 0.62}};
1605 float3x2 f32[2] = {{1.11, 1.21, 1.31, 1.41, 1.51, 1.61}, {1.12, 1.22, 1.32, 1.42, 1.52, 1.62}};
1606 float3 v[2] = {{2.11, 2.21, 2.31}, {2.41, 2.51, 2.61}};
1607 row_major float3x1 r31[2] = {{3.11, 3.21, 3.31}, {3.41, 3.51, 3.61}};
1608 row_major float1x3 r13[2] = {{4.11, 4.21, 4.31}, {4.41, 4.51, 4.61}};
1609 float4 main(float4 pos : POSITION) : POSITION
1610 {
1611     float4 tmp = 0.0f;
1612     tmp.zyw = v[1] + r13[1] + r31[1] + p[1].r[1];
1613     tmp.x += f * f_2[1] * pos.x * p[1].f_2.y;
1614     tmp.y += s.f * pos.y * s_2[0].i;
1615     tmp.z += s_3[0].f * pos.z * s_3[2].f * i[0] * f23[1]._11 * f32[1]._32;
1616     return tmp;
1617 }
1618 #endif
1619 static const DWORD test_get_shader_constant_variables_blob[] =
1620 {
1621 0xfffe0300, 0x0185fffe, 0x42415443, 0x0000001c, 0x000005df, 0xfffe0300, 0x0000000c, 0x0000001c,
1622 0x00000100, 0x000005d8, 0x0000010c, 0x002d0002, 0x00000001, 0x00000110, 0x00000120, 0x00000130,
1623 0x001d0002, 0x00000004, 0x00000134, 0x00000144, 0x000001a4, 0x00210002, 0x00000004, 0x000001a8,
1624 0x000001b8, 0x000001f8, 0x00250002, 0x00000002, 0x000001fc, 0x0000020c, 0x0000022c, 0x002f0002,
1625 0x00000001, 0x00000230, 0x00000240, 0x00000250, 0x00000002, 0x00000012, 0x000002b0, 0x000002c0,
1626 0x000003e0, 0x002b0002, 0x00000002, 0x000003e4, 0x000003f4, 0x00000414, 0x00120002, 0x00000006,
1627 0x00000418, 0x00000428, 0x00000488, 0x002e0002, 0x00000001, 0x000004ac, 0x000004bc, 0x000004dc,
1628 0x00270002, 0x00000002, 0x000004e0, 0x000004f0, 0x00000530, 0x00180002, 0x00000005, 0x00000534,
1629 0x00000544, 0x000005a4, 0x00290002, 0x00000002, 0x000005a8, 0x000005b8, 0xabab0066, 0x00030000,
1630 0x00010001, 0x00000001, 0x00000000, 0x3f8ccccd, 0x00000000, 0x00000000, 0x00000000, 0x00333266,
1631 0x00030003, 0x00030002, 0x00000002, 0x00000000, 0x3de147ae, 0x3ed1eb85, 0x00000000, 0x00000000,
1632 0x3e570a3d, 0x3f028f5c, 0x00000000, 0x00000000, 0x3e9eb852, 0x3f1c28f6, 0x00000000, 0x00000000,
1633 0x3df5c28f, 0x3ed70a3d, 0x00000000, 0x00000000, 0x3e6147ae, 0x3f051eb8, 0x00000000, 0x00000000,
1634 0x3ea3d70a, 0x3f1eb852, 0x00000000, 0x00000000, 0x00323366, 0x00030003, 0x00020003, 0x00000002,
1635 0x00000000, 0x3f8e147b, 0x3fa7ae14, 0x3fc147ae, 0x00000000, 0x3f9ae148, 0x3fb47ae1, 0x3fce147b,
1636 0x00000000, 0x3f8f5c29, 0x3fa8f5c3, 0x3fc28f5c, 0x00000000, 0x3f9c28f6, 0x3fb5c28f, 0x3fcf5c29,
1637 0x00000000, 0x00325f66, 0x00030000, 0x00010001, 0x00000002, 0x00000000, 0x40066666, 0x00000000,
1638 0x00000000, 0x00000000, 0x400ccccd, 0x00000000, 0x00000000, 0x00000000, 0xabab0069, 0x00020000,
1639 0x00010001, 0x00000001, 0x00000000, 0x40c00000, 0x00000000, 0x00000000, 0x00000000, 0x31690070,
1640 0xababab00, 0x00020000, 0x00010001, 0x00000001, 0x00000000, 0xab003269, 0x00030001, 0x00020001,
1641 0x00000001, 0x00000000, 0xabab0072, 0x00030002, 0x00010003, 0x00000002, 0x00000000, 0x00000252,
1642 0x00000258, 0x00000268, 0x00000258, 0x000001f8, 0x0000026c, 0x0000027c, 0x00000280, 0x00000005,
1643 0x000a0001, 0x00040002, 0x00000290, 0x41300000, 0x00000000, 0x00000000, 0x00000000, 0x41400000,
1644 0x00000000, 0x00000000, 0x00000000, 0x4151999a, 0x4161999a, 0x00000000, 0x00000000, 0x40470a3d,
1645 0x00000000, 0x00000000, 0x00000000, 0x404d70a4, 0x00000000, 0x00000000, 0x00000000, 0x4053d70a,
1646 0x00000000, 0x00000000, 0x00000000, 0x405a3d71, 0x00000000, 0x00000000, 0x00000000, 0x4060a3d7,
1647 0x00000000, 0x00000000, 0x00000000, 0x40670a3d, 0x00000000, 0x00000000, 0x00000000, 0x41700000,
1648 0x00000000, 0x00000000, 0x00000000, 0x41800000, 0x00000000, 0x00000000, 0x00000000, 0x4188cccd,
1649 0x4190cccd, 0x00000000, 0x00000000, 0x4083851f, 0x00000000, 0x00000000, 0x00000000, 0x4086b852,
1650 0x00000000, 0x00000000, 0x00000000, 0x4089eb85, 0x00000000, 0x00000000, 0x00000000, 0x408d1eb8,
1651 0x00000000, 0x00000000, 0x00000000, 0x409051ec, 0x00000000, 0x00000000, 0x00000000, 0x4093851f,
1652 0x00000000, 0x00000000, 0x00000000, 0x00333172, 0x00030002, 0x00030001, 0x00000002, 0x00000000,
1653 0x4083851f, 0x4086b852, 0x4089eb85, 0x00000000, 0x408d1eb8, 0x409051ec, 0x4093851f, 0x00000000,
1654 0x00313372, 0x00030002, 0x00010003, 0x00000002, 0x00000000, 0x40470a3d, 0x00000000, 0x00000000,
1655 0x00000000, 0x404d70a4, 0x00000000, 0x00000000, 0x00000000, 0x4053d70a, 0x00000000, 0x00000000,
1656 0x00000000, 0x405a3d71, 0x00000000, 0x00000000, 0x00000000, 0x4060a3d7, 0x00000000, 0x00000000,
1657 0x00000000, 0x40670a3d, 0x00000000, 0x00000000, 0x00000000, 0xabab0073, 0x00030000, 0x00010001,
1658 0x00000001, 0x00000000, 0x0000010c, 0x0000048c, 0x0000022c, 0x00000258, 0x00000005, 0x00020001,
1659 0x00020001, 0x0000049c, 0x40466666, 0x00000000, 0x00000000, 0x00000000, 0x41f80000, 0x00000000,
1660 0x00000000, 0x00000000, 0x00325f73, 0x00000005, 0x00020001, 0x00020002, 0x0000049c, 0x40833333,
1661 0x00000000, 0x00000000, 0x00000000, 0x42240000, 0x00000000, 0x00000000, 0x00000000, 0x40866666,
1662 0x00000000, 0x00000000, 0x00000000, 0x42280000, 0x00000000, 0x00000000, 0x00000000, 0x00335f73,
1663 0x00000005, 0x00020001, 0x00020003, 0x0000049c, 0x40a33333, 0x00000000, 0x00000000, 0x00000000,
1664 0x424c0000, 0x00000000, 0x00000000, 0x00000000, 0x40a66666, 0x00000000, 0x00000000, 0x00000000,
1665 0x42500000, 0x00000000, 0x00000000, 0x00000000, 0x40a9999a, 0x00000000, 0x00000000, 0x00000000,
1666 0x42540000, 0x00000000, 0x00000000, 0x00000000, 0xabab0076, 0x00030001, 0x00030001, 0x00000002,
1667 0x00000000, 0x40070a3d, 0x400d70a4, 0x4013d70a, 0x00000000, 0x401a3d71, 0x4020a3d7, 0x40270a3d,
1668 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
1669 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072, 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f,
1670 0x80000000, 0x900f0000, 0x0200001f, 0x80000000, 0xe00f0000, 0x02000001, 0x80070000, 0xa0e4002a,
1671 0x03000002, 0x80070000, 0x80e40000, 0xa0e4002c, 0x03000002, 0x80040000, 0x80aa0000, 0xa0000017,
1672 0x03000002, 0xe0080000, 0x80aa0000, 0xa0000011, 0x02000001, 0x80010001, 0xa000002d, 0x03000005,
1673 0x80040000, 0x80000001, 0xa0000026, 0x03000005, 0x80040000, 0x80aa0000, 0x90000000, 0x03000005,
1674 0xe0010000, 0x80aa0000, 0xa055000b, 0x03000002, 0x80020000, 0x80550000, 0xa0000016, 0x03000002,
1675 0x80010000, 0x80000000, 0xa0000015, 0x03000002, 0x80010000, 0x80000000, 0xa000000f, 0x03000002,
1676 0x80020000, 0x80550000, 0xa0000010, 0x03000005, 0x80040000, 0xa000002e, 0x90550000, 0x04000004,
1677 0xe0020000, 0x80aa0000, 0xa0000028, 0x80550000, 0x03000005, 0x80020000, 0xa0000018, 0x90aa0000,
1678 0x03000005, 0x80020000, 0x80550000, 0xa000001c, 0x03000005, 0x80020000, 0x80550000, 0xa000002f,
1679 0x03000005, 0x80020000, 0x80550000, 0xa0000020, 0x04000004, 0xe0040000, 0x80550000, 0xa0aa0024,
1680 0x80000000, 0x0000ffff,
1681 };
1682
1683 const struct {
1684     LPCSTR fullname;
1685     D3DXCONSTANT_DESC desc;
1686     UINT ctaboffset;
1687 }
1688 test_get_shader_constant_variables_data[] =
1689 {
1690     {"f",         {"f",   D3DXRS_FLOAT4, 45,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL},  72},
1691     {"f23",       {"f23", D3DXRS_FLOAT4, 29,  4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 2,  3, 2, 0, 48, NULL},  81},
1692     {"f23[0]",    {"f23", D3DXRS_FLOAT4, 29,  3, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 2,  3, 1, 0, 24, NULL},  81},
1693     {"f23[1]",    {"f23", D3DXRS_FLOAT4, 32,  1, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 2,  3, 1, 0, 24, NULL},  93},
1694     {"f32",       {"f32", D3DXRS_FLOAT4, 33,  4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3,  2, 2, 0, 48, NULL}, 110},
1695     {"f32[0]",    {"f32", D3DXRS_FLOAT4, 33,  2, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3,  2, 1, 0, 24, NULL}, 110},
1696     {"f32[1]",    {"f32", D3DXRS_FLOAT4, 35,  2, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3,  2, 1, 0, 24, NULL}, 118},
1697     {"f_2",       {"f_2", D3DXRS_FLOAT4, 37,  2, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 2, 0,  8, NULL}, 131},
1698     {"f_2[0]",    {"f_2", D3DXRS_FLOAT4, 37,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 131},
1699     {"f_2[1]",    {"f_2", D3DXRS_FLOAT4, 38,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 135},
1700     {"i",         {"i",   D3DXRS_FLOAT4, 47,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 144},
1701     {"i[0]",      {"i",   D3DXRS_FLOAT4, 47,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 144},
1702     {"p",         {"p",   D3DXRS_FLOAT4,  0, 18, D3DXPC_STRUCT,         D3DXPT_VOID,  1, 10, 2, 4, 80, NULL}, 176},
1703     {"p[0]",      {"p",   D3DXRS_FLOAT4,  0,  9, D3DXPC_STRUCT,         D3DXPT_VOID,  1, 10, 1, 4, 40, NULL}, 176},
1704     {"p[0].i1",   {"i1",  D3DXRS_FLOAT4,  0,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 176},
1705     {"p[0].i2",   {"i2",  D3DXRS_FLOAT4,  1,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 180},
1706     {"p[0].f_2",  {"f_2", D3DXRS_FLOAT4,  2,  1, D3DXPC_VECTOR,         D3DXPT_FLOAT, 1,  2, 1, 0,  8, NULL}, 184},
1707     {"p[0].r",    {"r",   D3DXRS_FLOAT4,  3,  6, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 2, 0, 24, NULL}, 188},
1708     {"p[0].r[0]", {"r",   D3DXRS_FLOAT4,  3,  3, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 1, 0, 12, NULL}, 188},
1709     {"p[0].r[1]", {"r",   D3DXRS_FLOAT4,  6,  3, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 1, 0, 12, NULL}, 200},
1710     {"p[1]",      {"p",   D3DXRS_FLOAT4,  9,  9, D3DXPC_STRUCT,         D3DXPT_VOID,  1, 10, 1, 4, 40, NULL}, 212},
1711     {"p[1].i1",   {"i1",  D3DXRS_FLOAT4,  9,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 212},
1712     {"p[1].i2",   {"i2",  D3DXRS_FLOAT4, 10,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 216},
1713     {"p[1].f_2",  {"f_2", D3DXRS_FLOAT4, 11,  1, D3DXPC_VECTOR,         D3DXPT_FLOAT, 1,  2, 1, 0,  8, NULL}, 220},
1714     {"p[1].r",    {"r",   D3DXRS_FLOAT4, 12,  6, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 2, 0, 24, NULL}, 224},
1715     {"p[1].r[0]", {"r",   D3DXRS_FLOAT4, 12,  3, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 1, 0, 12, NULL}, 224},
1716     {"p[1].r[1]", {"r",   D3DXRS_FLOAT4, 15,  3, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 1, 0, 12, NULL}, 236},
1717     {"r13",       {"r13", D3DXRS_FLOAT4, 43,  2, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 1,  3, 2, 0, 24, NULL}, 253},
1718     {"r13[0]",    {"r13", D3DXRS_FLOAT4, 43,  1, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 1,  3, 1, 0, 12, NULL}, 253},
1719     {"r13[1]",    {"r13", D3DXRS_FLOAT4, 44,  1, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 1,  3, 1, 0, 12, NULL}, 257},
1720     {"r31",       {"r31", D3DXRS_FLOAT4, 18,  6, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 2, 0, 24, NULL}, 266},
1721     {"r31[0]",    {"r31", D3DXRS_FLOAT4, 18,  3, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 1, 0, 12, NULL}, 266},
1722     {"r31[1]",    {"r31", D3DXRS_FLOAT4, 21,  3, D3DXPC_MATRIX_ROWS,    D3DXPT_FLOAT, 3,  1, 1, 0, 12, NULL}, 278},
1723     {"s",         {"s",   D3DXRS_FLOAT4, 46,  1, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 1, 2,  8, NULL}, 303},
1724     {"s.f",       {"f",   D3DXRS_FLOAT4, 46,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 303},
1725     {"s.i",       {"i",   D3DXRS_FLOAT4, 47,  0, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 307},
1726     {"s_2",       {"s_2", D3DXRS_FLOAT4, 39,  2, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 2, 2, 16, NULL}, 316},
1727     {"s_2[0]",    {"s_2", D3DXRS_FLOAT4, 39,  2, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 1, 2,  8, NULL}, 316},
1728     {"s_2[0].f",  {"f",   D3DXRS_FLOAT4, 39,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 316},
1729     {"s_2[0].i",  {"i",   D3DXRS_FLOAT4, 40,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 320},
1730     {"s_2[1]",    {"s_2", D3DXRS_FLOAT4, 41,  0, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 1, 2,  8, NULL}, 324},
1731     {"s_2[1].f",  {"f",   D3DXRS_FLOAT4, 41,  0, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 324},
1732     {"s_2[1].i",  {"i",   D3DXRS_FLOAT4, 41,  0, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 328},
1733     {"s_3",       {"s_3", D3DXRS_FLOAT4, 24,  5, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 3, 2, 24, NULL}, 337},
1734     {"s_3[0]",    {"s_3", D3DXRS_FLOAT4, 24,  2, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 1, 2,  8, NULL}, 337},
1735     {"s_3[0].f",  {"f",   D3DXRS_FLOAT4, 24,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 337},
1736     {"s_3[0].i",  {"i",   D3DXRS_FLOAT4, 25,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 341},
1737     {"s_3[1]",    {"s_3", D3DXRS_FLOAT4, 26,  2, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 1, 2,  8, NULL}, 345},
1738     {"s_3[1].f",  {"f",   D3DXRS_FLOAT4, 26,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 345},
1739     {"s_3[1].i",  {"i",   D3DXRS_FLOAT4, 27,  1, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 349},
1740     {"s_3[2]",    {"s_3", D3DXRS_FLOAT4, 28,  1, D3DXPC_STRUCT,         D3DXPT_VOID,  1,  2, 1, 2,  8, NULL}, 353},
1741     {"s_3[2].f",  {"f",   D3DXRS_FLOAT4, 28,  1, D3DXPC_SCALAR,         D3DXPT_FLOAT, 1,  1, 1, 0,  4, NULL}, 353},
1742     {"s_3[2].i",  {"i",   D3DXRS_FLOAT4, 29,  0, D3DXPC_SCALAR,         D3DXPT_INT,   1,  1, 1, 0,  4, NULL}, 357},
1743     {"v",         {"v",   D3DXRS_FLOAT4, 41,  2, D3DXPC_VECTOR,         D3DXPT_FLOAT, 1,  3, 2, 0, 24, NULL}, 366},
1744     {"v[0]",      {"v",   D3DXRS_FLOAT4, 41,  1, D3DXPC_VECTOR,         D3DXPT_FLOAT, 1,  3, 1, 0, 12, NULL}, 366},
1745     {"v[1]",      {"v",   D3DXRS_FLOAT4, 42,  1, D3DXPC_VECTOR,         D3DXPT_FLOAT, 1,  3, 1, 0, 12, NULL}, 370},
1746 };
1747
1748 static void test_get_shader_constant_variables(void)
1749 {
1750     ID3DXConstantTable *ctable;
1751     HRESULT hr;
1752     ULONG count;
1753     UINT i;
1754     UINT nr = 1;
1755     D3DXHANDLE constant, element;
1756     D3DXCONSTANT_DESC desc;
1757     DWORD *ctab;
1758
1759     hr = D3DXGetShaderConstantTable(test_get_shader_constant_variables_blob, &ctable);
1760     ok(hr == D3D_OK, "D3DXGetShaderConstantTable failed, got %08x, expected %08x\n", hr, D3D_OK);
1761
1762     ctab = ID3DXConstantTable_GetBufferPointer(ctable);
1763     ok(ctab[0] == test_get_shader_constant_variables_blob[3], "ID3DXConstantTable_GetBufferPointer failed\n");
1764
1765     for (i = 0; i < sizeof(test_get_shader_constant_variables_data) / sizeof(*test_get_shader_constant_variables_data); ++i)
1766     {
1767         LPCSTR fullname = test_get_shader_constant_variables_data[i].fullname;
1768         const D3DXCONSTANT_DESC *expected_desc = &test_get_shader_constant_variables_data[i].desc;
1769         UINT ctaboffset = test_get_shader_constant_variables_data[i].ctaboffset;
1770
1771         constant = ID3DXConstantTable_GetConstantByName(ctable, NULL, fullname);
1772         ok(constant != NULL, "GetConstantByName \"%s\" failed\n", fullname);
1773
1774         hr = ID3DXConstantTable_GetConstantDesc(ctable, constant, &desc, &nr);
1775         ok(hr == D3D_OK, "GetConstantDesc \"%s\" failed, got %08x, expected %08x\n", fullname, hr, D3D_OK);
1776
1777         ok(!strcmp(expected_desc->Name, desc.Name), "GetConstantDesc \"%s\" failed, got \"%s\", expected \"%s\"\n",
1778                 fullname, desc.Name, expected_desc->Name);
1779         ok(expected_desc->RegisterSet == desc.RegisterSet, "GetConstantDesc \"%s\" failed, got %#x, expected %#x\n",
1780                 fullname, desc.RegisterSet, expected_desc->RegisterSet);
1781         ok(expected_desc->RegisterIndex == desc.RegisterIndex, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1782                 fullname, desc.RegisterIndex, expected_desc->RegisterIndex);
1783         ok(expected_desc->RegisterCount == desc.RegisterCount, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1784                 fullname, desc.RegisterCount, expected_desc->RegisterCount);
1785         ok(expected_desc->Class == desc.Class, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1786                 fullname, desc.Class, expected_desc->Class);
1787         ok(expected_desc->Type == desc.Type, "GetConstantDesc \"%s\" failed, got %#x, expected %#x\n",
1788                 fullname, desc.Type, expected_desc->Type);
1789         ok(expected_desc->Rows == desc.Rows, "GetConstantDesc \"%s\" failed, got %#x, expected %#x\n",
1790                 fullname, desc.Rows, expected_desc->Rows);
1791         ok(expected_desc->Columns == desc.Columns, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1792                 fullname, desc.Columns, expected_desc->Columns);
1793         ok(expected_desc->Elements == desc.Elements, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1794                 fullname, desc.Elements, expected_desc->Elements);
1795         ok(expected_desc->StructMembers == desc.StructMembers, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1796                 fullname, desc.StructMembers, expected_desc->StructMembers);
1797         ok(expected_desc->Bytes == desc.Bytes, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1798                 fullname, desc.Bytes, expected_desc->Bytes);
1799         ok(ctaboffset == (DWORD *)desc.DefaultValue - ctab, "GetConstantDesc \"%s\" failed, got %u, expected %u\n",
1800            fullname, (UINT)((DWORD *)desc.DefaultValue - ctab), ctaboffset);
1801     }
1802
1803     element = ID3DXConstantTable_GetConstantElement(ctable, NULL, 0);
1804     ok(element == NULL, "GetConstantElement failed\n");
1805
1806     constant = ID3DXConstantTable_GetConstantByName(ctable, NULL, "i");
1807     ok(constant != NULL, "GetConstantByName failed\n");
1808
1809     element = ID3DXConstantTable_GetConstantByName(ctable, NULL, "i[0]");
1810     ok(constant == element, "GetConstantByName failed, got %p, expected %p\n", element, constant);
1811
1812     element = ID3DXConstantTable_GetConstantElement(ctable, "i", 0);
1813     ok(element == constant, "GetConstantElement failed, got %p, expected %p\n", element, constant);
1814
1815     constant = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f");
1816     ok(constant != NULL, "GetConstantByName failed\n");
1817
1818     element = ID3DXConstantTable_GetConstant(ctable, NULL, 0);
1819     ok(element == constant, "GetConstant failed, got %p, expected %p\n", element, constant);
1820
1821     element = ID3DXConstantTable_GetConstant(ctable, "invalid", 0);
1822     ok(element == NULL, "GetConstant failed\n");
1823
1824     element = ID3DXConstantTable_GetConstant(ctable, "f", 0);
1825     ok(element == NULL, "GetConstant failed\n");
1826
1827     element = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f[0]");
1828     ok(constant == element, "GetConstantByName failed, got %p, expected %p\n", element, constant);
1829
1830     element = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f[1]");
1831     ok(NULL == element, "GetConstantByName failed\n");
1832
1833     element = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f[0][0]");
1834     ok(constant == element, "GetConstantByName failed, got %p, expected %p\n", element, constant);
1835
1836     element = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f.");
1837     ok(element == NULL, "GetConstantByName failed\n");
1838
1839     element = ID3DXConstantTable_GetConstantElement(ctable, "f", 0);
1840     ok(element == constant, "GetConstantElement failed, got %p, expected %p\n", element, constant);
1841
1842     element = ID3DXConstantTable_GetConstantElement(ctable, "f", 1);
1843     ok(element == NULL, "GetConstantElement failed\n");
1844
1845     constant = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f_2[0]");
1846     ok(constant != NULL, "GetConstantByName failed\n");
1847
1848     element = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f_2");
1849     ok(element != constant, "GetConstantByName failed, got %p, expected %p\n", element, constant);
1850
1851     element = ID3DXConstantTable_GetConstantElement(ctable, "f_2", 0);
1852     ok(element == constant, "GetConstantElement failed, got %p, expected %p\n", element, constant);
1853
1854     constant = ID3DXConstantTable_GetConstantByName(ctable, NULL, "f_2[1]");
1855     ok(constant != NULL, "GetConstantByName failed\n");
1856
1857     element = ID3DXConstantTable_GetConstantElement(ctable, "f_2", 1);
1858     ok(element == constant, "GetConstantElement failed, got %p, expected %p\n", element, constant);
1859
1860     constant = ID3DXConstantTable_GetConstantByName(ctable, NULL, "s_2[0].f");
1861     ok(constant != NULL, "GetConstantByName failed\n");
1862
1863     element = ID3DXConstantTable_GetConstant(ctable, "s_2[0]", 0);
1864     ok(element == constant, "GetConstant failed, got %p, expected %p\n", element, constant);
1865
1866     element = ID3DXConstantTable_GetConstantByName(ctable, "s_2[0]", "f");
1867     ok(element == constant, "GetConstantByName failed, got %p, expected %p\n", element, constant);
1868
1869     element = ID3DXConstantTable_GetConstantByName(ctable, "s_2[0]", "invalid");
1870     ok(element == NULL, "GetConstantByName failed\n");
1871
1872     constant = ID3DXConstantTable_GetConstantByName(ctable, NULL, "s_2[0]");
1873     ok(constant != NULL, "GetConstantByName failed\n");
1874
1875     element = ID3DXConstantTable_GetConstantElement(ctable, "s_2[0]", 0);
1876     ok(constant == element, "GetConstantByName failed, got %p, expected %p\n", element, constant);
1877
1878     count = ID3DXConstantTable_Release(ctable);
1879     ok(count == 0, "Release failed, got %u, expected %u\n", count, 0);
1880 }
1881
1882 START_TEST(shader)
1883 {
1884     test_get_shader_size();
1885     test_get_shader_version();
1886     test_find_shader_comment();
1887     test_get_shader_constant_table_ex();
1888     test_constant_tables();
1889     test_setting_constants();
1890     test_get_sampler_index();
1891     test_get_shader_samplers();
1892     test_get_shader_constant_variables();
1893 }