wined3d: Rename gen_ffp_frag_op().
[wine.git] / dlls / d3dcompiler_43 / d3dcompiler_private.h
blob8dd56775f3fb3489a32babe203a973dd31442780
1 /*
2 * Copyright 2008 Stefan Dösinger
3 * Copyright 2009 Matteo Bruni
4 * Copyright 2010 Rico Schüller
5 * Copyright 2012 Matteo Bruni for CodeWeavers
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
22 #ifndef __WINE_D3DCOMPILER_PRIVATE_H
23 #define __WINE_D3DCOMPILER_PRIVATE_H
25 #include "wine/debug.h"
26 #include "wine/list.h"
27 #include "wine/rbtree.h"
28 #include "wine/heap.h"
30 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "objbase.h"
35 #include "d3dcompiler.h"
37 #include <assert.h>
40 * This doesn't belong here, but for some functions it is possible to return that value,
41 * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
42 * The original definition is in D3DX10core.h.
44 #define D3DERR_INVALIDCALL 0x8876086c
46 /* TRACE helper functions */
47 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part) DECLSPEC_HIDDEN;
48 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c) DECLSPEC_HIDDEN;
49 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t) DECLSPEC_HIDDEN;
51 enum shader_type
53 ST_UNKNOWN,
54 ST_VERTEX,
55 ST_PIXEL
58 enum bwriter_comparison_type
60 BWRITER_COMPARISON_NONE,
61 BWRITER_COMPARISON_GT,
62 BWRITER_COMPARISON_EQ,
63 BWRITER_COMPARISON_GE,
64 BWRITER_COMPARISON_LT,
65 BWRITER_COMPARISON_NE,
66 BWRITER_COMPARISON_LE
69 struct constant {
70 DWORD regnum;
71 union {
72 float f;
73 INT i;
74 BOOL b;
75 DWORD d;
76 } value[4];
79 struct shader_reg {
80 DWORD type;
81 DWORD regnum;
82 struct shader_reg *rel_reg;
83 DWORD srcmod;
84 union {
85 DWORD swizzle;
86 DWORD writemask;
87 } u;
90 struct instruction {
91 DWORD opcode;
92 DWORD dstmod;
93 DWORD shift;
94 enum bwriter_comparison_type comptype;
95 BOOL has_dst;
96 struct shader_reg dst;
97 struct shader_reg *src;
98 unsigned int num_srcs; /* For freeing the rel_regs */
99 BOOL has_predicate;
100 struct shader_reg predicate;
101 BOOL coissue;
104 struct declaration {
105 DWORD usage, usage_idx;
106 DWORD regnum;
107 DWORD mod;
108 DWORD writemask;
109 BOOL builtin;
112 struct samplerdecl {
113 DWORD type;
114 DWORD regnum;
115 DWORD mod;
118 struct bwriter_shader {
119 enum shader_type type;
120 unsigned char major_version, minor_version;
122 /* Local constants. Every constant that is not defined below is loaded from
123 * the global constant set at shader runtime
125 struct constant **constF;
126 struct constant **constI;
127 struct constant **constB;
128 unsigned int num_cf, num_ci, num_cb;
130 /* Declared input and output varyings */
131 struct declaration *inputs, *outputs;
132 unsigned int num_inputs, num_outputs;
133 struct samplerdecl *samplers;
134 unsigned int num_samplers;
136 /* Are special pixel shader 3.0 registers declared? */
137 BOOL vPos, vFace;
139 /* Array of shader instructions - The shader code itself */
140 struct instruction **instr;
141 unsigned int num_instrs, instr_alloc_size;
144 static inline void *d3dcompiler_alloc(SIZE_T size)
146 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
149 static inline void *d3dcompiler_realloc(void *ptr, SIZE_T size)
151 if (!ptr)
152 return d3dcompiler_alloc(size);
153 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
156 static inline BOOL d3dcompiler_free(void *ptr)
158 return HeapFree(GetProcessHeap(), 0, ptr);
161 static inline char *d3dcompiler_strdup(const char *string)
163 char *copy;
164 SIZE_T len;
166 if (!string)
167 return NULL;
169 len = strlen(string);
170 copy = d3dcompiler_alloc(len + 1);
171 if (copy)
172 memcpy(copy, string, len + 1);
173 return copy;
176 struct asm_parser;
178 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
179 * too it has to know it as well
181 struct rel_reg {
182 BOOL has_rel_reg;
183 DWORD type;
184 DWORD additional_offset;
185 DWORD rel_regnum;
186 DWORD swizzle;
189 #define MAX_SRC_REGS 4
191 struct src_regs {
192 struct shader_reg reg[MAX_SRC_REGS];
193 unsigned int count;
196 struct asmparser_backend {
197 void (*constF)(struct asm_parser *This, DWORD reg, float x, float y, float z, float w);
198 void (*constI)(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w);
199 void (*constB)(struct asm_parser *This, DWORD reg, BOOL x);
201 void (*dstreg)(struct asm_parser *This, struct instruction *instr,
202 const struct shader_reg *dst);
203 void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num,
204 const struct shader_reg *src);
206 void (*predicate)(struct asm_parser *This,
207 const struct shader_reg *predicate);
208 void (*coissue)(struct asm_parser *This);
210 void (*dcl_output)(struct asm_parser *This, DWORD usage, DWORD num,
211 const struct shader_reg *reg);
212 void (*dcl_input)(struct asm_parser *This, DWORD usage, DWORD num,
213 DWORD mod, const struct shader_reg *reg);
214 void (*dcl_sampler)(struct asm_parser *This, DWORD samptype, DWORD mod,
215 DWORD regnum, unsigned int line_no);
217 void (*end)(struct asm_parser *This);
219 void (*instr)(struct asm_parser *parser, DWORD opcode, DWORD mod, DWORD shift,
220 enum bwriter_comparison_type comp, const struct shader_reg *dst,
221 const struct src_regs *srcs, int expectednsrcs);
224 struct instruction *alloc_instr(unsigned int srcs) DECLSPEC_HIDDEN;
225 BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr) DECLSPEC_HIDDEN;
226 BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w) DECLSPEC_HIDDEN;
227 BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w) DECLSPEC_HIDDEN;
228 BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x) DECLSPEC_HIDDEN;
229 BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, DWORD usage_idx,
230 DWORD mod, BOOL output, DWORD regnum, DWORD writemask, BOOL builtin) DECLSPEC_HIDDEN;
231 BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype, DWORD mod, DWORD regnum) DECLSPEC_HIDDEN;
233 #define MESSAGEBUFFER_INITIAL_SIZE 256
235 enum parse_status
237 PARSE_SUCCESS = 0,
238 PARSE_WARN = 1,
239 PARSE_ERR = 2
242 struct compilation_messages
244 char *string;
245 unsigned int size;
246 unsigned int capacity;
249 struct asm_parser
251 /* The function table of the parser implementation */
252 const struct asmparser_backend *funcs;
254 /* Private data follows */
255 struct bwriter_shader *shader;
256 unsigned int m3x3pad_count;
258 enum parse_status status;
259 struct compilation_messages messages;
260 unsigned int line_no;
263 extern struct asm_parser asm_ctx DECLSPEC_HIDDEN;
265 void create_vs10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
266 void create_vs11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
267 void create_vs20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
268 void create_vs2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
269 void create_vs30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
270 void create_ps10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
271 void create_ps11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
272 void create_ps12_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
273 void create_ps13_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
274 void create_ps14_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
275 void create_ps20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
276 void create_ps2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
277 void create_ps30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
279 struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN;
281 #ifdef __GNUC__
282 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
283 #else
284 #define PRINTF_ATTR(fmt,args)
285 #endif
287 void compilation_message(struct compilation_messages *msg, const char *fmt, __ms_va_list args) DECLSPEC_HIDDEN;
288 void WINAPIV asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
289 static inline void set_parse_status(enum parse_status *current, enum parse_status update)
291 if (update == PARSE_ERR)
292 *current = PARSE_ERR;
293 else if (update == PARSE_WARN && *current == PARSE_SUCCESS)
294 *current = PARSE_WARN;
297 /* Debug utility routines */
298 const char *debug_print_srcmod(DWORD mod) DECLSPEC_HIDDEN;
299 const char *debug_print_dstmod(DWORD mod) DECLSPEC_HIDDEN;
300 const char *debug_print_shift(DWORD shift) DECLSPEC_HIDDEN;
301 const char *debug_print_dstreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
302 const char *debug_print_srcreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
303 const char *debug_print_comp(DWORD comp) DECLSPEC_HIDDEN;
304 const char *debug_print_opcode(DWORD opcode) DECLSPEC_HIDDEN;
306 /* Used to signal an incorrect swizzle/writemask */
307 #define SWIZZLE_ERR ~0U
309 /* Enumerations and defines used in the bytecode writer intermediate
310 * representation. */
311 enum bwritershader_instruction_opcode_type
313 BWRITERSIO_NOP,
314 BWRITERSIO_MOV,
315 BWRITERSIO_ADD,
316 BWRITERSIO_SUB,
317 BWRITERSIO_MAD,
318 BWRITERSIO_MUL,
319 BWRITERSIO_RCP,
320 BWRITERSIO_RSQ,
321 BWRITERSIO_DP3,
322 BWRITERSIO_DP4,
323 BWRITERSIO_MIN,
324 BWRITERSIO_MAX,
325 BWRITERSIO_SLT,
326 BWRITERSIO_SGE,
327 BWRITERSIO_EXP,
328 BWRITERSIO_LOG,
329 BWRITERSIO_LIT,
330 BWRITERSIO_DST,
331 BWRITERSIO_LRP,
332 BWRITERSIO_FRC,
333 BWRITERSIO_M4x4,
334 BWRITERSIO_M4x3,
335 BWRITERSIO_M3x4,
336 BWRITERSIO_M3x3,
337 BWRITERSIO_M3x2,
338 BWRITERSIO_CALL,
339 BWRITERSIO_CALLNZ,
340 BWRITERSIO_LOOP,
341 BWRITERSIO_RET,
342 BWRITERSIO_ENDLOOP,
343 BWRITERSIO_LABEL,
344 BWRITERSIO_DCL,
345 BWRITERSIO_POW,
346 BWRITERSIO_CRS,
347 BWRITERSIO_SGN,
348 BWRITERSIO_ABS,
349 BWRITERSIO_NRM,
350 BWRITERSIO_SINCOS,
351 BWRITERSIO_REP,
352 BWRITERSIO_ENDREP,
353 BWRITERSIO_IF,
354 BWRITERSIO_IFC,
355 BWRITERSIO_ELSE,
356 BWRITERSIO_ENDIF,
357 BWRITERSIO_BREAK,
358 BWRITERSIO_BREAKC,
359 BWRITERSIO_MOVA,
360 BWRITERSIO_DEFB,
361 BWRITERSIO_DEFI,
363 BWRITERSIO_TEXCOORD,
364 BWRITERSIO_TEXKILL,
365 BWRITERSIO_TEX,
366 BWRITERSIO_TEXBEM,
367 BWRITERSIO_TEXBEML,
368 BWRITERSIO_TEXREG2AR,
369 BWRITERSIO_TEXREG2GB,
370 BWRITERSIO_TEXM3x2PAD,
371 BWRITERSIO_TEXM3x2TEX,
372 BWRITERSIO_TEXM3x3PAD,
373 BWRITERSIO_TEXM3x3TEX,
374 BWRITERSIO_TEXM3x3SPEC,
375 BWRITERSIO_TEXM3x3VSPEC,
376 BWRITERSIO_EXPP,
377 BWRITERSIO_LOGP,
378 BWRITERSIO_CND,
379 BWRITERSIO_DEF,
380 BWRITERSIO_TEXREG2RGB,
381 BWRITERSIO_TEXDP3TEX,
382 BWRITERSIO_TEXM3x2DEPTH,
383 BWRITERSIO_TEXDP3,
384 BWRITERSIO_TEXM3x3,
385 BWRITERSIO_TEXDEPTH,
386 BWRITERSIO_CMP,
387 BWRITERSIO_BEM,
388 BWRITERSIO_DP2ADD,
389 BWRITERSIO_DSX,
390 BWRITERSIO_DSY,
391 BWRITERSIO_TEXLDD,
392 BWRITERSIO_SETP,
393 BWRITERSIO_TEXLDL,
394 BWRITERSIO_BREAKP,
395 BWRITERSIO_TEXLDP,
396 BWRITERSIO_TEXLDB,
398 BWRITERSIO_PHASE,
399 BWRITERSIO_COMMENT,
400 BWRITERSIO_END,
403 enum bwritershader_param_register_type
405 BWRITERSPR_TEMP,
406 BWRITERSPR_INPUT,
407 BWRITERSPR_CONST,
408 BWRITERSPR_ADDR,
409 BWRITERSPR_TEXTURE,
410 BWRITERSPR_RASTOUT,
411 BWRITERSPR_ATTROUT,
412 BWRITERSPR_TEXCRDOUT,
413 BWRITERSPR_OUTPUT,
414 BWRITERSPR_CONSTINT,
415 BWRITERSPR_COLOROUT,
416 BWRITERSPR_DEPTHOUT,
417 BWRITERSPR_SAMPLER,
418 BWRITERSPR_CONSTBOOL,
419 BWRITERSPR_LOOP,
420 BWRITERSPR_MISCTYPE,
421 BWRITERSPR_LABEL,
422 BWRITERSPR_PREDICATE
425 enum bwritervs_rastout_offsets
427 BWRITERSRO_POSITION,
428 BWRITERSRO_FOG,
429 BWRITERSRO_POINT_SIZE
432 #define BWRITERSP_WRITEMASK_0 0x1 /* .x r */
433 #define BWRITERSP_WRITEMASK_1 0x2 /* .y g */
434 #define BWRITERSP_WRITEMASK_2 0x4 /* .z b */
435 #define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
436 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
438 enum bwritershader_param_dstmod_type
440 BWRITERSPDM_NONE = 0,
441 BWRITERSPDM_SATURATE = 1,
442 BWRITERSPDM_PARTIALPRECISION = 2,
443 BWRITERSPDM_MSAMPCENTROID = 4,
446 enum bwritersampler_texture_type
448 BWRITERSTT_UNKNOWN = 0,
449 BWRITERSTT_1D = 1,
450 BWRITERSTT_2D = 2,
451 BWRITERSTT_CUBE = 3,
452 BWRITERSTT_VOLUME = 4,
455 #define BWRITERSI_TEXLD_PROJECT 1
456 #define BWRITERSI_TEXLD_BIAS 2
458 enum bwritershader_param_srcmod_type
460 BWRITERSPSM_NONE = 0,
461 BWRITERSPSM_NEG,
462 BWRITERSPSM_BIAS,
463 BWRITERSPSM_BIASNEG,
464 BWRITERSPSM_SIGN,
465 BWRITERSPSM_SIGNNEG,
466 BWRITERSPSM_COMP,
467 BWRITERSPSM_X2,
468 BWRITERSPSM_X2NEG,
469 BWRITERSPSM_DZ,
470 BWRITERSPSM_DW,
471 BWRITERSPSM_ABS,
472 BWRITERSPSM_ABSNEG,
473 BWRITERSPSM_NOT,
476 #define BWRITER_SM1_VS 0xfffeu
477 #define BWRITER_SM1_PS 0xffffu
479 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
480 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
482 #define BWRITERVS_X_X (0)
483 #define BWRITERVS_X_Y (1)
484 #define BWRITERVS_X_Z (2)
485 #define BWRITERVS_X_W (3)
487 #define BWRITERVS_Y_X (0 << 2)
488 #define BWRITERVS_Y_Y (1 << 2)
489 #define BWRITERVS_Y_Z (2 << 2)
490 #define BWRITERVS_Y_W (3 << 2)
492 #define BWRITERVS_Z_X (0 << 4)
493 #define BWRITERVS_Z_Y (1 << 4)
494 #define BWRITERVS_Z_Z (2 << 4)
495 #define BWRITERVS_Z_W (3 << 4)
497 #define BWRITERVS_W_X (0 << 6)
498 #define BWRITERVS_W_Y (1 << 6)
499 #define BWRITERVS_W_Z (2 << 6)
500 #define BWRITERVS_W_W (3 << 6)
502 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
504 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
505 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
506 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
507 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
509 enum bwriterdeclusage
511 BWRITERDECLUSAGE_POSITION,
512 BWRITERDECLUSAGE_BLENDWEIGHT,
513 BWRITERDECLUSAGE_BLENDINDICES,
514 BWRITERDECLUSAGE_NORMAL,
515 BWRITERDECLUSAGE_PSIZE,
516 BWRITERDECLUSAGE_TEXCOORD,
517 BWRITERDECLUSAGE_TANGENT,
518 BWRITERDECLUSAGE_BINORMAL,
519 BWRITERDECLUSAGE_TESSFACTOR,
520 BWRITERDECLUSAGE_POSITIONT,
521 BWRITERDECLUSAGE_COLOR,
522 BWRITERDECLUSAGE_FOG,
523 BWRITERDECLUSAGE_DEPTH,
524 BWRITERDECLUSAGE_SAMPLE
527 /* ps 1.x texture registers mappings */
528 #define T0_REG 2
529 #define T1_REG 3
530 #define T2_REG 4
531 #define T3_REG 5
533 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) DECLSPEC_HIDDEN;
534 HRESULT shader_write_bytecode(const struct bwriter_shader *shader, DWORD **result, DWORD *size) DECLSPEC_HIDDEN;
535 void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN;
537 /* The general IR structure is inspired by Mesa GLSL hir, even though the code
538 * ends up being quite different in practice. Anyway, here comes the relevant
539 * licensing information.
541 * Copyright © 2010 Intel Corporation
543 * Permission is hereby granted, free of charge, to any person obtaining a
544 * copy of this software and associated documentation files (the "Software"),
545 * to deal in the Software without restriction, including without limitation
546 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
547 * and/or sell copies of the Software, and to permit persons to whom the
548 * Software is furnished to do so, subject to the following conditions:
550 * The above copyright notice and this permission notice (including the next
551 * paragraph) shall be included in all copies or substantial portions of the
552 * Software.
554 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
555 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
556 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
557 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
558 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
559 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
560 * DEALINGS IN THE SOFTWARE.
563 enum hlsl_type_class
565 HLSL_CLASS_SCALAR,
566 HLSL_CLASS_VECTOR,
567 HLSL_CLASS_MATRIX,
568 HLSL_CLASS_LAST_NUMERIC = HLSL_CLASS_MATRIX,
569 HLSL_CLASS_STRUCT,
570 HLSL_CLASS_ARRAY,
571 HLSL_CLASS_OBJECT,
574 enum hlsl_base_type
576 HLSL_TYPE_FLOAT,
577 HLSL_TYPE_HALF,
578 HLSL_TYPE_DOUBLE,
579 HLSL_TYPE_INT,
580 HLSL_TYPE_UINT,
581 HLSL_TYPE_BOOL,
582 HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL,
583 HLSL_TYPE_SAMPLER,
584 HLSL_TYPE_TEXTURE,
585 HLSL_TYPE_PIXELSHADER,
586 HLSL_TYPE_VERTEXSHADER,
587 HLSL_TYPE_STRING,
588 HLSL_TYPE_VOID,
591 enum hlsl_sampler_dim
593 HLSL_SAMPLER_DIM_GENERIC,
594 HLSL_SAMPLER_DIM_1D,
595 HLSL_SAMPLER_DIM_2D,
596 HLSL_SAMPLER_DIM_3D,
597 HLSL_SAMPLER_DIM_CUBE,
598 HLSL_SAMPLER_DIM_MAX = HLSL_SAMPLER_DIM_CUBE
601 enum hlsl_matrix_majority
603 HLSL_COLUMN_MAJOR,
604 HLSL_ROW_MAJOR
607 struct hlsl_type
609 struct list entry;
610 struct wine_rb_entry scope_entry;
611 enum hlsl_type_class type;
612 enum hlsl_base_type base_type;
613 enum hlsl_sampler_dim sampler_dim;
614 const char *name;
615 unsigned int modifiers;
616 unsigned int dimx;
617 unsigned int dimy;
618 unsigned int reg_size;
619 union
621 struct list *elements;
622 struct
624 struct hlsl_type *type;
625 unsigned int elements_count;
626 } array;
627 } e;
630 struct hlsl_struct_field
632 struct list entry;
633 struct hlsl_type *type;
634 const char *name;
635 const char *semantic;
636 DWORD modifiers;
637 unsigned int reg_offset;
640 struct source_location
642 const char *file;
643 unsigned int line;
644 unsigned int col;
647 enum hlsl_ir_node_type
649 HLSL_IR_ASSIGNMENT = 0,
650 HLSL_IR_CONSTANT,
651 HLSL_IR_EXPR,
652 HLSL_IR_IF,
653 HLSL_IR_LOAD,
654 HLSL_IR_LOOP,
655 HLSL_IR_JUMP,
656 HLSL_IR_SWIZZLE,
659 struct hlsl_ir_node
661 struct list entry;
662 enum hlsl_ir_node_type type;
663 struct hlsl_type *data_type;
665 struct list uses;
667 struct source_location loc;
669 /* Liveness ranges. "index" is the index of this instruction. Since this is
670 * essentially an SSA value, the earliest live point is the index. This is
671 * true even for loops, since currently we can't have a reference to a
672 * value generated in an earlier iteration of the loop. */
673 unsigned int index, last_read;
676 struct hlsl_src
678 struct hlsl_ir_node *node;
679 struct list entry;
682 #define HLSL_STORAGE_EXTERN 0x00000001
683 #define HLSL_STORAGE_NOINTERPOLATION 0x00000002
684 #define HLSL_MODIFIER_PRECISE 0x00000004
685 #define HLSL_STORAGE_SHARED 0x00000008
686 #define HLSL_STORAGE_GROUPSHARED 0x00000010
687 #define HLSL_STORAGE_STATIC 0x00000020
688 #define HLSL_STORAGE_UNIFORM 0x00000040
689 #define HLSL_STORAGE_VOLATILE 0x00000080
690 #define HLSL_MODIFIER_CONST 0x00000100
691 #define HLSL_MODIFIER_ROW_MAJOR 0x00000200
692 #define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400
693 #define HLSL_STORAGE_IN 0x00000800
694 #define HLSL_STORAGE_OUT 0x00001000
696 #define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_STORAGE_VOLATILE | \
697 HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \
698 HLSL_MODIFIER_COLUMN_MAJOR)
700 #define HLSL_MODIFIERS_MAJORITY_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
702 struct reg_reservation
704 enum bwritershader_param_register_type type;
705 DWORD regnum;
708 struct hlsl_ir_var
710 struct hlsl_type *data_type;
711 struct source_location loc;
712 const char *name;
713 const char *semantic;
714 unsigned int modifiers;
715 const struct reg_reservation *reg_reservation;
716 struct list scope_entry, param_entry;
718 unsigned int first_write, last_read;
721 struct hlsl_ir_function
723 struct wine_rb_entry entry;
724 const char *name;
725 struct wine_rb_tree overloads;
726 BOOL intrinsic;
729 struct hlsl_ir_function_decl
731 struct hlsl_type *return_type;
732 struct hlsl_ir_var *return_var;
733 struct source_location loc;
734 struct wine_rb_entry entry;
735 struct hlsl_ir_function *func;
736 const char *semantic;
737 struct list *parameters;
738 struct list *body;
741 struct hlsl_ir_if
743 struct hlsl_ir_node node;
744 struct hlsl_src condition;
745 struct list then_instrs;
746 struct list else_instrs;
749 struct hlsl_ir_loop
751 struct hlsl_ir_node node;
752 /* loop condition is stored in the body (as "if (!condition) break;") */
753 struct list body;
754 unsigned int next_index; /* liveness index of the end of the loop */
757 enum hlsl_ir_expr_op {
758 HLSL_IR_UNOP_BIT_NOT = 0,
759 HLSL_IR_UNOP_LOGIC_NOT,
760 HLSL_IR_UNOP_NEG,
761 HLSL_IR_UNOP_ABS,
762 HLSL_IR_UNOP_SIGN,
763 HLSL_IR_UNOP_RCP,
764 HLSL_IR_UNOP_RSQ,
765 HLSL_IR_UNOP_SQRT,
766 HLSL_IR_UNOP_NRM,
767 HLSL_IR_UNOP_EXP2,
768 HLSL_IR_UNOP_LOG2,
770 HLSL_IR_UNOP_CAST,
772 HLSL_IR_UNOP_FRACT,
774 HLSL_IR_UNOP_SIN,
775 HLSL_IR_UNOP_COS,
776 HLSL_IR_UNOP_SIN_REDUCED, /* Reduced range [-pi, pi] */
777 HLSL_IR_UNOP_COS_REDUCED, /* Reduced range [-pi, pi] */
779 HLSL_IR_UNOP_DSX,
780 HLSL_IR_UNOP_DSY,
782 HLSL_IR_UNOP_SAT,
784 HLSL_IR_UNOP_PREINC,
785 HLSL_IR_UNOP_PREDEC,
786 HLSL_IR_UNOP_POSTINC,
787 HLSL_IR_UNOP_POSTDEC,
789 HLSL_IR_BINOP_ADD,
790 HLSL_IR_BINOP_SUB,
791 HLSL_IR_BINOP_MUL,
792 HLSL_IR_BINOP_DIV,
794 HLSL_IR_BINOP_MOD,
796 HLSL_IR_BINOP_LESS,
797 HLSL_IR_BINOP_GREATER,
798 HLSL_IR_BINOP_LEQUAL,
799 HLSL_IR_BINOP_GEQUAL,
800 HLSL_IR_BINOP_EQUAL,
801 HLSL_IR_BINOP_NEQUAL,
803 HLSL_IR_BINOP_LOGIC_AND,
804 HLSL_IR_BINOP_LOGIC_OR,
806 HLSL_IR_BINOP_LSHIFT,
807 HLSL_IR_BINOP_RSHIFT,
808 HLSL_IR_BINOP_BIT_AND,
809 HLSL_IR_BINOP_BIT_OR,
810 HLSL_IR_BINOP_BIT_XOR,
812 HLSL_IR_BINOP_DOT,
813 HLSL_IR_BINOP_CRS,
814 HLSL_IR_BINOP_MIN,
815 HLSL_IR_BINOP_MAX,
817 HLSL_IR_BINOP_POW,
819 HLSL_IR_TEROP_LERP,
821 HLSL_IR_SEQUENCE,
824 struct hlsl_ir_expr
826 struct hlsl_ir_node node;
827 enum hlsl_ir_expr_op op;
828 struct hlsl_src operands[3];
831 enum hlsl_ir_jump_type
833 HLSL_IR_JUMP_BREAK,
834 HLSL_IR_JUMP_CONTINUE,
835 HLSL_IR_JUMP_DISCARD,
836 HLSL_IR_JUMP_RETURN,
839 struct hlsl_ir_jump
841 struct hlsl_ir_node node;
842 enum hlsl_ir_jump_type type;
845 struct hlsl_ir_swizzle
847 struct hlsl_ir_node node;
848 struct hlsl_src val;
849 DWORD swizzle;
852 struct hlsl_deref
854 struct hlsl_ir_var *var;
855 struct hlsl_src offset;
858 struct hlsl_ir_load
860 struct hlsl_ir_node node;
861 struct hlsl_deref src;
864 struct hlsl_ir_assignment
866 struct hlsl_ir_node node;
867 struct hlsl_deref lhs;
868 struct hlsl_src rhs;
869 unsigned char writemask;
872 struct hlsl_ir_constant
874 struct hlsl_ir_node node;
875 union
877 unsigned u[4];
878 int i[4];
879 float f[4];
880 double d[4];
881 BOOL b[4];
882 } value;
885 struct hlsl_scope
887 struct list entry;
888 struct list vars;
889 struct wine_rb_tree types;
890 struct hlsl_scope *upper;
893 /* Structures used only during parsing */
894 struct parse_parameter
896 struct hlsl_type *type;
897 const char *name;
898 const char *semantic;
899 const struct reg_reservation *reg_reservation;
900 unsigned int modifiers;
903 struct parse_colon_attribute
905 const char *semantic;
906 struct reg_reservation *reg_reservation;
909 struct parse_initializer
911 struct hlsl_ir_node **args;
912 unsigned int args_count;
913 struct list *instrs;
916 struct parse_variable_def
918 struct list entry;
919 struct source_location loc;
921 char *name;
922 unsigned int array_size;
923 const char *semantic;
924 struct reg_reservation *reg_reservation;
925 struct parse_initializer initializer;
928 struct parse_function
930 char *name;
931 struct hlsl_ir_function_decl *decl;
934 struct parse_if_body
936 struct list *then_instrs;
937 struct list *else_instrs;
940 enum parse_unary_op
942 UNARY_OP_PLUS,
943 UNARY_OP_MINUS,
944 UNARY_OP_LOGICNOT,
945 UNARY_OP_BITNOT,
948 enum parse_assign_op
950 ASSIGN_OP_ASSIGN,
951 ASSIGN_OP_ADD,
952 ASSIGN_OP_SUB,
953 ASSIGN_OP_MUL,
954 ASSIGN_OP_DIV,
955 ASSIGN_OP_MOD,
956 ASSIGN_OP_LSHIFT,
957 ASSIGN_OP_RSHIFT,
958 ASSIGN_OP_AND,
959 ASSIGN_OP_OR,
960 ASSIGN_OP_XOR,
963 struct hlsl_parse_ctx
965 const char **source_files;
966 unsigned int source_files_count;
967 const char *source_file;
968 unsigned int line_no;
969 unsigned int column;
970 enum parse_status status;
971 struct compilation_messages messages;
973 struct hlsl_scope *cur_scope;
974 struct hlsl_scope *globals;
975 struct list scopes;
977 struct list types;
978 struct wine_rb_tree functions;
979 const struct hlsl_ir_function_decl *cur_function;
981 enum hlsl_matrix_majority matrix_majority;
983 struct
985 struct hlsl_type *scalar[HLSL_TYPE_LAST_SCALAR + 1];
986 struct hlsl_type *vector[HLSL_TYPE_LAST_SCALAR + 1][4];
987 struct hlsl_type *sampler[HLSL_SAMPLER_DIM_MAX + 1];
988 struct hlsl_type *Void;
989 } builtin_types;
991 struct list static_initializers;
994 extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN;
996 enum hlsl_error_level
998 HLSL_LEVEL_ERROR = 0,
999 HLSL_LEVEL_WARNING,
1000 HLSL_LEVEL_NOTE,
1003 void WINAPIV hlsl_message(const char *fmt, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN;
1004 void WINAPIV hlsl_report_message(const struct source_location loc,
1005 enum hlsl_error_level level, const char *fmt, ...) PRINTF_ATTR(3,4) DECLSPEC_HIDDEN;
1007 static inline struct hlsl_ir_expr *expr_from_node(const struct hlsl_ir_node *node)
1009 assert(node->type == HLSL_IR_EXPR);
1010 return CONTAINING_RECORD(node, struct hlsl_ir_expr, node);
1013 static inline struct hlsl_ir_load *load_from_node(const struct hlsl_ir_node *node)
1015 assert(node->type == HLSL_IR_LOAD);
1016 return CONTAINING_RECORD(node, struct hlsl_ir_load, node);
1019 static inline struct hlsl_ir_constant *constant_from_node(const struct hlsl_ir_node *node)
1021 assert(node->type == HLSL_IR_CONSTANT);
1022 return CONTAINING_RECORD(node, struct hlsl_ir_constant, node);
1025 static inline struct hlsl_ir_jump *jump_from_node(const struct hlsl_ir_node *node)
1027 assert(node->type == HLSL_IR_JUMP);
1028 return CONTAINING_RECORD(node, struct hlsl_ir_jump, node);
1031 static inline struct hlsl_ir_assignment *assignment_from_node(const struct hlsl_ir_node *node)
1033 assert(node->type == HLSL_IR_ASSIGNMENT);
1034 return CONTAINING_RECORD(node, struct hlsl_ir_assignment, node);
1037 static inline struct hlsl_ir_swizzle *swizzle_from_node(const struct hlsl_ir_node *node)
1039 assert(node->type == HLSL_IR_SWIZZLE);
1040 return CONTAINING_RECORD(node, struct hlsl_ir_swizzle, node);
1043 static inline struct hlsl_ir_if *if_from_node(const struct hlsl_ir_node *node)
1045 assert(node->type == HLSL_IR_IF);
1046 return CONTAINING_RECORD(node, struct hlsl_ir_if, node);
1049 static inline struct hlsl_ir_loop *loop_from_node(const struct hlsl_ir_node *node)
1051 assert(node->type == HLSL_IR_LOOP);
1052 return CONTAINING_RECORD(node, struct hlsl_ir_loop, node);
1055 static inline struct hlsl_ir_node *node_from_list(struct list *list)
1057 return LIST_ENTRY(list_tail(list), struct hlsl_ir_node, entry);
1060 static inline void init_node(struct hlsl_ir_node *node, enum hlsl_ir_node_type type,
1061 struct hlsl_type *data_type, struct source_location loc)
1063 node->type = type;
1064 node->data_type = data_type;
1065 node->loc = loc;
1066 list_init(&node->uses);
1069 static inline void hlsl_src_from_node(struct hlsl_src *src, struct hlsl_ir_node *node)
1071 src->node = node;
1072 if (node)
1073 list_add_tail(&node->uses, &src->entry);
1076 static inline void hlsl_src_remove(struct hlsl_src *src)
1078 if (src->node)
1079 list_remove(&src->entry);
1080 src->node = NULL;
1083 struct hlsl_ir_node *add_assignment(struct list *instrs, struct hlsl_ir_node *lhs,
1084 enum parse_assign_op assign_op, struct hlsl_ir_node *rhs) DECLSPEC_HIDDEN;
1085 struct hlsl_ir_expr *add_expr(struct list *instrs, enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[3],
1086 struct source_location *loc) DECLSPEC_HIDDEN;
1087 struct hlsl_ir_node *add_implicit_conversion(struct list *instrs, struct hlsl_ir_node *node, struct hlsl_type *type,
1088 struct source_location *loc) DECLSPEC_HIDDEN;
1090 struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
1091 struct source_location *loc) DECLSPEC_HIDDEN;
1092 struct hlsl_ir_node *new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
1093 struct hlsl_ir_node *arg2) DECLSPEC_HIDDEN;
1094 struct hlsl_ir_node *new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg,
1095 struct source_location loc) DECLSPEC_HIDDEN;
1097 BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN;
1098 struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
1099 void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
1100 struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class,
1101 enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN;
1102 struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN;
1103 struct hlsl_type *clone_hlsl_type(struct hlsl_type *old, unsigned int default_majority) DECLSPEC_HIDDEN;
1104 struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN;
1105 BOOL is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
1106 BOOL find_function(const char *name) DECLSPEC_HIDDEN;
1107 unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
1108 BOOL compare_hlsl_types(const struct hlsl_type *t1, const struct hlsl_type *t2) DECLSPEC_HIDDEN;
1109 BOOL compatible_data_types(struct hlsl_type *s1, struct hlsl_type *s2) DECLSPEC_HIDDEN;
1110 void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
1111 BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
1112 void init_functions_tree(struct wine_rb_tree *funcs) DECLSPEC_HIDDEN;
1113 void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl,
1114 BOOL intrinsic) DECLSPEC_HIDDEN;
1115 HRESULT parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
1116 const char *entrypoint, ID3D10Blob **shader, char **messages) DECLSPEC_HIDDEN;
1118 const char *debug_base_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
1119 const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
1120 const char *debug_modifiers(DWORD modifiers) DECLSPEC_HIDDEN;
1121 const char *debug_node_type(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
1122 void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
1124 void free_hlsl_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
1125 void free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
1126 void free_instr_list(struct list *list) DECLSPEC_HIDDEN;
1127 void free_function_rb(struct wine_rb_entry *entry, void *context) DECLSPEC_HIDDEN;
1129 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
1130 ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
1131 ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
1132 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
1133 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
1134 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
1135 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
1136 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
1137 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
1138 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
1139 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
1140 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
1141 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
1142 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
1143 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
1144 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
1146 struct dxbc_section
1148 DWORD tag;
1149 const char *data;
1150 DWORD data_size;
1153 struct dxbc
1155 UINT size;
1156 UINT count;
1157 struct dxbc_section *sections;
1160 HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN;
1161 void dxbc_destroy(struct dxbc *dxbc) DECLSPEC_HIDDEN;
1162 HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) DECLSPEC_HIDDEN;
1163 HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, DWORD data_size) DECLSPEC_HIDDEN;
1164 HRESULT dxbc_init(struct dxbc *dxbc, unsigned int size) DECLSPEC_HIDDEN;
1166 static inline DWORD read_dword(const char **ptr)
1168 DWORD r;
1169 memcpy(&r, *ptr, sizeof(r));
1170 *ptr += sizeof(r);
1171 return r;
1174 static inline void write_dword(char **ptr, DWORD d)
1176 memcpy(*ptr, &d, sizeof(d));
1177 *ptr += sizeof(d);
1180 void skip_dword_unknown(const char **ptr, unsigned int count) DECLSPEC_HIDDEN;
1182 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */