wpp: Free the include filename on error (Valgrind).
[wine.git] / dlls / d3dcompiler_43 / asmshader.y
blob5948d57d5edc2abd52b9eb624ac79f8f4dde34bb
1 /*
2 * Direct3D shader assembler
4 * Copyright 2008 Stefan Dösinger
5 * Copyright 2009 Matteo Bruni
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
25 #include "wine/debug.h"
27 #include "d3dcompiler_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
31 struct asm_parser asm_ctx;
33 void asmparser_message(struct asm_parser *ctx, const char *fmt, ...)
35 va_list args;
37 va_start(args, fmt);
38 compilation_message(&ctx->messages, fmt, args);
39 va_end(args);
42 static void asmshader_error(char const *s) {
43 asmparser_message(&asm_ctx, "Line %u: Error \"%s\" from bison\n", asm_ctx.line_no, s);
44 set_parse_status(&asm_ctx.status, PARSE_ERR);
47 static void set_rel_reg(struct shader_reg *reg, struct rel_reg *rel) {
48 /* We can have an additional offset without true relative addressing
49 * ex. c2[ 4 ] */
50 reg->regnum += rel->additional_offset;
51 if(!rel->has_rel_reg) {
52 reg->rel_reg = NULL;
53 } else {
54 reg->rel_reg = d3dcompiler_alloc(sizeof(*reg->rel_reg));
55 if(!reg->rel_reg) {
56 return;
58 reg->rel_reg->type = rel->type;
59 reg->rel_reg->u.swizzle = rel->swizzle;
60 reg->rel_reg->regnum = rel->rel_regnum;
64 /* Needed lexer functions declarations */
65 int asmshader_lex(void);
70 %union {
71 struct {
72 float val;
73 BOOL integer;
74 } immval;
75 BOOL immbool;
76 unsigned int regnum;
77 struct shader_reg reg;
78 DWORD srcmod;
79 DWORD writemask;
80 struct {
81 DWORD writemask;
82 DWORD idx;
83 DWORD last;
84 } wm_components;
85 DWORD swizzle;
86 struct {
87 DWORD swizzle;
88 DWORD idx;
89 } sw_components;
90 DWORD component;
91 struct {
92 DWORD mod;
93 DWORD shift;
94 } modshift;
95 enum bwriter_comparison_type comptype;
96 struct {
97 DWORD dclusage;
98 unsigned int regnum;
99 } declaration;
100 enum bwritersampler_texture_type samplertype;
101 struct rel_reg rel_reg;
102 struct src_regs sregs;
105 /* Common instructions between vertex and pixel shaders */
106 %token INSTR_ADD
107 %token INSTR_NOP
108 %token INSTR_MOV
109 %token INSTR_SUB
110 %token INSTR_MAD
111 %token INSTR_MUL
112 %token INSTR_RCP
113 %token INSTR_RSQ
114 %token INSTR_DP3
115 %token INSTR_DP4
116 %token INSTR_MIN
117 %token INSTR_MAX
118 %token INSTR_SLT
119 %token INSTR_SGE
120 %token INSTR_ABS
121 %token INSTR_EXP
122 %token INSTR_LOG
123 %token INSTR_EXPP
124 %token INSTR_LOGP
125 %token INSTR_DST
126 %token INSTR_LRP
127 %token INSTR_FRC
128 %token INSTR_POW
129 %token INSTR_CRS
130 %token INSTR_SGN
131 %token INSTR_NRM
132 %token INSTR_SINCOS
133 %token INSTR_M4x4
134 %token INSTR_M4x3
135 %token INSTR_M3x4
136 %token INSTR_M3x3
137 %token INSTR_M3x2
138 %token INSTR_DCL
139 %token INSTR_DEF
140 %token INSTR_DEFB
141 %token INSTR_DEFI
142 %token INSTR_REP
143 %token INSTR_ENDREP
144 %token INSTR_IF
145 %token INSTR_ELSE
146 %token INSTR_ENDIF
147 %token INSTR_BREAK
148 %token INSTR_BREAKP
149 %token INSTR_CALL
150 %token INSTR_CALLNZ
151 %token INSTR_LOOP
152 %token INSTR_RET
153 %token INSTR_ENDLOOP
154 %token INSTR_LABEL
155 %token INSTR_SETP
156 %token INSTR_TEXLDL
158 /* Vertex shader only instructions */
159 %token INSTR_LIT
160 %token INSTR_MOVA
162 /* Pixel shader only instructions */
163 %token INSTR_CND
164 %token INSTR_CMP
165 %token INSTR_DP2ADD
166 %token INSTR_TEXCOORD
167 %token INSTR_TEXCRD
168 %token INSTR_TEXKILL
169 %token INSTR_TEX
170 %token INSTR_TEXLD
171 %token INSTR_TEXBEM
172 %token INSTR_TEXBEML
173 %token INSTR_TEXREG2AR
174 %token INSTR_TEXREG2GB
175 %token INSTR_TEXREG2RGB
176 %token INSTR_TEXM3x2PAD
177 %token INSTR_TEXM3x2TEX
178 %token INSTR_TEXM3x3PAD
179 %token INSTR_TEXM3x3SPEC
180 %token INSTR_TEXM3x3VSPEC
181 %token INSTR_TEXM3x3TEX
182 %token INSTR_TEXDP3TEX
183 %token INSTR_TEXM3x2DEPTH
184 %token INSTR_TEXDP3
185 %token INSTR_TEXM3x3
186 %token INSTR_TEXDEPTH
187 %token INSTR_BEM
188 %token INSTR_DSX
189 %token INSTR_DSY
190 %token INSTR_TEXLDP
191 %token INSTR_TEXLDB
192 %token INSTR_TEXLDD
193 %token INSTR_PHASE
195 /* Registers */
196 %token <regnum> REG_TEMP
197 %token <regnum> REG_OUTPUT
198 %token <regnum> REG_INPUT
199 %token <regnum> REG_CONSTFLOAT
200 %token <regnum> REG_CONSTINT
201 %token <regnum> REG_CONSTBOOL
202 %token <regnum> REG_TEXTURE
203 %token <regnum> REG_SAMPLER
204 %token <regnum> REG_TEXCRDOUT
205 %token REG_OPOS
206 %token REG_OFOG
207 %token REG_OPTS
208 %token <regnum> REG_VERTEXCOLOR
209 %token <regnum> REG_FRAGCOLOR
210 %token REG_FRAGDEPTH
211 %token REG_VPOS
212 %token REG_VFACE
213 %token REG_ADDRESS
214 %token REG_LOOP
215 %token REG_PREDICATE
216 %token <regnum> REG_LABEL
218 /* Version tokens */
219 %token VER_VS10
220 %token VER_VS11
221 %token VER_VS20
222 %token VER_VS2X
223 %token VER_VS30
225 %token VER_PS10
226 %token VER_PS11
227 %token VER_PS12
228 %token VER_PS13
229 %token VER_PS14
230 %token VER_PS20
231 %token VER_PS2X
232 %token VER_PS30
234 /* Output modifiers */
235 %token SHIFT_X2
236 %token SHIFT_X4
237 %token SHIFT_X8
238 %token SHIFT_D2
239 %token SHIFT_D4
240 %token SHIFT_D8
241 %token MOD_SAT
242 %token MOD_PP
243 %token MOD_CENTROID
245 /* Compare tokens */
246 %token COMP_GT
247 %token COMP_LT
248 %token COMP_GE
249 %token COMP_LE
250 %token COMP_EQ
251 %token COMP_NE
253 /* Source register modifiers */
254 %token SMOD_BIAS
255 %token SMOD_SCALEBIAS
256 %token SMOD_DZ
257 %token SMOD_DW
258 %token SMOD_ABS
259 %token SMOD_NOT
261 /* Sampler types */
262 %token SAMPTYPE_1D
263 %token SAMPTYPE_2D
264 %token SAMPTYPE_CUBE
265 %token SAMPTYPE_VOLUME
267 /* Usage declaration tokens */
268 %token <regnum> USAGE_POSITION
269 %token <regnum> USAGE_BLENDWEIGHT
270 %token <regnum> USAGE_BLENDINDICES
271 %token <regnum> USAGE_NORMAL
272 %token <regnum> USAGE_PSIZE
273 %token <regnum> USAGE_TEXCOORD
274 %token <regnum> USAGE_TANGENT
275 %token <regnum> USAGE_BINORMAL
276 %token <regnum> USAGE_TESSFACTOR
277 %token <regnum> USAGE_POSITIONT
278 %token <regnum> USAGE_COLOR
279 %token <regnum> USAGE_FOG
280 %token <regnum> USAGE_DEPTH
281 %token <regnum> USAGE_SAMPLE
283 /* Misc stuff */
284 %token <component> COMPONENT
285 %token <immval> IMMVAL
286 %token <immbool> IMMBOOL
288 %type <reg> dreg_name
289 %type <reg> dreg
290 %type <reg> sreg_name
291 %type <reg> relreg_name
292 %type <reg> sreg
293 %type <srcmod> smod
294 %type <writemask> writemask
295 %type <wm_components> wm_components
296 %type <swizzle> swizzle
297 %type <sw_components> sw_components
298 %type <modshift> omods
299 %type <modshift> omodifier
300 %type <comptype> comp
301 %type <declaration> dclusage
302 %type <reg> dcl_inputreg
303 %type <samplertype> sampdcl
304 %type <rel_reg> rel_reg
305 %type <reg> predicate
306 %type <immval> immsum
307 %type <sregs> sregs
311 shader: version_marker instructions
313 asm_ctx.funcs->end(&asm_ctx);
316 version_marker: VER_VS10
318 TRACE("Vertex shader 1.0\n");
319 create_vs10_parser(&asm_ctx);
321 | VER_VS11
323 TRACE("Vertex shader 1.1\n");
324 create_vs11_parser(&asm_ctx);
326 | VER_VS20
328 TRACE("Vertex shader 2.0\n");
329 create_vs20_parser(&asm_ctx);
331 | VER_VS2X
333 TRACE("Vertex shader 2.x\n");
334 create_vs2x_parser(&asm_ctx);
336 | VER_VS30
338 TRACE("Vertex shader 3.0\n");
339 create_vs30_parser(&asm_ctx);
341 | VER_PS10
343 TRACE("Pixel shader 1.0\n");
344 create_ps10_parser(&asm_ctx);
346 | VER_PS11
348 TRACE("Pixel shader 1.1\n");
349 create_ps11_parser(&asm_ctx);
351 | VER_PS12
353 TRACE("Pixel shader 1.2\n");
354 create_ps12_parser(&asm_ctx);
356 | VER_PS13
358 TRACE("Pixel shader 1.3\n");
359 create_ps13_parser(&asm_ctx);
361 | VER_PS14
363 TRACE("Pixel shader 1.4\n");
364 create_ps14_parser(&asm_ctx);
366 | VER_PS20
368 TRACE("Pixel shader 2.0\n");
369 create_ps20_parser(&asm_ctx);
371 | VER_PS2X
373 TRACE("Pixel shader 2.x\n");
374 create_ps2x_parser(&asm_ctx);
376 | VER_PS30
378 TRACE("Pixel shader 3.0\n");
379 create_ps30_parser(&asm_ctx);
382 instructions: /* empty */
383 | instructions complexinstr
385 /* Nothing to do */
388 complexinstr: instruction
392 | predicate instruction
394 TRACE("predicate\n");
395 asm_ctx.funcs->predicate(&asm_ctx, &$1);
397 | '+' instruction
399 TRACE("coissue\n");
400 asm_ctx.funcs->coissue(&asm_ctx);
403 instruction: INSTR_ADD omods dreg ',' sregs
405 TRACE("ADD\n");
406 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ADD, $2.mod, $2.shift, 0, &$3, &$5, 2);
408 | INSTR_NOP
410 TRACE("NOP\n");
411 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NOP, 0, 0, 0, 0, 0, 0);
413 | INSTR_MOV omods dreg ',' sregs
415 TRACE("MOV\n");
416 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOV, $2.mod, $2.shift, 0, &$3, &$5, 1);
418 | INSTR_SUB omods dreg ',' sregs
420 TRACE("SUB\n");
421 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SUB, $2.mod, $2.shift, 0, &$3, &$5, 2);
423 | INSTR_MAD omods dreg ',' sregs
425 TRACE("MAD\n");
426 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAD, $2.mod, $2.shift, 0, &$3, &$5, 3);
428 | INSTR_MUL omods dreg ',' sregs
430 TRACE("MUL\n");
431 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MUL, $2.mod, $2.shift, 0, &$3, &$5, 2);
433 | INSTR_RCP omods dreg ',' sregs
435 TRACE("RCP\n");
436 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RCP, $2.mod, $2.shift, 0, &$3, &$5, 1);
438 | INSTR_RSQ omods dreg ',' sregs
440 TRACE("RSQ\n");
441 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RSQ, $2.mod, $2.shift, 0, &$3, &$5, 1);
443 | INSTR_DP3 omods dreg ',' sregs
445 TRACE("DP3\n");
446 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP3, $2.mod, $2.shift, 0, &$3, &$5, 2);
448 | INSTR_DP4 omods dreg ',' sregs
450 TRACE("DP4\n");
451 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP4, $2.mod, $2.shift, 0, &$3, &$5, 2);
453 | INSTR_MIN omods dreg ',' sregs
455 TRACE("MIN\n");
456 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MIN, $2.mod, $2.shift, 0, &$3, &$5, 2);
458 | INSTR_MAX omods dreg ',' sregs
460 TRACE("MAX\n");
461 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MAX, $2.mod, $2.shift, 0, &$3, &$5, 2);
463 | INSTR_SLT omods dreg ',' sregs
465 TRACE("SLT\n");
466 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SLT, $2.mod, $2.shift, 0, &$3, &$5, 2);
468 | INSTR_SGE omods dreg ',' sregs
470 TRACE("SGE\n");
471 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGE, $2.mod, $2.shift, 0, &$3, &$5, 2);
473 | INSTR_ABS omods dreg ',' sregs
475 TRACE("ABS\n");
476 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ABS, $2.mod, $2.shift, 0, &$3, &$5, 1);
478 | INSTR_EXP omods dreg ',' sregs
480 TRACE("EXP\n");
481 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXP, $2.mod, $2.shift, 0, &$3, &$5, 1);
483 | INSTR_LOG omods dreg ',' sregs
485 TRACE("LOG\n");
486 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOG, $2.mod, $2.shift, 0, &$3, &$5, 1);
488 | INSTR_LOGP omods dreg ',' sregs
490 TRACE("LOGP\n");
491 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOGP, $2.mod, $2.shift, 0, &$3, &$5, 1);
493 | INSTR_EXPP omods dreg ',' sregs
495 TRACE("EXPP\n");
496 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_EXPP, $2.mod, $2.shift, 0, &$3, &$5, 1);
498 | INSTR_DST omods dreg ',' sregs
500 TRACE("DST\n");
501 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DST, $2.mod, $2.shift, 0, &$3, &$5, 2);
503 | INSTR_LRP omods dreg ',' sregs
505 TRACE("LRP\n");
506 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LRP, $2.mod, $2.shift, 0, &$3, &$5, 3);
508 | INSTR_FRC omods dreg ',' sregs
510 TRACE("FRC\n");
511 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_FRC, $2.mod, $2.shift, 0, &$3, &$5, 1);
513 | INSTR_POW omods dreg ',' sregs
515 TRACE("POW\n");
516 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_POW, $2.mod, $2.shift, 0, &$3, &$5, 2);
518 | INSTR_CRS omods dreg ',' sregs
520 TRACE("CRS\n");
521 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CRS, $2.mod, $2.shift, 0, &$3, &$5, 2);
523 | INSTR_SGN omods dreg ',' sregs
525 TRACE("SGN\n");
526 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SGN, $2.mod, $2.shift, 0, &$3, &$5, 3);
528 | INSTR_NRM omods dreg ',' sregs
530 TRACE("NRM\n");
531 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_NRM, $2.mod, $2.shift, 0, &$3, &$5, 1);
533 | INSTR_SINCOS omods dreg ',' sregs
535 TRACE("SINCOS\n");
536 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SINCOS, $2.mod, $2.shift, 0, &$3, &$5, 1);
538 | INSTR_M4x4 omods dreg ',' sregs
540 TRACE("M4x4\n");
541 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x4, $2.mod, $2.shift, 0, &$3, &$5, 2);
543 | INSTR_M4x3 omods dreg ',' sregs
545 TRACE("M4x3\n");
546 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M4x3, $2.mod, $2.shift, 0, &$3, &$5, 2);
548 | INSTR_M3x4 omods dreg ',' sregs
550 TRACE("M3x4\n");
551 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x4, $2.mod, $2.shift, 0, &$3, &$5, 2);
553 | INSTR_M3x3 omods dreg ',' sregs
555 TRACE("M3x3\n");
556 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x3, $2.mod, $2.shift, 0, &$3, &$5, 2);
558 | INSTR_M3x2 omods dreg ',' sregs
560 TRACE("M3x2\n");
561 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_M3x2, $2.mod, $2.shift, 0, &$3, &$5, 2);
563 | INSTR_DCL dclusage REG_OUTPUT
565 struct shader_reg reg;
566 TRACE("Output reg declaration\n");
567 ZeroMemory(&reg, sizeof(reg));
568 reg.type = BWRITERSPR_OUTPUT;
569 reg.regnum = $3;
570 reg.rel_reg = NULL;
571 reg.srcmod = 0;
572 reg.u.writemask = BWRITERSP_WRITEMASK_ALL;
573 asm_ctx.funcs->dcl_output(&asm_ctx, $2.dclusage, $2.regnum, &reg);
575 | INSTR_DCL dclusage REG_OUTPUT writemask
577 struct shader_reg reg;
578 TRACE("Output reg declaration\n");
579 ZeroMemory(&reg, sizeof(reg));
580 reg.type = BWRITERSPR_OUTPUT;
581 reg.regnum = $3;
582 reg.rel_reg = NULL;
583 reg.srcmod = 0;
584 reg.u.writemask = $4;
585 asm_ctx.funcs->dcl_output(&asm_ctx, $2.dclusage, $2.regnum, &reg);
587 | INSTR_DCL dclusage omods dcl_inputreg
589 struct shader_reg reg;
590 TRACE("Input reg declaration\n");
591 if($3.shift != 0) {
592 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
593 asm_ctx.line_no);
594 set_parse_status(&asm_ctx.status, PARSE_ERR);
596 if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) ||
597 asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) {
598 asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n",
599 asm_ctx.line_no);
600 set_parse_status(&asm_ctx.status, PARSE_ERR);
602 ZeroMemory(&reg, sizeof(reg));
603 reg.type = $4.type;
604 reg.regnum = $4.regnum;
605 reg.rel_reg = NULL;
606 reg.srcmod = 0;
607 reg.u.writemask = BWRITERSP_WRITEMASK_ALL;
608 asm_ctx.funcs->dcl_input(&asm_ctx, $2.dclusage, $2.regnum, $3.mod, &reg);
610 | INSTR_DCL dclusage omods dcl_inputreg writemask
612 struct shader_reg reg;
613 TRACE("Input reg declaration\n");
614 if($3.shift != 0) {
615 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
616 asm_ctx.line_no);
617 set_parse_status(&asm_ctx.status, PARSE_ERR);
619 if(asm_ctx.shader->version == BWRITERPS_VERSION(2, 0) ||
620 asm_ctx.shader->version == BWRITERPS_VERSION(2, 1)) {
621 asmparser_message(&asm_ctx, "Line %u: Declaration not supported in PS 2\n",
622 asm_ctx.line_no);
623 set_parse_status(&asm_ctx.status, PARSE_ERR);
625 ZeroMemory(&reg, sizeof(reg));
626 reg.type = $4.type;
627 reg.regnum = $4.regnum;
628 reg.rel_reg = NULL;
629 reg.srcmod = 0;
630 reg.u.writemask = $5;
631 asm_ctx.funcs->dcl_input(&asm_ctx, $2.dclusage, $2.regnum, $3.mod, &reg);
633 | INSTR_DCL omods dcl_inputreg
635 struct shader_reg reg;
636 TRACE("Input reg declaration\n");
637 if($2.shift != 0) {
638 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
639 asm_ctx.line_no);
640 set_parse_status(&asm_ctx.status, PARSE_ERR);
642 if(asm_ctx.shader->type != ST_PIXEL) {
643 asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n",
644 asm_ctx.line_no);
645 set_parse_status(&asm_ctx.status, PARSE_ERR);
647 ZeroMemory(&reg, sizeof(reg));
648 reg.type = $3.type;
649 reg.regnum = $3.regnum;
650 reg.rel_reg = NULL;
651 reg.srcmod = 0;
652 reg.u.writemask = BWRITERSP_WRITEMASK_ALL;
653 asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, $2.mod, &reg);
655 | INSTR_DCL omods dcl_inputreg writemask
657 struct shader_reg reg;
658 TRACE("Input reg declaration\n");
659 if($2.shift != 0) {
660 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
661 asm_ctx.line_no);
662 set_parse_status(&asm_ctx.status, PARSE_ERR);
664 if(asm_ctx.shader->type != ST_PIXEL) {
665 asmparser_message(&asm_ctx, "Line %u: Declaration needs a semantic\n",
666 asm_ctx.line_no);
667 set_parse_status(&asm_ctx.status, PARSE_ERR);
669 ZeroMemory(&reg, sizeof(reg));
670 reg.type = $3.type;
671 reg.regnum = $3.regnum;
672 reg.rel_reg = NULL;
673 reg.srcmod = 0;
674 reg.u.writemask = $4;
675 asm_ctx.funcs->dcl_input(&asm_ctx, 0, 0, $2.mod, &reg);
677 | INSTR_DCL sampdcl omods REG_SAMPLER
679 TRACE("Sampler declared\n");
680 if($3.shift != 0) {
681 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
682 asm_ctx.line_no);
683 set_parse_status(&asm_ctx.status, PARSE_ERR);
685 asm_ctx.funcs->dcl_sampler(&asm_ctx, $2, $3.mod, $4, asm_ctx.line_no);
687 | INSTR_DCL omods REG_SAMPLER
689 TRACE("Sampler declared\n");
690 if($2.shift != 0) {
691 asmparser_message(&asm_ctx, "Line %u: Shift modifier not allowed here\n",
692 asm_ctx.line_no);
693 set_parse_status(&asm_ctx.status, PARSE_ERR);
695 if(asm_ctx.shader->type != ST_PIXEL) {
696 asmparser_message(&asm_ctx, "Line %u: Declaration needs a sampler type\n",
697 asm_ctx.line_no);
698 set_parse_status(&asm_ctx.status, PARSE_ERR);
700 asm_ctx.funcs->dcl_sampler(&asm_ctx, BWRITERSTT_UNKNOWN, $2.mod, $3, asm_ctx.line_no);
702 | INSTR_DCL sampdcl omods dcl_inputreg
704 TRACE("Error rule: sampler decl of input reg\n");
705 asmparser_message(&asm_ctx, "Line %u: Sampler declarations of input regs is not valid\n",
706 asm_ctx.line_no);
707 set_parse_status(&asm_ctx.status, PARSE_WARN);
709 | INSTR_DCL sampdcl omods REG_OUTPUT
711 TRACE("Error rule: sampler decl of output reg\n");
712 asmparser_message(&asm_ctx, "Line %u: Sampler declarations of output regs is not valid\n",
713 asm_ctx.line_no);
714 set_parse_status(&asm_ctx.status, PARSE_WARN);
716 | INSTR_DEF REG_CONSTFLOAT ',' IMMVAL ',' IMMVAL ',' IMMVAL ',' IMMVAL
718 asm_ctx.funcs->constF(&asm_ctx, $2, $4.val, $6.val, $8.val, $10.val);
720 | INSTR_DEFI REG_CONSTINT ',' IMMVAL ',' IMMVAL ',' IMMVAL ',' IMMVAL
722 asm_ctx.funcs->constI(&asm_ctx, $2, $4.val, $6.val, $8.val, $10.val);
724 | INSTR_DEFB REG_CONSTBOOL ',' IMMBOOL
726 asm_ctx.funcs->constB(&asm_ctx, $2, $4);
728 | INSTR_REP sregs
730 TRACE("REP\n");
731 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_REP, 0, 0, 0, 0, &$2, 1);
733 | INSTR_ENDREP
735 TRACE("ENDREP\n");
736 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDREP, 0, 0, 0, 0, 0, 0);
738 | INSTR_IF sregs
740 TRACE("IF\n");
741 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IF, 0, 0, 0, 0, &$2, 1);
743 | INSTR_IF comp sregs
745 TRACE("IFC\n");
746 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_IFC, 0, 0, $2, 0, &$3, 2);
748 | INSTR_ELSE
750 TRACE("ELSE\n");
751 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ELSE, 0, 0, 0, 0, 0, 0);
753 | INSTR_ENDIF
755 TRACE("ENDIF\n");
756 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDIF, 0, 0, 0, 0, 0, 0);
758 | INSTR_BREAK
760 TRACE("BREAK\n");
761 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAK, 0, 0, 0, 0, 0, 0);
763 | INSTR_BREAK comp sregs
765 TRACE("BREAKC\n");
766 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKC, 0, 0, $2, 0, &$3, 2);
768 | INSTR_BREAKP sregs
770 TRACE("BREAKP\n");
771 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BREAKP, 0, 0, 0, 0, &$2, 1);
773 | INSTR_CALL sregs
775 TRACE("CALL\n");
776 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALL, 0, 0, 0, 0, &$2, 1);
778 | INSTR_CALLNZ sregs
780 TRACE("CALLNZ\n");
781 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CALLNZ, 0, 0, 0, 0, &$2, 2);
783 | INSTR_LOOP sregs
785 TRACE("LOOP\n");
786 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LOOP, 0, 0, 0, 0, &$2, 2);
788 | INSTR_RET
790 TRACE("RET\n");
791 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_RET, 0, 0, 0, 0, 0, 0);
793 | INSTR_ENDLOOP
795 TRACE("ENDLOOP\n");
796 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_ENDLOOP, 0, 0, 0, 0, 0, 0);
798 | INSTR_LABEL sregs
800 TRACE("LABEL\n");
801 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LABEL, 0, 0, 0, 0, &$2, 1);
803 | INSTR_SETP comp dreg ',' sregs
805 TRACE("SETP\n");
806 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_SETP, 0, 0, $2, &$3, &$5, 2);
808 | INSTR_TEXLDL omods dreg ',' sregs
810 TRACE("TEXLDL\n");
811 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDL, $2.mod, $2.shift, 0, &$3, &$5, 2);
813 | INSTR_LIT omods dreg ',' sregs
815 TRACE("LIT\n");
816 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_LIT, $2.mod, $2.shift, 0, &$3, &$5, 1);
818 | INSTR_MOVA omods dreg ',' sregs
820 TRACE("MOVA\n");
821 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_MOVA, $2.mod, $2.shift, 0, &$3, &$5, 1);
823 | INSTR_CND omods dreg ',' sregs
825 TRACE("CND\n");
826 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CND, $2.mod, $2.shift, 0, &$3, &$5, 3);
828 | INSTR_CMP omods dreg ',' sregs
830 TRACE("CMP\n");
831 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_CMP, $2.mod, $2.shift, 0, &$3, &$5, 3);
833 | INSTR_DP2ADD omods dreg ',' sregs
835 TRACE("DP2ADD\n");
836 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DP2ADD, $2.mod, $2.shift, 0, &$3, &$5, 3);
838 | INSTR_TEXCOORD omods dreg
840 TRACE("TEXCOORD\n");
841 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, $2.mod, $2.shift, 0, &$3, 0, 0);
843 | INSTR_TEXCRD omods dreg ',' sregs
845 TRACE("TEXCRD\n");
846 /* texcoord and texcrd share the same opcode */
847 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXCOORD, $2.mod, $2.shift, 0, &$3, &$5, 1);
849 | INSTR_TEXKILL dreg
851 TRACE("TEXKILL\n");
852 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXKILL, 0, 0, 0, &$2, 0, 0);
854 | INSTR_TEX omods dreg
856 TRACE("TEX\n");
857 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, $2.mod, $2.shift, 0, &$3, 0, 0);
859 | INSTR_TEXDEPTH omods dreg
861 TRACE("TEXDEPTH\n");
862 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDEPTH, $2.mod, $2.shift, 0, &$3, 0, 0);
864 | INSTR_TEXLD omods dreg ',' sregs
866 TRACE("TEXLD\n");
867 /* There is more than one acceptable syntax for texld:
868 with 1 sreg (PS 1.4) or
869 with 2 sregs (PS 2.0+)
870 Moreover, texld shares the same opcode as the tex instruction,
871 so there are a total of 3 valid syntaxes
872 These variations are handled in asmparser.c */
873 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEX, $2.mod, $2.shift, 0, &$3, &$5, 2);
875 | INSTR_TEXLDP omods dreg ',' sregs
877 TRACE("TEXLDP\n");
878 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDP, $2.mod, $2.shift, 0, &$3, &$5, 2);
880 | INSTR_TEXLDB omods dreg ',' sregs
882 TRACE("TEXLDB\n");
883 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDB, $2.mod, $2.shift, 0, &$3, &$5, 2);
885 | INSTR_TEXBEM omods dreg ',' sregs
887 TRACE("TEXBEM\n");
888 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEM, $2.mod, $2.shift, 0, &$3, &$5, 1);
890 | INSTR_TEXBEML omods dreg ',' sregs
892 TRACE("TEXBEML\n");
893 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXBEML, $2.mod, $2.shift, 0, &$3, &$5, 1);
895 | INSTR_TEXREG2AR omods dreg ',' sregs
897 TRACE("TEXREG2AR\n");
898 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2AR, $2.mod, $2.shift, 0, &$3, &$5, 1);
900 | INSTR_TEXREG2GB omods dreg ',' sregs
902 TRACE("TEXREG2GB\n");
903 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2GB, $2.mod, $2.shift, 0, &$3, &$5, 1);
905 | INSTR_TEXREG2RGB omods dreg ',' sregs
907 TRACE("TEXREG2RGB\n");
908 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXREG2RGB, $2.mod, $2.shift, 0, &$3, &$5, 1);
910 | INSTR_TEXM3x2PAD omods dreg ',' sregs
912 TRACE("TEXM3x2PAD\n");
913 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2PAD, $2.mod, $2.shift, 0, &$3, &$5, 1);
915 | INSTR_TEXM3x3PAD omods dreg ',' sregs
917 TRACE("INSTR_TEXM3x3PAD\n");
918 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3PAD, $2.mod, $2.shift, 0, &$3, &$5, 1);
920 | INSTR_TEXM3x3SPEC omods dreg ',' sregs
922 TRACE("TEXM3x3SPEC\n");
923 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3SPEC, $2.mod, $2.shift, 0, &$3, &$5, 2);
925 | INSTR_TEXM3x3VSPEC omods dreg ',' sregs
927 TRACE("TEXM3x3VSPEC\n");
928 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3VSPEC, $2.mod, $2.shift, 0, &$3, &$5, 1);
930 | INSTR_TEXM3x3TEX omods dreg ',' sregs
932 TRACE("TEXM3x3TEX\n");
933 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3TEX, $2.mod, $2.shift, 0, &$3, &$5, 1);
935 | INSTR_TEXDP3TEX omods dreg ',' sregs
937 TRACE("TEXDP3TEX\n");
938 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3TEX, $2.mod, $2.shift, 0, &$3, &$5, 1);
940 | INSTR_TEXM3x2DEPTH omods dreg ',' sregs
942 TRACE("TEXM3x2DEPTH\n");
943 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2DEPTH, $2.mod, $2.shift, 0, &$3, &$5, 1);
945 | INSTR_TEXM3x2TEX omods dreg ',' sregs
947 TRACE("TEXM3x2TEX\n");
948 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x2TEX, $2.mod, $2.shift, 0, &$3, &$5, 1);
950 | INSTR_TEXDP3 omods dreg ',' sregs
952 TRACE("TEXDP3\n");
953 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXDP3, $2.mod, $2.shift, 0, &$3, &$5, 1);
955 | INSTR_TEXM3x3 omods dreg ',' sregs
957 TRACE("TEXM3x3\n");
958 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXM3x3, $2.mod, $2.shift, 0, &$3, &$5, 1);
960 | INSTR_BEM omods dreg ',' sregs
962 TRACE("BEM\n");
963 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_BEM, $2.mod, $2.shift, 0, &$3, &$5, 2);
965 | INSTR_DSX omods dreg ',' sregs
967 TRACE("DSX\n");
968 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSX, $2.mod, $2.shift, 0, &$3, &$5, 1);
970 | INSTR_DSY omods dreg ',' sregs
972 TRACE("DSY\n");
973 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_DSY, $2.mod, $2.shift, 0, &$3, &$5, 1);
975 | INSTR_TEXLDD omods dreg ',' sregs
977 TRACE("TEXLDD\n");
978 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_TEXLDD, $2.mod, $2.shift, 0, &$3, &$5, 4);
980 | INSTR_PHASE
982 TRACE("PHASE\n");
983 asm_ctx.funcs->instr(&asm_ctx, BWRITERSIO_PHASE, 0, 0, 0, 0, 0, 0);
987 dreg: dreg_name rel_reg
989 $$.regnum = $1.regnum;
990 $$.type = $1.type;
991 $$.u.writemask = BWRITERSP_WRITEMASK_ALL;
992 $$.srcmod = BWRITERSPSM_NONE;
993 set_rel_reg(&$$, &$2);
995 | dreg_name writemask
997 $$.regnum = $1.regnum;
998 $$.type = $1.type;
999 $$.u.writemask = $2;
1000 $$.srcmod = BWRITERSPSM_NONE;
1001 $$.rel_reg = NULL;
1004 dreg_name: REG_TEMP
1006 $$.regnum = $1; $$.type = BWRITERSPR_TEMP;
1008 | REG_OUTPUT
1010 $$.regnum = $1; $$.type = BWRITERSPR_OUTPUT;
1012 | REG_INPUT
1014 $$.regnum = $1; $$.type = BWRITERSPR_INPUT;
1016 | REG_CONSTFLOAT
1018 asmparser_message(&asm_ctx, "Line %u: Register c%u is not a valid destination register\n",
1019 asm_ctx.line_no, $1);
1020 set_parse_status(&asm_ctx.status, PARSE_WARN);
1022 | REG_CONSTINT
1024 asmparser_message(&asm_ctx, "Line %u: Register i%u is not a valid destination register\n",
1025 asm_ctx.line_no, $1);
1026 set_parse_status(&asm_ctx.status, PARSE_WARN);
1028 | REG_CONSTBOOL
1030 asmparser_message(&asm_ctx, "Line %u: Register b%u is not a valid destination register\n",
1031 asm_ctx.line_no, $1);
1032 set_parse_status(&asm_ctx.status, PARSE_WARN);
1034 | REG_TEXTURE
1036 $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE;
1038 | REG_TEXCRDOUT
1040 $$.regnum = $1; $$.type = BWRITERSPR_TEXCRDOUT;
1042 | REG_SAMPLER
1044 asmparser_message(&asm_ctx, "Line %u: Register s%u is not a valid destination register\n",
1045 asm_ctx.line_no, $1);
1046 set_parse_status(&asm_ctx.status, PARSE_WARN);
1048 | REG_OPOS
1050 $$.regnum = BWRITERSRO_POSITION; $$.type = BWRITERSPR_RASTOUT;
1052 | REG_OPTS
1054 $$.regnum = BWRITERSRO_POINT_SIZE; $$.type = BWRITERSPR_RASTOUT;
1056 | REG_OFOG
1058 $$.regnum = BWRITERSRO_FOG; $$.type = BWRITERSPR_RASTOUT;
1060 | REG_VERTEXCOLOR
1062 $$.regnum = $1; $$.type = BWRITERSPR_ATTROUT;
1064 | REG_FRAGCOLOR
1066 $$.regnum = $1; $$.type = BWRITERSPR_COLOROUT;
1068 | REG_FRAGDEPTH
1070 $$.regnum = 0; $$.type = BWRITERSPR_DEPTHOUT;
1072 | REG_PREDICATE
1074 $$.regnum = 0; $$.type = BWRITERSPR_PREDICATE;
1076 | REG_VPOS
1078 asmparser_message(&asm_ctx, "Line %u: Register vPos is not a valid destination register\n",
1079 asm_ctx.line_no);
1080 set_parse_status(&asm_ctx.status, PARSE_WARN);
1082 | REG_VFACE
1084 asmparser_message(&asm_ctx, "Line %u: Register vFace is not a valid destination register\n",
1085 asm_ctx.line_no);
1086 set_parse_status(&asm_ctx.status, PARSE_WARN);
1088 | REG_ADDRESS
1090 /* index 0 is hardcoded for the addr register */
1091 $$.regnum = 0; $$.type = BWRITERSPR_ADDR;
1093 | REG_LOOP
1095 asmparser_message(&asm_ctx, "Line %u: Register aL is not a valid destination register\n",
1096 asm_ctx.line_no);
1097 set_parse_status(&asm_ctx.status, PARSE_WARN);
1100 writemask: '.' wm_components
1102 if($2.writemask == SWIZZLE_ERR) {
1103 asmparser_message(&asm_ctx, "Line %u: Invalid writemask specified\n",
1104 asm_ctx.line_no);
1105 set_parse_status(&asm_ctx.status, PARSE_ERR);
1106 /* Provide a correct writemask to prevent following complaints */
1107 $$ = BWRITERSP_WRITEMASK_ALL;
1109 else {
1110 $$ = $2.writemask;
1111 TRACE("Writemask: %x\n", $$);
1115 wm_components: COMPONENT
1117 $$.writemask = 1 << $1;
1118 $$.last = $1;
1119 $$.idx = 1;
1121 | wm_components COMPONENT
1123 if($1.writemask == SWIZZLE_ERR || $1.idx == 4)
1124 /* Wrong writemask */
1125 $$.writemask = SWIZZLE_ERR;
1126 else {
1127 if($2 <= $1.last)
1128 $$.writemask = SWIZZLE_ERR;
1129 else {
1130 $$.writemask = $1.writemask | (1 << $2);
1131 $$.idx = $1.idx + 1;
1136 swizzle: /* empty */
1138 $$ = BWRITERVS_NOSWIZZLE;
1139 TRACE("Default swizzle: %08x\n", $$);
1141 | '.' sw_components
1143 if($2.swizzle == SWIZZLE_ERR) {
1144 asmparser_message(&asm_ctx, "Line %u: Invalid swizzle\n",
1145 asm_ctx.line_no);
1146 set_parse_status(&asm_ctx.status, PARSE_ERR);
1147 /* Provide a correct swizzle to prevent following complaints */
1148 $$ = BWRITERVS_NOSWIZZLE;
1150 else {
1151 DWORD last, i;
1153 $$ = $2.swizzle << BWRITERVS_SWIZZLE_SHIFT;
1154 /* Fill the swizzle by extending the last component */
1155 last = ($2.swizzle >> 2 * ($2.idx - 1)) & 0x03;
1156 for(i = $2.idx; i < 4; i++){
1157 $$ |= last << (BWRITERVS_SWIZZLE_SHIFT + 2 * i);
1159 TRACE("Got a swizzle: %08x\n", $$);
1163 sw_components: COMPONENT
1165 $$.swizzle = $1;
1166 $$.idx = 1;
1168 | sw_components COMPONENT
1170 if($1.idx == 4) {
1171 /* Too many sw_components */
1172 $$.swizzle = SWIZZLE_ERR;
1173 $$.idx = 4;
1175 else {
1176 $$.swizzle = $1.swizzle | ($2 << 2 * $1.idx);
1177 $$.idx = $1.idx + 1;
1181 omods: /* Empty */
1183 $$.mod = 0;
1184 $$.shift = 0;
1186 | omods omodifier
1188 $$.mod = $1.mod | $2.mod;
1189 if($1.shift && $2.shift) {
1190 asmparser_message(&asm_ctx, "Line %u: More than one shift flag\n",
1191 asm_ctx.line_no);
1192 set_parse_status(&asm_ctx.status, PARSE_ERR);
1193 $$.shift = $1.shift;
1194 } else {
1195 $$.shift = $1.shift | $2.shift;
1199 omodifier: SHIFT_X2
1201 $$.mod = 0;
1202 $$.shift = 1;
1204 | SHIFT_X4
1206 $$.mod = 0;
1207 $$.shift = 2;
1209 | SHIFT_X8
1211 $$.mod = 0;
1212 $$.shift = 3;
1214 | SHIFT_D2
1216 $$.mod = 0;
1217 $$.shift = 15;
1219 | SHIFT_D4
1221 $$.mod = 0;
1222 $$.shift = 14;
1224 | SHIFT_D8
1226 $$.mod = 0;
1227 $$.shift = 13;
1229 | MOD_SAT
1231 $$.mod = BWRITERSPDM_SATURATE;
1232 $$.shift = 0;
1234 | MOD_PP
1236 $$.mod = BWRITERSPDM_PARTIALPRECISION;
1237 $$.shift = 0;
1239 | MOD_CENTROID
1241 $$.mod = BWRITERSPDM_MSAMPCENTROID;
1242 $$.shift = 0;
1245 sregs: sreg
1247 $$.reg[0] = $1;
1248 $$.count = 1;
1250 | sregs ',' sreg
1252 if($$.count == MAX_SRC_REGS){
1253 asmparser_message(&asm_ctx, "Line %u: Too many source registers in this instruction\n",
1254 asm_ctx.line_no);
1255 set_parse_status(&asm_ctx.status, PARSE_ERR);
1257 else
1258 $$.reg[$$.count++] = $3;
1261 sreg: sreg_name rel_reg swizzle
1263 $$.type = $1.type;
1264 $$.regnum = $1.regnum;
1265 $$.u.swizzle = $3;
1266 $$.srcmod = BWRITERSPSM_NONE;
1267 set_rel_reg(&$$, &$2);
1269 | sreg_name rel_reg smod swizzle
1271 $$.type = $1.type;
1272 $$.regnum = $1.regnum;
1273 set_rel_reg(&$$, &$2);
1274 $$.srcmod = $3;
1275 $$.u.swizzle = $4;
1277 | '-' sreg_name rel_reg swizzle
1279 $$.type = $2.type;
1280 $$.regnum = $2.regnum;
1281 $$.srcmod = BWRITERSPSM_NEG;
1282 set_rel_reg(&$$, &$3);
1283 $$.u.swizzle = $4;
1285 | '-' sreg_name rel_reg smod swizzle
1287 $$.type = $2.type;
1288 $$.regnum = $2.regnum;
1289 set_rel_reg(&$$, &$3);
1290 switch($4) {
1291 case BWRITERSPSM_BIAS: $$.srcmod = BWRITERSPSM_BIASNEG; break;
1292 case BWRITERSPSM_X2: $$.srcmod = BWRITERSPSM_X2NEG; break;
1293 case BWRITERSPSM_SIGN: $$.srcmod = BWRITERSPSM_SIGNNEG; break;
1294 case BWRITERSPSM_ABS: $$.srcmod = BWRITERSPSM_ABSNEG; break;
1295 case BWRITERSPSM_DZ:
1296 asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DZ\n",
1297 asm_ctx.line_no);
1298 set_parse_status(&asm_ctx.status, PARSE_ERR);
1299 break;
1300 case BWRITERSPSM_DW:
1301 asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: NEG and DW\n",
1302 asm_ctx.line_no);
1303 set_parse_status(&asm_ctx.status, PARSE_ERR);
1304 break;
1305 default:
1306 FIXME("Unhandled combination of NEGATE and %u\n", $4);
1308 $$.u.swizzle = $5;
1310 | IMMVAL '-' sreg_name rel_reg swizzle
1312 if($1.val != 1.0 || (!$1.integer)) {
1313 asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP, "
1314 "%g - reg found\n", asm_ctx.line_no, $1.val);
1315 set_parse_status(&asm_ctx.status, PARSE_ERR);
1317 /* Complement - not compatible with other source modifiers */
1318 $$.type = $3.type;
1319 $$.regnum = $3.regnum;
1320 $$.srcmod = BWRITERSPSM_COMP;
1321 set_rel_reg(&$$, &$4);
1322 $$.u.swizzle = $5;
1324 | IMMVAL '-' sreg_name rel_reg smod swizzle
1326 /* For nicer error reporting */
1327 if($1.val != 1.0 || (!$1.integer)) {
1328 asmparser_message(&asm_ctx, "Line %u: Only \"1 - reg\" is valid for D3DSPSM_COMP\n",
1329 asm_ctx.line_no);
1330 set_parse_status(&asm_ctx.status, PARSE_ERR);
1331 } else {
1332 asmparser_message(&asm_ctx, "Line %u: Incompatible source modifiers: D3DSPSM_COMP and %s\n",
1333 asm_ctx.line_no,
1334 debug_print_srcmod($5));
1335 set_parse_status(&asm_ctx.status, PARSE_ERR);
1338 | SMOD_NOT sreg_name swizzle
1340 $$.type = $2.type;
1341 $$.regnum = $2.regnum;
1342 $$.rel_reg = NULL;
1343 $$.srcmod = BWRITERSPSM_NOT;
1344 $$.u.swizzle = $3;
1347 rel_reg: /* empty */
1349 $$.has_rel_reg = FALSE;
1350 $$.additional_offset = 0;
1352 | '[' immsum ']'
1354 $$.has_rel_reg = FALSE;
1355 $$.additional_offset = $2.val;
1357 | '[' relreg_name swizzle ']'
1359 $$.has_rel_reg = TRUE;
1360 $$.type = $2.type;
1361 $$.additional_offset = 0;
1362 $$.rel_regnum = $2.regnum;
1363 $$.swizzle = $3;
1365 | '[' immsum '+' relreg_name swizzle ']'
1367 $$.has_rel_reg = TRUE;
1368 $$.type = $4.type;
1369 $$.additional_offset = $2.val;
1370 $$.rel_regnum = $4.regnum;
1371 $$.swizzle = $5;
1373 | '[' relreg_name swizzle '+' immsum ']'
1375 $$.has_rel_reg = TRUE;
1376 $$.type = $2.type;
1377 $$.additional_offset = $5.val;
1378 $$.rel_regnum = $2.regnum;
1379 $$.swizzle = $3;
1381 | '[' immsum '+' relreg_name swizzle '+' immsum ']'
1383 $$.has_rel_reg = TRUE;
1384 $$.type = $4.type;
1385 $$.additional_offset = $2.val + $7.val;
1386 $$.rel_regnum = $4.regnum;
1387 $$.swizzle = $5;
1390 immsum: IMMVAL
1392 if(!$1.integer) {
1393 asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n",
1394 asm_ctx.line_no, $1.val);
1395 set_parse_status(&asm_ctx.status, PARSE_ERR);
1397 $$.val = $1.val;
1399 | immsum '+' IMMVAL
1401 if(!$3.integer) {
1402 asmparser_message(&asm_ctx, "Line %u: Unexpected float %f\n",
1403 asm_ctx.line_no, $3.val);
1404 set_parse_status(&asm_ctx.status, PARSE_ERR);
1406 $$.val = $1.val + $3.val;
1409 smod: SMOD_BIAS
1411 $$ = BWRITERSPSM_BIAS;
1413 | SHIFT_X2
1415 $$ = BWRITERSPSM_X2;
1417 | SMOD_SCALEBIAS
1419 $$ = BWRITERSPSM_SIGN;
1421 | SMOD_DZ
1423 $$ = BWRITERSPSM_DZ;
1425 | SMOD_DW
1427 $$ = BWRITERSPSM_DW;
1429 | SMOD_ABS
1431 $$ = BWRITERSPSM_ABS;
1434 relreg_name: REG_ADDRESS
1436 $$.regnum = 0; $$.type = BWRITERSPR_ADDR;
1438 | REG_LOOP
1440 $$.regnum = 0; $$.type = BWRITERSPR_LOOP;
1443 sreg_name: REG_TEMP
1445 $$.regnum = $1; $$.type = BWRITERSPR_TEMP;
1447 | REG_OUTPUT
1449 asmparser_message(&asm_ctx, "Line %u: Register o%u is not a valid source register\n",
1450 asm_ctx.line_no, $1);
1451 set_parse_status(&asm_ctx.status, PARSE_WARN);
1453 | REG_INPUT
1455 $$.regnum = $1; $$.type = BWRITERSPR_INPUT;
1457 | REG_CONSTFLOAT
1459 $$.regnum = $1; $$.type = BWRITERSPR_CONST;
1461 | REG_CONSTINT
1463 $$.regnum = $1; $$.type = BWRITERSPR_CONSTINT;
1465 | REG_CONSTBOOL
1467 $$.regnum = $1; $$.type = BWRITERSPR_CONSTBOOL;
1469 | REG_TEXTURE
1471 $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE;
1473 | REG_TEXCRDOUT
1475 asmparser_message(&asm_ctx, "Line %u: Register oT%u is not a valid source register\n",
1476 asm_ctx.line_no, $1);
1477 set_parse_status(&asm_ctx.status, PARSE_WARN);
1479 | REG_SAMPLER
1481 $$.regnum = $1; $$.type = BWRITERSPR_SAMPLER;
1483 | REG_OPOS
1485 asmparser_message(&asm_ctx, "Line %u: Register oPos is not a valid source register\n",
1486 asm_ctx.line_no);
1487 set_parse_status(&asm_ctx.status, PARSE_WARN);
1489 | REG_OFOG
1491 asmparser_message(&asm_ctx, "Line %u: Register oFog is not a valid source register\n",
1492 asm_ctx.line_no);
1493 set_parse_status(&asm_ctx.status, PARSE_WARN);
1495 | REG_VERTEXCOLOR
1497 asmparser_message(&asm_ctx, "Line %u: Register oD%u is not a valid source register\n",
1498 asm_ctx.line_no, $1);
1499 set_parse_status(&asm_ctx.status, PARSE_WARN);
1501 | REG_FRAGCOLOR
1503 asmparser_message(&asm_ctx, "Line %u: Register oC%u is not a valid source register\n",
1504 asm_ctx.line_no, $1);
1505 set_parse_status(&asm_ctx.status, PARSE_WARN);
1507 | REG_FRAGDEPTH
1509 asmparser_message(&asm_ctx, "Line %u: Register oDepth is not a valid source register\n",
1510 asm_ctx.line_no);
1511 set_parse_status(&asm_ctx.status, PARSE_WARN);
1513 | REG_PREDICATE
1515 $$.regnum = 0; $$.type = BWRITERSPR_PREDICATE;
1517 | REG_VPOS
1519 $$.regnum = 0; $$.type = BWRITERSPR_MISCTYPE;
1521 | REG_VFACE
1523 $$.regnum = 1; $$.type = BWRITERSPR_MISCTYPE;
1525 | REG_ADDRESS
1527 $$.regnum = 0; $$.type = BWRITERSPR_ADDR;
1529 | REG_LOOP
1531 $$.regnum = 0; $$.type = BWRITERSPR_LOOP;
1533 | REG_LABEL
1535 $$.regnum = $1; $$.type = BWRITERSPR_LABEL;
1538 comp: COMP_GT { $$ = BWRITER_COMPARISON_GT; }
1539 | COMP_LT { $$ = BWRITER_COMPARISON_LT; }
1540 | COMP_GE { $$ = BWRITER_COMPARISON_GE; }
1541 | COMP_LE { $$ = BWRITER_COMPARISON_LE; }
1542 | COMP_EQ { $$ = BWRITER_COMPARISON_EQ; }
1543 | COMP_NE { $$ = BWRITER_COMPARISON_NE; }
1545 dclusage: USAGE_POSITION
1547 TRACE("dcl_position%u\n", $1);
1548 $$.regnum = $1;
1549 $$.dclusage = BWRITERDECLUSAGE_POSITION;
1551 | USAGE_BLENDWEIGHT
1553 TRACE("dcl_blendweight%u\n", $1);
1554 $$.regnum = $1;
1555 $$.dclusage = BWRITERDECLUSAGE_BLENDWEIGHT;
1557 | USAGE_BLENDINDICES
1559 TRACE("dcl_blendindices%u\n", $1);
1560 $$.regnum = $1;
1561 $$.dclusage = BWRITERDECLUSAGE_BLENDINDICES;
1563 | USAGE_NORMAL
1565 TRACE("dcl_normal%u\n", $1);
1566 $$.regnum = $1;
1567 $$.dclusage = BWRITERDECLUSAGE_NORMAL;
1569 | USAGE_PSIZE
1571 TRACE("dcl_psize%u\n", $1);
1572 $$.regnum = $1;
1573 $$.dclusage = BWRITERDECLUSAGE_PSIZE;
1575 | USAGE_TEXCOORD
1577 TRACE("dcl_texcoord%u\n", $1);
1578 $$.regnum = $1;
1579 $$.dclusage = BWRITERDECLUSAGE_TEXCOORD;
1581 | USAGE_TANGENT
1583 TRACE("dcl_tangent%u\n", $1);
1584 $$.regnum = $1;
1585 $$.dclusage = BWRITERDECLUSAGE_TANGENT;
1587 | USAGE_BINORMAL
1589 TRACE("dcl_binormal%u\n", $1);
1590 $$.regnum = $1;
1591 $$.dclusage = BWRITERDECLUSAGE_BINORMAL;
1593 | USAGE_TESSFACTOR
1595 TRACE("dcl_tessfactor%u\n", $1);
1596 $$.regnum = $1;
1597 $$.dclusage = BWRITERDECLUSAGE_TESSFACTOR;
1599 | USAGE_POSITIONT
1601 TRACE("dcl_positiont%u\n", $1);
1602 $$.regnum = $1;
1603 $$.dclusage = BWRITERDECLUSAGE_POSITIONT;
1605 | USAGE_COLOR
1607 TRACE("dcl_color%u\n", $1);
1608 $$.regnum = $1;
1609 $$.dclusage = BWRITERDECLUSAGE_COLOR;
1611 | USAGE_FOG
1613 TRACE("dcl_fog%u\n", $1);
1614 $$.regnum = $1;
1615 $$.dclusage = BWRITERDECLUSAGE_FOG;
1617 | USAGE_DEPTH
1619 TRACE("dcl_depth%u\n", $1);
1620 $$.regnum = $1;
1621 $$.dclusage = BWRITERDECLUSAGE_DEPTH;
1623 | USAGE_SAMPLE
1625 TRACE("dcl_sample%u\n", $1);
1626 $$.regnum = $1;
1627 $$.dclusage = BWRITERDECLUSAGE_SAMPLE;
1630 dcl_inputreg: REG_INPUT
1632 $$.regnum = $1; $$.type = BWRITERSPR_INPUT;
1634 | REG_TEXTURE
1636 $$.regnum = $1; $$.type = BWRITERSPR_TEXTURE;
1639 sampdcl: SAMPTYPE_1D
1641 $$ = BWRITERSTT_1D;
1643 | SAMPTYPE_2D
1645 $$ = BWRITERSTT_2D;
1647 | SAMPTYPE_CUBE
1649 $$ = BWRITERSTT_CUBE;
1651 | SAMPTYPE_VOLUME
1653 $$ = BWRITERSTT_VOLUME;
1656 predicate: '(' REG_PREDICATE swizzle ')'
1658 $$.type = BWRITERSPR_PREDICATE;
1659 $$.regnum = 0;
1660 $$.rel_reg = NULL;
1661 $$.srcmod = BWRITERSPSM_NONE;
1662 $$.u.swizzle = $3;
1664 | '(' SMOD_NOT REG_PREDICATE swizzle ')'
1666 $$.type = BWRITERSPR_PREDICATE;
1667 $$.regnum = 0;
1668 $$.rel_reg = NULL;
1669 $$.srcmod = BWRITERSPSM_NOT;
1670 $$.u.swizzle = $4;
1675 struct bwriter_shader *parse_asm_shader(char **messages)
1677 struct bwriter_shader *ret = NULL;
1679 asm_ctx.shader = NULL;
1680 asm_ctx.status = PARSE_SUCCESS;
1681 asm_ctx.messages.size = asm_ctx.messages.capacity = 0;
1682 asm_ctx.line_no = 1;
1684 asmshader_parse();
1686 if (asm_ctx.status != PARSE_ERR)
1687 ret = asm_ctx.shader;
1688 else if (asm_ctx.shader)
1689 SlDeleteShader(asm_ctx.shader);
1691 if (messages)
1693 if (asm_ctx.messages.size)
1695 /* Shrink the buffer to the used size */
1696 *messages = d3dcompiler_realloc(asm_ctx.messages.string, asm_ctx.messages.size + 1);
1697 if (!*messages)
1699 ERR("Out of memory, no messages reported\n");
1700 d3dcompiler_free(asm_ctx.messages.string);
1703 else
1705 *messages = NULL;
1708 else
1710 if (asm_ctx.messages.capacity)
1711 d3dcompiler_free(asm_ctx.messages.string);
1714 return ret;