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