wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / d3dcompiler_43 / tests / asm.c
blob749b1153267bb5550f07cc5ae43bc7fe5a275325
1 /*
2 * Copyright (C) 2010 Matteo Bruni
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
18 #define COBJMACROS
19 #define CONST_VTABLE
20 #include "wine/test.h"
22 #include <d3d9types.h>
23 #include <d3dcommon.h>
24 #include <d3dcompiler.h>
26 /* TODO: maybe this is defined in some header file,
27 perhaps with a different name? */
28 #define D3DXERR_INVALIDDATA 0x88760b59
30 static HRESULT (WINAPI *pD3DAssemble)(const void *data, SIZE_T datasize, const char *filename,
31 const D3D_SHADER_MACRO *defines, ID3DInclude *include, UINT flags, ID3DBlob **shader,
32 ID3DBlob **error_messages);
33 static pD3DPreprocess ppD3DPreprocess;
35 struct shader_test {
36 const char *text;
37 const DWORD bytes[128];
40 static void dump_shader(DWORD *shader) {
41 unsigned int i = 0, j = 0;
42 do {
43 trace("0x%08x ", shader[i]);
44 j++;
45 i++;
46 if(j == 6) trace("\n");
47 } while(shader[i - 1] != D3DSIO_END);
48 if(j != 6) trace("\n");
51 static void exec_tests(const char *name, struct shader_test tests[], unsigned int count) {
52 HRESULT hr;
53 DWORD *res;
54 unsigned int i, j;
55 BOOL diff;
56 ID3DBlob *shader, *messages;
58 for(i = 0; i < count; i++) {
59 /* D3DAssemble sets messages to 0 if there aren't error messages */
60 messages = NULL;
61 hr = pD3DAssemble(tests[i].text, strlen(tests[i].text), NULL,
62 NULL, NULL, D3DCOMPILE_SKIP_VALIDATION,
63 &shader, &messages);
64 ok(hr == S_OK, "Test %s, shader %d: D3DAssemble failed with error 0x%x - %d\n", name, i, hr, hr & 0x0000FFFF);
65 if(messages) {
66 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
67 ID3D10Blob_Release(messages);
69 if(FAILED(hr)) continue;
71 j = 0;
72 diff = FALSE;
73 res = ID3D10Blob_GetBufferPointer(shader);
74 while(res[j] != D3DSIO_END && tests[i].bytes[j] != D3DSIO_END) {
75 if(res[j] != tests[i].bytes[j]) diff = TRUE;
76 j++;
78 /* Both must have an end token */
79 if(res[j] != tests[i].bytes[j]) diff = TRUE;
81 if(diff) {
82 ok(FALSE, "Test %s, shader %d: Generated code differs\n", name, i);
83 dump_shader(res);
85 ID3D10Blob_Release(shader);
89 static void preproc_test(void) {
90 struct shader_test tests[] = {
91 { /* shader 0 */
92 "vs.1.1\r\n"
93 "//some comments\r\n"
94 "//other comments\n"
95 "; yet another comment\r\n"
96 "add r0, r0, r1\n",
97 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
99 { /* shader 1 */
100 "#line 1 \"vertex.vsh\"\n"
101 "vs.1.1\n",
102 {0xfffe0101, 0x0000ffff}
104 { /* shader 2 */
105 "#define REG 1 + 2 +\\\n"
106 "3 + 4\n"
107 "vs.1.1\n"
108 "mov r0, c0[ REG ]\n",
109 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4000a, 0x0000ffff}
113 exec_tests("preproc", tests, ARRAY_SIZE(tests));
116 static void ps_1_1_test(void) {
117 struct shader_test tests[] = {
118 { /* shader 0 */
119 "ps.1.1\r\n"
120 "tex t0\r\n"
121 "add r0.rgb, r0, r1\r\n"
122 "+mov r0.a, t0\r\n",
123 {0xffff0101, 0x00000042, 0xb00f0000, 0x00000002, 0x80070000, 0x80e40000,
124 0x80e40001, 0x40000001, 0x80080000, 0xb0e40000, 0x0000ffff}
126 { /* shader 1 */
127 "ps.1.1\n"
128 "mov_d4 r0, r1\n",
129 {0xffff0101, 0x00000001, 0x8e0f0000, 0x80e40001, 0x0000ffff}
131 { /* shader 2 */
132 "ps_1_1\n"
133 "def c2, 0, 0., 0, 0.\n",
134 {0xffff0101, 0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x00000000,
135 0x00000000, 0x0000ffff}
139 exec_tests("ps_1_1", tests, ARRAY_SIZE(tests));
142 static void vs_1_1_test(void) {
143 struct shader_test tests[] = {
144 /* Basic instruction tests */
145 { /* shader 0 */
146 "vs_1_1\n"
147 "add r0, r1, r2\n",
148 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
150 { /* shader 1 */
151 "vs_1_1\n"
152 "nop\n",
153 {0xfffe0101, 0x00000000, 0x0000ffff}
155 /* Output register tests */
156 { /* shader 2 */
157 "vs_1_1\n"
158 "mov oPos, c0\n",
159 {0xfffe0101, 0x00000001, 0xc00f0000, 0xa0e40000, 0x0000ffff}
161 { /* shader 3 */
162 "vs_1_1\n"
163 "mov oT0, c0\n",
164 {0xfffe0101, 0x00000001, 0xe00f0000, 0xa0e40000, 0x0000ffff}
166 { /* shader 4 */
167 "vs_1_1\n"
168 "mov oT5, c0\n",
169 {0xfffe0101, 0x00000001, 0xe00f0005, 0xa0e40000, 0x0000ffff}
171 { /* shader 5 */
172 "vs_1_1\n"
173 "mov oD0, c0\n",
174 {0xfffe0101, 0x00000001, 0xd00f0000, 0xa0e40000, 0x0000ffff}
176 { /* shader 6 */
177 "vs_1_1\n"
178 "mov oD1, c0\n",
179 {0xfffe0101, 0x00000001, 0xd00f0001, 0xa0e40000, 0x0000ffff}
181 { /* shader 7 */
182 "vs_1_1\n"
183 "mov oFog, c0.x\n",
184 {0xfffe0101, 0x00000001, 0xc00f0001, 0xa0000000, 0x0000ffff}
186 { /* shader 8 */
187 "vs_1_1\n"
188 "mov oPts, c0.x\n",
189 {0xfffe0101, 0x00000001, 0xc00f0002, 0xa0000000, 0x0000ffff}
191 /* A bunch of tests for declarations */
192 { /* shader 9 */
193 "vs_1_1\n"
194 "dcl_position0 v0",
195 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0000, 0x0000ffff}
197 { /* shader 10 */
198 "vs_1_1\n"
199 "dcl_position v1",
200 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0001, 0x0000ffff}
202 { /* shader 11 */
203 "vs_1_1\n"
204 "dcl_normal12 v15",
205 {0xfffe0101, 0x0000001f, 0x800c0003, 0x900f000f, 0x0000ffff}
207 { /* shader 12 */
208 "vs_1_1\n"
209 "add r0, v0, v1\n",
210 {0xfffe0101, 0x00000002, 0x800f0000, 0x90e40000, 0x90e40001, 0x0000ffff}
212 { /* shader 13 */
213 "vs_1_1\n"
214 "def c12, 0, -1, -0.5, 1024\n",
215 {0xfffe0101, 0x00000051, 0xa00f000c, 0x00000000, 0xbf800000, 0xbf000000,
216 0x44800000, 0x0000ffff}
218 { /* shader 14: writemasks, swizzles */
219 "vs_1_1\n"
220 "dp4 r0.xw, r1.wzyx, r2.xxww\n",
221 {0xfffe0101, 0x00000009, 0x80090000, 0x801b0001, 0x80f00002, 0x0000ffff}
223 { /* shader 15: negation input modifier. Other modifiers not supprted in vs_1_1 */
224 "vs_1_1\n"
225 "add r0, -r0.x, -r1\n",
226 {0xfffe0101, 0x00000002, 0x800f0000, 0x81000000, 0x81e40001, 0x0000ffff}
228 { /* shader 16: relative addressing */
229 "vs_1_1\n"
230 "mov r0, c0[a0.x]\n",
231 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42000, 0x0000ffff}
233 { /* shader 17: relative addressing */
234 "vs_1_1\n"
235 "mov r0, c1[a0.x + 2]\n",
236 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42003, 0x0000ffff}
238 { /* shader 18 */
239 "vs_1_1\n"
240 "def c0, 1.0f, 1.0f, 1.0f, 0.5f\n",
241 {0xfffe0101, 0x00000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000,
242 0x3f000000, 0x0000ffff}
244 /* Other relative addressing tests */
245 { /* shader 19 */
246 "vs_1_1\n"
247 "mov r0, c[ a0.x + 12 ]\n",
248 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200c, 0x0000ffff}
250 { /* shader 20 */
251 "vs_1_1\n"
252 "mov r0, c[ 2 + a0.x ]\n",
253 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42002, 0x0000ffff}
255 { /* shader 21 */
256 "vs_1_1\n"
257 "mov r0, c[ 2 + a0.x + 12 ]\n",
258 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200e, 0x0000ffff}
260 { /* shader 22 */
261 "vs_1_1\n"
262 "mov r0, c[ 2 + 10 + 12 ]\n",
263 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40018, 0x0000ffff}
265 { /* shader 23 */
266 "vs_1_1\n"
267 "mov r0, c4[ 2 ]\n",
268 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40006, 0x0000ffff}
270 { /* shader 24 */
271 "vs_1_1\n"
272 "rcp r0, v0.x\n",
273 {0xfffe0101, 0x00000006, 0x800f0000, 0x90000000, 0x0000ffff}
275 { /* shader 25 */
276 "vs.1.1\n"
277 "rsq r0, v0.x\n",
278 {0xfffe0101, 0x00000007, 0x800f0000, 0x90000000, 0x0000ffff}
282 exec_tests("vs_1_1", tests, ARRAY_SIZE(tests));
285 static void ps_1_3_test(void) {
286 struct shader_test tests[] = {
287 /* Basic instruction tests */
288 { /* shader 0 */
289 "ps_1_3\n"
290 "mov r0, r1\n",
291 {0xffff0103, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
293 { /* shader 1 */
294 "ps_1_3\n"
295 "add r0, r1, r0\n",
296 {0xffff0103, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40000, 0x0000ffff}
298 /* Color interpolator tests */
299 { /* shader 2 */
300 "ps_1_3\n"
301 "mov r0, v0\n",
302 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40000, 0x0000ffff}
304 { /* shader 3 */
305 "ps_1_3\n"
306 "mov r0, v1\n",
307 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
309 /* Texture sampling instructions */
310 { /* shader 4 */
311 "ps_1_3\n"
312 "tex t0\n",
313 {0xffff0103, 0x00000042, 0xb00f0000, 0x0000ffff}
315 { /* shader 5 */
316 "ps_1_3\n"
317 "tex t0\n"
318 "texreg2ar t1, t0\n",
319 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000045, 0xb00f0001, 0xb0e40000,
320 0x0000ffff}
322 { /* shader 6 */
323 "ps_1_3\n"
324 "tex t0\n"
325 "texreg2gb t1, t0\n",
326 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000046, 0xb00f0001, 0xb0e40000,
327 0x0000ffff}
329 { /* shader 7 */
330 "ps_1_3\n"
331 "tex t0\n"
332 "texreg2rgb t1, t0\n",
333 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000052, 0xb00f0001, 0xb0e40000,
334 0x0000ffff}
336 { /* shader 8 */
337 "ps_1_3\n"
338 "cnd r0, r1, r0, v0\n",
339 {0xffff0103, 0x00000050, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
340 0x0000ffff}
342 { /* shader 9 */
343 "ps_1_3\n"
344 "cmp r0, r1, r0, v0\n",
345 {0xffff0103, 0x00000058, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
346 0x0000ffff}
348 { /* shader 10 */
349 "ps_1_3\n"
350 "texkill t0\n",
351 {0xffff0103, 0x00000041, 0xb00f0000, 0x0000ffff}
353 { /* shader 11 */
354 "ps_1_3\n"
355 "tex t0\n"
356 "texm3x2pad t1, t0\n"
357 "texm3x2tex t2, t0\n",
358 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
359 0x00000048, 0xb00f0002, 0xb0e40000, 0x0000ffff}
361 { /* shader 12 */
362 "ps_1_3\n"
363 "tex t0\n"
364 "texm3x2pad t1, t0\n"
365 "texm3x2depth t2, t0\n",
366 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
367 0x00000054, 0xb00f0002, 0xb0e40000, 0x0000ffff}
369 { /* shader 13 */
370 "ps_1_3\n"
371 "tex t0\n"
372 "texbem t1, t0\n",
373 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000043, 0xb00f0001, 0xb0e40000,
374 0x0000ffff}
376 { /* shader 14 */
377 "ps_1_3\n"
378 "tex t0\n"
379 "texbeml t1, t0\n",
380 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000044, 0xb00f0001, 0xb0e40000,
381 0x0000ffff}
383 { /* shader 15 */
384 "ps_1_3\n"
385 "tex t0\n"
386 "texdp3tex t1, t0\n",
387 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000053, 0xb00f0001, 0xb0e40000,
388 0x0000ffff}
390 { /* shader 16 */
391 "ps_1_3\n"
392 "tex t0\n"
393 "texdp3 t1, t0\n",
394 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000055, 0xb00f0001, 0xb0e40000,
395 0x0000ffff}
397 { /* shader 17 */
398 "ps_1_3\n"
399 "tex t0\n"
400 "texm3x3pad t1, t0\n"
401 "texm3x3pad t2, t0\n"
402 "texm3x3tex t3, t0\n",
403 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
404 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004a, 0xb00f0003, 0xb0e40000,
405 0x0000ffff}
407 { /* shader 18 */
408 "ps_1_3\n"
409 "tex t0\n"
410 "texm3x3pad t1, t0\n"
411 "texm3x3pad t2, t0\n"
412 "texm3x3 t3, t0\n",
413 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
414 0x00000049, 0xb00f0002, 0xb0e40000, 0x00000056, 0xb00f0003, 0xb0e40000,
415 0x0000ffff}
417 { /* shader 19 */
418 "ps_1_3\n"
419 "tex t0\n"
420 "texm3x3pad t1, t0\n"
421 "texm3x3pad t2, t0\n"
422 "texm3x3spec t3, t0, c0\n",
423 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
424 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004c, 0xb00f0003, 0xb0e40000,
425 0xa0e40000, 0x0000ffff}
427 { /* shader 20 */
428 "ps_1_3\n"
429 "tex t0\n"
430 "texm3x3pad t1, t0\n"
431 "texm3x3pad t2, t0\n"
432 "texm3x3vspec t3, t0\n",
433 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
434 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004d, 0xb00f0003, 0xb0e40000,
435 0x0000ffff}
437 { /* shader 21 */
438 "ps_1_3\n"
439 "texcoord t0\n",
440 {0xffff0103, 0x00000040, 0xb00f0000, 0x0000ffff}
442 /* Modifiers, shifts */
443 { /* shader 22 */
444 "ps_1_3\n"
445 "mov_x2_sat r0, 1 - r1\n",
446 {0xffff0103, 0x00000001, 0x811f0000, 0x86e40001, 0x0000ffff}
448 { /* shader 23 */
449 "ps_1_3\n"
450 "mov_d8 r0, -r1\n",
451 {0xffff0103, 0x00000001, 0x8d0f0000, 0x81e40001, 0x0000ffff}
453 { /* shader 24 */
454 "ps_1_3\n"
455 "mov_sat r0, r1_bx2\n",
456 {0xffff0103, 0x00000001, 0x801f0000, 0x84e40001, 0x0000ffff}
458 { /* shader 25 */
459 "ps_1_3\n"
460 "mov_sat r0, r1_bias\n",
461 {0xffff0103, 0x00000001, 0x801f0000, 0x82e40001, 0x0000ffff}
463 { /* shader 26 */
464 "ps_1_3\n"
465 "mov_sat r0, -r1_bias\n",
466 {0xffff0103, 0x00000001, 0x801f0000, 0x83e40001, 0x0000ffff}
468 { /* shader 27 */
469 "ps_1_3\n"
470 "mov_sat r0, -r1_bx2\n",
471 {0xffff0103, 0x00000001, 0x801f0000, 0x85e40001, 0x0000ffff}
473 { /* shader 28 */
474 "ps_1_3\n"
475 "mov_sat r0, -r1_x2\n",
476 {0xffff0103, 0x00000001, 0x801f0000, 0x88e40001, 0x0000ffff}
478 { /* shader 29 */
479 "ps_1_3\n"
480 "mov_x4_sat r0.a, -r1_bx2.a\n",
481 {0xffff0103, 0x00000001, 0x82180000, 0x85ff0001, 0x0000ffff}
483 { /* shader 30 */
484 "ps_1_3\n"
485 "texcoord_x2 t0\n",
486 {0xffff0103, 0x00000040, 0xb10f0000, 0x0000ffff}
488 { /* shader 31 */
489 "ps_1_3\n"
490 "tex_x2 t0\n",
491 {0xffff0103, 0x00000042, 0xb10f0000, 0x0000ffff}
493 { /* shader 32 */
494 "ps_1_3\n"
495 "texreg2ar_x4 t0, t1\n",
496 {0xffff0103, 0x00000045, 0xb20f0000, 0xb0e40001, 0x0000ffff}
498 { /* shader 33 */
499 "ps_1_3\n"
500 "texbem_d4 t1, t0\n",
501 {0xffff0103, 0x00000043, 0xbe0f0001, 0xb0e40000, 0x0000ffff}
503 { /* shader 34 */
504 "ps_1_3\n"
505 "tex t0\n"
506 "texm3x3pad_x2 t1, t0\n"
507 "texm3x3pad_x2 t2, t0\n"
508 "texm3x3tex_x2 t3, t0\n",
509 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb10f0001, 0xb0e40000,
510 0x00000049, 0xb10f0002, 0xb0e40000, 0x0000004a, 0xb10f0003, 0xb0e40000,
511 0x0000ffff}
513 { /* shader 35 */
514 "ps.1.3\n"
515 "tex t0\n"
516 "texdp3tex_x8 t1, t0\n",
517 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000053, 0xb30f0001, 0xb0e40000,
518 0x0000ffff}
522 exec_tests("ps_1_3", tests, ARRAY_SIZE(tests));
525 static void ps_1_4_test(void) {
526 struct shader_test tests[] = {
527 /* Basic instruction tests */
528 { /* shader 0 */
529 "ps_1_4\n"
530 "mov r0, r1\n",
531 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
533 { /* shader 1 */
534 "ps_1_4\n"
535 "mov r0, r5\n",
536 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40005, 0x0000ffff}
538 { /* shader 2 */
539 "ps_1_4\n"
540 "mov r0, c7\n",
541 {0xffff0104, 0x00000001, 0x800f0000, 0xa0e40007, 0x0000ffff}
543 { /* shader 3 */
544 "ps_1_4\n"
545 "mov r0, v1\n",
546 {0xffff0104, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
548 { /* shader 4 */
549 "ps_1_4\n"
550 "phase\n",
551 {0xffff0104, 0x0000fffd, 0x0000ffff}
553 { /* shader 5 */
554 "ps_1_4\n"
555 "texcrd r0, t0\n",
556 {0xffff0104, 0x00000040, 0x800f0000, 0xb0e40000, 0x0000ffff}
558 { /* shader 6 */
559 "ps_1_4\n"
560 "texcrd r4, t3\n",
561 {0xffff0104, 0x00000040, 0x800f0004, 0xb0e40003, 0x0000ffff}
563 { /* shader 7 */
564 "ps_1_4\n"
565 "texcrd_sat r4, t3\n",
566 {0xffff0104, 0x00000040, 0x801f0004, 0xb0e40003, 0x0000ffff}
568 { /* shader 8 */
569 "ps_1_4\n"
570 "texld r0, t0\n",
571 {0xffff0104, 0x00000042, 0x800f0000, 0xb0e40000, 0x0000ffff}
573 { /* shader 9 */
574 "ps_1_4\n"
575 "texld r1, t4\n",
576 {0xffff0104, 0x00000042, 0x800f0001, 0xb0e40004, 0x0000ffff}
578 { /* shader 10 */
579 "ps_1_4\n"
580 "texld r5, r0\n",
581 {0xffff0104, 0x00000042, 0x800f0005, 0x80e40000, 0x0000ffff}
583 { /* shader 11 */
584 "ps_1_4\n"
585 "texld r5, c0\n", /* Assembly succeeds, validation fails */
586 {0xffff0104, 0x00000042, 0x800f0005, 0xa0e40000, 0x0000ffff}
588 { /* shader 12 */
589 "ps_1_4\n"
590 "texld r5, r2_dz\n",
591 {0xffff0104, 0x00000042, 0x800f0005, 0x89e40002, 0x0000ffff}
593 { /* shader 13 */
594 "ps_1_4\n"
595 "bem r1.rg, c0, r0\n",
596 {0xffff0104, 0x00000059, 0x80030001, 0xa0e40000, 0x80e40000, 0x0000ffff}
598 { /* shader 14 */
599 "ps_1_4\n"
600 "texdepth r5\n",
601 {0xffff0104, 0x00000057, 0x800f0005, 0x0000ffff}
603 { /* shader 15 */
604 "ps_1_4\n"
605 "add r0, r1, r2_bx2\n",
606 {0xffff0104, 0x00000002, 0x800f0000, 0x80e40001, 0x84e40002, 0x0000ffff}
608 { /* shader 16 */
609 "ps_1_4\n"
610 "add_x4 r0, r1, r2\n",
611 {0xffff0104, 0x00000002, 0x820f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
613 { /* shader 17 */
614 "ps_1_4\n"
615 "add r0.rgb, r1, r2\n"
616 "+add r0.a, r1, r2\n",
617 {0xffff0104, 0x00000002, 0x80070000, 0x80e40001, 0x80e40002, 0x40000002,
618 0x80080000, 0x80e40001, 0x80e40002, 0x0000ffff}
620 { /* shader 18 */
621 "ps_1_4\n"
622 "texdepth_x2 r5\n",
623 {0xffff0104, 0x00000057, 0x810f0005, 0x0000ffff}
625 { /* shader 18 */
626 "ps.1.4\n"
627 "bem_d2 r1, c0, r0\n",
628 {0xffff0104, 0x00000059, 0x8f0f0001, 0xa0e40000, 0x80e40000, 0x0000ffff}
632 exec_tests("ps_1_4", tests, ARRAY_SIZE(tests));
635 static void vs_2_0_test(void) {
636 struct shader_test tests[] = {
637 /* Basic instruction tests */
638 { /* shader 0 */
639 "vs_2_0\n"
640 "mov r0, r1\n",
641 {0xfffe0200, 0x02000001, 0x800f0000, 0x80e40001, 0x0000ffff}
643 { /* shader 1 */
644 "vs_2_0\n"
645 "lrp r0, v0, c0, r1\n",
646 {0xfffe0200, 0x04000012, 0x800f0000, 0x90e40000, 0xa0e40000, 0x80e40001,
647 0x0000ffff}
649 { /* shader 2 */
650 "vs_2_0\n"
651 "dp4 oPos, v0, c0\n",
652 {0xfffe0200, 0x03000009, 0xc00f0000, 0x90e40000, 0xa0e40000, 0x0000ffff}
654 { /* shader 3 */
655 "vs_2_0\n"
656 "mov r0, c0[a0.x]\n",
657 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0000000, 0x0000ffff}
659 { /* shader 4 */
660 "vs_2_0\n"
661 "mov r0, c0[a0.y]\n",
662 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0550000, 0x0000ffff}
664 { /* shader 5 */
665 "vs_2_0\n"
666 "mov r0, c0[a0.z]\n",
667 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0aa0000, 0x0000ffff}
669 { /* shader 6 */
670 "vs_2_0\n"
671 "mov r0, c0[a0.w]\n",
672 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0ff0000, 0x0000ffff}
674 { /* shader 7 */
675 "vs_2_0\n"
676 "mov r0, c0[a0.w].x\n",
677 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0002000, 0xb0ff0000, 0x0000ffff}
679 { /* shader 8 */
680 "vs_2_0\n"
681 "mov r0, -c0[a0.w+5].x\n",
682 {0xfffe0200, 0x03000001, 0x800f0000, 0xa1002005, 0xb0ff0000, 0x0000ffff}
684 { /* shader 9 */
685 "vs_2_0\n"
686 "mov r0, c0[a0]\n",
687 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0e40000, 0x0000ffff}
689 { /* shader 10 */
690 "vs_2_0\n"
691 "mov r0, c0[a0.xyww]\n",
692 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0f40000, 0x0000ffff}
694 { /* shader 11 */
695 "vs_2_0\n"
696 "add r0, c0[a0.x], c1[a0.y]\n", /* validation would fail on this line */
697 {0xfffe0200, 0x05000002, 0x800f0000, 0xa0e42000, 0xb0000000, 0xa0e42001,
698 0xb0550000, 0x0000ffff}
700 { /* shader 12 */
701 "vs_2_0\n"
702 "rep i0\n"
703 "endrep\n",
704 {0xfffe0200, 0x01000026, 0xf0e40000, 0x00000027, 0x0000ffff}
706 { /* shader 13 */
707 "vs_2_0\n"
708 "if b0\n"
709 "else\n"
710 "endif\n",
711 {0xfffe0200, 0x01000028, 0xe0e40800, 0x0000002a, 0x0000002b, 0x0000ffff}
713 { /* shader 14 */
714 "vs_2_0\n"
715 "loop aL, i0\n"
716 "endloop\n",
717 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x0000001d, 0x0000ffff}
719 { /* shader 15 */
720 "vs_2_0\n"
721 "nrm r0, c0\n",
722 {0xfffe0200, 0x02000024, 0x800f0000, 0xa0e40000, 0x0000ffff}
724 { /* shader 16 */
725 "vs_2_0\n"
726 "crs r0, r1, r2\n",
727 {0xfffe0200, 0x03000021, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
729 { /* shader 17 */
730 "vs_2_0\n"
731 "sgn r0, r1, r2, r3\n",
732 {0xfffe0200, 0x04000022, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
733 0x0000ffff}
735 { /* shader 18 */
736 "vs_2_0\n"
737 "sincos r0, r1, r2, r3\n",
738 {0xfffe0200, 0x04000025, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
739 0x0000ffff}
741 { /* shader 19 */
742 "vs_2_0\n"
743 "pow r0, r1, r2\n",
744 {0xfffe0200, 0x03000020, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
746 { /* shader 20 */
747 "vs_2_0\n"
748 "mova a0.y, c0.z\n",
749 {0xfffe0200, 0x0200002e, 0xb0020000, 0xa0aa0000, 0x0000ffff}
751 { /* shader 21 */
752 "vs_2_0\n"
753 "defb b0, true\n"
754 "defb b1, false\n",
755 {0xfffe0200, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
756 0x00000000, 0x0000ffff}
758 { /* shader 22 */
759 "vs_2_0\n"
760 "defi i0, -1, 1, 10, 0\n"
761 "defi i1, 0, 40, 30, 10\n",
762 {0xfffe0200, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
763 0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
764 0x0000000a, 0x0000ffff}
766 { /* shader 23 */
767 "vs_2_0\n"
768 "loop aL, i0\n"
769 "mov r0, c0[aL]\n"
770 "endloop\n",
771 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
772 0xa0e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
774 { /* shader 24 */
775 "vs_2_0\n"
776 "call l0\n"
777 "ret\n"
778 "label l0\n"
779 "ret\n",
780 {0xfffe0200, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
781 0x0000001c, 0x0000ffff}
783 { /* shader 25 */
784 "vs_2_0\n"
785 "callnz l0, b0\n"
786 "ret\n"
787 "label l0\n"
788 "ret\n",
789 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
790 0xa0e41000, 0x0000001c, 0x0000ffff}
792 { /* shader 26 */
793 "vs_2_0\n"
794 "callnz l0, !b0\n"
795 "ret\n"
796 "label l0\n"
797 "ret\n",
798 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
799 0xa0e41000, 0x0000001c, 0x0000ffff}
801 { /* shader 27 */
802 "vs_2_0\n"
803 "if !b0\n"
804 "else\n"
805 "endif\n",
806 {0xfffe0200, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
808 { /* shader 28 */
809 "vs_2_0\n"
810 "call l3\n"
811 "ret\n"
812 "label l3\n"
813 "ret\n",
814 {0xfffe0200, 0x01000019, 0xa0e41003, 0x0000001c, 0x0100001e, 0xa0e41003, 0x0000001c, 0x0000ffff}
816 { /* shader 29: labels up to 2047 are accepted even in vs_2_0 */
817 "vs.2.0\n"
818 "call l2047\n",
819 {0xfffe0200, 0x01000019, 0xa0e417ff, 0x0000ffff}
823 exec_tests("vs_2_0", tests, ARRAY_SIZE(tests));
826 static void vs_2_x_test(void) {
827 struct shader_test tests[] = {
828 { /* shader 0 */
829 "vs_2_x\n"
830 "rep i0\n"
831 "break\n"
832 "endrep\n",
833 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
835 { /* shader 1 */
836 "vs_2_x\n"
837 "if_ge r0, r1\n"
838 "endif\n",
839 {0xfffe0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
841 { /* shader 2 */
842 "vs_2_x\n"
843 "rep i0\n"
844 "break_ne r0, r1\n"
845 "endrep",
846 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
847 0x00000027, 0x0000ffff}
850 /* predicates */
851 { /* shader 3 */
852 "vs_2_x\n"
853 "setp_gt p0, r0, r1\n"
854 "(!p0) add r2, r2, r3\n",
855 {0xfffe0201, 0x0301005e, 0xb00f1000, 0x80e40000, 0x80e40001, 0x14000002,
856 0x800f0002, 0xbde41000, 0x80e40002, 0x80e40003, 0x0000ffff}
858 { /* shader 4 */
859 "vs_2_x\n"
860 "if p0.x\n"
861 "else\n"
862 "endif\n",
863 {0xfffe0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
865 { /* shader 5 */
866 "vs_2_x\n"
867 "callnz l0, !p0.z\n"
868 "ret\n"
869 "label l0\n"
870 "ret\n",
871 {0xfffe0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
872 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
874 { /* shader 6 */
875 "vs.2.x\n"
876 "rep i0\n"
877 "breakp p0.w\n"
878 "endrep\n",
879 {0xfffe0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
880 0x00000027, 0x0000ffff}
884 exec_tests("vs_2_x", tests, ARRAY_SIZE(tests));
887 static void ps_2_0_test(void) {
888 struct shader_test tests[] = {
889 { /* shader 0 */
890 "ps_2_0\n"
891 "dcl_2d s0\n",
892 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
894 { /* shader 1 */
895 "ps_2_0\n"
896 "dcl_cube s0\n",
897 {0xffff0200, 0x0200001f, 0x98000000, 0xa00f0800, 0x0000ffff}
899 { /* shader 2 */
900 "ps_2_0\n"
901 "dcl_volume s0\n",
902 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0000ffff}
904 { /* shader 3 */
905 "ps_2_0\n"
906 "dcl_volume s0\n"
907 "dcl_cube s1\n"
908 "dcl_2d s2\n",
909 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0200001f, 0x98000000,
910 0xa00f0801, 0x0200001f, 0x90000000, 0xa00f0802, 0x0000ffff}
912 { /* shader 4 */
913 "ps_2_0\n"
914 "mov r0, t0\n",
915 {0xffff0200, 0x02000001, 0x800f0000, 0xb0e40000, 0x0000ffff}
917 { /* shader 5 */
918 "ps_2_0\n"
919 "dcl_2d s2\n"
920 "texld r0, t1, s2\n",
921 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000,
922 0xb0e40001, 0xa0e40802, 0x0000ffff}
924 { /* shader 6 */
925 "ps_2_0\n"
926 "texkill t0\n",
927 {0xffff0200, 0x01000041, 0xb00f0000, 0x0000ffff}
929 { /* shader 7 */
930 "ps_2_0\n"
931 "mov oC0, c0\n"
932 "mov oC1, c1\n",
933 {0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x02000001, 0x800f0801,
934 0xa0e40001, 0x0000ffff}
936 { /* shader 8 */
937 "ps_2_0\n"
938 "mov oDepth, c0.x\n",
939 {0xffff0200, 0x02000001, 0x900f0800, 0xa0000000, 0x0000ffff}
941 { /* shader 9 */
942 "ps_2_0\n"
943 "dcl_2d s2\n"
944 "texldp r0, t1, s2\n",
945 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03010042, 0x800f0000,
946 0xb0e40001, 0xa0e40802, 0x0000ffff}
948 { /* shader 10 */
949 "ps.2.0\n"
950 "dcl_2d s2\n"
951 "texldb r0, t1, s2\n",
952 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03020042, 0x800f0000,
953 0xb0e40001, 0xa0e40802, 0x0000ffff}
957 exec_tests("ps_2_0", tests, ARRAY_SIZE(tests));
960 static void ps_2_x_test(void) {
961 struct shader_test tests[] = {
962 /* defb and defi are not supposed to work in ps_2_0 (even if defb actually works in ps_2_0 with native) */
963 { /* shader 0 */
964 "ps_2_x\n"
965 "defb b0, true\n"
966 "defb b1, false\n",
967 {0xffff0201, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
968 0x00000000, 0x0000ffff}
970 { /* shader 1 */
971 "ps_2_x\n"
972 "defi i0, -1, 1, 10, 0\n"
973 "defi i1, 0, 40, 30, 10\n",
974 {0xffff0201, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
975 0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
976 0x0000000a, 0x0000ffff}
978 { /* shader 2 */
979 "ps_2_x\n"
980 "dsx r0, r0\n",
981 {0xffff0201, 0x0200005b, 0x800f0000, 0x80e40000, 0x0000ffff}
983 { /* shader 3 */
984 "ps_2_x\n"
985 "dsy r0, r0\n",
986 {0xffff0201, 0x0200005c, 0x800f0000, 0x80e40000, 0x0000ffff}
988 { /* shader 4 */
989 "ps_2_x\n"
990 "dcl_2d s2\n"
991 "texldd r0, v1, s2, r3, r4\n",
992 {0xffff0201, 0x0200001f, 0x90000000, 0xa00f0802, 0x0500005d, 0x800f0000,
993 0x90e40001, 0xa0e40802, 0x80e40003, 0x80e40004, 0x0000ffff}
995 /* Static flow control tests */
996 { /* shader 5 */
997 "ps_2_x\n"
998 "call l0\n"
999 "ret\n"
1000 "label l0\n"
1001 "ret\n",
1002 {0xffff0201, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
1003 0x0000001c, 0x0000ffff}
1005 { /* shader 6 */
1006 "ps_2_x\n"
1007 "callnz l0, b0\n"
1008 "ret\n"
1009 "label l0\n"
1010 "ret\n",
1011 {0xffff0201, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
1012 0xa0e41000, 0x0000001c, 0x0000ffff}
1014 { /* shader 7 */
1015 "ps_2_x\n"
1016 "callnz l0, !b0\n"
1017 "ret\n"
1018 "label l0\n"
1019 "ret\n",
1020 {0xffff0201, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
1021 0xa0e41000, 0x0000001c, 0x0000ffff}
1023 { /* shader 8 */
1024 "ps_2_x\n"
1025 "if !b0\n"
1026 "else\n"
1027 "endif\n",
1028 {0xffff0201, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
1030 /* Dynamic flow control tests */
1031 { /* shader 9 */
1032 "ps_2_x\n"
1033 "rep i0\n"
1034 "break\n"
1035 "endrep\n",
1036 {0xffff0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
1038 { /* shader 10 */
1039 "ps_2_x\n"
1040 "if_ge r0, r1\n"
1041 "endif\n",
1042 {0xffff0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
1044 { /* shader 11 */
1045 "ps_2_x\n"
1046 "rep i0\n"
1047 "break_ne r0, r1\n"
1048 "endrep",
1049 {0xffff0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
1050 0x00000027, 0x0000ffff}
1052 /* Predicates */
1053 { /* shader 12 */
1054 "ps_2_x\n"
1055 "setp_gt p0, r0, r1\n"
1056 "(!p0) add r2, r2, r3\n",
1057 {0xffff0201, 0x0301005e, 0xb00f1000, 0x80e40000, 0x80e40001, 0x14000002,
1058 0x800f0002, 0xbde41000, 0x80e40002, 0x80e40003, 0x0000ffff}
1060 { /* shader 13 */
1061 "ps_2_x\n"
1062 "if p0.x\n"
1063 "else\n"
1064 "endif\n",
1065 {0xffff0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
1067 { /* shader 14 */
1068 "ps_2_x\n"
1069 "callnz l0, !p0.z\n"
1070 "ret\n"
1071 "label l0\n"
1072 "ret\n",
1073 {0xffff0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
1074 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
1076 { /* shader 15 */
1077 "ps_2_x\n"
1078 "rep i0\n"
1079 "breakp p0.w\n"
1080 "endrep\n",
1081 {0xffff0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
1082 0x00000027, 0x0000ffff}
1084 { /* shader 16 */
1085 "ps.2.x\n"
1086 "call l2047\n"
1087 "ret\n"
1088 "label l2047\n"
1089 "ret\n",
1090 {0xffff0201, 0x01000019, 0xa0e417ff, 0x0000001c, 0x0100001e, 0xa0e417ff,
1091 0x0000001c, 0x0000ffff}
1095 exec_tests("ps_2_x", tests, ARRAY_SIZE(tests));
1098 static void vs_3_0_test(void) {
1099 struct shader_test tests[] = {
1100 { /* shader 0 */
1101 "vs_3_0\n"
1102 "mov r0, c0\n",
1103 {0xfffe0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1105 { /* shader 1 */
1106 "vs_3_0\n"
1107 "dcl_2d s0\n",
1108 {0xfffe0300, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
1110 { /* shader 2 */
1111 "vs_3_0\n"
1112 "dcl_position o0\n",
1113 {0xfffe0300, 0x0200001f, 0x80000000, 0xe00f0000, 0x0000ffff}
1115 { /* shader 3 */
1116 "vs_3_0\n"
1117 "dcl_texcoord12 o11\n",
1118 {0xfffe0300, 0x0200001f, 0x800c0005, 0xe00f000b, 0x0000ffff}
1120 { /* shader 4 */
1121 "vs_3_0\n"
1122 "texldl r0, v0, s0\n",
1123 {0xfffe0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1125 { /* shader 5 */
1126 "vs_3_0\n"
1127 "mov r0, c0[aL]\n",
1128 {0xfffe0300, 0x03000001, 0x800f0000, 0xa0e42000, 0xf0e40800, 0x0000ffff}
1130 { /* shader 6 */
1131 "vs_3_0\n"
1132 "mov o[ a0.x + 12 ], r0\n",
1133 {0xfffe0300, 0x03000001, 0xe00f200c, 0xb0000000, 0x80e40000, 0x0000ffff}
1135 { /* shader 7 */
1136 "vs_3_0\n"
1137 "add_sat r0, r0, r1\n",
1138 {0xfffe0300, 0x03000002, 0x801f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1140 { /* shader 8 */
1141 "vs_3_0\n"
1142 "mov r2, r1_abs\n",
1143 {0xfffe0300, 0x02000001, 0x800f0002, 0x8be40001, 0x0000ffff}
1145 { /* shader 9 */
1146 "vs_3_0\n"
1147 "mov r2, r1.xygb\n",
1148 {0xfffe0300, 0x02000001, 0x800f0002, 0x80940001, 0x0000ffff}
1150 { /* shader 10 */
1151 "vs_3_0\n"
1152 "mov r2.xyb, r1\n",
1153 {0xfffe0300, 0x02000001, 0x80070002, 0x80e40001, 0x0000ffff}
1155 { /* shader 11 */
1156 "vs_3_0\n"
1157 "mova_sat a0.x, r1\n",
1158 {0xfffe0300, 0x0200002e, 0xb0110000, 0x80e40001, 0x0000ffff}
1160 { /* shader 12 */
1161 "vs_3_0\n"
1162 "sincos r0, r1\n",
1163 {0xfffe0300, 0x02000025, 0x800f0000, 0x80e40001, 0x0000ffff}
1165 { /* shader 13 */
1166 "vs_3_0\n"
1167 "def c0, 1.0f, 1.0f, 1.0f, 0.5f\n",
1168 {0xfffe0300, 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000,
1169 0x3f000000, 0x0000ffff}
1171 { /* shader 14: no register number checks with relative addressing */
1172 "vs.3.0\n"
1173 "add r0, v20[aL], r2\n",
1174 {0xfffe0300, 0x04000002, 0x800f0000, 0x90e42014, 0xf0e40800, 0x80e40002,
1175 0x0000ffff}
1180 exec_tests("vs_3_0", tests, ARRAY_SIZE(tests));
1183 static void ps_3_0_test(void) {
1184 struct shader_test tests[] = {
1185 { /* shader 0 */
1186 "ps_3_0\n"
1187 "mov r0, c0\n",
1188 {0xffff0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1190 { /* shader 1 */
1191 "ps_3_0\n"
1192 "dcl_normal5 v0\n",
1193 {0xffff0300, 0x0200001f, 0x80050003, 0x900f0000, 0x0000ffff}
1195 { /* shader 2 */
1196 "ps_3_0\n"
1197 "mov r0, vPos\n",
1198 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41000, 0x0000ffff}
1200 { /* shader 3 */
1201 "ps_3_0\n"
1202 "mov r0, vFace\n",
1203 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41001, 0x0000ffff}
1205 { /* shader 4 */
1206 "ps_3_0\n"
1207 "mov r0, v[ aL + 12 ]\n",
1208 {0xffff0300, 0x03000001, 0x800f0000, 0x90e4200c, 0xf0e40800, 0x0000ffff}
1210 { /* shader 5 */
1211 "ps_3_0\n"
1212 "loop aL, i0\n"
1213 "mov r0, v0[aL]\n"
1214 "endloop\n",
1215 {0xffff0300, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
1216 0x90e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
1218 { /* shader 6 */
1219 "ps_3_0\n"
1220 "texldl r0, v0, s0\n",
1221 {0xffff0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1223 { /* shader 7 */
1224 "ps_3_0\n"
1225 "add_pp r0, r0, r1\n",
1226 {0xffff0300, 0x03000002, 0x802f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1228 { /* shader 8 */
1229 "ps_3_0\n"
1230 "dsx_sat r0, r1\n",
1231 {0xffff0300, 0x0200005b, 0x801f0000, 0x80e40001, 0x0000ffff}
1233 { /* shader 9 */
1234 "ps_3_0\n"
1235 "texldd_pp r0, r1, r2, r3, r4\n",
1236 {0xffff0300, 0x0500005d, 0x802f0000, 0x80e40001, 0x80e40002, 0x80e40003,
1237 0x80e40004, 0x0000ffff}
1239 { /* shader 10 */
1240 "ps_3_0\n"
1241 "texkill v0\n",
1242 {0xffff0300, 0x01000041, 0x900f0000, 0x0000ffff}
1244 { /* shader 11 */
1245 "ps_3_0\n"
1246 "add oC3, r0, r1\n",
1247 {0xffff0300, 0x03000002, 0x800f0803, 0x80e40000, 0x80e40001, 0x0000ffff}
1249 { /* shader 12 */
1250 "ps_3_0\n"
1251 "dcl_texcoord0_centroid v0\n",
1252 {0xffff0300, 0x0200001f, 0x80000005, 0x904f0000, 0x0000ffff}
1254 { /* shader 13 */
1255 "ps_3_0\n"
1256 "dcl_2d_centroid s0\n",
1257 {0xffff0300, 0x0200001f, 0x90000000, 0xa04f0800, 0x0000ffff}
1259 { /* shader 14 */
1260 "ps.3.0\n"
1261 "dcl_2d_pp s0\n",
1262 {0xffff0300, 0x0200001f, 0x90000000, 0xa02f0800, 0x0000ffff}
1266 exec_tests("ps_3_0", tests, ARRAY_SIZE(tests));
1269 static void failure_test(void) {
1270 const char * tests[] = {
1271 /* shader 0: instruction modifier not allowed */
1272 "ps_3_0\n"
1273 "dcl_2d s2\n"
1274 "texldd_x2 r0, v1, s2, v3, v4\n",
1275 /* shader 1: coissue not supported in vertex shaders */
1276 "vs.1.1\r\n"
1277 "add r0.rgb, r0, r1\n"
1278 "+add r0.a, r0, r2\n",
1279 /* shader 2: coissue not supported in pixel shader version >= 2.0 */
1280 "ps_2_0\n"
1281 "texld r0, t0, s0\n"
1282 "add r0.rgb, r0, r1\n"
1283 "+add r0.a, r0, v1\n",
1284 /* shader 3: predicates not supported in vertex shader < 2.0 */
1285 "vs_1_1\n"
1286 "(p0) add r0, r0, v0\n",
1287 /* shader 4: register a0 doesn't exist in pixel shaders */
1288 "ps_3_0\n"
1289 "mov r0, v[ a0 + 12 ]\n",
1290 /* shader 5: s0 doesn't exist in vs_1_1 */
1291 "vs_1_1\n"
1292 "mov r0, s0\n",
1293 /* shader 6: aL is a scalar register, no swizzles allowed */
1294 "ps_3_0\n"
1295 "mov r0, v[ aL.x + 12 ]\n",
1296 /* shader 7: tn doesn't exist in ps_3_0 */
1297 "ps_3_0\n"
1298 "dcl_2d s2\n"
1299 "texldd r0, t1, s2, v3, v4\n",
1300 /* shader 8: two shift modifiers */
1301 "ps_1_3\n"
1302 "mov_x2_x2 r0, r1\n",
1303 /* shader 9: too many source registers for mov instruction */
1304 "vs_1_1\n"
1305 "mov r0, r1, r2\n",
1306 /* shader 10: invalid combination of negate and divide modifiers */
1307 "ps_1_4\n"
1308 "texld r5, -r2_dz\n",
1309 /* shader 11: complement modifier not allowed in >= PS 2 */
1310 "ps_2_0\n"
1311 "mov r2, 1 - r0\n",
1312 /* shader 12: invalid modifier */
1313 "vs_3_0\n"
1314 "mov r2, 2 - r0\n",
1315 /* shader 13: float value in relative addressing */
1316 "vs_3_0\n"
1317 "mov r2, c[ aL + 3.4 ]\n",
1318 /* shader 14: complement modifier not available in VS */
1319 "vs_3_0\n"
1320 "mov r2, 1 - r1\n",
1321 /* shader 15: _x2 modifier not available in VS */
1322 "vs_1_1\n"
1323 "mov r2, r1_x2\n",
1324 /* shader 16: _abs modifier not available in < VS 3.0 */
1325 "vs_1_1\n"
1326 "mov r2, r1_abs\n",
1327 /* shader 17: _x2 modifier not available in >= PS 2.0 */
1328 "ps_2_0\n"
1329 "mov r0, r1_x2\n",
1330 /* shader 18: wrong swizzle */
1331 "vs_2_0\n"
1332 "mov r0, r1.abcd\n",
1333 /* shader 19: wrong swizzle */
1334 "vs_2_0\n"
1335 "mov r0, r1.xyzwx\n",
1336 /* shader 20: wrong swizzle */
1337 "vs_2_0\n"
1338 "mov r0, r1.\n",
1339 /* shader 21: invalid writemask */
1340 "vs_2_0\n"
1341 "mov r0.xxyz, r1\n",
1342 /* shader 22: register r5 doesn't exist in PS < 1.4 */
1343 "ps_1_3\n"
1344 "mov r5, r0\n",
1345 /* shader 23: can't declare output registers in a pixel shader */
1346 "ps_3_0\n"
1347 "dcl_positiont o0\n",
1348 /* shader 24: _pp instruction modifier not allowed in vertex shaders */
1349 "vs_3_0\n"
1350 "add_pp r0, r0, r1\n",
1351 /* shader 25: _x4 instruction modified not allowed in > ps_1_x */
1352 "ps_3_0\n"
1353 "add_x4 r0, r0, r1\n",
1354 /* shader 26: there aren't oCx registers in ps_1_x */
1355 "ps_1_3\n"
1356 "add oC0, r0, r1\n",
1357 /* shader 27: oC3 is the max in >= ps_2_0 */
1358 "ps_3_0\n"
1359 "add oC4, r0, r1\n",
1360 /* shader 28: register v17 doesn't exist */
1361 "vs_3_0\n"
1362 "add r0, r0, v17\n",
1363 /* shader 29: register o13 doesn't exist */
1364 "vs_3_0\n"
1365 "add o13, r0, r1\n",
1366 /* shader 30: label > 2047 not allowed */
1367 "vs_3_0\n"
1368 "call l2048\n",
1369 /* shader 31: s20 register does not exist */
1370 "ps_3_0\n"
1371 "texld r0, r1, s20\n",
1372 /* shader 32: t5 not allowed in ps_1_3 */
1373 "ps_1_3\n"
1374 "tex t5\n",
1375 /* shader 33: no temporary registers relative addressing */
1376 "vs_3_0\n"
1377 "add r0, r0[ a0.x ], r1\n",
1378 /* shader 34: no input registers relative addressing in vs_2_0 */
1379 "vs_2_0\n"
1380 "add r0, v[ a0.x ], r1\n",
1381 /* shader 35: no aL register in ps_2_0 */
1382 "ps_2_0\n"
1383 "add r0, v[ aL ], r1\n",
1384 /* shader 36: no relative addressing in ps_2_0 */
1385 "ps_2_0\n"
1386 "add r0, v[ r0 ], r1\n",
1387 /* shader 37: no a0 register in ps_3_0 */
1388 "ps_3_0\n"
1389 "add r0, v[ a0.x ], r1\n",
1390 /* shader 38: only a0.x accepted in vs_1_1 */
1391 "vs_1_1\n"
1392 "mov r0, c0[ a0 ]\n",
1393 /* shader 39: invalid modifier for dcl instruction */
1394 "ps_3_0\n"
1395 "dcl_texcoord0_sat v0\n",
1396 /* shader 40: shift not allowed */
1397 "ps_3_0\n"
1398 "dcl_texcoord0_x2 v0\n",
1399 /* shader 41: no modifier allowed with dcl instruction in vs */
1400 "vs_3_0\n"
1401 "dcl_texcoord0_centroid v0\n",
1402 /* shader 42: no modifiers with vs dcl sampler instruction */
1403 "vs_3_0\n"
1404 "dcl_2d_pp s0\n",
1405 /* shader 43: */
1406 "ps_2_0\n"
1407 "texm3x3vspec t3, t0\n",
1409 HRESULT hr;
1410 unsigned int i;
1411 ID3DBlob *shader, *messages;
1413 for(i = 0; i < ARRAY_SIZE(tests); i++)
1415 shader = NULL;
1416 messages = NULL;
1417 hr = pD3DAssemble(tests[i], strlen(tests[i]), NULL,
1418 NULL, NULL, D3DCOMPILE_SKIP_VALIDATION,
1419 &shader, &messages);
1420 ok(hr == D3DXERR_INVALIDDATA, "Failure test, shader %d: "
1421 "expected D3DAssemble failure with D3DXERR_INVALIDDATA, "
1422 "got 0x%x - %d\n", i, hr, hr & 0x0000FFFF);
1423 if(messages) {
1424 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1425 ID3D10Blob_Release(messages);
1427 if(shader) {
1428 DWORD *res = ID3D10Blob_GetBufferPointer(shader);
1429 dump_shader(res);
1430 ID3D10Blob_Release(shader);
1435 static HRESULT WINAPI testD3DInclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type,
1436 const char *filename, const void *parent_data, const void **data, UINT *bytes)
1438 static const char include[] = "#define REGISTER r0\nvs.1.1\n";
1439 static const char include2[] = "#include \"incl3.vsh\"\n";
1440 static const char include3[] = "vs.1.1\n";
1441 static const char include4[] = "#include <incl3.vsh>\n";
1442 char *buffer;
1444 trace("include_type = %d, filename %s\n", include_type, filename);
1445 trace("parent_data (%p) -> %s\n", parent_data, parent_data ? (char *)parent_data : "(null)");
1447 if (!strcmp(filename, "incl.vsh"))
1449 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include));
1450 CopyMemory(buffer, include, sizeof(include));
1451 *bytes = sizeof(include);
1452 ok(!parent_data, "Wrong parent_data value.\n");
1454 else if (!strcmp(filename, "incl2.vsh"))
1456 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include2));
1457 CopyMemory(buffer, include2, sizeof(include2));
1458 *bytes = sizeof(include2);
1459 ok(!parent_data, "Wrong parent_data value.\n");
1460 ok(include_type == D3D_INCLUDE_LOCAL, "Wrong include type %d.\n", include_type);
1462 else if (!strcmp(filename, "incl3.vsh"))
1464 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include3));
1465 CopyMemory(buffer, include3, sizeof(include3));
1466 *bytes = sizeof(include3);
1467 /* Also check for the correct parent_data content */
1468 ok(parent_data != NULL
1469 && (!strncmp(include2, parent_data, strlen(include2))
1470 || !strncmp(include4, parent_data, strlen(include4))),
1471 "Wrong parent_data value.\n");
1473 else if (!strcmp(filename, "incl4.vsh"))
1475 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include4));
1476 CopyMemory(buffer, include4, sizeof(include4));
1477 *bytes = sizeof(include4);
1478 ok(parent_data == NULL, "Wrong parent_data value.\n");
1479 ok(include_type == D3D_INCLUDE_SYSTEM, "Wrong include type %d.\n", include_type);
1481 else if (!strcmp(filename, "includes/incl.vsh"))
1483 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include));
1484 CopyMemory(buffer, include, sizeof(include));
1485 *bytes = sizeof(include);
1486 ok(!parent_data, "Wrong parent_data value.\n");
1488 else
1490 ok(FALSE, "Unexpected file %s included.\n", filename);
1491 return E_FAIL;
1494 *data = buffer;
1496 return S_OK;
1499 static HRESULT WINAPI testD3DInclude_close(ID3DInclude *iface, const void *data)
1501 HeapFree(GetProcessHeap(), 0, (void *)data);
1502 return S_OK;
1505 static const struct ID3DIncludeVtbl D3DInclude_Vtbl =
1507 testD3DInclude_open,
1508 testD3DInclude_close
1511 struct D3DIncludeImpl {
1512 ID3DInclude ID3DInclude_iface;
1515 static void assembleshader_test(void) {
1516 static const char test1[] =
1518 "vs.1.1\n"
1519 "mov DEF2, v0\n"
1521 static const char testshader[] =
1523 "#include \"incl.vsh\"\n"
1524 "mov REGISTER, v0\n"
1526 static const D3D_SHADER_MACRO defines[] =
1529 "DEF1", "10 + 15"
1532 "DEF2", "r0"
1535 NULL, NULL
1538 HRESULT hr;
1539 ID3DBlob *shader, *messages;
1540 struct D3DIncludeImpl include;
1542 /* defines test */
1543 shader = NULL;
1544 messages = NULL;
1545 hr = pD3DAssemble(test1, strlen(test1), NULL,
1546 defines, NULL, D3DCOMPILE_SKIP_VALIDATION,
1547 &shader, &messages);
1548 ok(hr == S_OK, "defines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1549 if(messages) {
1550 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1551 ID3D10Blob_Release(messages);
1553 if(shader) ID3D10Blob_Release(shader);
1555 /* NULL messages test */
1556 shader = NULL;
1557 hr = pD3DAssemble(test1, strlen(test1), NULL,
1558 defines, NULL, D3DCOMPILE_SKIP_VALIDATION,
1559 &shader, NULL);
1560 ok(hr == S_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1561 if(shader) ID3D10Blob_Release(shader);
1563 /* NULL shader test */
1564 messages = NULL;
1565 hr = pD3DAssemble(test1, strlen(test1), NULL,
1566 defines, NULL, D3DCOMPILE_SKIP_VALIDATION,
1567 NULL, &messages);
1568 ok(hr == S_OK, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1569 if(messages) {
1570 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1571 ID3D10Blob_Release(messages);
1574 /* D3DInclude test */
1575 shader = NULL;
1576 messages = NULL;
1577 include.ID3DInclude_iface.lpVtbl = &D3DInclude_Vtbl;
1578 hr = pD3DAssemble(testshader, strlen(testshader), NULL, NULL, &include.ID3DInclude_iface,
1579 D3DCOMPILE_SKIP_VALIDATION, &shader, &messages);
1580 ok(hr == S_OK, "D3DInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1581 if(messages) {
1582 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1583 ID3D10Blob_Release(messages);
1585 if(shader) ID3D10Blob_Release(shader);
1587 /* NULL shader tests */
1588 shader = NULL;
1589 messages = NULL;
1590 hr = pD3DAssemble(NULL, 0, NULL,
1591 NULL, NULL, D3DCOMPILE_SKIP_VALIDATION,
1592 &shader, &messages);
1593 ok(hr == D3DXERR_INVALIDDATA, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1594 if(messages) {
1595 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1596 ID3D10Blob_Release(messages);
1598 if(shader) ID3D10Blob_Release(shader);
1601 static void d3dpreprocess_test(void)
1603 static const char test1[] =
1605 "vs.1.1\n"
1606 "mov DEF2, v0\n"
1608 static const char quotation_marks_test[] =
1610 "vs.1.1\n"
1611 "; ' comment\n"
1612 "; \" comment\n"
1613 "mov 0, v0\n"
1615 static const char *include_test_shaders[] =
1617 "#include \"incl.vsh\"\n"
1618 "mov REGISTER, v0\n",
1620 "#include \"incl2.vsh\"\n"
1621 "mov REGISTER, v0\n",
1623 "#include <incl.vsh>\n"
1624 "mov REGISTER, v0\n",
1626 "#include <incl4.vsh>\n"
1627 "mov REGISTER, v0\n",
1629 "#include \"includes/incl.vsh\"\n"
1630 "mov REGISTER, v0\n"
1632 HRESULT hr;
1633 ID3DBlob *shader, *messages;
1634 static const D3D_SHADER_MACRO defines[] =
1637 "DEF1", "10 + 15"
1640 "DEF2", "r0"
1643 NULL, NULL
1646 struct D3DIncludeImpl include;
1647 unsigned int i;
1649 /* pDefines test */
1650 shader = NULL;
1651 messages = NULL;
1652 hr = ppD3DPreprocess(test1, strlen(test1), NULL,
1653 defines, NULL, &shader, &messages);
1654 ok(hr == S_OK, "pDefines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1655 if (messages)
1657 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1658 ID3D10Blob_Release(messages);
1660 if (shader) ID3D10Blob_Release(shader);
1662 /* NULL messages test */
1663 shader = NULL;
1664 hr = ppD3DPreprocess(test1, strlen(test1), NULL,
1665 defines, NULL, &shader, NULL);
1666 ok(hr == S_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1667 if (shader) ID3D10Blob_Release(shader);
1669 /* NULL shader test */
1670 messages = NULL;
1671 hr = ppD3DPreprocess(test1, strlen(test1), NULL,
1672 defines, NULL, NULL, &messages);
1673 ok(hr == E_INVALIDARG, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1674 if (messages)
1676 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1677 ID3D10Blob_Release(messages);
1680 /* quotation marks test */
1681 shader = NULL;
1682 messages = NULL;
1683 hr = ppD3DPreprocess(quotation_marks_test, strlen(quotation_marks_test), NULL,
1684 NULL, NULL, &shader, &messages);
1685 todo_wine ok(hr == S_OK, "quotation marks test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1686 if (messages)
1688 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1689 ID3D10Blob_Release(messages);
1691 if (shader) ID3D10Blob_Release(shader);
1693 /* pInclude tests */
1694 include.ID3DInclude_iface.lpVtbl = &D3DInclude_Vtbl;
1695 for (i = 0; i < ARRAY_SIZE(include_test_shaders); ++i)
1697 shader = NULL;
1698 messages = NULL;
1699 hr = ppD3DPreprocess(include_test_shaders[i], strlen(include_test_shaders[i]), NULL, NULL,
1700 &include.ID3DInclude_iface, &shader, &messages);
1701 ok(hr == S_OK, "pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1702 if (messages)
1704 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1705 ID3D10Blob_Release(messages);
1707 if (shader) ID3D10Blob_Release(shader);
1710 /* NULL shader tests */
1711 shader = NULL;
1712 messages = NULL;
1713 hr = ppD3DPreprocess(NULL, 0, NULL,
1714 NULL, NULL, &shader, &messages);
1715 ok(hr == E_INVALIDARG, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1716 if (messages)
1718 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1719 ID3D10Blob_Release(messages);
1721 if (shader) ID3D10Blob_Release(shader);
1724 static BOOL load_d3dcompiler(void)
1726 HMODULE module;
1728 #if D3D_COMPILER_VERSION == 47
1729 if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE;
1730 #else
1731 if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE;
1732 #endif
1734 pD3DAssemble = (void*)GetProcAddress(module, "D3DAssemble");
1735 ppD3DPreprocess = (void*)GetProcAddress(module, "D3DPreprocess");
1736 return TRUE;
1739 START_TEST(asm)
1741 if (!load_d3dcompiler())
1743 win_skip("Could not load DLL.\n");
1744 return;
1747 preproc_test();
1748 ps_1_1_test();
1749 vs_1_1_test();
1750 ps_1_3_test();
1751 ps_1_4_test();
1752 vs_2_0_test();
1753 vs_2_x_test();
1754 ps_2_0_test();
1755 ps_2_x_test();
1756 vs_3_0_test();
1757 ps_3_0_test();
1759 failure_test();
1761 assembleshader_test();
1763 d3dpreprocess_test();