d3dx9_36/tests: Extended ID3DXConstantTable tests.
[wine.git] / dlls / d3dx9_36 / tests / shader.c
bloba4bbc22c629a756e3851dd6011cf0f9abe77a810
1 /*
2 * Copyright 2008 Luis Busquets
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wine/test.h"
20 #include "d3dx9.h"
22 static const DWORD simple_vs[] = {
23 0xfffe0101, /* vs_1_1 */
24 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
25 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
26 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
27 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
28 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
29 0x0000ffff}; /* END */
31 static const DWORD simple_ps[] = {
32 0xffff0101, /* ps_1_1 */
33 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
34 0x00000042, 0xb00f0000, /* tex t0 */
35 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
36 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
37 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
38 0x0000ffff}; /* END */
40 #define FCC_TEXT MAKEFOURCC('T','E','X','T')
41 #define FCC_CTAB MAKEFOURCC('C','T','A','B')
43 static const DWORD shader_with_ctab[] = {
44 0xfffe0300, /* vs_3_0 */
45 0x0002fffe, FCC_TEXT, 0x00000000, /* TEXT comment */
46 0x0008fffe, FCC_CTAB, 0x0000001c, 0x00000010, 0xfffe0300, 0x00000000, /* CTAB comment */
47 0x00000000, 0x00000000, 0x00000000,
48 0x0004fffe, FCC_TEXT, 0x00000000, 0x00000000, 0x00000000, /* TEXT comment */
49 0x0000ffff}; /* END */
51 static const DWORD shader_with_invalid_ctab[] = {
52 0xfffe0300, /* vs_3_0 */
53 0x0005fffe, FCC_CTAB, /* CTAB comment */
54 0x0000001c, 0x000000a9, 0xfffe0300,
55 0x00000000, 0x00000000,
56 0x0000ffff}; /* END */
58 static const DWORD shader_with_ctab_constants[] = {
59 0xfffe0300, /* vs_3_0 */
60 0x002efffe, FCC_CTAB, /* CTAB comment */
61 0x0000001c, 0x000000a4, 0xfffe0300, 0x00000003, 0x0000001c, 0x20008100, /* Header */
62 0x0000009c,
63 0x00000058, 0x00070002, 0x00000001, 0x00000064, 0x00000000, /* Constant 1 desc */
64 0x00000074, 0x00000002, 0x00000004, 0x00000080, 0x00000000, /* Constant 2 desc */
65 0x00000090, 0x00040002, 0x00000003, 0x00000080, 0x00000000, /* Constant 3 desc */
66 0x736e6f43, 0x746e6174, 0xabab0031, /* Constant 1 name string */
67 0x00030001, 0x00040001, 0x00000001, 0x00000000, /* Constant 1 type desc */
68 0x736e6f43, 0x746e6174, 0xabab0032, /* Constant 2 name string */
69 0x00030003, 0x00040004, 0x00000001, 0x00000000, /* Constant 2 & 3 type desc */
70 0x736e6f43, 0x746e6174, 0xabab0033, /* Constant 3 name string */
71 0x335f7376, 0xab00305f, /* Target name string */
72 0x656e6957, 0x6f727020, 0x7463656a, 0xababab00, /* Creator name string */
73 0x0000ffff}; /* END */
75 static const DWORD ctab_basic[] = { /* 0123456789ABCDEF */
76 0xfffe0200, 0x0052fffe, 0x42415443, 0x0000001c, /* ......R.CTAB.... */
77 0x00000113, 0xfffe0200, 0x00000006, 0x0000001c, /* ................ */
78 0x00000100, 0x0000010c, 0x00000094, 0x00080002, /* ................ */
79 0x00000001, 0x00000098, 0x00000000, 0x000000a8, /* ................ */
80 0x00060002, 0x00000001, 0x000000ac, 0x00000000, /* ................ */
81 0x000000bc, 0x00070002, 0x00000001, 0x000000c0, /* ................ */
82 0x00000000, 0x000000d0, 0x00040002, 0x00000001, /* ................ */
83 0x000000d4, 0x00000000, 0x000000e4, 0x00050002, /* ................ */
84 0x00000001, 0x000000e8, 0x00000000, 0x000000f8, /* ................ */
85 0x00000002, 0x00000004, 0x000000fc, 0x00000000, /* ................ */
86 0xabab0062, 0x00010000, 0x00010001, 0x00000001, /* b............... */
87 0x00000000, 0xabab0066, 0x00030000, 0x00010001, /* ....f........... */
88 0x00000001, 0x00000000, 0xab003466, 0x00030001, /* ........f4...... */
89 0x00040001, 0x00000001, 0x00000000, 0xabab0069, /* ............i... */
90 0x00020000, 0x00010001, 0x00000001, 0x00000000, /* ................ */
91 0xab003469, 0x00020001, 0x00040001, 0x00000001, /* i4.............. */
92 0x00000000, 0x0070766d, 0x00030003, 0x00040004, /* ....mvp......... */
93 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, /* ........vs_2_0.M */
94 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, /* icrosoft.(R).HLS */
95 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, /* L.Shader.Compile */
96 0x2e392072, 0x392e3932, 0x332e3235, 0x00313131, /* r.9.29.952.3111. */
97 0x0000ffff}; /* END */
99 static const D3DXCONSTANT_DESC ctab_basic_expected[] = {
100 {"mvp", D3DXRS_FLOAT4, 0, 4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4, 1, 0, 64, 0},
101 {"i", D3DXRS_FLOAT4, 4, 1, D3DXPC_SCALAR, D3DXPT_INT, 1, 1, 1, 0, 4, 0},
102 {"i4", D3DXRS_FLOAT4, 5, 1, D3DXPC_VECTOR, D3DXPT_INT, 1, 4, 1, 0, 16, 0},
103 {"f", D3DXRS_FLOAT4, 6, 1, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 1, 0, 4, 0},
104 {"f4", D3DXRS_FLOAT4, 7, 1, D3DXPC_VECTOR, D3DXPT_FLOAT, 1, 4, 1, 0, 16, 0}};
106 static const DWORD ctab_matrices[] = { /* 0123456789ABCDEF */
107 0xfffe0300, 0x003afffe, 0x42415443, 0x0000001c, /* ......:.CTAB.... */
108 0x000000b3, 0xfffe0300, 0x00000003, 0x0000001c, /* ................ */
109 0x00000100, 0x000000ac, 0x00000058, 0x00070002, /* ........X....... */
110 0x00000001, 0x00000064, 0x00000000, 0x00000074, /* ....d.......t... */
111 0x00000002, 0x00000004, 0x00000080, 0x00000000, /* ................ */
112 0x00000090, 0x00040002, 0x00000003, 0x0000009c, /* ................ */
113 0x00000000, 0x74616d66, 0x33786972, 0xab003178, /* ....fmatrix3x1.. */
114 0x00030003, 0x00010003, 0x00000001, 0x00000000, /* ................ */
115 0x74616d66, 0x34786972, 0xab003478, 0x00030003, /* fmatrix4x4...... */
116 0x00040004, 0x00000001, 0x00000000, 0x74616d69, /* ............imat */
117 0x32786972, 0xab003378, 0x00020003, 0x00030002, /* rix2x3.......... */
118 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, /* ........vs_3_0.M */
119 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, /* icrosoft.(R).HLS */
120 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, /* L.Shader.Compile */
121 0x2e392072, 0x392e3932, 0x332e3235, 0x00313131, /* r.9.29.952.3111. */
122 0x0000ffff}; /* END */
124 static const D3DXCONSTANT_DESC ctab_matrices_expected[] = {
125 {"fmatrix4x4", D3DXRS_FLOAT4, 0, 4, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4, 1, 0, 64, 0},
126 {"imatrix2x3", D3DXRS_FLOAT4, 4, 3, D3DXPC_MATRIX_COLUMNS, D3DXPT_INT, 2, 3, 1, 0, 24, 0},
127 {"fmatrix3x1", D3DXRS_FLOAT4, 7, 1, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 3, 1, 1, 0, 12, 0}};
129 static const DWORD ctab_arrays[] = { /* 0123456789ABCDEF */
130 0xfffe0200, 0x005cfffe, 0x42415443, 0x0000001c, /* ......\.CTAB.... */
131 0x0000013b, 0xfffe0200, 0x00000006, 0x0000001c, /* ;............... */
132 0x00000100, 0x00000134, 0x00000094, 0x000e0002, /* ....4........... */
133 0x00000002, 0x0000009c, 0x00000000, 0x000000ac, /* ................ */
134 0x00100002, 0x00000002, 0x000000b8, 0x00000000, /* ................ */
135 0x000000c8, 0x00080002, 0x00000004, 0x000000d0, /* ................ */
136 0x00000000, 0x000000e0, 0x00000002, 0x00000008, /* ................ */
137 0x000000ec, 0x00000000, 0x000000fc, 0x000c0002, /* ................ */
138 0x00000002, 0x00000108, 0x00000000, 0x00000118, /* ................ */
139 0x00120002, 0x00000001, 0x00000124, 0x00000000, /* ........$....... */
140 0x72726162, 0xab007961, 0x00010000, 0x00010001, /* barray.......... */
141 0x00000002, 0x00000000, 0x63657662, 0x61727261, /* ........bvecarra */
142 0xabab0079, 0x00010001, 0x00030001, 0x00000003, /* y............... */
143 0x00000000, 0x72726166, 0xab007961, 0x00030000, /* ....farray...... */
144 0x00010001, 0x00000004, 0x00000000, 0x78746d66, /* ............fmtx */
145 0x61727261, 0xabab0079, 0x00030003, 0x00040004, /* array........... */
146 0x00000002, 0x00000000, 0x63657666, 0x61727261, /* ........fvecarra */
147 0xabab0079, 0x00030001, 0x00040001, 0x00000002, /* y............... */
148 0x00000000, 0x63657669, 0x61727261, 0xabab0079, /* ....ivecarray... */
149 0x00020001, 0x00040001, 0x00000001, 0x00000000, /* ................ */
150 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73, /* vs_2_0.Microsoft */
151 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, /* .(R).HLSL.Shader */
152 0x6d6f4320, 0x656c6970, 0x2e392072, 0x392e3932, /* .Compiler.9.29.9 */
153 0x332e3235, 0x00313131, 0x0000ffff}; /* 52.3111. END */
155 static const D3DXCONSTANT_DESC ctab_arrays_expected[] = {
156 {"fmtxarray", D3DXRS_FLOAT4, 0, 8, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4, 2, 0, 128, 0},
157 {"farray", D3DXRS_FLOAT4, 8, 4, D3DXPC_SCALAR, D3DXPT_FLOAT, 1, 1, 4, 0, 16, 0},
158 {"fvecarray", D3DXRS_FLOAT4, 12, 2, D3DXPC_VECTOR, D3DXPT_FLOAT, 1, 4, 2, 0, 32, 0},
159 {"barray", D3DXRS_FLOAT4, 14, 2, D3DXPC_SCALAR, D3DXPT_BOOL, 1, 1, 2, 0, 8, 0},
160 {"bvecarray", D3DXRS_FLOAT4, 16, 2, D3DXPC_VECTOR, D3DXPT_BOOL, 1, 3, 3, 0, 36, 0},
161 {"ivecarray", D3DXRS_FLOAT4, 18, 1, D3DXPC_VECTOR, D3DXPT_INT, 1, 4, 1, 0, 16, 0}};
163 static void test_get_shader_size(void)
165 UINT shader_size, expected;
167 shader_size = D3DXGetShaderSize(simple_vs);
168 expected = sizeof(simple_vs);
169 ok(shader_size == expected, "Got shader size %u, expected %u\n", shader_size, expected);
171 shader_size = D3DXGetShaderSize(simple_ps);
172 expected = sizeof(simple_ps);
173 ok(shader_size == expected, "Got shader size %u, expected %u\n", shader_size, expected);
175 shader_size = D3DXGetShaderSize(NULL);
176 ok(shader_size == 0, "Got shader size %u, expected 0\n", shader_size);
179 static void test_get_shader_version(void)
181 DWORD shader_version;
183 shader_version = D3DXGetShaderVersion(simple_vs);
184 ok(shader_version == D3DVS_VERSION(1, 1), "Got shader version 0x%08x, expected 0x%08x\n",
185 shader_version, D3DVS_VERSION(1, 1));
187 shader_version = D3DXGetShaderVersion(simple_ps);
188 ok(shader_version == D3DPS_VERSION(1, 1), "Got shader version 0x%08x, expected 0x%08x\n",
189 shader_version, D3DPS_VERSION(1, 1));
191 shader_version = D3DXGetShaderVersion(NULL);
192 ok(shader_version == 0, "Got shader version 0x%08x, expected 0\n", shader_version);
195 static void test_find_shader_comment(void)
197 HRESULT hr;
198 LPCVOID data;
199 UINT size;
201 hr = D3DXFindShaderComment(NULL, MAKEFOURCC('C','T','A','B'), &data, &size);
202 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
204 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), NULL, &size);
205 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
207 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), &data, NULL);
208 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
210 hr = D3DXFindShaderComment(shader_with_ctab, 0, &data, &size);
211 ok(hr == S_FALSE, "Got result %x, expected 1 (S_FALSE)\n", hr);
213 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('X','X','X','X'), &data, &size);
214 ok(hr == S_FALSE, "Got result %x, expected 1 (S_FALSE)\n", hr);
216 hr = D3DXFindShaderComment(shader_with_ctab, MAKEFOURCC('C','T','A','B'), &data, &size);
217 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
218 ok(data == (LPCVOID)(shader_with_ctab + 6), "Got result %p, expected %p\n", data, shader_with_ctab + 6);
219 ok(size == 28, "Got result %d, expected 28\n", size);
222 static void test_get_shader_constant_table_ex(void)
224 LPD3DXCONSTANTTABLE constant_table = NULL;
225 HRESULT hr;
226 LPVOID data;
227 DWORD size;
228 D3DXCONSTANTTABLE_DESC desc;
230 hr = D3DXGetShaderConstantTableEx(NULL, 0, &constant_table);
231 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
233 /* No CTAB data */
234 hr = D3DXGetShaderConstantTableEx(simple_ps, 0, &constant_table);
235 ok(hr == D3DXERR_INVALIDDATA, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DXERR_INVALIDDATA);
237 /* With invalid CTAB data */
238 hr = D3DXGetShaderConstantTableEx(shader_with_invalid_ctab, 0, &constant_table);
239 ok(hr == D3DXERR_INVALIDDATA || broken(hr == D3D_OK), /* winxp 64-bit, w2k3 64-bit */
240 "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, D3DXERR_INVALIDDATA);
241 if (constant_table) ID3DXConstantTable_Release(constant_table);
243 hr = D3DXGetShaderConstantTableEx(shader_with_ctab, 0, &constant_table);
244 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
246 if (constant_table)
248 size = ID3DXConstantTable_GetBufferSize(constant_table);
249 ok(size == 28, "Got result %x, expected 28\n", size);
251 data = ID3DXConstantTable_GetBufferPointer(constant_table);
252 ok(!memcmp(data, shader_with_ctab + 6, size), "Retrieved wrong CTAB data\n");
254 hr = ID3DXConstantTable_GetDesc(constant_table, NULL);
255 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
257 hr = ID3DXConstantTable_GetDesc(constant_table, &desc);
258 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
259 ok(desc.Creator == (LPCSTR)data + 0x10, "Got result %p, expected %p\n", desc.Creator, (LPCSTR)data + 0x10);
260 ok(desc.Version == D3DVS_VERSION(3, 0), "Got result %x, expected %x\n", desc.Version, D3DVS_VERSION(3, 0));
261 ok(desc.Constants == 0, "Got result %x, expected 0\n", desc.Constants);
263 ID3DXConstantTable_Release(constant_table);
266 hr = D3DXGetShaderConstantTableEx(shader_with_ctab_constants, 0, &constant_table);
267 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
269 if (SUCCEEDED(hr))
271 D3DXHANDLE constant;
272 D3DXCONSTANT_DESC constant_desc;
273 D3DXCONSTANT_DESC constant_desc_save;
274 UINT nb;
276 /* Test GetDesc */
277 hr = ID3DXConstantTable_GetDesc(constant_table, &desc);
278 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
279 ok(!strcmp(desc.Creator, "Wine project"), "Got result '%s', expected 'Wine project'\n", desc.Creator);
280 ok(desc.Version == D3DVS_VERSION(3, 0), "Got result %x, expected %x\n", desc.Version, D3DVS_VERSION(3, 0));
281 ok(desc.Constants == 3, "Got result %x, expected 3\n", desc.Constants);
283 /* Test GetConstant */
284 constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 0);
285 ok(constant != NULL, "No constant found\n");
286 hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
287 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
288 ok(!strcmp(constant_desc.Name, "Constant1"), "Got result '%s', expected 'Constant1'\n",
289 constant_desc.Name);
290 ok(constant_desc.Class == D3DXPC_VECTOR, "Got result %x, expected %u (D3DXPC_VECTOR)\n",
291 constant_desc.Class, D3DXPC_VECTOR);
292 ok(constant_desc.Type == D3DXPT_FLOAT, "Got result %x, expected %u (D3DXPT_FLOAT)\n",
293 constant_desc.Type, D3DXPT_FLOAT);
294 ok(constant_desc.Rows == 1, "Got result %x, expected 1\n", constant_desc.Rows);
295 ok(constant_desc.Columns == 4, "Got result %x, expected 4\n", constant_desc.Columns);
297 constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 1);
298 ok(constant != NULL, "No constant found\n");
299 hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
300 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
301 ok(!strcmp(constant_desc.Name, "Constant2"), "Got result '%s', expected 'Constant2'\n",
302 constant_desc.Name);
303 ok(constant_desc.Class == D3DXPC_MATRIX_COLUMNS, "Got result %x, expected %u (D3DXPC_MATRIX_COLUMNS)\n",
304 constant_desc.Class, D3DXPC_MATRIX_COLUMNS);
305 ok(constant_desc.Type == D3DXPT_FLOAT, "Got result %x, expected %u (D3DXPT_FLOAT)\n",
306 constant_desc.Type, D3DXPT_FLOAT);
307 ok(constant_desc.Rows == 4, "Got result %x, expected 1\n", constant_desc.Rows);
308 ok(constant_desc.Columns == 4, "Got result %x, expected 4\n", constant_desc.Columns);
310 constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 2);
311 ok(constant != NULL, "No constant found\n");
312 hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
313 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
314 ok(!strcmp(constant_desc.Name, "Constant3"), "Got result '%s', expected 'Constant3'\n",
315 constant_desc.Name);
316 ok(constant_desc.Class == D3DXPC_MATRIX_COLUMNS, "Got result %x, expected %u (D3DXPC_MATRIX_COLUMNS)\n",
317 constant_desc.Class, D3DXPC_MATRIX_COLUMNS);
318 ok(constant_desc.Type == D3DXPT_FLOAT, "Got result %x, expected %u (D3DXPT_FLOAT)\n",
319 constant_desc.Type, D3DXPT_FLOAT);
320 ok(constant_desc.Rows == 4, "Got result %x, expected 1\n", constant_desc.Rows);
321 ok(constant_desc.Columns == 4, "Got result %x, expected 4\n", constant_desc.Columns);
322 constant_desc_save = constant_desc; /* For GetConstantDesc test */
324 constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 3);
325 ok(constant == NULL, "Got result %p, expected NULL\n", constant);
327 /* Test GetConstantByName */
328 constant = ID3DXConstantTable_GetConstantByName(constant_table, NULL, "Constant unknown");
329 ok(constant == NULL, "Got result %p, expected NULL\n", constant);
330 constant = ID3DXConstantTable_GetConstantByName(constant_table, NULL, "Constant3");
331 ok(constant != NULL, "No constant found\n");
332 hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, &nb);
333 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
334 ok(!memcmp(&constant_desc, &constant_desc_save, sizeof(D3DXCONSTANT_DESC)), "Got different constant data\n");
336 /* Test GetConstantDesc */
337 constant = ID3DXConstantTable_GetConstant(constant_table, NULL, 0);
338 ok(constant != NULL, "No constant found\n");
339 hr = ID3DXConstantTable_GetConstantDesc(constant_table, NULL, &constant_desc, &nb);
340 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
341 hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, NULL, &nb);
342 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
343 hr = ID3DXConstantTable_GetConstantDesc(constant_table, constant, &constant_desc, NULL);
344 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
345 hr = ID3DXConstantTable_GetConstantDesc(constant_table, "Constant unknow", &constant_desc, &nb);
346 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
347 hr = ID3DXConstantTable_GetConstantDesc(constant_table, "Constant3", &constant_desc, &nb);
348 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
349 ok(!memcmp(&constant_desc, &constant_desc_save, sizeof(D3DXCONSTANT_DESC)), "Got different constant data\n");
351 ID3DXConstantTable_Release(constant_table);
355 static void test_constant_table(const char *test_name, const DWORD *ctable_fn,
356 const D3DXCONSTANT_DESC *expecteds, UINT count)
358 UINT i;
359 ID3DXConstantTable *ctable;
361 HRESULT res;
363 /* Get the constant table from the shader itself */
364 res = D3DXGetShaderConstantTable(ctable_fn, &ctable);
365 ok(res == D3D_OK, "D3DXGetShaderConstantTable failed on %p: got %08x\n", test_name, res);
367 for (i = 0; i < count; i++)
369 const D3DXCONSTANT_DESC *expected = &expecteds[i];
370 D3DXHANDLE const_handle;
371 D3DXCONSTANT_DESC actual;
372 UINT pCount = 1;
374 const_handle = ID3DXConstantTable_GetConstantByName(ctable, NULL, expected->Name);
376 ID3DXConstantTable_GetConstantDesc(ctable, const_handle, &actual, &pCount);
377 ok(pCount == 1, "Got more or less descriptions: %d\n", pCount);
379 ok(strcmp(actual.Name, expected->Name) == 0,
380 "%s in %s: Got different names: Got %s, expected %s\n", expected->Name,
381 test_name, actual.Name, expected->Name);
382 ok(actual.RegisterSet == expected->RegisterSet,
383 "%s in %s: Got different register sets: Got %d, expected %d\n",
384 expected->Name, test_name, actual.RegisterSet, expected->RegisterSet);
385 ok(actual.RegisterIndex == expected->RegisterIndex,
386 "%s in %s: Got different register indices: Got %d, expected %d\n",
387 expected->Name, test_name, actual.RegisterIndex, expected->RegisterIndex);
388 ok(actual.RegisterCount == expected->RegisterCount,
389 "%s in %s: Got different register counts: Got %d, expected %d\n",
390 expected->Name, test_name, actual.RegisterCount, expected->RegisterCount);
391 ok(actual.Class == expected->Class,
392 "%s in %s: Got different classes: Got %d, expected %d\n", expected->Name,
393 test_name, actual.Class, expected->Class);
394 ok(actual.Type == expected->Type,
395 "%s in %s: Got different types: Got %d, expected %d\n", expected->Name,
396 test_name, actual.Type, expected->Type);
397 ok(actual.Rows == expected->Rows && actual.Columns == expected->Columns,
398 "%s in %s: Got different dimensions: Got (%d, %d), expected (%d, %d)\n",
399 expected->Name, test_name, actual.Rows, actual.Columns, expected->Rows,
400 expected->Columns);
401 ok(actual.Elements == expected->Elements,
402 "%s in %s: Got different element count: Got %d, expected %d\n",
403 expected->Name, test_name, actual.Elements, expected->Elements);
404 ok(actual.StructMembers == expected->StructMembers,
405 "%s in %s: Got different struct member count: Got %d, expected %d\n",
406 expected->Name, test_name, actual.StructMembers, expected->StructMembers);
407 ok(actual.Bytes == expected->Bytes,
408 "%s in %s: Got different byte count: Got %d, expected %d\n",
409 expected->Name, test_name, actual.Bytes, expected->Bytes);
412 /* Finally, release the constant table */
413 ID3DXConstantTable_Release(ctable);
416 static void test_constant_tables(void)
418 test_constant_table("test_basic", ctab_basic, ctab_basic_expected,
419 sizeof(ctab_basic_expected)/sizeof(*ctab_basic_expected));
420 test_constant_table("test_matrices", ctab_matrices, ctab_matrices_expected,
421 sizeof(ctab_matrices_expected)/sizeof(*ctab_matrices_expected));
422 test_constant_table("test_arrays", ctab_arrays, ctab_arrays_expected,
423 sizeof(ctab_arrays_expected)/sizeof(*ctab_arrays_expected));
426 START_TEST(shader)
428 test_get_shader_size();
429 test_get_shader_version();
430 test_find_shader_comment();
431 test_get_shader_constant_table_ex();
432 test_constant_tables();