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
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 HRESULT WINAPI D3DAssemble(LPCVOID data, SIZE_T datasize, LPCSTR filename,
31 const D3D_SHADER_MACRO *defines, LPD3DINCLUDE include,
33 LPD3DBLOB* shader, LPD3DBLOB* error_messages);
37 const DWORD bytes[128];
40 static void dump_shader(DWORD *shader) {
41 unsigned int i = 0, j = 0;
43 trace("0x%08x ", shader[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) {
56 LPD3DBLOB shader, messages;
58 for(i = 0; i < count; i++) {
59 /* D3DAssemble sets messages to 0 if there aren't error messages */
61 hr = D3DAssemble(tests[i].text, strlen(tests[i].text), NULL,
62 NULL, NULL, D3DCOMPILE_SKIP_VALIDATION,
64 ok(hr == S_OK, "Test %s, shader %d: D3DAssemble failed with error 0x%x - %d\n", name, i, hr, hr & 0x0000FFFF);
66 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
67 ID3D10Blob_Release(messages);
69 if(FAILED(hr)) continue;
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;
78 /* Both must have an end token */
79 if(res[j] != tests[i].bytes[j]) diff = TRUE;
82 ok(FALSE, "Test %s, shader %d: Generated code differs\n", name, i);
85 ID3D10Blob_Release(shader);
89 static void preproc_test(void) {
90 struct shader_test tests[] = {
95 "; yet another comment\r\n"
97 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
100 "#line 1 \"vertex.vsh\"\n"
102 {0xfffe0101, 0x0000ffff}
105 "#define REG 1 + 2 +\\\n"
108 "mov r0, c0[ REG ]\n",
109 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4000a, 0x0000ffff}
113 exec_tests("preproc", tests, sizeof(tests) / sizeof(tests[0]));
116 static void ps_1_1_test(void) {
117 struct shader_test tests[] = {
121 "add r0.rgb, r0, r1\r\n"
123 {0xffff0101, 0x00000042, 0xb00f0000, 0x00000002, 0x80070000, 0x80e40000,
124 0x80e40001, 0x40000001, 0x80080000, 0xb0e40000, 0x0000ffff}
129 {0xffff0101, 0x00000001, 0x8e0f0000, 0x80e40001, 0x0000ffff}
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, sizeof(tests) / sizeof(tests[0]));
142 static void vs_1_1_test(void) {
143 struct shader_test tests[] = {
144 /* Basic instruction tests */
148 {0xfffe0101, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
153 {0xfffe0101, 0x00000000, 0x0000ffff}
155 /* Output register tests */
159 {0xfffe0101, 0x00000001, 0xc00f0000, 0xa0e40000, 0x0000ffff}
164 {0xfffe0101, 0x00000001, 0xe00f0000, 0xa0e40000, 0x0000ffff}
169 {0xfffe0101, 0x00000001, 0xe00f0005, 0xa0e40000, 0x0000ffff}
174 {0xfffe0101, 0x00000001, 0xd00f0000, 0xa0e40000, 0x0000ffff}
179 {0xfffe0101, 0x00000001, 0xd00f0001, 0xa0e40000, 0x0000ffff}
184 {0xfffe0101, 0x00000001, 0xc00f0001, 0xa0000000, 0x0000ffff}
189 {0xfffe0101, 0x00000001, 0xc00f0002, 0xa0000000, 0x0000ffff}
191 /* A bunch of tests for declarations */
195 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0000, 0x0000ffff}
200 {0xfffe0101, 0x0000001f, 0x80000000, 0x900f0001, 0x0000ffff}
205 {0xfffe0101, 0x0000001f, 0x800c0003, 0x900f000f, 0x0000ffff}
210 {0xfffe0101, 0x00000002, 0x800f0000, 0x90e40000, 0x90e40001, 0x0000ffff}
214 "def c12, 0, -1, -0.5, 1024\n",
215 {0xfffe0101, 0x00000051, 0xa00f000c, 0x00000000, 0xbf800000, 0xbf000000,
216 0x44800000, 0x0000ffff}
218 { /* shader 14: writemasks, swizzles */
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 */
225 "add r0, -r0.x, -r1\n",
226 {0xfffe0101, 0x00000002, 0x800f0000, 0x81000000, 0x81e40001, 0x0000ffff}
228 { /* shader 16: relative addressing */
230 "mov r0, c0[a0.x]\n",
231 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42000, 0x0000ffff}
233 { /* shader 17: relative addressing */
235 "mov r0, c1[a0.x + 2]\n",
236 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42003, 0x0000ffff}
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 */
247 "mov r0, c[ a0.x + 12 ]\n",
248 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200c, 0x0000ffff}
252 "mov r0, c[ 2 + a0.x ]\n",
253 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e42002, 0x0000ffff}
257 "mov r0, c[ 2 + a0.x + 12 ]\n",
258 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e4200e, 0x0000ffff}
262 "mov r0, c[ 2 + 10 + 12 ]\n",
263 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40018, 0x0000ffff}
268 {0xfffe0101, 0x00000001, 0x800f0000, 0xa0e40006, 0x0000ffff}
273 {0xfffe0101, 0x00000006, 0x800f0000, 0x90000000, 0x0000ffff}
278 {0xfffe0101, 0x00000007, 0x800f0000, 0x90000000, 0x0000ffff}
282 exec_tests("vs_1_1", tests, sizeof(tests) / sizeof(tests[0]));
285 static void ps_1_3_test(void) {
286 struct shader_test tests[] = {
287 /* Basic instruction tests */
291 {0xffff0103, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
296 {0xffff0103, 0x00000002, 0x800f0000, 0x80e40001, 0x80e40000, 0x0000ffff}
298 /* Color interpolator tests */
302 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40000, 0x0000ffff}
307 {0xffff0103, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
309 /* Texture sampling instructions */
313 {0xffff0103, 0x00000042, 0xb00f0000, 0x0000ffff}
318 "texreg2ar t1, t0\n",
319 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000045, 0xb00f0001, 0xb0e40000,
325 "texreg2gb t1, t0\n",
326 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000046, 0xb00f0001, 0xb0e40000,
332 "texreg2rgb t1, t0\n",
333 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000052, 0xb00f0001, 0xb0e40000,
338 "cnd r0, r1, r0, v0\n",
339 {0xffff0103, 0x00000050, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
344 "cmp r0, r1, r0, v0\n",
345 {0xffff0103, 0x00000058, 0x800f0000, 0x80e40001, 0x80e40000, 0x90e40000,
351 {0xffff0103, 0x00000041, 0xb00f0000, 0x0000ffff}
356 "texm3x2pad t1, t0\n"
357 "texm3x2tex t2, t0\n",
358 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
359 0x00000048, 0xb00f0002, 0xb0e40000, 0x0000ffff}
364 "texm3x2pad t1, t0\n"
365 "texm3x2depth t2, t0\n",
366 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000047, 0xb00f0001, 0xb0e40000,
367 0x00000054, 0xb00f0002, 0xb0e40000, 0x0000ffff}
373 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000043, 0xb00f0001, 0xb0e40000,
380 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000044, 0xb00f0001, 0xb0e40000,
386 "texdp3tex t1, t0\n",
387 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000053, 0xb00f0001, 0xb0e40000,
394 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000055, 0xb00f0001, 0xb0e40000,
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,
410 "texm3x3pad t1, t0\n"
411 "texm3x3pad t2, t0\n"
413 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000049, 0xb00f0001, 0xb0e40000,
414 0x00000049, 0xb00f0002, 0xb0e40000, 0x00000056, 0xb00f0003, 0xb0e40000,
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}
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,
440 {0xffff0103, 0x00000040, 0xb00f0000, 0x0000ffff}
442 /* Modifiers, shifts */
445 "mov_x2_sat r0, 1 - r1\n",
446 {0xffff0103, 0x00000001, 0x811f0000, 0x86e40001, 0x0000ffff}
451 {0xffff0103, 0x00000001, 0x8d0f0000, 0x81e40001, 0x0000ffff}
455 "mov_sat r0, r1_bx2\n",
456 {0xffff0103, 0x00000001, 0x801f0000, 0x84e40001, 0x0000ffff}
460 "mov_sat r0, r1_bias\n",
461 {0xffff0103, 0x00000001, 0x801f0000, 0x82e40001, 0x0000ffff}
465 "mov_sat r0, -r1_bias\n",
466 {0xffff0103, 0x00000001, 0x801f0000, 0x83e40001, 0x0000ffff}
470 "mov_sat r0, -r1_bx2\n",
471 {0xffff0103, 0x00000001, 0x801f0000, 0x85e40001, 0x0000ffff}
475 "mov_sat r0, -r1_x2\n",
476 {0xffff0103, 0x00000001, 0x801f0000, 0x88e40001, 0x0000ffff}
480 "mov_x4_sat r0.a, -r1_bx2.a\n",
481 {0xffff0103, 0x00000001, 0x82180000, 0x85ff0001, 0x0000ffff}
486 {0xffff0103, 0x00000040, 0xb10f0000, 0x0000ffff}
491 {0xffff0103, 0x00000042, 0xb10f0000, 0x0000ffff}
495 "texreg2ar_x4 t0, t1\n",
496 {0xffff0103, 0x00000045, 0xb20f0000, 0xb0e40001, 0x0000ffff}
500 "texbem_d4 t1, t0\n",
501 {0xffff0103, 0x00000043, 0xbe0f0001, 0xb0e40000, 0x0000ffff}
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,
516 "texdp3tex_x8 t1, t0\n",
517 {0xffff0103, 0x00000042, 0xb00f0000, 0x00000053, 0xb30f0001, 0xb0e40000,
522 exec_tests("ps_1_3", tests, sizeof(tests) / sizeof(tests[0]));
525 static void ps_1_4_test(void) {
526 struct shader_test tests[] = {
527 /* Basic instruction tests */
531 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40001, 0x0000ffff}
536 {0xffff0104, 0x00000001, 0x800f0000, 0x80e40005, 0x0000ffff}
541 {0xffff0104, 0x00000001, 0x800f0000, 0xa0e40007, 0x0000ffff}
546 {0xffff0104, 0x00000001, 0x800f0000, 0x90e40001, 0x0000ffff}
551 {0xffff0104, 0x0000fffd, 0x0000ffff}
556 {0xffff0104, 0x00000040, 0x800f0000, 0xb0e40000, 0x0000ffff}
561 {0xffff0104, 0x00000040, 0x800f0004, 0xb0e40003, 0x0000ffff}
565 "texcrd_sat r4, t3\n",
566 {0xffff0104, 0x00000040, 0x801f0004, 0xb0e40003, 0x0000ffff}
571 {0xffff0104, 0x00000042, 0x800f0000, 0xb0e40000, 0x0000ffff}
576 {0xffff0104, 0x00000042, 0x800f0001, 0xb0e40004, 0x0000ffff}
581 {0xffff0104, 0x00000042, 0x800f0005, 0x80e40000, 0x0000ffff}
585 "texld r5, c0\n", /* Assembly succeeds, validation fails */
586 {0xffff0104, 0x00000042, 0x800f0005, 0xa0e40000, 0x0000ffff}
591 {0xffff0104, 0x00000042, 0x800f0005, 0x89e40002, 0x0000ffff}
595 "bem r1.rg, c0, r0\n",
596 {0xffff0104, 0x00000059, 0x80030001, 0xa0e40000, 0x80e40000, 0x0000ffff}
601 {0xffff0104, 0x00000057, 0x800f0005, 0x0000ffff}
605 "add r0, r1, r2_bx2\n",
606 {0xffff0104, 0x00000002, 0x800f0000, 0x80e40001, 0x84e40002, 0x0000ffff}
610 "add_x4 r0, r1, r2\n",
611 {0xffff0104, 0x00000002, 0x820f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
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}
623 {0xffff0104, 0x00000057, 0x810f0005, 0x0000ffff}
627 "bem_d2 r1, c0, r0\n",
628 {0xffff0104, 0x00000059, 0x8f0f0001, 0xa0e40000, 0x80e40000, 0x0000ffff}
632 exec_tests("ps_1_4", tests, sizeof(tests) / sizeof(tests[0]));
635 static void vs_2_0_test(void) {
636 struct shader_test tests[] = {
637 /* Basic instruction tests */
641 {0xfffe0200, 0x02000001, 0x800f0000, 0x80e40001, 0x0000ffff}
645 "lrp r0, v0, c0, r1\n",
646 {0xfffe0200, 0x04000012, 0x800f0000, 0x90e40000, 0xa0e40000, 0x80e40001,
651 "dp4 oPos, v0, c0\n",
652 {0xfffe0200, 0x03000009, 0xc00f0000, 0x90e40000, 0xa0e40000, 0x0000ffff}
656 "mov r0, c0[a0.x]\n",
657 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0000000, 0x0000ffff}
661 "mov r0, c0[a0.y]\n",
662 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0550000, 0x0000ffff}
666 "mov r0, c0[a0.z]\n",
667 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0aa0000, 0x0000ffff}
671 "mov r0, c0[a0.w]\n",
672 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0ff0000, 0x0000ffff}
676 "mov r0, c0[a0.w].x\n",
677 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0002000, 0xb0ff0000, 0x0000ffff}
681 "mov r0, -c0[a0.w+5].x\n",
682 {0xfffe0200, 0x03000001, 0x800f0000, 0xa1002005, 0xb0ff0000, 0x0000ffff}
687 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0e40000, 0x0000ffff}
691 "mov r0, c0[a0.xyww]\n",
692 {0xfffe0200, 0x03000001, 0x800f0000, 0xa0e42000, 0xb0f40000, 0x0000ffff}
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}
704 {0xfffe0200, 0x01000026, 0xf0e40000, 0x00000027, 0x0000ffff}
711 {0xfffe0200, 0x01000028, 0xe0e40800, 0x0000002a, 0x0000002b, 0x0000ffff}
717 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x0000001d, 0x0000ffff}
722 {0xfffe0200, 0x02000024, 0x800f0000, 0xa0e40000, 0x0000ffff}
727 {0xfffe0200, 0x03000021, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
731 "sgn r0, r1, r2, r3\n",
732 {0xfffe0200, 0x04000022, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
737 "sincos r0, r1, r2, r3\n",
738 {0xfffe0200, 0x04000025, 0x800f0000, 0x80e40001, 0x80e40002, 0x80e40003,
744 {0xfffe0200, 0x03000020, 0x800f0000, 0x80e40001, 0x80e40002, 0x0000ffff}
749 {0xfffe0200, 0x0200002e, 0xb0020000, 0xa0aa0000, 0x0000ffff}
755 {0xfffe0200, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
756 0x00000000, 0x0000ffff}
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}
771 {0xfffe0200, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
772 0xa0e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
780 {0xfffe0200, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
781 0x0000001c, 0x0000ffff}
789 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
790 0xa0e41000, 0x0000001c, 0x0000ffff}
798 {0xfffe0200, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
799 0xa0e41000, 0x0000001c, 0x0000ffff}
806 {0xfffe0200, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
814 {0xfffe0200, 0x01000019, 0xa0e41003, 0x0000001c, 0x0100001e, 0xa0e41003, 0x0000001c, 0x0000ffff}
816 { /* shader 29: labels up to 2047 are accepted even in vs_2_0 */
819 {0xfffe0200, 0x01000019, 0xa0e417ff, 0x0000ffff}
823 exec_tests("vs_2_0", tests, sizeof(tests) / sizeof(tests[0]));
826 static void vs_2_x_test(void) {
827 struct shader_test tests[] = {
833 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
839 {0xfffe0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
846 {0xfffe0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
847 0x00000027, 0x0000ffff}
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}
863 {0xfffe0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
871 {0xfffe0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
872 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
879 {0xfffe0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
880 0x00000027, 0x0000ffff}
884 exec_tests("vs_2_x", tests, sizeof(tests) / sizeof(tests[0]));
887 static void ps_2_0_test(void) {
888 struct shader_test tests[] = {
892 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
897 {0xffff0200, 0x0200001f, 0x98000000, 0xa00f0800, 0x0000ffff}
902 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0000ffff}
909 {0xffff0200, 0x0200001f, 0xa0000000, 0xa00f0800, 0x0200001f, 0x98000000,
910 0xa00f0801, 0x0200001f, 0x90000000, 0xa00f0802, 0x0000ffff}
915 {0xffff0200, 0x02000001, 0x800f0000, 0xb0e40000, 0x0000ffff}
920 "texld r0, t1, s2\n",
921 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000,
922 0xb0e40001, 0xa0e40802, 0x0000ffff}
927 {0xffff0200, 0x01000041, 0xb00f0000, 0x0000ffff}
933 {0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x02000001, 0x800f0801,
934 0xa0e40001, 0x0000ffff}
938 "mov oDepth, c0.x\n",
939 {0xffff0200, 0x02000001, 0x900f0800, 0xa0000000, 0x0000ffff}
944 "texldp r0, t1, s2\n",
945 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03010042, 0x800f0000,
946 0xb0e40001, 0xa0e40802, 0x0000ffff}
951 "texldb r0, t1, s2\n",
952 {0xffff0200, 0x0200001f, 0x90000000, 0xa00f0802, 0x03020042, 0x800f0000,
953 0xb0e40001, 0xa0e40802, 0x0000ffff}
957 exec_tests("ps_2_0", tests, sizeof(tests) / sizeof(tests[0]));
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) */
967 {0xffff0201, 0x0200002f, 0xe00f0800, 0x00000001, 0x0200002f, 0xe00f0801,
968 0x00000000, 0x0000ffff}
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}
981 {0xffff0201, 0x0200005b, 0x800f0000, 0x80e40000, 0x0000ffff}
986 {0xffff0201, 0x0200005c, 0x800f0000, 0x80e40000, 0x0000ffff}
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 */
1002 {0xffff0201, 0x01000019, 0xa0e41000, 0x0000001c, 0x0100001e, 0xa0e41000,
1003 0x0000001c, 0x0000ffff}
1011 {0xffff0201, 0x0200001a, 0xa0e41000, 0xe0e40800, 0x0000001c, 0x0100001e,
1012 0xa0e41000, 0x0000001c, 0x0000ffff}
1020 {0xffff0201, 0x0200001a, 0xa0e41000, 0xede40800, 0x0000001c, 0x0100001e,
1021 0xa0e41000, 0x0000001c, 0x0000ffff}
1028 {0xffff0201, 0x01000028, 0xede40800, 0x0000002a, 0x0000002b, 0x0000ffff}
1030 /* Dynamic flow control tests */
1036 {0xffff0201, 0x01000026, 0xf0e40000, 0x0000002c, 0x00000027, 0x0000ffff}
1042 {0xffff0201, 0x02030029, 0x80e40000, 0x80e40001, 0x0000002b, 0x0000ffff}
1049 {0xffff0201, 0x01000026, 0xf0e40000, 0x0205002d, 0x80e40000, 0x80e40001,
1050 0x00000027, 0x0000ffff}
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}
1065 {0xffff0201, 0x01000028, 0xb0001000, 0x0000002a, 0x0000002b, 0x0000ffff}
1069 "callnz l0, !p0.z\n"
1073 {0xffff0201, 0x0200001a, 0xa0e41000, 0xbdaa1000, 0x0000001c,
1074 0x0100001e, 0xa0e41000, 0x0000001c, 0x0000ffff}
1081 {0xffff0201, 0x01000026, 0xf0e40000, 0x01000060, 0xb0ff1000,
1082 0x00000027, 0x0000ffff}
1090 {0xffff0201, 0x01000019, 0xa0e417ff, 0x0000001c, 0x0100001e, 0xa0e417ff,
1091 0x0000001c, 0x0000ffff}
1095 exec_tests("ps_2_x", tests, sizeof(tests) / sizeof(tests[0]));
1098 static void vs_3_0_test(void) {
1099 struct shader_test tests[] = {
1103 {0xfffe0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1108 {0xfffe0300, 0x0200001f, 0x90000000, 0xa00f0800, 0x0000ffff}
1112 "dcl_position o0\n",
1113 {0xfffe0300, 0x0200001f, 0x80000000, 0xe00f0000, 0x0000ffff}
1117 "dcl_texcoord12 o11\n",
1118 {0xfffe0300, 0x0200001f, 0x800c0005, 0xe00f000b, 0x0000ffff}
1122 "texldl r0, v0, s0\n",
1123 {0xfffe0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1128 {0xfffe0300, 0x03000001, 0x800f0000, 0xa0e42000, 0xf0e40800, 0x0000ffff}
1132 "mov o[ a0.x + 12 ], r0\n",
1133 {0xfffe0300, 0x03000001, 0xe00f200c, 0xb0000000, 0x80e40000, 0x0000ffff}
1137 "add_sat r0, r0, r1\n",
1138 {0xfffe0300, 0x03000002, 0x801f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1143 {0xfffe0300, 0x02000001, 0x800f0002, 0x8be40001, 0x0000ffff}
1147 "mov r2, r1.xygb\n",
1148 {0xfffe0300, 0x02000001, 0x800f0002, 0x80940001, 0x0000ffff}
1153 {0xfffe0300, 0x02000001, 0x80070002, 0x80e40001, 0x0000ffff}
1157 "mova_sat a0.x, r1\n",
1158 {0xfffe0300, 0x0200002e, 0xb0110000, 0x80e40001, 0x0000ffff}
1163 {0xfffe0300, 0x02000025, 0x800f0000, 0x80e40001, 0x0000ffff}
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 */
1173 "add r0, v20[aL], r2\n",
1174 {0xfffe0300, 0x04000002, 0x800f0000, 0x90e42014, 0xf0e40800, 0x80e40002,
1180 exec_tests("vs_3_0", tests, sizeof(tests) / sizeof(tests[0]));
1183 static void ps_3_0_test(void) {
1184 struct shader_test tests[] = {
1188 {0xffff0300, 0x02000001, 0x800f0000, 0xa0e40000, 0x0000ffff}
1193 {0xffff0300, 0x0200001f, 0x80050003, 0x900f0000, 0x0000ffff}
1198 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41000, 0x0000ffff}
1203 {0xffff0300, 0x02000001, 0x800f0000, 0x90e41001, 0x0000ffff}
1207 "mov r0, v[ aL + 12 ]\n",
1208 {0xffff0300, 0x03000001, 0x800f0000, 0x90e4200c, 0xf0e40800, 0x0000ffff}
1215 {0xffff0300, 0x0200001b, 0xf0e40800, 0xf0e40000, 0x03000001, 0x800f0000,
1216 0x90e42000, 0xf0e40800, 0x0000001d, 0x0000ffff}
1220 "texldl r0, v0, s0\n",
1221 {0xffff0300, 0x0300005f, 0x800f0000, 0x90e40000, 0xa0e40800, 0x0000ffff}
1225 "add_pp r0, r0, r1\n",
1226 {0xffff0300, 0x03000002, 0x802f0000, 0x80e40000, 0x80e40001, 0x0000ffff}
1231 {0xffff0300, 0x0200005b, 0x801f0000, 0x80e40001, 0x0000ffff}
1235 "texldd_pp r0, r1, r2, r3, r4\n",
1236 {0xffff0300, 0x0500005d, 0x802f0000, 0x80e40001, 0x80e40002, 0x80e40003,
1237 0x80e40004, 0x0000ffff}
1242 {0xffff0300, 0x01000041, 0x900f0000, 0x0000ffff}
1246 "add oC3, r0, r1\n",
1247 {0xffff0300, 0x03000002, 0x800f0803, 0x80e40000, 0x80e40001, 0x0000ffff}
1251 "dcl_texcoord0_centroid v0\n",
1252 {0xffff0300, 0x0200001f, 0x80000005, 0x904f0000, 0x0000ffff}
1256 "dcl_2d_centroid s0\n",
1257 {0xffff0300, 0x0200001f, 0x90000000, 0xa04f0800, 0x0000ffff}
1262 {0xffff0300, 0x0200001f, 0x90000000, 0xa02f0800, 0x0000ffff}
1266 exec_tests("ps_3_0", tests, sizeof(tests) / sizeof(tests[0]));
1269 static void failure_test(void) {
1270 const char * tests[] = {
1271 /* shader 0: instruction modifier not allowed */
1274 "texldd_x2 r0, v1, s2, v3, v4\n",
1275 /* shader 1: coissue not supported in vertex shaders */
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 */
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 */
1286 "(p0) add r0, r0, v0\n",
1287 /* shader 4: register a0 doesn't exist in pixel shaders */
1289 "mov r0, v[ a0 + 12 ]\n",
1290 /* shader 5: s0 doesn't exist in vs_1_1 */
1293 /* shader 6: aL is a scalar register, no swizzles allowed */
1295 "mov r0, v[ aL.x + 12 ]\n",
1296 /* shader 7: tn doesn't exist in ps_3_0 */
1299 "texldd r0, t1, s2, v3, v4\n",
1300 /* shader 8: two shift modifiers */
1302 "mov_x2_x2 r0, r1\n",
1303 /* shader 9: too many source registers for mov instruction */
1306 /* shader 10: invalid combination of negate and divide modifiers */
1308 "texld r5, -r2_dz\n",
1309 /* shader 11: complement modifier not allowed in >= PS 2 */
1312 /* shader 12: invalid modifier */
1315 /* shader 13: float value in relative addressing */
1317 "mov r2, c[ aL + 3.4 ]\n",
1318 /* shader 14: complement modifier not available in VS */
1321 /* shader 15: _x2 modifier not available in VS */
1324 /* shader 16: _abs modifier not available in < VS 3.0 */
1327 /* shader 17: _x2 modifier not available in >= PS 2.0 */
1330 /* shader 18: wrong swizzle */
1332 "mov r0, r1.abcd\n",
1333 /* shader 19: wrong swizzle */
1335 "mov r0, r1.xyzwx\n",
1336 /* shader 20: wrong swizzle */
1339 /* shader 21: invalid writemask */
1341 "mov r0.xxyz, r1\n",
1342 /* shader 22: register r5 doesn't exist in PS < 1.4 */
1345 /* shader 23: can't declare output registers in a pixel shader */
1347 "dcl_positiont o0\n",
1348 /* shader 24: _pp instruction modifier not allowed in vertex shaders */
1350 "add_pp r0, r0, r1\n",
1351 /* shader 25: _x4 instruction modified not allowed in > ps_1_x */
1353 "add_x4 r0, r0, r1\n",
1354 /* shader 26: there aren't oCx registers in ps_1_x */
1356 "add oC0, r0, r1\n",
1357 /* shader 27: oC3 is the max in >= ps_2_0 */
1359 "add oC4, r0, r1\n",
1360 /* shader 28: register v17 doesn't exist */
1362 "add r0, r0, v17\n",
1363 /* shader 29: register o13 doesn't exist */
1365 "add o13, r0, r1\n",
1366 /* shader 30: label > 2047 not allowed */
1369 /* shader 31: s20 register does not exist */
1371 "texld r0, r1, s20\n",
1372 /* shader 32: t5 not allowed in ps_1_3 */
1375 /* shader 33: no temporary registers relative addressing */
1377 "add r0, r0[ a0.x ], r1\n",
1378 /* shader 34: no input registers relative addressing in vs_2_0 */
1380 "add r0, v[ a0.x ], r1\n",
1381 /* shader 35: no aL register in ps_2_0 */
1383 "add r0, v[ aL ], r1\n",
1384 /* shader 36: no relative addressing in ps_2_0 */
1386 "add r0, v[ r0 ], r1\n",
1387 /* shader 37: no a0 register in ps_3_0 */
1389 "add r0, v[ a0.x ], r1\n",
1390 /* shader 38: only a0.x accepted in vs_1_1 */
1392 "mov r0, c0[ a0 ]\n",
1393 /* shader 39: invalid modifier for dcl instruction */
1395 "dcl_texcoord0_sat v0\n",
1396 /* shader 40: shift not allowed */
1398 "dcl_texcoord0_x2 v0\n",
1399 /* shader 41: no modifier allowed with dcl instruction in vs */
1401 "dcl_texcoord0_centroid v0\n",
1402 /* shader 42: no modifiers with vs dcl sampler instruction */
1407 "texm3x3vspec t3, t0\n",
1411 LPD3DBLOB shader, messages;
1413 for(i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++) {
1416 hr = D3DAssemble(tests[i], strlen(tests[i]), NULL,
1417 NULL, NULL, D3DCOMPILE_SKIP_VALIDATION,
1418 &shader, &messages);
1419 ok(hr == D3DXERR_INVALIDDATA, "Failure test, shader %d: "
1420 "expected D3DAssemble failure with D3DXERR_INVALIDDATA, "
1421 "got 0x%x - %d\n", i, hr, hr & 0x0000FFFF);
1423 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1424 ID3D10Blob_Release(messages);
1427 DWORD *res = ID3D10Blob_GetBufferPointer(shader);
1429 ID3D10Blob_Release(shader);
1434 static HRESULT WINAPI testD3DInclude_open(ID3DInclude *iface, D3D_INCLUDE_TYPE include_type,
1435 const char *filename, const void *parent_data, const void **data, UINT *bytes)
1438 char include[] = "#define REGISTER r0\nvs.1.1\n";
1439 char include2[] = "#include \"incl3.vsh\"\n";
1440 char include3[] = "vs.1.1\n";
1442 trace("filename %s\n", filename);
1443 trace("parent_data (%p) -> %s\n", parent_data, parent_data ? (char *)parent_data : "(null)");
1445 if (!strcmp(filename, "incl.vsh"))
1447 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include));
1448 CopyMemory(buffer, include, sizeof(include));
1449 *bytes = sizeof(include);
1451 else if (!strcmp(filename, "incl3.vsh"))
1453 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include3));
1454 CopyMemory(buffer, include3, sizeof(include3));
1455 *bytes = sizeof(include3);
1456 /* Also check for the correct parent_data content */
1457 ok(parent_data != NULL && !strncmp(include2, parent_data, strlen(include2)), "wrong parent_data value\n");
1461 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(include2));
1462 CopyMemory(buffer, include2, sizeof(include2));
1463 *bytes = sizeof(include2);
1471 static HRESULT WINAPI testD3DInclude_close(ID3DInclude *iface, const void *data)
1473 HeapFree(GetProcessHeap(), 0, (LPVOID)data);
1477 static const struct ID3DIncludeVtbl D3DInclude_Vtbl =
1479 testD3DInclude_open,
1480 testD3DInclude_close
1483 struct D3DIncludeImpl {
1484 ID3DInclude ID3DInclude_iface;
1487 static void assembleshader_test(void) {
1488 const char test1[] = {
1492 const char testshader[] = {
1493 "#include \"incl.vsh\"\n"
1494 "mov REGISTER, v0\n"
1497 LPD3DBLOB shader, messages;
1498 D3D_SHADER_MACRO defines[] = {
1509 struct D3DIncludeImpl include;
1514 hr = D3DAssemble(test1, strlen(test1), NULL,
1515 defines, NULL, D3DCOMPILE_SKIP_VALIDATION,
1516 &shader, &messages);
1517 ok(hr == S_OK, "defines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1519 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1520 ID3D10Blob_Release(messages);
1522 if(shader) ID3D10Blob_Release(shader);
1524 /* NULL messages test */
1526 hr = D3DAssemble(test1, strlen(test1), NULL,
1527 defines, NULL, D3DCOMPILE_SKIP_VALIDATION,
1529 ok(hr == S_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1530 if(shader) ID3D10Blob_Release(shader);
1532 /* NULL shader test */
1534 hr = D3DAssemble(test1, strlen(test1), NULL,
1535 defines, NULL, D3DCOMPILE_SKIP_VALIDATION,
1537 ok(hr == S_OK, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1539 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1540 ID3D10Blob_Release(messages);
1543 /* D3DInclude test */
1546 include.ID3DInclude_iface.lpVtbl = &D3DInclude_Vtbl;
1547 hr = D3DAssemble(testshader, strlen(testshader), NULL, NULL, &include.ID3DInclude_iface,
1548 D3DCOMPILE_SKIP_VALIDATION, &shader, &messages);
1549 ok(hr == S_OK, "D3DInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1551 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1552 ID3D10Blob_Release(messages);
1554 if(shader) ID3D10Blob_Release(shader);
1556 /* NULL shader tests */
1559 hr = D3DAssemble(NULL, 0, NULL,
1560 NULL, NULL, D3DCOMPILE_SKIP_VALIDATION,
1561 &shader, &messages);
1562 ok(hr == D3DXERR_INVALIDDATA, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1564 trace("D3DAssemble messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1565 ID3D10Blob_Release(messages);
1567 if(shader) ID3D10Blob_Release(shader);
1570 static void d3dpreprocess_test(void)
1572 const char test1[] =
1577 const char testshader[] =
1579 "#include \"incl.vsh\"\n"
1580 "mov REGISTER, v0\n"
1582 const char testshader2[] =
1584 "#include \"incl2.vsh\"\n"
1585 "mov REGISTER, v0\n"
1588 ID3DBlob *shader, *messages;
1589 D3D_SHADER_MACRO defines[] =
1601 struct D3DIncludeImpl include;
1606 hr = D3DPreprocess(test1, strlen(test1), NULL,
1607 defines, NULL, &shader, &messages);
1608 ok(hr == S_OK, "pDefines test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1611 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1612 ID3D10Blob_Release(messages);
1614 if (shader) ID3D10Blob_Release(shader);
1616 /* NULL messages test */
1618 hr = D3DPreprocess(test1, strlen(test1), NULL,
1619 defines, NULL, &shader, NULL);
1620 ok(hr == S_OK, "NULL messages test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1621 if (shader) ID3D10Blob_Release(shader);
1623 /* NULL shader test */
1625 hr = D3DPreprocess(test1, strlen(test1), NULL,
1626 defines, NULL, NULL, &messages);
1627 ok(hr == E_INVALIDARG, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1630 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1631 ID3D10Blob_Release(messages);
1637 include.ID3DInclude_iface.lpVtbl = &D3DInclude_Vtbl;
1638 hr = D3DPreprocess(testshader, strlen(testshader), NULL, NULL, &include.ID3DInclude_iface,
1639 &shader, &messages);
1640 ok(hr == S_OK, "pInclude test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1643 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1644 ID3D10Blob_Release(messages);
1646 if (shader) ID3D10Blob_Release(shader);
1648 /* recursive #include test */
1651 hr = D3DPreprocess(testshader2, strlen(testshader2), NULL, NULL, &include.ID3DInclude_iface,
1652 &shader, &messages);
1653 ok(hr == S_OK, "D3DPreprocess test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1656 trace("recursive D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1657 ID3D10Blob_Release(messages);
1659 if (shader) ID3D10Blob_Release(shader);
1661 /* NULL shader tests */
1664 hr = D3DPreprocess(NULL, 0, NULL,
1665 NULL, NULL, &shader, &messages);
1666 ok(hr == E_INVALIDARG, "NULL shader test failed with error 0x%x - %d\n", hr, hr & 0x0000FFFF);
1669 trace("D3DPreprocess messages:\n%s", (char *)ID3D10Blob_GetBufferPointer(messages));
1670 ID3D10Blob_Release(messages);
1672 if (shader) ID3D10Blob_Release(shader);
1691 assembleshader_test();
1693 d3dpreprocess_test();