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
24 #include "wine/port.h"
25 #include "wine/debug.h"
27 #include "d3dx9_36_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL
(asmshader
);
33 struct asm_parser asm_ctx
;
35 /* Needed lexer functions declarations */
36 void asmshader_error
(const char *s
);
37 int asmshader_lex
(void);
39 void set_rel_reg
(struct shader_reg
*reg
, struct rel_reg
*rel
) {
40 /* We can have an additional offset without true relative addressing
42 reg
->regnum
+= rel
->additional_offset
;
43 if
(!rel
->has_rel_reg
) {
46 reg
->rel_reg
= asm_alloc
(sizeof
(*reg
->rel_reg
));
50 reg
->rel_reg
->type
= rel
->type
;
51 reg
->rel_reg
->swizzle
= rel
->swizzle
;
52 reg
->rel_reg
->regnum
= rel
->rel_regnum
;
65 struct shader_reg reg
;
83 BWRITER_COMPARISON_TYPE comptype
;
88 BWRITERSAMPLER_TEXTURE_TYPE samplertype
;
89 struct rel_reg rel_reg
;
90 struct src_regs sregs
;
93 /* Common instructions between vertex and pixel shaders */
146 /* Vertex shader only instructions */
150 /* Pixel shader only instructions */
162 %token
<regnum
> REG_TEMP
163 %token
<regnum
> REG_OUTPUT
164 %token
<regnum
> REG_INPUT
165 %token
<regnum
> REG_CONSTFLOAT
166 %token
<regnum
> REG_CONSTINT
167 %token
<regnum
> REG_CONSTBOOL
168 %token
<regnum
> REG_TEXTURE
169 %token
<regnum
> REG_SAMPLER
170 %token
<regnum
> REG_TEXCRDOUT
174 %token
<regnum
> REG_VERTEXCOLOR
175 %token
<regnum
> REG_FRAGCOLOR
182 %token
<regnum
> REG_LABEL
200 /* Output modifiers */
213 /* Source register modifiers */
221 %token SAMPTYPE_VOLUME
223 /* Usage declaration tokens */
224 %token
<regnum
> USAGE_POSITION
225 %token
<regnum
> USAGE_BLENDWEIGHT
226 %token
<regnum
> USAGE_BLENDINDICES
227 %token
<regnum
> USAGE_NORMAL
228 %token
<regnum
> USAGE_PSIZE
229 %token
<regnum
> USAGE_TEXCOORD
230 %token
<regnum
> USAGE_TANGENT
231 %token
<regnum
> USAGE_BINORMAL
232 %token
<regnum
> USAGE_TESSFACTOR
233 %token
<regnum
> USAGE_POSITIONT
234 %token
<regnum
> USAGE_COLOR
235 %token
<regnum
> USAGE_FOG
236 %token
<regnum
> USAGE_DEPTH
237 %token
<regnum
> USAGE_SAMPLE
240 %token
<component
> COMPONENT
241 %token
<immval
> IMMVAL
242 %token
<immbool
> IMMBOOL
244 %type
<reg
> dreg_name
246 %type
<reg
> sreg_name
247 %type
<reg
> relreg_name
250 %type
<writemask
> writemask
251 %type
<wm_components
> wm_components
252 %type
<swizzle
> swizzle
253 %type
<sw_components
> sw_components
254 %type
<modshift
> omods
255 %type
<modshift
> omodifier
256 %type
<comptype
> comp
257 %type
<declaration
> dclusage
258 %type
<samplertype
> sampdcl
259 %type
<rel_reg
> rel_reg
260 %type
<reg
> predicate
261 %type
<immval
> immsum
266 shader: version_marker instructions
268 asm_ctx.funcs
->end
(&asm_ctx
);
271 version_marker: VER_VS10
273 TRACE
("Vertex shader 1.0\n");
274 set_parse_status
(&asm_ctx
, PARSE_ERR
);
279 TRACE
("Vertex shader 1.1\n");
280 set_parse_status
(&asm_ctx
, PARSE_ERR
);
285 TRACE
("Vertex shader 2.0\n");
286 set_parse_status
(&asm_ctx
, PARSE_ERR
);
291 TRACE
("Vertex shader 2.x\n");
292 set_parse_status
(&asm_ctx
, PARSE_ERR
);
297 TRACE
("Vertex shader 3.0\n");
298 create_vs30_parser
(&asm_ctx
);
302 TRACE
("Pixel shader 1.0\n");
303 set_parse_status
(&asm_ctx
, PARSE_ERR
);
308 TRACE
("Pixel shader 1.1\n");
309 set_parse_status
(&asm_ctx
, PARSE_ERR
);
314 TRACE
("Pixel shader 1.2\n");
315 set_parse_status
(&asm_ctx
, PARSE_ERR
);
320 TRACE
("Pixel shader 1.3\n");
321 set_parse_status
(&asm_ctx
, PARSE_ERR
);
326 TRACE
("Pixel shader 1.4\n");
327 set_parse_status
(&asm_ctx
, PARSE_ERR
);
332 TRACE
("Pixel shader 2.0\n");
333 set_parse_status
(&asm_ctx
, PARSE_ERR
);
338 TRACE
("Pixel shader 2.x\n");
339 set_parse_status
(&asm_ctx
, PARSE_ERR
);
344 TRACE
("Pixel shader 3.0\n");
345 create_ps30_parser
(&asm_ctx
);
348 instructions: /* empty */
349 | instructions complexinstr
354 complexinstr: instruction
358 | predicate instruction
360 TRACE
("predicate\n");
361 asm_ctx.funcs
->predicate
(&asm_ctx
, &$1);
364 instruction: INSTR_ADD omods dreg
',' sregs
367 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_ADD
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
372 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_NOP
, 0, 0, 0, 0, 0, 0);
374 | INSTR_MOV omods dreg
',' sregs
377 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_MOV
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
379 | INSTR_SUB omods dreg
',' sregs
382 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_SUB
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
384 | INSTR_MAD omods dreg
',' sregs
387 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_MAD
, $2.mod
, $2.shift
, 0, &$3, &$5, 3);
389 | INSTR_MUL omods dreg
',' sregs
392 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_MUL
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
394 | INSTR_RCP omods dreg
',' sregs
397 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_RCP
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
399 | INSTR_RSQ omods dreg
',' sregs
402 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_RSQ
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
404 | INSTR_DP3 omods dreg
',' sregs
407 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_DP3
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
409 | INSTR_DP4 omods dreg
',' sregs
412 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_DP4
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
414 | INSTR_MIN omods dreg
',' sregs
417 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_MIN
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
419 | INSTR_MAX omods dreg
',' sregs
422 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_MAX
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
424 | INSTR_SLT omods dreg
',' sregs
427 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_SLT
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
429 | INSTR_SGE omods dreg
',' sregs
432 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_SGE
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
434 | INSTR_ABS omods dreg
',' sregs
437 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_ABS
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
439 | INSTR_EXP omods dreg
',' sregs
442 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_EXP
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
444 | INSTR_LOG omods dreg
',' sregs
447 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_LOG
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
449 | INSTR_LOGP omods dreg
',' sregs
452 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_LOGP
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
454 | INSTR_EXPP omods dreg
',' sregs
457 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_EXPP
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
459 | INSTR_DST omods dreg
',' sregs
462 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_DST
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
464 | INSTR_LRP omods dreg
',' sregs
467 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_LRP
, $2.mod
, $2.shift
, 0, &$3, &$5, 3);
469 | INSTR_FRC omods dreg
',' sregs
472 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_FRC
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
474 | INSTR_POW omods dreg
',' sregs
477 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_POW
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
479 | INSTR_CRS omods dreg
',' sregs
482 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_CRS
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
484 | INSTR_SGN omods dreg
',' sregs
487 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_SGN
, $2.mod
, $2.shift
, 0, &$3, &$5, 3);
489 | INSTR_NRM omods dreg
',' sregs
492 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_NRM
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
494 | INSTR_SINCOS omods dreg
',' sregs
497 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_SINCOS
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
499 | INSTR_M4x4 omods dreg
',' sregs
502 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_M4x4
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
504 | INSTR_M4x3 omods dreg
',' sregs
507 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_M4x3
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
509 | INSTR_M3x4 omods dreg
',' sregs
512 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_M3x4
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
514 | INSTR_M3x3 omods dreg
',' sregs
517 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_M3x3
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
519 | INSTR_M3x2 omods dreg
',' sregs
522 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_M3x2
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
524 | INSTR_DCL dclusage REG_OUTPUT
526 struct shader_reg reg
;
527 TRACE
("Output reg declaration\n");
528 ZeroMemory
(®
, sizeof
(reg
));
529 reg.type
= BWRITERSPR_OUTPUT
;
533 reg.writemask
= BWRITERSP_WRITEMASK_ALL
;
534 asm_ctx.funcs
->dcl_output
(&asm_ctx
, $2.dclusage
, $2.regnum
, ®
);
536 | INSTR_DCL dclusage REG_OUTPUT writemask
538 struct shader_reg reg
;
539 TRACE
("Output reg declaration\n");
540 ZeroMemory
(®
, sizeof
(reg
));
541 reg.type
= BWRITERSPR_OUTPUT
;
546 asm_ctx.funcs
->dcl_output
(&asm_ctx
, $2.dclusage
, $2.regnum
, ®
);
548 | INSTR_DCL dclusage REG_INPUT
550 struct shader_reg reg
;
551 TRACE
("Input reg declaration\n");
552 ZeroMemory
(®
, sizeof
(reg
));
553 reg.type
= BWRITERSPR_INPUT
;
557 reg.writemask
= BWRITERSP_WRITEMASK_ALL
;
558 asm_ctx.funcs
->dcl_input
(&asm_ctx
, $2.dclusage
, $2.regnum
, ®
);
560 | INSTR_DCL dclusage REG_INPUT writemask
562 struct shader_reg reg
;
563 TRACE
("Input reg declaration\n");
564 ZeroMemory
(®
, sizeof
(reg
));
565 reg.type
= BWRITERSPR_INPUT
;
570 asm_ctx.funcs
->dcl_input
(&asm_ctx
, $2.dclusage
, $2.regnum
, ®
);
572 | INSTR_DCL sampdcl REG_SAMPLER
574 TRACE
("Sampler declared\n");
575 asm_ctx.funcs
->dcl_sampler
(&asm_ctx
, $2, $3, asm_ctx.line_no
);
577 | INSTR_DCL sampdcl REG_INPUT
579 TRACE
("Error rule: sampler decl of input reg\n");
580 asmparser_message
(&asm_ctx
, "Line %u: Sampler declarations of input regs is not valid\n",
582 set_parse_status
(&asm_ctx
, PARSE_WARN
);
584 | INSTR_DCL sampdcl REG_OUTPUT
586 TRACE
("Error rule: sampler decl of output reg\n");
587 asmparser_message
(&asm_ctx
, "Line %u: Sampler declarations of output regs is not valid\n",
589 set_parse_status
(&asm_ctx
, PARSE_WARN
);
591 | INSTR_DEF REG_CONSTFLOAT
',' IMMVAL
',' IMMVAL
',' IMMVAL
',' IMMVAL
593 asm_ctx.funcs
->constF
(&asm_ctx
, $2, $4.val
, $6.val
, $8.val
, $10.val
);
595 | INSTR_DEFI REG_CONSTINT
',' IMMVAL
',' IMMVAL
',' IMMVAL
',' IMMVAL
597 asm_ctx.funcs
->constI
(&asm_ctx
, $2, $4.val
, $6.val
, $8.val
, $10.val
);
599 | INSTR_DEFB REG_CONSTBOOL
',' IMMBOOL
601 asm_ctx.funcs
->constB
(&asm_ctx
, $2, $4);
606 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_REP
, 0, 0, 0, 0, &$2, 1);
611 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_ENDREP
, 0, 0, 0, 0, 0, 0);
616 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_IF
, 0, 0, 0, 0, &$2, 1);
618 | INSTR_IF comp sregs
621 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_IFC
, 0, 0, $2, 0, &$3, 2);
626 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_ELSE
, 0, 0, 0, 0, 0, 0);
631 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_ENDIF
, 0, 0, 0, 0, 0, 0);
636 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_BREAK
, 0, 0, 0, 0, 0, 0);
638 | INSTR_BREAK comp sregs
641 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_BREAKC
, 0, 0, $2, 0, &$3, 2);
646 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_BREAKP
, 0, 0, 0, 0, &$2, 1);
651 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_CALL
, 0, 0, 0, 0, &$2, 1);
656 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_CALLNZ
, 0, 0, 0, 0, &$2, 2);
661 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_LOOP
, 0, 0, 0, 0, &$2, 2);
666 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_RET
, 0, 0, 0, 0, 0, 0);
671 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_ENDLOOP
, 0, 0, 0, 0, 0, 0);
676 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_LABEL
, 0, 0, 0, 0, &$2, 1);
678 | INSTR_SETP comp dreg
',' sregs
681 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_SETP
, 0, 0, $2, &$3, &$5, 2);
683 | INSTR_TEXLDL omods dreg
',' sregs
686 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_TEXLDL
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
688 | INSTR_LIT omods dreg
',' sregs
691 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_LIT
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
693 | INSTR_MOVA omods dreg
',' sregs
696 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_MOVA
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
698 | INSTR_CMP omods dreg
',' sregs
701 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_CMP
, $2.mod
, $2.shift
, 0, &$3, &$5, 3);
703 | INSTR_DP2ADD omods dreg
',' sregs
706 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_DP2ADD
, $2.mod
, $2.shift
, 0, &$3, &$5, 3);
711 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_TEXKILL
, 0, 0, 0, &$2, 0, 0);
713 | INSTR_TEXLD omods dreg
',' sregs
716 /* There is more than one acceptable syntax for texld:
717 with 1 sreg (PS 1.4) or
718 with 2 sregs (PS 2.0+)
719 Moreover, texld shares the same opcode as the tex instruction,
720 so there are a total of 3 valid syntaxes
721 These variations are handled in asmparser.c */
722 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_TEX
, $2.mod
, $2.shift
, 0, &$3, &$5, 2);
724 | INSTR_TEXLDP omods dreg
',' sregs
727 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_TEX |
( BWRITERSI_TEXLD_PROJECT
<< BWRITER_OPCODESPECIFICCONTROL_SHIFT
), $2.mod
, $2.shift
, 0, &$3, &$5, 2);
729 | INSTR_TEXLDB omods dreg
',' sregs
732 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_TEX |
( BWRITERSI_TEXLD_BIAS
<< BWRITER_OPCODESPECIFICCONTROL_SHIFT
), $2.mod
, $2.shift
, 0, &$3, &$5, 2);
734 | INSTR_DSX omods dreg
',' sregs
737 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_DSX
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
739 | INSTR_DSY omods dreg
',' sregs
742 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_DSY
, $2.mod
, $2.shift
, 0, &$3, &$5, 1);
744 | INSTR_TEXLDD omods dreg
',' sregs
747 asm_ctx.funcs
->instr
(&asm_ctx
, BWRITERSIO_TEXLDD
, $2.mod
, $2.shift
, 0, &$3, &$5, 4);
750 dreg: dreg_name rel_reg
752 $$.regnum
= $1.regnum
;
754 $$.writemask
= BWRITERSP_WRITEMASK_ALL
;
755 $$.srcmod
= BWRITERSPSM_NONE
;
756 set_rel_reg
(&$$
, &$2);
758 | dreg_name writemask
760 $$.regnum
= $1.regnum
;
763 $$.srcmod
= BWRITERSPSM_NONE
;
769 $$.regnum
= $1; $$.type
= BWRITERSPR_TEMP
;
773 $$.regnum
= $1; $$.type
= BWRITERSPR_OUTPUT
;
777 $$.regnum
= $1; $$.type
= BWRITERSPR_INPUT
;
781 asmparser_message
(&asm_ctx
, "Line %u: Register c%u is not a valid destination register\n",
782 asm_ctx.line_no
, $1);
783 set_parse_status
(&asm_ctx
, PARSE_WARN
);
787 asmparser_message
(&asm_ctx
, "Line %u: Register i%u is not a valid destination register\n",
788 asm_ctx.line_no
, $1);
789 set_parse_status
(&asm_ctx
, PARSE_WARN
);
793 asmparser_message
(&asm_ctx
, "Line %u: Register b%u is not a valid destination register\n",
794 asm_ctx.line_no
, $1);
795 set_parse_status
(&asm_ctx
, PARSE_WARN
);
799 $$.regnum
= $1; $$.type
= BWRITERSPR_TEXTURE
;
803 $$.regnum
= $1; $$.type
= BWRITERSPR_TEXCRDOUT
;
807 asmparser_message
(&asm_ctx
, "Line %u: Register s%u is not a valid destination register\n",
808 asm_ctx.line_no
, $1);
809 set_parse_status
(&asm_ctx
, PARSE_WARN
);
813 $$.regnum
= BWRITERSRO_POSITION
; $$.type
= BWRITERSPR_RASTOUT
;
817 $$.regnum
= BWRITERSRO_POINT_SIZE
; $$.type
= BWRITERSPR_RASTOUT
;
821 $$.regnum
= BWRITERSRO_FOG
; $$.type
= BWRITERSPR_RASTOUT
;
825 $$.regnum
= $1; $$.type
= BWRITERSPR_ATTROUT
;
829 $$.regnum
= $1; $$.type
= BWRITERSPR_COLOROUT
;
833 $$.regnum
= 0; $$.type
= BWRITERSPR_DEPTHOUT
;
837 $$.regnum
= 0; $$.type
= BWRITERSPR_PREDICATE
;
841 asmparser_message
(&asm_ctx
, "Line %u: Register vPos is not a valid destination register\n",
843 set_parse_status
(&asm_ctx
, PARSE_WARN
);
847 asmparser_message
(&asm_ctx
, "Line %u: Register vFace is not a valid destination register\n",
849 set_parse_status
(&asm_ctx
, PARSE_WARN
);
853 /* index 0 is hardcoded for the addr register */
854 $$.regnum
= 0; $$.type
= BWRITERSPR_ADDR
;
858 asmparser_message
(&asm_ctx
, "Line %u: Register aL is not a valid destination register\n",
860 set_parse_status
(&asm_ctx
, PARSE_WARN
);
863 writemask: '.' wm_components
865 if
($2.writemask
== SWIZZLE_ERR
) {
866 asmparser_message
(&asm_ctx
, "Line %u: Invalid writemask specified\n",
868 set_parse_status
(&asm_ctx
, PARSE_ERR
);
869 /* Provide a correct writemask to prevent following complaints */
870 $$
= BWRITERSP_WRITEMASK_ALL
;
874 TRACE
("Writemask: %x\n", $$
);
878 wm_components: COMPONENT
880 $$.writemask
= 1 << $1;
884 | wm_components COMPONENT
886 if
($1.writemask
== SWIZZLE_ERR ||
$1.idx
== 4)
887 /* Wrong writemask */
888 $$.writemask
= SWIZZLE_ERR
;
891 $$.writemask
= SWIZZLE_ERR
;
893 $$.writemask
= $1.writemask |
(1 << $2);
901 $$
= BWRITERVS_NOSWIZZLE
;
902 TRACE
("Default swizzle: %08x\n", $$
);
906 if
($2.swizzle
== SWIZZLE_ERR
) {
907 asmparser_message
(&asm_ctx
, "Line %u: Invalid swizzle\n",
909 set_parse_status
(&asm_ctx
, PARSE_ERR
);
910 /* Provide a correct swizzle to prevent following complaints */
911 $$
= BWRITERVS_NOSWIZZLE
;
916 $$
= $2.swizzle
<< BWRITERVS_SWIZZLE_SHIFT
;
917 /* Fill the swizzle by extending the last component */
918 last
= ($2.swizzle
>> 2 * ($2.idx
- 1)) & 0x03;
919 for
(i
= $2.idx
; i
< 4; i
++){
920 $$ |
= last
<< (BWRITERVS_SWIZZLE_SHIFT
+ 2 * i
);
922 TRACE
("Got a swizzle: %08x\n", $$
);
926 sw_components: COMPONENT
931 | sw_components COMPONENT
934 /* Too many sw_components */
935 $$.swizzle
= SWIZZLE_ERR
;
939 $$.swizzle
= $1.swizzle |
($2 << 2 * $1.idx
);
951 $$.mod
= $1.mod |
$2.mod
;
952 if
($1.shift
&& $2.shift
) {
953 asmparser_message
(&asm_ctx
, "Line %u: More than one shift flag\n",
955 set_parse_status
(&asm_ctx
, PARSE_ERR
);
958 $$.shift
= $1.shift |
$2.shift
;
964 $$.mod
= BWRITERSPDM_SATURATE
;
969 $$.mod
= BWRITERSPDM_PARTIALPRECISION
;
974 $$.mod
= BWRITERSPDM_MSAMPCENTROID
;
985 if
($$.count
== MAX_SRC_REGS
){
986 asmparser_message
(&asm_ctx
, "Line %u: Too many source registers in this instruction\n",
988 set_parse_status
(&asm_ctx
, PARSE_ERR
);
991 $$.reg
[$$.count
++] = $3;
994 sreg: sreg_name rel_reg swizzle
997 $$.regnum
= $1.regnum
;
999 $$.srcmod
= BWRITERSPSM_NONE
;
1000 set_rel_reg
(&$$
, &$2);
1002 | sreg_name rel_reg smod swizzle
1005 $$.regnum
= $1.regnum
;
1006 set_rel_reg
(&$$
, &$2);
1010 |
'-' sreg_name rel_reg swizzle
1013 $$.regnum
= $2.regnum
;
1014 $$.srcmod
= BWRITERSPSM_NEG
;
1015 set_rel_reg
(&$$
, &$3);
1018 |
'-' sreg_name rel_reg smod swizzle
1021 $$.regnum
= $2.regnum
;
1022 set_rel_reg
(&$$
, &$3);
1024 case BWRITERSPSM_ABS
: $$.srcmod
= BWRITERSPSM_ABSNEG
; break
;
1026 FIXME
("Unhandled combination of NEGATE and %u\n", $4);
1030 | SMOD_NOT sreg_name swizzle
1033 $$.regnum
= $2.regnum
;
1035 $$.srcmod
= BWRITERSPSM_NOT
;
1039 rel_reg: /* empty */
1041 $$.has_rel_reg
= FALSE
;
1042 $$.additional_offset
= 0;
1046 $$.has_rel_reg
= FALSE
;
1047 $$.additional_offset
= $2.val
;
1049 |
'[' relreg_name swizzle
']'
1051 $$.has_rel_reg
= TRUE
;
1053 $$.additional_offset
= 0;
1054 $$.rel_regnum
= $2.regnum
;
1057 |
'[' immsum
'+' relreg_name swizzle
']'
1059 $$.has_rel_reg
= TRUE
;
1061 $$.additional_offset
= $2.val
;
1062 $$.rel_regnum
= $4.regnum
;
1065 |
'[' relreg_name swizzle
'+' immsum
']'
1067 $$.has_rel_reg
= TRUE
;
1069 $$.additional_offset
= $5.val
;
1070 $$.rel_regnum
= $2.regnum
;
1073 |
'[' immsum
'+' relreg_name swizzle
'+' immsum
']'
1075 $$.has_rel_reg
= TRUE
;
1077 $$.additional_offset
= $2.val
+ $7.val
;
1078 $$.rel_regnum
= $4.regnum
;
1085 asmparser_message
(&asm_ctx
, "Line %u: Unexpected float %f\n",
1086 asm_ctx.line_no
, $1.val
);
1087 set_parse_status
(&asm_ctx
, PARSE_ERR
);
1094 asmparser_message
(&asm_ctx
, "Line %u: Unexpected float %f\n",
1095 asm_ctx.line_no
, $3.val
);
1096 set_parse_status
(&asm_ctx
, PARSE_ERR
);
1098 $$.val
= $1.val
+ $3.val
;
1103 $$
= BWRITERSPSM_ABS
;
1106 relreg_name: REG_ADDRESS
1108 $$.regnum
= 0; $$.type
= BWRITERSPR_ADDR
;
1112 $$.regnum
= 0; $$.type
= BWRITERSPR_LOOP
;
1117 $$.regnum
= $1; $$.type
= BWRITERSPR_TEMP
;
1121 asmparser_message
(&asm_ctx
, "Line %u: Register o%u is not a valid source register\n",
1122 asm_ctx.line_no
, $1);
1123 set_parse_status
(&asm_ctx
, PARSE_WARN
);
1127 $$.regnum
= $1; $$.type
= BWRITERSPR_INPUT
;
1131 $$.regnum
= $1; $$.type
= BWRITERSPR_CONST
;
1135 $$.regnum
= $1; $$.type
= BWRITERSPR_CONSTINT
;
1139 $$.regnum
= $1; $$.type
= BWRITERSPR_CONSTBOOL
;
1143 $$.regnum
= $1; $$.type
= BWRITERSPR_TEXTURE
;
1147 asmparser_message
(&asm_ctx
, "Line %u: Register oT%u is not a valid source register\n",
1148 asm_ctx.line_no
, $1);
1149 set_parse_status
(&asm_ctx
, PARSE_WARN
);
1153 $$.regnum
= $1; $$.type
= BWRITERSPR_SAMPLER
;
1157 asmparser_message
(&asm_ctx
, "Line %u: Register oPos is not a valid source register\n",
1159 set_parse_status
(&asm_ctx
, PARSE_WARN
);
1163 asmparser_message
(&asm_ctx
, "Line %u: Register oFog is not a valid source register\n",
1165 set_parse_status
(&asm_ctx
, PARSE_WARN
);
1169 asmparser_message
(&asm_ctx
, "Line %u: Register oD%u is not a valid source register\n",
1170 asm_ctx.line_no
, $1);
1171 set_parse_status
(&asm_ctx
, PARSE_WARN
);
1175 asmparser_message
(&asm_ctx
, "Line %u: Register oC%u is not a valid source register\n",
1176 asm_ctx.line_no
, $1);
1177 set_parse_status
(&asm_ctx
, PARSE_WARN
);
1181 asmparser_message
(&asm_ctx
, "Line %u: Register oDepth is not a valid source register\n",
1183 set_parse_status
(&asm_ctx
, PARSE_WARN
);
1187 $$.regnum
= 0; $$.type
= BWRITERSPR_PREDICATE
;
1191 $$.regnum
= 0; $$.type
= BWRITERSPR_MISCTYPE
;
1195 $$.regnum
= 1; $$.type
= BWRITERSPR_MISCTYPE
;
1199 $$.regnum
= 0; $$.type
= BWRITERSPR_ADDR
;
1203 $$.regnum
= 0; $$.type
= BWRITERSPR_LOOP
;
1207 $$.regnum
= $1; $$.type
= BWRITERSPR_LABEL
;
1210 comp: COMP_GT
{ $$
= BWRITER_COMPARISON_GT
; }
1211 | COMP_LT
{ $$
= BWRITER_COMPARISON_LT
; }
1212 | COMP_GE
{ $$
= BWRITER_COMPARISON_GE
; }
1213 | COMP_LE
{ $$
= BWRITER_COMPARISON_LE
; }
1214 | COMP_EQ
{ $$
= BWRITER_COMPARISON_EQ
; }
1215 | COMP_NE
{ $$
= BWRITER_COMPARISON_NE
; }
1217 dclusage: USAGE_POSITION
1219 TRACE
("dcl_position%u\n", $1);
1221 $$.dclusage
= BWRITERDECLUSAGE_POSITION
;
1225 TRACE
("dcl_blendweight%u\n", $1);
1227 $$.dclusage
= BWRITERDECLUSAGE_BLENDWEIGHT
;
1229 | USAGE_BLENDINDICES
1231 TRACE
("dcl_blendindices%u\n", $1);
1233 $$.dclusage
= BWRITERDECLUSAGE_BLENDINDICES
;
1237 TRACE
("dcl_normal%u\n", $1);
1239 $$.dclusage
= BWRITERDECLUSAGE_NORMAL
;
1243 TRACE
("dcl_psize%u\n", $1);
1245 $$.dclusage
= BWRITERDECLUSAGE_PSIZE
;
1249 TRACE
("dcl_texcoord%u\n", $1);
1251 $$.dclusage
= BWRITERDECLUSAGE_TEXCOORD
;
1255 TRACE
("dcl_tangent%u\n", $1);
1257 $$.dclusage
= BWRITERDECLUSAGE_TANGENT
;
1261 TRACE
("dcl_binormal%u\n", $1);
1263 $$.dclusage
= BWRITERDECLUSAGE_BINORMAL
;
1267 TRACE
("dcl_tessfactor%u\n", $1);
1269 $$.dclusage
= BWRITERDECLUSAGE_TESSFACTOR
;
1273 TRACE
("dcl_positiont%u\n", $1);
1275 $$.dclusage
= BWRITERDECLUSAGE_POSITIONT
;
1279 TRACE
("dcl_color%u\n", $1);
1281 $$.dclusage
= BWRITERDECLUSAGE_COLOR
;
1285 TRACE
("dcl_fog%u\n", $1);
1287 $$.dclusage
= BWRITERDECLUSAGE_FOG
;
1291 TRACE
("dcl_depth%u\n", $1);
1293 $$.dclusage
= BWRITERDECLUSAGE_DEPTH
;
1297 TRACE
("dcl_sample%u\n", $1);
1299 $$.dclusage
= BWRITERDECLUSAGE_SAMPLE
;
1302 sampdcl: SAMPTYPE_1D
1312 $$
= BWRITERSTT_CUBE
;
1316 $$
= BWRITERSTT_VOLUME
;
1319 predicate: '(' REG_PREDICATE swizzle
')'
1321 $$.type
= BWRITERSPR_PREDICATE
;
1324 $$.srcmod
= BWRITERSPSM_NONE
;
1327 |
'(' SMOD_NOT REG_PREDICATE swizzle
')'
1329 $$.type
= BWRITERSPR_PREDICATE
;
1332 $$.srcmod
= BWRITERSPSM_NOT
;
1338 void asmshader_error
(char const *s
) {
1339 asmparser_message
(&asm_ctx
, "Line %u: Error \"%s\" from bison\n", asm_ctx.line_no
, s
);
1340 set_parse_status
(&asm_ctx
, PARSE_ERR
);
1343 /* Error reporting function */
1344 void asmparser_message
(struct asm_parser
*ctx
, const char *fmt
, ...
) {
1349 if
(ctx
->messagecapacity
== 0) {
1350 ctx
->messages
= asm_alloc
(MESSAGEBUFFER_INITIAL_SIZE
);
1351 if
(ctx
->messages
== NULL
) {
1352 ERR
("Error allocating memory for parser messages\n");
1355 ctx
->messagecapacity
= MESSAGEBUFFER_INITIAL_SIZE
;
1359 va_start
(args
, fmt
);
1360 rc
= vsnprintf
(ctx
->messages
+ ctx
->messagesize
,
1361 ctx
->messagecapacity
- ctx
->messagesize
, fmt
, args
);
1364 if
(rc
< 0 ||
/* C89 */
1365 rc
>= ctx
->messagecapacity
- ctx
->messagesize
) { /* C99 */
1366 /* Resize the buffer */
1367 newsize
= ctx
->messagecapacity
* 2;
1368 newbuffer
= asm_realloc
(ctx
->messages
, newsize
);
1369 if
(newbuffer
== NULL
){
1370 ERR
("Error reallocating memory for parser messages\n");
1373 ctx
->messages
= newbuffer
;
1374 ctx
->messagecapacity
= newsize
;
1376 ctx
->messagesize
+= rc
;
1382 /* New status is the worst between current status and parameter value */
1383 void set_parse_status
(struct asm_parser
*ctx
, enum parse_status status
) {
1384 if
(status
== PARSE_ERR
) ctx
->status
= PARSE_ERR
;
1385 else if
(status
== PARSE_WARN
&& ctx
->status
== PARSE_SUCCESS
) ctx
->status
= PARSE_WARN
;
1388 struct bwriter_shader
*parse_asm_shader
(char **messages
) {
1389 struct bwriter_shader
*ret
= NULL
;
1391 asm_ctx.shader
= NULL
;
1392 asm_ctx.status
= PARSE_SUCCESS
;
1393 asm_ctx.messagesize
= asm_ctx.messagecapacity
= 0;
1394 asm_ctx.line_no
= 1;
1398 if
(asm_ctx.status
!= PARSE_ERR
) ret
= asm_ctx.shader
;
1399 else if
(asm_ctx.shader
) SlDeleteShader
(asm_ctx.shader
);
1402 if
(asm_ctx.messagesize
) {
1403 /* Shrink the buffer to the used size */
1404 *messages
= asm_realloc
(asm_ctx.messages
, asm_ctx.messagesize
+ 1);
1406 ERR
("Out of memory, no messages reported\n");
1407 asm_free
(asm_ctx.messages
);
1413 if
(asm_ctx.messagecapacity
) asm_free
(asm_ctx.messages
);