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
19 #include "wine/test.h"
21 #include <d3d9types.h>
22 #include <d3dcommon.h>
23 #include <d3dcompiler.h>
25 /* TODO: maybe this is defined in some header file,
26 perhaps with a different name? */
27 #define D3DXERR_INVALIDDATA 0x88760b59
29 HRESULT WINAPI
D3DAssemble(LPCVOID data
, SIZE_T datasize
, LPCSTR filename
,
30 const D3D_SHADER_MACRO
*defines
, LPD3DINCLUDE include
,
32 LPD3DBLOB
* shader
, LPD3DBLOB
* error_messages
);
36 const DWORD bytes
[128];
39 static void dump_shader(DWORD
*shader
) {
40 unsigned int i
= 0, j
= 0;
42 trace("0x%08x ", shader
[i
]);
45 if(j
== 6) trace("\n");
46 } while(shader
[i
- 1] != D3DSIO_END
);
47 if(j
!= 6) trace("\n");
50 static void exec_tests(const char *name
, struct shader_test tests
[], unsigned int count
) {
55 LPD3DBLOB shader
, messages
;
57 for(i
= 0; i
< count
; i
++) {
58 /* D3DAssemble sets messages to 0 if there aren't error messages */
60 hr
= D3DAssemble(tests
[i
].text
, strlen(tests
[i
].text
), NULL
,
61 NULL
, NULL
, D3DCOMPILE_SKIP_VALIDATION
,
63 ok(hr
== S_OK
, "Test %s, shader %d: D3DAssemble failed with error 0x%x - %d\n", name
, i
, hr
, hr
& 0x0000FFFF);
65 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
66 ID3D10Blob_Release(messages
);
68 if(FAILED(hr
)) continue;
72 res
= ID3D10Blob_GetBufferPointer(shader
);
73 while(res
[j
] != D3DSIO_END
&& tests
[i
].bytes
[j
] != D3DSIO_END
) {
74 if(res
[j
] != tests
[i
].bytes
[j
]) diff
= TRUE
;
77 /* Both must have an end token */
78 if(res
[j
] != tests
[i
].bytes
[j
]) diff
= TRUE
;
81 ok(FALSE
, "Test %s, shader %d: Generated code differs\n", name
, i
);
84 ID3D10Blob_Release(shader
);
88 static void preproc_test(void) {
89 struct shader_test tests
[] = {
94 "; yet another comment\r\n"
96 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
99 "#line 1 \"vertex.vsh\"\n"
101 {0xfffe0101, 0x0000ffff}
104 "#define REG 1 + 2 +\\\n"
107 "mov r0, c0[ REG ]\n",
108 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4000a, 0x0000ffff}
112 exec_tests("preproc", tests
, sizeof(tests
) / sizeof(tests
[0]));
115 static void ps_1_1_test(void) {
116 struct shader_test tests
[] = {
120 "add r0.rgb, r0, r1\r\n"
122 {0xffff0101, 0x00000042, 0xb00f0000, 0x00000002, 0x80070000, 0x80e40000,
123 0x80e40001, 0x40000001, 0x80080000, 0xb0e40000, 0x0000ffff}
128 {0xffff0101, 0x00000001, 0x8e0f0000, 0x80e40001, 0x0000ffff}
132 exec_tests("ps_1_1", tests
, sizeof(tests
) / sizeof(tests
[0]));
135 static void vs_1_1_test(void) {
136 struct shader_test tests
[] = {
137 /* Basic instruction tests */
141 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
146 {0xfffe0101, 0x00000000, 0x0000ffff}
148 /* Output register tests */
152 {0xfffe0101, 0x00000001, 0xc00f0000, 0xa0e40000, 0x0000ffff}
157 {0xfffe0101, 0x00000001, 0xe00f0000, 0xa0e40000, 0x0000ffff}
162 {0xfffe0101, 0x00000001, 0xe00f0005, 0xa0e40000, 0x0000ffff}
167 {0xfffe0101, 0x00000001, 0xd00f0000, 0xa0e40000, 0x0000ffff}
172 {0xfffe0101, 0x00000001, 0xd00f0001, 0xa0e40000, 0x0000ffff}
177 {0xfffe0101, 0x00000001, 0xc00f0001, 0xa0000000, 0x0000ffff}
182 {0xfffe0101, 0x00000001, 0xc00f0002, 0xa0000000, 0x0000ffff}
184 /* A bunch of tests for declarations */
188 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0000, 0x0000ffff}
193 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0001, 0x0000ffff}
198 {0xfffe0101, 0x0000001f, 0x800c0003, 0x900f000f, 0x0000ffff}
203 {0xfffe0101, 0x00000002, 0x800f0000, 0x90e40000, 0x90e40001, 0x0000ffff}
207 "def c12, 0, -1, -0.5, 1024\n",
208 {0xfffe0101, 0x00000051, 0xa00f000c, 0x00000000, 0xbf800000, 0xbf000000,
209 0x44800000, 0x0000ffff}
211 { /* shader 14: writemasks, swizzles */
213 "dp4 r0.xw, r1.wzyx, r2.xxww\n",
214 {0xfffe0101, 0x00000009, 0x80090000, 0x801b0001, 0x80f00002, 0x0000ffff}
216 { /* shader 15: negation input modifier. Other modifiers not supprted in vs_1_1 */
218 "add r0, -r0.x, -r1\n",
219 {0xfffe0101, 0x00000002, 0x800f0000, 0x81000000, 0x81e40001, 0x0000ffff}
221 { /* shader 16: relative addressing */
223 "mov r0, c0[a0.x]\n",
224 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42000, 0x0000ffff}
226 { /* shader 17: relative addressing */
228 "mov r0, c1[a0.x + 2]\n",
229 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42003, 0x0000ffff}
233 "def c0, 1.0f, 1.0f, 1.0f, 0.5f\n",
234 {0xfffe0101, 0x00000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000,
235 0x3f000000, 0x0000ffff}
237 /* Other relative addressing tests */
240 "mov r0, c[ a0.x + 12 ]\n",
241 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200c, 0x0000ffff}
245 "mov r0, c[ 2 + a0.x ]\n",
246 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42002, 0x0000ffff}
250 "mov r0, c[ 2 + a0.x + 12 ]\n",
251 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200e, 0x0000ffff}
255 "mov r0, c[ 2 + 10 + 12 ]\n",
256 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40018, 0x0000ffff}
261 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40006, 0x0000ffff}
266 {0xfffe0101, 0x00000006, 0x800f0000, 0x90000000, 0x0000ffff}
271 {0xfffe0101, 0x00000007, 0x800f0000, 0x90000000, 0x0000ffff}
275 exec_tests("vs_1_1", tests
, sizeof(tests
) / sizeof(tests
[0]));
278 static void ps_1_3_test(void) {
279 struct shader_test tests
[] = {
280 /* Basic instruction tests */
284 {0xffff0103, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
289 {0xffff0103, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40000, 0x0000ffff}
291 /* Color interpolator tests */
295 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40000, 0x0000ffff}
300 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
302 /* Texture sampling instructions */
306 {0xffff0103, 0x00000042, 0xb00f0000, 0x0000ffff}
311 "texreg2ar t1, t0\n",
312 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000045, 0xb00f0001, 0xb0e40000,
318 "texreg2gb t1, t0\n",
319 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000046, 0xb00f0001, 0xb0e40000,
325 "texreg2rgb t1, t0\n",
326 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000052, 0xb00f0001, 0xb0e40000,
331 "cnd r0, r1, r0, v0\n",
332 {0xffff0103, 0x00000050, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
337 "cmp r0, r1, r0, v0\n",
338 {0xffff0103, 0x00000058, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
344 {0xffff0103, 0x00000041, 0xb00f0000, 0x0000ffff}
349 "texm3x2pad t1, t0\n"
350 "texm3x2tex t2, t0\n",
351 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
352 0x00000048, 0xb00f0002, 0xb0e40000, 0x0000ffff}
357 "texm3x2pad t1, t0\n"
358 "texm3x2depth t2, t0\n",
359 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
360 0x00000054, 0xb00f0002, 0xb0e40000, 0x0000ffff}
366 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000043, 0xb00f0001, 0xb0e40000,
373 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000044, 0xb00f0001, 0xb0e40000,
379 "texdp3tex t1, t0\n",
380 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000053, 0xb00f0001, 0xb0e40000,
387 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000055, 0xb00f0001, 0xb0e40000,
393 "texm3x3pad t1, t0\n"
394 "texm3x3pad t2, t0\n"
395 "texm3x3tex t3, t0\n",
396 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
397 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004a, 0xb00f0003, 0xb0e40000,
403 "texm3x3pad t1, t0\n"
404 "texm3x3pad t2, t0\n"
406 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
407 0x00000049, 0xb00f0002, 0xb0e40000, 0x00000056, 0xb00f0003, 0xb0e40000,
413 "texm3x3pad t1, t0\n"
414 "texm3x3pad t2, t0\n"
415 "texm3x3spec t3, t0, c0\n",
416 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
417 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004c, 0xb00f0003, 0xb0e40000,
418 0xa0e40000, 0x0000ffff}
423 "texm3x3pad t1, t0\n"
424 "texm3x3pad t2, t0\n"
425 "texm3x3vspec t3, t0\n",
426 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
427 0x00000049, 0xb00f0002, 0xb0e40000, 0x0000004d, 0xb00f0003, 0xb0e40000,
433 {0xffff0103, 0x00000040, 0xb00f0000, 0x0000ffff}
435 /* Modifiers, shifts */
438 "mov_x2_sat r0, 1 - r1\n",
439 {0xffff0103, 0x00000001, 0x811f0000, 0x86e40001, 0x0000ffff}
444 {0xffff0103, 0x00000001, 0x8d0f0000, 0x81e40001, 0x0000ffff}
448 "mov_sat r0, r1_bx2\n",
449 {0xffff0103, 0x00000001, 0x801f0000, 0x84e40001, 0x0000ffff}
453 "mov_sat r0, r1_bias\n",
454 {0xffff0103, 0x00000001, 0x801f0000, 0x82e40001, 0x0000ffff}
458 "mov_sat r0, -r1_bias\n",
459 {0xffff0103, 0x00000001, 0x801f0000, 0x83e40001, 0x0000ffff}
463 "mov_sat r0, -r1_bx2\n",
464 {0xffff0103, 0x00000001, 0x801f0000, 0x85e40001, 0x0000ffff}
468 "mov_sat r0, -r1_x2\n",
469 {0xffff0103, 0x00000001, 0x801f0000, 0x88e40001, 0x0000ffff}
473 "mov_x4_sat r0.a, -r1_bx2.a\n",
474 {0xffff0103, 0x00000001, 0x82180000, 0x85ff0001, 0x0000ffff}
479 {0xffff0103, 0x00000040, 0xb10f0000, 0x0000ffff}
484 {0xffff0103, 0x00000042, 0xb10f0000, 0x0000ffff}
488 "texreg2ar_x4 t0, t1\n",
489 {0xffff0103, 0x00000045, 0xb20f0000, 0xb0e40001, 0x0000ffff}
493 "texbem_d4 t1, t0\n",
494 {0xffff0103, 0x00000043, 0xbe0f0001, 0xb0e40000, 0x0000ffff}
499 "texm3x3pad_x2 t1, t0\n"
500 "texm3x3pad_x2 t2, t0\n"
501 "texm3x3tex_x2 t3, t0\n",
502 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb10f0001, 0xb0e40000,
503 0x00000049, 0xb10f0002, 0xb0e40000, 0x0000004a, 0xb10f0003, 0xb0e40000,
509 "texdp3tex_x8 t1, t0\n",
510 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000053, 0xb30f0001, 0xb0e40000,
515 exec_tests("ps_1_3", tests
, sizeof(tests
) / sizeof(tests
[0]));
518 static void ps_1_4_test(void) {
519 struct shader_test tests
[] = {
520 /* Basic instruction tests */
524 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
529 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40005, 0x0000ffff}
534 {0xffff0104, 0x00000001, 0x800f0000, 0xa0e40007, 0x0000ffff}
539 {0xffff0104, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
544 {0xffff0104, 0x0000fffd, 0x0000ffff}
549 {0xffff0104, 0x00000040, 0x800f0000, 0xb0e40000, 0x0000ffff}
554 {0xffff0104, 0x00000040, 0x800f0004, 0xb0e40003, 0x0000ffff}
558 "texcrd_sat r4, t3\n",
559 {0xffff0104, 0x00000040, 0x801f0004, 0xb0e40003, 0x0000ffff}
564 {0xffff0104, 0x00000042, 0x800f0000, 0xb0e40000, 0x0000ffff}
569 {0xffff0104, 0x00000042, 0x800f0001, 0xb0e40004, 0x0000ffff}
574 {0xffff0104, 0x00000042, 0x800f0005, 0x80e40000, 0x0000ffff}
578 "texld r5, c0\n", /* Assembly succeeds, validation fails */
579 {0xffff0104, 0x00000042, 0x800f0005, 0xa0e40000, 0x0000ffff}
584 {0xffff0104, 0x00000042, 0x800f0005, 0x89e40002, 0x0000ffff}
588 "bem r1.rg, c0, r0\n",
589 {0xffff0104, 0x00000059, 0x80030001, 0xa0e40000, 0x80e40000, 0x0000ffff}
594 {0xffff0104, 0x00000057, 0x800f0005, 0x0000ffff}
598 "add r0, r1, r2_bx2\n",
599 {0xffff0104, 0x00000002, 0x800f0000, 0x80e40001, 0x84e40002, 0x0000ffff}
603 "add_x4 r0, r1, r2\n",
604 {0xffff0104, 0x00000002, 0x820f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
608 "add r0.rgb, r1, r2\n"
609 "+add r0.a, r1, r2\n",
610 {0xffff0104, 0x00000002, 0x80070000, 0x80e40001, 0x80e40002, 0x40000002,
611 0x80080000, 0x80e40001, 0x80e40002, 0x0000ffff}
616 {0xffff0104, 0x00000057, 0x810f0005, 0x0000ffff}
620 "bem_d2 r1, c0, r0\n",
621 {0xffff0104, 0x00000059, 0x8f0f0001, 0xa0e40000, 0x80e40000, 0x0000ffff}
625 exec_tests("ps_1_4", tests
, sizeof(tests
) / sizeof(tests
[0]));
628 static void vs_2_0_test(void) {
629 struct shader_test tests
[] = {
630 /* Basic instruction tests */
634 {0xfffe0200, 0x02000001, 0x800f0000, 0x80e40001, 0x0000ffff}
638 "lrp r0, v0, c0, r1\n",
639 {0xfffe0200, 0x04000012, 0x800f0000, 0x90e40000, 0xa0e40000, 0x80e40001,
644 "dp4 oPos, v0, c0\n",
645 {0xfffe0200, 0x03000009, 0xc00f0000, 0x90e40000, 0xa0e40000, 0x0000ffff}
649 "mov r0, c0[a0.x]\n",
650 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0000000, 0x0000ffff}
654 "mov r0, c0[a0.y]\n",
655 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0550000, 0x0000ffff}
659 "mov r0, c0[a0.z]\n",
660 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0aa0000, 0x0000ffff}
664 "mov r0, c0[a0.w]\n",
665 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0ff0000, 0x0000ffff}
669 "mov r0, c0[a0.w].x\n",
670 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0002000, 0xb0ff0000, 0x0000ffff}
674 "mov r0, -c0[a0.w+5].x\n",
675 {0xfffe0200, 0x03000001, 0x800f0000, 0xa1002005, 0xb0ff0000, 0x0000ffff}
680 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0e40000, 0x0000ffff}
684 "mov r0, c0[a0.xyww]\n",
685 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0f40000, 0x0000ffff}
689 "add r0, c0[a0.x], c1[a0.y]\n", /* validation would fail on this line */
690 {0xfffe0200, 0x05000002, 0x800f0000, 0xa0e42000, 0xb0000000, 0xa0e42001,
691 0xb0550000, 0x0000ffff}
697 {0xfffe0200, 0x01000026, 0xf0e40000, 0x00000027, 0x0000ffff}
704 {0xfffe0200, 0x01000028, 0xe0e40800, 0x0000002a, 0x0000002b, 0x0000ffff}
710 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x0000001d, 0x0000ffff}
715 {0xfffe0200, 0x02000024, 0x800f0000, 0xa0e40000, 0x0000ffff}
720 {0xfffe0200, 0x03000021, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
724 "sgn r0, r1, r2, r3\n",
725 {0xfffe0200, 0x04000022, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
730 "sincos r0, r1, r2, r3\n",
731 {0xfffe0200, 0x04000025, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
737 {0xfffe0200, 0x03000020, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
742 {0xfffe0200, 0x0200002e, 0xb0020000, 0xa0aa0000, 0x0000ffff}
748 {0xfffe0200, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
749 0x00000000, 0x0000ffff}
753 "defi i0, -1, 1, 10, 0\n"
754 "defi i1, 0, 40, 30, 10\n",
755 {0xfffe0200, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
756 0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
757 0x0000000a, 0x0000ffff}
764 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
765 0xa0e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
773 {0xfffe0200, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
774 0x0000001c, 0x0000ffff}
782 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
783 0xa0e41000, 0x0000001c, 0x0000ffff}
791 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
792 0xa0e41000, 0x0000001c, 0x0000ffff}
799 {0xfffe0200, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
807 {0xfffe0200, 0x01000019, 0xa0e41003, 0x0000001c, 0x0100001e, 0xa0e41003, 0x0000001c, 0x0000ffff}
809 { /* shader 29: labels up to 2047 are accepted even in vs_2_0 */
812 {0xfffe0200, 0x01000019, 0xa0e417ff, 0x0000ffff}
816 exec_tests("vs_2_0", tests
, sizeof(tests
) / sizeof(tests
[0]));
819 static void vs_2_x_test(void) {
820 struct shader_test tests
[] = {
826 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
832 {0xfffe0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
839 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
840 0x00000027, 0x0000ffff}
846 "setp_gt p0, r0, r1\n"
847 "(!p0) add r2, r2, r3\n",
848 {0xfffe0201, 0x0301005e, 0xb00f1000, 0x80e40000, 0x80e40001, 0x14000002,
849 0x800f0002, 0xbde41000, 0x80e40002, 0x80e40003, 0x0000ffff}
856 {0xfffe0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
864 {0xfffe0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
865 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
872 {0xfffe0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
873 0x00000027, 0x0000ffff}
877 exec_tests("vs_2_x", tests
, sizeof(tests
) / sizeof(tests
[0]));
880 static void ps_2_0_test(void) {
881 struct shader_test tests
[] = {
885 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
890 {0xffff0200, 0x0200001f, 0x98000000, 0xa00f0800, 0x0000ffff}
895 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0000ffff}
902 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0200001f, 0x98000000,
903 0xa00f0801, 0x0200001f, 0x90000000, 0xa00f0802, 0x0000ffff}
908 {0xffff0200, 0x02000001, 0x800f0000, 0xb0e40000, 0x0000ffff}
913 "texld r0, t1, s2\n",
914 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000,
915 0xb0e40001, 0xa0e40802, 0x0000ffff}
920 {0xffff0200, 0x01000041, 0xb00f0000, 0x0000ffff}
926 {0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x02000001, 0x800f0801,
927 0xa0e40001, 0x0000ffff}
931 "mov oDepth, c0.x\n",
932 {0xffff0200, 0x02000001, 0x900f0800, 0xa0000000, 0x0000ffff}
937 "texldp r0, t1, s2\n",
938 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03010042, 0x800f0000,
939 0xb0e40001, 0xa0e40802, 0x0000ffff}
944 "texldb r0, t1, s2\n",
945 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03020042, 0x800f0000,
946 0xb0e40001, 0xa0e40802, 0x0000ffff}
950 exec_tests("ps_2_0", tests
, sizeof(tests
) / sizeof(tests
[0]));
953 static void ps_2_x_test(void) {
954 struct shader_test tests
[] = {
955 /* defb and defi are not supposed to work in ps_2_0 (even if defb actually works in ps_2_0 with native) */
960 {0xffff0201, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
961 0x00000000, 0x0000ffff}
965 "defi i0, -1, 1, 10, 0\n"
966 "defi i1, 0, 40, 30, 10\n",
967 {0xffff0201, 0x05000030, 0xf00f0000, 0xffffffff, 0x00000001, 0x0000000a,
968 0x00000000, 0x05000030, 0xf00f0001, 0x00000000, 0x00000028, 0x0000001e,
969 0x0000000a, 0x0000ffff}
974 {0xffff0201, 0x0200005b, 0x800f0000, 0x80e40000, 0x0000ffff}
979 {0xffff0201, 0x0200005c, 0x800f0000, 0x80e40000, 0x0000ffff}
984 "texldd r0, v1, s2, r3, r4\n",
985 {0xffff0201, 0x0200001f, 0x90000000, 0xa00f0802, 0x0500005d, 0x800f0000,
986 0x90e40001, 0xa0e40802, 0x80e40003, 0x80e40004, 0x0000ffff}
988 /* Static flow control tests */
995 {0xffff0201, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
996 0x0000001c, 0x0000ffff}
1004 {0xffff0201, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
1005 0xa0e41000, 0x0000001c, 0x0000ffff}
1013 {0xffff0201, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
1014 0xa0e41000, 0x0000001c, 0x0000ffff}
1021 {0xffff0201, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
1023 /* Dynamic flow control tests */
1029 {0xffff0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
1035 {0xffff0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
1042 {0xffff0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
1043 0x00000027, 0x0000ffff}
1048 "setp_gt p0, r0, r1\n"
1049 "(!p0) add r2, r2, r3\n",
1050 {0xffff0201, 0x0301005e, 0xb00f1000, 0x80e40000, 0x80e40001, 0x14000002,
1051 0x800f0002, 0xbde41000, 0x80e40002, 0x80e40003, 0x0000ffff}
1058 {0xffff0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
1062 "callnz l0, !p0.z\n"
1066 {0xffff0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
1067 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
1074 {0xffff0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
1075 0x00000027, 0x0000ffff}
1083 {0xffff0201, 0x01000019, 0xa0e417ff, 0x0000001c, 0x0100001e, 0xa0e417ff,
1084 0x0000001c, 0x0000ffff}
1088 exec_tests("ps_2_x", tests
, sizeof(tests
) / sizeof(tests
[0]));
1091 static void vs_3_0_test(void) {
1092 struct shader_test tests
[] = {
1096 {0xfffe0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1101 {0xfffe0300, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
1105 "dcl_position o0\n",
1106 {0xfffe0300, 0x0200001f, 0x80000000, 0xe00f0000, 0x0000ffff}
1110 "dcl_texcoord12 o11\n",
1111 {0xfffe0300, 0x0200001f, 0x800c0005, 0xe00f000b, 0x0000ffff}
1115 "texldl r0, v0, s0\n",
1116 {0xfffe0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1121 {0xfffe0300, 0x03000001, 0x800f0000, 0xa0e42000, 0xf0e40800, 0x0000ffff}
1125 "mov o[ a0.x + 12 ], r0\n",
1126 {0xfffe0300, 0x03000001, 0xe00f200c, 0xb0000000, 0x80e40000, 0x0000ffff}
1130 "add_sat r0, r0, r1\n",
1131 {0xfffe0300, 0x03000002, 0x801f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1136 {0xfffe0300, 0x02000001, 0x800f0002, 0x8be40001, 0x0000ffff}
1140 "mov r2, r1.xygb\n",
1141 {0xfffe0300, 0x02000001, 0x800f0002, 0x80940001, 0x0000ffff}
1146 {0xfffe0300, 0x02000001, 0x80070002, 0x80e40001, 0x0000ffff}
1150 "mova_sat a0.x, r1\n",
1151 {0xfffe0300, 0x0200002e, 0xb0110000, 0x80e40001, 0x0000ffff}
1156 {0xfffe0300, 0x02000025, 0x800f0000, 0x80e40001, 0x0000ffff}
1160 "def c0, 1.0f, 1.0f, 1.0f, 0.5f\n",
1161 {0xfffe0300, 0x05000051, 0xa00f0000, 0x3f800000, 0x3f800000, 0x3f800000,
1162 0x3f000000, 0x0000ffff}
1164 { /* shader 14: no register number checks with relative addressing */
1166 "add r0, v20[aL], r2\n",
1167 {0xfffe0300, 0x04000002, 0x800f0000, 0x90e42014, 0xf0e40800, 0x80e40002,
1173 exec_tests("vs_3_0", tests
, sizeof(tests
) / sizeof(tests
[0]));
1176 static void ps_3_0_test(void) {
1177 struct shader_test tests
[] = {
1181 {0xffff0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1186 {0xffff0300, 0x0200001f, 0x80050003, 0x900f0000, 0x0000ffff}
1191 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41000, 0x0000ffff}
1196 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41001, 0x0000ffff}
1200 "mov r0, v[ aL + 12 ]\n",
1201 {0xffff0300, 0x03000001, 0x800f0000, 0x90e4200c, 0xf0e40800, 0x0000ffff}
1208 {0xffff0300, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
1209 0x90e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
1213 "texldl r0, v0, s0\n",
1214 {0xffff0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1218 "add_pp r0, r0, r1\n",
1219 {0xffff0300, 0x03000002, 0x802f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1224 {0xffff0300, 0x0200005b, 0x801f0000, 0x80e40001, 0x0000ffff}
1228 "texldd_pp r0, r1, r2, r3, r4\n",
1229 {0xffff0300, 0x0500005d, 0x802f0000, 0x80e40001, 0x80e40002, 0x80e40003,
1230 0x80e40004, 0x0000ffff}
1235 {0xffff0300, 0x01000041, 0x900f0000, 0x0000ffff}
1239 "add oC3, r0, r1\n",
1240 {0xffff0300, 0x03000002, 0x800f0803, 0x80e40000, 0x80e40001, 0x0000ffff}
1244 "dcl_texcoord0_centroid v0\n",
1245 {0xffff0300, 0x0200001f, 0x80000005, 0x904f0000, 0x0000ffff}
1249 "dcl_2d_centroid s0\n",
1250 {0xffff0300, 0x0200001f, 0x90000000, 0xa04f0800, 0x0000ffff}
1255 {0xffff0300, 0x0200001f, 0x90000000, 0xa02f0800, 0x0000ffff}
1259 exec_tests("ps_3_0", tests
, sizeof(tests
) / sizeof(tests
[0]));
1262 static void failure_test(void) {
1263 const char * tests
[] = {
1264 /* shader 0: instruction modifier not allowed */
1267 "texldd_x2 r0, v1, s2, v3, v4\n",
1268 /* shader 1: coissue not supported in vertex shaders */
1270 "add r0.rgb, r0, r1\n"
1271 "+add r0.a, r0, r2\n",
1272 /* shader 2: coissue not supported in pixel shader version >= 2.0 */
1274 "texld r0, t0, s0\n"
1275 "add r0.rgb, r0, r1\n"
1276 "+add r0.a, r0, v1\n",
1277 /* shader 3: predicates not supported in vertex shader < 2.0 */
1279 "(p0) add r0, r0, v0\n",
1280 /* shader 4: register a0 doesn't exist in pixel shaders */
1282 "mov r0, v[ a0 + 12 ]\n",
1283 /* shader 5: s0 doesn't exist in vs_1_1 */
1286 /* shader 6: aL is a scalar register, no swizzles allowed */
1288 "mov r0, v[ aL.x + 12 ]\n",
1289 /* shader 7: tn doesn't exist in ps_3_0 */
1292 "texldd r0, t1, s2, v3, v4\n",
1293 /* shader 8: two shift modifiers */
1295 "mov_x2_x2 r0, r1\n",
1296 /* shader 9: too many source registers for mov instruction */
1299 /* shader 10: invalid combination of negate and divide modifiers */
1301 "texld r5, -r2_dz\n",
1302 /* shader 11: complement modifier not allowed in >= PS 2 */
1305 /* shader 12: invalid modifier */
1308 /* shader 13: float value in relative addressing */
1310 "mov r2, c[ aL + 3.4 ]\n",
1311 /* shader 14: complement modifier not available in VS */
1314 /* shader 15: _x2 modifier not available in VS */
1317 /* shader 16: _abs modifier not available in < VS 3.0 */
1320 /* shader 17: _x2 modifier not available in >= PS 2.0 */
1323 /* shader 18: wrong swizzle */
1325 "mov r0, r1.abcd\n",
1326 /* shader 19: wrong swizzle */
1328 "mov r0, r1.xyzwx\n",
1329 /* shader 20: wrong swizzle */
1332 /* shader 21: invalid writemask */
1334 "mov r0.xxyz, r1\n",
1335 /* shader 22: register r5 doesn't exist in PS < 1.4 */
1338 /* shader 23: can't declare output registers in a pixel shader */
1340 "dcl_positiont o0\n",
1341 /* shader 24: _pp instruction modifier not allowed in vertex shaders */
1343 "add_pp r0, r0, r1\n",
1344 /* shader 25: _x4 instruction modified not allowed in > ps_1_x */
1346 "add_x4 r0, r0, r1\n",
1347 /* shader 26: there aren't oCx registers in ps_1_x */
1349 "add oC0, r0, r1\n",
1350 /* shader 27: oC3 is the max in >= ps_2_0 */
1352 "add oC4, r0, r1\n",
1353 /* shader 28: register v17 doesn't exist */
1355 "add r0, r0, v17\n",
1356 /* shader 29: register o13 doesn't exist */
1358 "add o13, r0, r1\n",
1359 /* shader 30: label > 2047 not allowed */
1362 /* shader 31: s20 register does not exist */
1364 "texld r0, r1, s20\n",
1365 /* shader 32: t5 not allowed in ps_1_3 */
1368 /* shader 33: no temporary registers relative addressing */
1370 "add r0, r0[ a0.x ], r1\n",
1371 /* shader 34: no input registers relative addressing in vs_2_0 */
1373 "add r0, v[ a0.x ], r1\n",
1374 /* shader 35: no aL register in ps_2_0 */
1376 "add r0, v[ aL ], r1\n",
1377 /* shader 36: no relative addressing in ps_2_0 */
1379 "add r0, v[ r0 ], r1\n",
1380 /* shader 37: no a0 register in ps_3_0 */
1382 "add r0, v[ a0.x ], r1\n",
1383 /* shader 38: only a0.x accepted in vs_1_1 */
1385 "mov r0, c0[ a0 ]\n",
1386 /* shader 39: invalid modifier for dcl instruction */
1388 "dcl_texcoord0_sat v0\n",
1389 /* shader 40: shift not allowed */
1391 "dcl_texcoord0_x2 v0\n",
1392 /* shader 41: no modifier allowed with dcl instruction in vs */
1394 "dcl_texcoord0_centroid v0\n",
1395 /* shader 42: no modifiers with vs dcl sampler instruction */
1400 "texm3x3vspec t3, t0\n",
1404 LPD3DBLOB shader
, messages
;
1406 for(i
= 0; i
< (sizeof(tests
) / sizeof(tests
[0])); i
++) {
1409 hr
= D3DAssemble(tests
[i
], strlen(tests
[i
]), NULL
,
1410 NULL
, NULL
, D3DCOMPILE_SKIP_VALIDATION
,
1411 &shader
, &messages
);
1412 ok(hr
== D3DXERR_INVALIDDATA
, "Failure test, shader %d: "
1413 "expected D3DAssemble failure with D3DXERR_INVALIDDATA, "
1414 "got 0x%x - %d\n", i
, hr
, hr
& 0x0000FFFF);
1416 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1417 ID3D10Blob_Release(messages
);
1420 DWORD
*res
= ID3D10Blob_GetBufferPointer(shader
);
1422 ID3D10Blob_Release(shader
);
1427 static HRESULT WINAPI
testD3DInclude_open(ID3DInclude
*iface
, D3D_INCLUDE_TYPE include_type
,
1428 const char *filename
, const void *parent_data
, const void **data
, UINT
*bytes
)
1431 char include
[] = "#define REGISTER r0\nvs.1.1\n";
1432 char include2
[] = "#include \"incl3.vsh\"\n";
1433 char include3
[] = "vs.1.1\n";
1435 trace("filename %s\n", filename
);
1436 trace("parent_data (%p) -> %s\n", parent_data
, (char *)parent_data
);
1438 if (!strcmp(filename
, "incl.vsh"))
1440 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(include
));
1441 CopyMemory(buffer
, include
, sizeof(include
));
1442 *bytes
= sizeof(include
);
1444 else if (!strcmp(filename
, "incl3.vsh"))
1446 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(include3
));
1447 CopyMemory(buffer
, include3
, sizeof(include3
));
1448 *bytes
= sizeof(include3
);
1449 /* Also check for the correct parent_data content */
1450 ok(parent_data
!= NULL
&& !strncmp(include2
, parent_data
, strlen(include2
)), "wrong parent_data value\n");
1454 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(include2
));
1455 CopyMemory(buffer
, include2
, sizeof(include2
));
1456 *bytes
= sizeof(include2
);
1464 static HRESULT WINAPI
testD3DInclude_close(ID3DInclude
*iface
, const void *data
)
1466 HeapFree(GetProcessHeap(), 0, (LPVOID
)data
);
1470 static const struct ID3DIncludeVtbl D3DInclude_Vtbl
=
1472 testD3DInclude_open
,
1473 testD3DInclude_close
1476 struct D3DIncludeImpl
{
1477 const ID3DIncludeVtbl
*lpVtbl
;
1480 static void assembleshader_test(void) {
1481 const char test1
[] = {
1485 const char testshader
[] = {
1486 "#include \"incl.vsh\"\n"
1487 "mov REGISTER, v0\n"
1490 LPD3DBLOB shader
, messages
;
1491 D3D_SHADER_MACRO defines
[] = {
1502 struct D3DIncludeImpl include
;
1507 hr
= D3DAssemble(test1
, strlen(test1
), NULL
,
1508 defines
, NULL
, D3DCOMPILE_SKIP_VALIDATION
,
1509 &shader
, &messages
);
1510 ok(hr
== S_OK
, "defines test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1512 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1513 ID3D10Blob_Release(messages
);
1515 if(shader
) ID3D10Blob_Release(shader
);
1517 /* NULL messages test */
1519 hr
= D3DAssemble(test1
, strlen(test1
), NULL
,
1520 defines
, NULL
, D3DCOMPILE_SKIP_VALIDATION
,
1522 ok(hr
== S_OK
, "NULL messages test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1523 if(shader
) ID3D10Blob_Release(shader
);
1525 /* NULL shader test */
1527 hr
= D3DAssemble(test1
, strlen(test1
), NULL
,
1528 defines
, NULL
, D3DCOMPILE_SKIP_VALIDATION
,
1530 ok(hr
== S_OK
, "NULL shader test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1532 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1533 ID3D10Blob_Release(messages
);
1536 /* D3DInclude test */
1539 include
.lpVtbl
= &D3DInclude_Vtbl
;
1540 hr
= D3DAssemble(testshader
, strlen(testshader
), NULL
,
1541 NULL
, (LPD3DINCLUDE
)&include
, D3DCOMPILE_SKIP_VALIDATION
,
1542 &shader
, &messages
);
1543 ok(hr
== S_OK
, "D3DInclude test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1545 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1546 ID3D10Blob_Release(messages
);
1548 if(shader
) ID3D10Blob_Release(shader
);
1550 /* NULL shader tests */
1553 hr
= D3DAssemble(NULL
, 0, NULL
,
1554 NULL
, NULL
, D3DCOMPILE_SKIP_VALIDATION
,
1555 &shader
, &messages
);
1556 ok(hr
== D3DXERR_INVALIDDATA
, "NULL shader test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1558 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1559 ID3D10Blob_Release(messages
);
1561 if(shader
) ID3D10Blob_Release(shader
);
1564 static void d3dpreprocess_test(void)
1566 const char test1
[] =
1571 const char testshader
[] =
1573 "#include \"incl.vsh\"\n"
1574 "mov REGISTER, v0\n"
1576 const char testshader2
[] =
1578 "#include \"incl2.vsh\"\n"
1579 "mov REGISTER, v0\n"
1582 ID3DBlob
*shader
, *messages
;
1583 D3D_SHADER_MACRO defines
[] =
1595 struct D3DIncludeImpl include
;
1600 hr
= D3DPreprocess(test1
, strlen(test1
), NULL
,
1601 defines
, NULL
, &shader
, &messages
);
1602 ok(hr
== S_OK
, "pDefines test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1605 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1606 ID3D10Blob_Release(messages
);
1608 if (shader
) ID3D10Blob_Release(shader
);
1610 /* NULL messages test */
1612 hr
= D3DPreprocess(test1
, strlen(test1
), NULL
,
1613 defines
, NULL
, &shader
, NULL
);
1614 ok(hr
== S_OK
, "NULL messages test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1615 if (shader
) ID3D10Blob_Release(shader
);
1617 /* NULL shader test */
1619 hr
= D3DPreprocess(test1
, strlen(test1
), NULL
,
1620 defines
, NULL
, NULL
, &messages
);
1621 ok(hr
== E_INVALIDARG
, "NULL shader test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1624 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1625 ID3D10Blob_Release(messages
);
1631 include
.lpVtbl
= &D3DInclude_Vtbl
;
1632 hr
= D3DPreprocess(testshader
, strlen(testshader
), NULL
,
1633 NULL
, (ID3DInclude
*)&include
, &shader
, &messages
);
1634 ok(hr
== S_OK
, "pInclude test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1637 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1638 ID3D10Blob_Release(messages
);
1640 if (shader
) ID3D10Blob_Release(shader
);
1642 /* recursive #include test */
1645 hr
= D3DPreprocess(testshader2
, strlen(testshader2
), NULL
,
1646 NULL
, (ID3DInclude
*)&include
, &shader
, &messages
);
1647 ok(hr
== S_OK
, "D3DPreprocess test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1650 trace("recursive D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1651 ID3D10Blob_Release(messages
);
1653 if (shader
) ID3D10Blob_Release(shader
);
1655 /* NULL shader tests */
1658 hr
= D3DPreprocess(NULL
, 0, NULL
,
1659 NULL
, NULL
, &shader
, &messages
);
1660 ok(hr
== E_INVALIDARG
, "NULL shader test failed with error 0x%x - %d\n", hr
, hr
& 0x0000FFFF);
1663 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages
));
1664 ID3D10Blob_Release(messages
);
1666 if (shader
) ID3D10Blob_Release(shader
);
1685 assembleshader_test();
1687 d3dpreprocess_test();