d3dcompiler: Store the pointer to the struct field in the dereference node.
[wine] / dlls / d3dcompiler_43 / d3dcompiler_private.h
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
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #ifndef __WINE_D3DCOMPILER_PRIVATE_H
23 #define __WINE_D3DCOMPILER_PRIVATE_H
24
25 #include "wine/debug.h"
26 #include "wine/list.h"
27 #include "wine/rbtree.h"
28
29 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "objbase.h"
33
34 #include "d3dcompiler.h"
35
36 #include <assert.h>
37
38 /*
39  * This doesn't belong here, but for some functions it is possible to return that value,
40  * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
41  * The original definition is in D3DX10core.h.
42  */
43 #define D3DERR_INVALIDCALL 0x8876086c
44
45 /* TRACE helper functions */
46 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part) DECLSPEC_HIDDEN;
47 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c) DECLSPEC_HIDDEN;
48 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t) DECLSPEC_HIDDEN;
49
50 enum shader_type
51 {
52     ST_VERTEX,
53     ST_PIXEL,
54 };
55
56 typedef enum BWRITER_COMPARISON_TYPE {
57     BWRITER_COMPARISON_NONE,
58     BWRITER_COMPARISON_GT,
59     BWRITER_COMPARISON_EQ,
60     BWRITER_COMPARISON_GE,
61     BWRITER_COMPARISON_LT,
62     BWRITER_COMPARISON_NE,
63     BWRITER_COMPARISON_LE
64 } BWRITER_COMPARISON_TYPE;
65
66 struct constant {
67     DWORD                   regnum;
68     union {
69         float               f;
70         INT                 i;
71         BOOL                b;
72         DWORD               d;
73     }                       value[4];
74 };
75
76 struct shader_reg {
77     DWORD                   type;
78     DWORD                   regnum;
79     struct shader_reg       *rel_reg;
80     DWORD                   srcmod;
81     union {
82         DWORD               swizzle;
83         DWORD               writemask;
84     } u;
85 };
86
87 struct instruction {
88     DWORD                   opcode;
89     DWORD                   dstmod;
90     DWORD                   shift;
91     BWRITER_COMPARISON_TYPE comptype;
92     BOOL                    has_dst;
93     struct shader_reg       dst;
94     struct shader_reg       *src;
95     unsigned int            num_srcs; /* For freeing the rel_regs */
96     BOOL                    has_predicate;
97     struct shader_reg       predicate;
98     BOOL                    coissue;
99 };
100
101 struct declaration {
102     DWORD                   usage, usage_idx;
103     DWORD                   regnum;
104     DWORD                   mod;
105     DWORD                   writemask;
106     BOOL                    builtin;
107 };
108
109 struct samplerdecl {
110     DWORD                   type;
111     DWORD                   regnum;
112     DWORD                   mod;
113 };
114
115 #define INSTRARRAY_INITIAL_SIZE 8
116 struct bwriter_shader {
117     enum shader_type        type;
118
119     /* Shader version selected */
120     DWORD                   version;
121
122     /* Local constants. Every constant that is not defined below is loaded from
123      * the global constant set at shader runtime
124      */
125     struct constant         **constF;
126     struct constant         **constI;
127     struct constant         **constB;
128     unsigned int            num_cf, num_ci, num_cb;
129
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;
135
136     /* Are special pixel shader 3.0 registers declared? */
137     BOOL                    vPos, vFace;
138
139     /* Array of shader instructions - The shader code itself */
140     struct instruction      **instr;
141     unsigned int            num_instrs, instr_alloc_size;
142 };
143
144 static inline void *d3dcompiler_alloc(SIZE_T size)
145 {
146     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
147 }
148
149 static inline void *d3dcompiler_realloc(void *ptr, SIZE_T size)
150 {
151     return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
152 }
153
154 static inline BOOL d3dcompiler_free(void *ptr)
155 {
156     return HeapFree(GetProcessHeap(), 0, ptr);
157 }
158
159 static inline char *d3dcompiler_strdup(const char *string)
160 {
161     char *copy;
162     SIZE_T len;
163
164     if (!string)
165         return NULL;
166
167     len = strlen(string);
168     copy = d3dcompiler_alloc(len + 1);
169     if (copy)
170         memcpy(copy, string, len + 1);
171     return copy;
172 }
173
174 struct asm_parser;
175
176 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
177  * too it has to know it as well
178  */
179 struct rel_reg {
180     BOOL            has_rel_reg;
181     DWORD           type;
182     DWORD           additional_offset;
183     DWORD           rel_regnum;
184     DWORD           swizzle;
185 };
186
187 #define MAX_SRC_REGS 4
188
189 struct src_regs {
190     struct shader_reg reg[MAX_SRC_REGS];
191     unsigned int      count;
192 };
193
194 struct asmparser_backend {
195     void (*constF)(struct asm_parser *This, DWORD reg, float x, float y, float z, float w);
196     void (*constI)(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w);
197     void (*constB)(struct asm_parser *This, DWORD reg, BOOL x);
198
199     void (*dstreg)(struct asm_parser *This, struct instruction *instr,
200                    const struct shader_reg *dst);
201     void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num,
202                    const struct shader_reg *src);
203
204     void (*predicate)(struct asm_parser *This,
205                       const struct shader_reg *predicate);
206     void (*coissue)(struct asm_parser *This);
207
208     void (*dcl_output)(struct asm_parser *This, DWORD usage, DWORD num,
209                        const struct shader_reg *reg);
210     void (*dcl_input)(struct asm_parser *This, DWORD usage, DWORD num,
211                       DWORD mod, const struct shader_reg *reg);
212     void (*dcl_sampler)(struct asm_parser *This, DWORD samptype, DWORD mod,
213                         DWORD regnum, unsigned int line_no);
214
215     void (*end)(struct asm_parser *This);
216
217     void (*instr)(struct asm_parser *This, DWORD opcode, DWORD mod, DWORD shift,
218                   BWRITER_COMPARISON_TYPE comp, const struct shader_reg *dst,
219                   const struct src_regs *srcs, int expectednsrcs);
220 };
221
222 struct instruction *alloc_instr(unsigned int srcs) DECLSPEC_HIDDEN;
223 BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr) DECLSPEC_HIDDEN;
224 BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w) DECLSPEC_HIDDEN;
225 BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w) DECLSPEC_HIDDEN;
226 BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x) DECLSPEC_HIDDEN;
227 BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, DWORD usage_idx,
228         DWORD mod, BOOL output, DWORD regnum, DWORD writemask, BOOL builtin) DECLSPEC_HIDDEN;
229 BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype, DWORD mod, DWORD regnum) DECLSPEC_HIDDEN;
230
231 #define MESSAGEBUFFER_INITIAL_SIZE 256
232
233 enum parse_status
234 {
235     PARSE_SUCCESS = 0,
236     PARSE_WARN = 1,
237     PARSE_ERR = 2
238 };
239
240 struct compilation_messages
241 {
242     char *string;
243     unsigned int size;
244     unsigned int capacity;
245 };
246
247 struct asm_parser
248 {
249     /* The function table of the parser implementation */
250     const struct asmparser_backend *funcs;
251
252     /* Private data follows */
253     struct bwriter_shader *shader;
254     unsigned int m3x3pad_count;
255
256     enum parse_status status;
257     struct compilation_messages messages;
258     unsigned int line_no;
259 };
260
261 extern struct asm_parser asm_ctx DECLSPEC_HIDDEN;
262
263 void create_vs10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
264 void create_vs11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
265 void create_vs20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
266 void create_vs2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
267 void create_vs30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
268 void create_ps10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
269 void create_ps11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
270 void create_ps12_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
271 void create_ps13_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
272 void create_ps14_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
273 void create_ps20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
274 void create_ps2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
275 void create_ps30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
276
277 struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN;
278
279 #ifdef __GNUC__
280 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
281 #else
282 #define PRINTF_ATTR(fmt,args)
283 #endif
284
285 void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args) DECLSPEC_HIDDEN;
286 void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
287 static inline void set_parse_status(enum parse_status *current, enum parse_status update)
288 {
289     if (update == PARSE_ERR)
290         *current = PARSE_ERR;
291     else if (update == PARSE_WARN && *current == PARSE_SUCCESS)
292         *current = PARSE_WARN;
293 }
294
295 /* A reasonable value as initial size */
296 #define BYTECODEBUFFER_INITIAL_SIZE 32
297 struct bytecode_buffer {
298     DWORD *data;
299     DWORD size;
300     DWORD alloc_size;
301     /* For tracking rare out of memory situations without passing
302      * return values around everywhere
303      */
304     HRESULT state;
305 };
306
307 struct bc_writer; /* Predeclaration for use in vtable parameters */
308
309 typedef void (*instr_writer)(struct bc_writer *This,
310                              const struct instruction *instr,
311                              struct bytecode_buffer *buffer);
312
313 struct bytecode_backend {
314     void (*header)(struct bc_writer *This, const struct bwriter_shader *shader,
315                    struct bytecode_buffer *buffer);
316     void (*end)(struct bc_writer *This, const struct bwriter_shader *shader,
317                 struct bytecode_buffer *buffer);
318     void (*srcreg)(struct bc_writer *This, const struct shader_reg *reg,
319                    struct bytecode_buffer *buffer);
320     void (*dstreg)(struct bc_writer *This, const struct shader_reg *reg,
321                    struct bytecode_buffer *buffer, DWORD shift, DWORD mod);
322     void (*opcode)(struct bc_writer *This, const struct instruction *instr,
323                    DWORD token, struct bytecode_buffer *buffer);
324
325     const struct instr_handler_table {
326         DWORD opcode;
327         instr_writer func;
328     } *instructions;
329 };
330
331 /* Bytecode writing stuff */
332 struct bc_writer {
333     const struct bytecode_backend *funcs;
334
335     /* Avoid result checking */
336     HRESULT                       state;
337
338     DWORD                         version;
339
340     /* Vertex shader varying mapping */
341     DWORD                         oPos_regnum;
342     DWORD                         oD_regnum[2];
343     DWORD                         oT_regnum[8];
344     DWORD                         oFog_regnum;
345     DWORD                         oFog_mask;
346     DWORD                         oPts_regnum;
347     DWORD                         oPts_mask;
348
349     /* Pixel shader specific members */
350     DWORD                         t_regnum[8];
351     DWORD                         v_regnum[2];
352 };
353
354 /* Debug utility routines */
355 const char *debug_print_srcmod(DWORD mod) DECLSPEC_HIDDEN;
356 const char *debug_print_dstmod(DWORD mod) DECLSPEC_HIDDEN;
357 const char *debug_print_shift(DWORD shift) DECLSPEC_HIDDEN;
358 const char *debug_print_dstreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
359 const char *debug_print_srcreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
360 const char *debug_print_comp(DWORD comp) DECLSPEC_HIDDEN;
361 const char *debug_print_opcode(DWORD opcode) DECLSPEC_HIDDEN;
362
363 /* Used to signal an incorrect swizzle/writemask */
364 #define SWIZZLE_ERR ~0U
365
366 /*
367   Enumerations and defines used in the bytecode writer
368   intermediate representation
369 */
370 typedef enum _BWRITERSHADER_INSTRUCTION_OPCODE_TYPE {
371     BWRITERSIO_NOP,
372     BWRITERSIO_MOV,
373     BWRITERSIO_ADD,
374     BWRITERSIO_SUB,
375     BWRITERSIO_MAD,
376     BWRITERSIO_MUL,
377     BWRITERSIO_RCP,
378     BWRITERSIO_RSQ,
379     BWRITERSIO_DP3,
380     BWRITERSIO_DP4,
381     BWRITERSIO_MIN,
382     BWRITERSIO_MAX,
383     BWRITERSIO_SLT,
384     BWRITERSIO_SGE,
385     BWRITERSIO_EXP,
386     BWRITERSIO_LOG,
387     BWRITERSIO_LIT,
388     BWRITERSIO_DST,
389     BWRITERSIO_LRP,
390     BWRITERSIO_FRC,
391     BWRITERSIO_M4x4,
392     BWRITERSIO_M4x3,
393     BWRITERSIO_M3x4,
394     BWRITERSIO_M3x3,
395     BWRITERSIO_M3x2,
396     BWRITERSIO_CALL,
397     BWRITERSIO_CALLNZ,
398     BWRITERSIO_LOOP,
399     BWRITERSIO_RET,
400     BWRITERSIO_ENDLOOP,
401     BWRITERSIO_LABEL,
402     BWRITERSIO_DCL,
403     BWRITERSIO_POW,
404     BWRITERSIO_CRS,
405     BWRITERSIO_SGN,
406     BWRITERSIO_ABS,
407     BWRITERSIO_NRM,
408     BWRITERSIO_SINCOS,
409     BWRITERSIO_REP,
410     BWRITERSIO_ENDREP,
411     BWRITERSIO_IF,
412     BWRITERSIO_IFC,
413     BWRITERSIO_ELSE,
414     BWRITERSIO_ENDIF,
415     BWRITERSIO_BREAK,
416     BWRITERSIO_BREAKC,
417     BWRITERSIO_MOVA,
418     BWRITERSIO_DEFB,
419     BWRITERSIO_DEFI,
420
421     BWRITERSIO_TEXCOORD,
422     BWRITERSIO_TEXKILL,
423     BWRITERSIO_TEX,
424     BWRITERSIO_TEXBEM,
425     BWRITERSIO_TEXBEML,
426     BWRITERSIO_TEXREG2AR,
427     BWRITERSIO_TEXREG2GB,
428     BWRITERSIO_TEXM3x2PAD,
429     BWRITERSIO_TEXM3x2TEX,
430     BWRITERSIO_TEXM3x3PAD,
431     BWRITERSIO_TEXM3x3TEX,
432     BWRITERSIO_TEXM3x3SPEC,
433     BWRITERSIO_TEXM3x3VSPEC,
434     BWRITERSIO_EXPP,
435     BWRITERSIO_LOGP,
436     BWRITERSIO_CND,
437     BWRITERSIO_DEF,
438     BWRITERSIO_TEXREG2RGB,
439     BWRITERSIO_TEXDP3TEX,
440     BWRITERSIO_TEXM3x2DEPTH,
441     BWRITERSIO_TEXDP3,
442     BWRITERSIO_TEXM3x3,
443     BWRITERSIO_TEXDEPTH,
444     BWRITERSIO_CMP,
445     BWRITERSIO_BEM,
446     BWRITERSIO_DP2ADD,
447     BWRITERSIO_DSX,
448     BWRITERSIO_DSY,
449     BWRITERSIO_TEXLDD,
450     BWRITERSIO_SETP,
451     BWRITERSIO_TEXLDL,
452     BWRITERSIO_BREAKP,
453     BWRITERSIO_TEXLDP,
454     BWRITERSIO_TEXLDB,
455
456     BWRITERSIO_PHASE,
457     BWRITERSIO_COMMENT,
458     BWRITERSIO_END,
459 } BWRITERSHADER_INSTRUCTION_OPCODE_TYPE;
460
461 typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE {
462     BWRITERSPR_TEMP,
463     BWRITERSPR_INPUT,
464     BWRITERSPR_CONST,
465     BWRITERSPR_ADDR,
466     BWRITERSPR_TEXTURE,
467     BWRITERSPR_RASTOUT,
468     BWRITERSPR_ATTROUT,
469     BWRITERSPR_TEXCRDOUT,
470     BWRITERSPR_OUTPUT,
471     BWRITERSPR_CONSTINT,
472     BWRITERSPR_COLOROUT,
473     BWRITERSPR_DEPTHOUT,
474     BWRITERSPR_SAMPLER,
475     BWRITERSPR_CONSTBOOL,
476     BWRITERSPR_LOOP,
477     BWRITERSPR_MISCTYPE,
478     BWRITERSPR_LABEL,
479     BWRITERSPR_PREDICATE
480 } BWRITERSHADER_PARAM_REGISTER_TYPE;
481
482 typedef enum _BWRITERVS_RASTOUT_OFFSETS
483 {
484     BWRITERSRO_POSITION,
485     BWRITERSRO_FOG,
486     BWRITERSRO_POINT_SIZE
487 } BWRITERVS_RASTOUT_OFFSETS;
488
489 #define BWRITERSP_WRITEMASK_0   0x1 /* .x r */
490 #define BWRITERSP_WRITEMASK_1   0x2 /* .y g */
491 #define BWRITERSP_WRITEMASK_2   0x4 /* .z b */
492 #define BWRITERSP_WRITEMASK_3   0x8 /* .w a */
493 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
494
495 typedef enum _BWRITERSHADER_PARAM_DSTMOD_TYPE {
496     BWRITERSPDM_NONE = 0,
497     BWRITERSPDM_SATURATE = 1,
498     BWRITERSPDM_PARTIALPRECISION = 2,
499     BWRITERSPDM_MSAMPCENTROID = 4,
500 } BWRITERSHADER_PARAM_DSTMOD_TYPE;
501
502 typedef enum _BWRITERSAMPLER_TEXTURE_TYPE {
503     BWRITERSTT_UNKNOWN = 0,
504     BWRITERSTT_1D = 1,
505     BWRITERSTT_2D = 2,
506     BWRITERSTT_CUBE = 3,
507     BWRITERSTT_VOLUME = 4,
508 } BWRITERSAMPLER_TEXTURE_TYPE;
509
510 #define BWRITERSI_TEXLD_PROJECT 1
511 #define BWRITERSI_TEXLD_BIAS    2
512
513 typedef enum _BWRITERSHADER_PARAM_SRCMOD_TYPE {
514     BWRITERSPSM_NONE = 0,
515     BWRITERSPSM_NEG,
516     BWRITERSPSM_BIAS,
517     BWRITERSPSM_BIASNEG,
518     BWRITERSPSM_SIGN,
519     BWRITERSPSM_SIGNNEG,
520     BWRITERSPSM_COMP,
521     BWRITERSPSM_X2,
522     BWRITERSPSM_X2NEG,
523     BWRITERSPSM_DZ,
524     BWRITERSPSM_DW,
525     BWRITERSPSM_ABS,
526     BWRITERSPSM_ABSNEG,
527     BWRITERSPSM_NOT,
528 } BWRITERSHADER_PARAM_SRCMOD_TYPE;
529
530 #define BWRITER_SM1_VS  0xfffe
531 #define BWRITER_SM1_PS  0xffff
532
533 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
534 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
535
536 #define BWRITERVS_SWIZZLE_SHIFT      16
537 #define BWRITERVS_SWIZZLE_MASK       (0xFF << BWRITERVS_SWIZZLE_SHIFT)
538
539 #define BWRITERVS_X_X       (0 << BWRITERVS_SWIZZLE_SHIFT)
540 #define BWRITERVS_X_Y       (1 << BWRITERVS_SWIZZLE_SHIFT)
541 #define BWRITERVS_X_Z       (2 << BWRITERVS_SWIZZLE_SHIFT)
542 #define BWRITERVS_X_W       (3 << BWRITERVS_SWIZZLE_SHIFT)
543
544 #define BWRITERVS_Y_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 2))
545 #define BWRITERVS_Y_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 2))
546 #define BWRITERVS_Y_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 2))
547 #define BWRITERVS_Y_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
548
549 #define BWRITERVS_Z_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 4))
550 #define BWRITERVS_Z_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 4))
551 #define BWRITERVS_Z_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 4))
552 #define BWRITERVS_Z_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
553
554 #define BWRITERVS_W_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 6))
555 #define BWRITERVS_W_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 6))
556 #define BWRITERVS_W_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 6))
557 #define BWRITERVS_W_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 6))
558
559 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
560
561 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
562 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
563 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
564 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
565
566 typedef enum _BWRITERDECLUSAGE {
567     BWRITERDECLUSAGE_POSITION,
568     BWRITERDECLUSAGE_BLENDWEIGHT,
569     BWRITERDECLUSAGE_BLENDINDICES,
570     BWRITERDECLUSAGE_NORMAL,
571     BWRITERDECLUSAGE_PSIZE,
572     BWRITERDECLUSAGE_TEXCOORD,
573     BWRITERDECLUSAGE_TANGENT,
574     BWRITERDECLUSAGE_BINORMAL,
575     BWRITERDECLUSAGE_TESSFACTOR,
576     BWRITERDECLUSAGE_POSITIONT,
577     BWRITERDECLUSAGE_COLOR,
578     BWRITERDECLUSAGE_FOG,
579     BWRITERDECLUSAGE_DEPTH,
580     BWRITERDECLUSAGE_SAMPLE
581 } BWRITERDECLUSAGE;
582
583 /* ps 1.x texture registers mappings */
584 #define T0_REG          2
585 #define T1_REG          3
586 #define T2_REG          4
587 #define T3_REG          5
588
589 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) DECLSPEC_HIDDEN;
590 HRESULT SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result, DWORD *size) DECLSPEC_HIDDEN;
591 void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN;
592
593 /* The general IR structure is inspired by Mesa GLSL hir, even though the code
594  * ends up being quite different in practice. Anyway, here comes the relevant
595  * licensing information.
596  *
597  * Copyright Â© 2010 Intel Corporation
598  *
599  * Permission is hereby granted, free of charge, to any person obtaining a
600  * copy of this software and associated documentation files (the "Software"),
601  * to deal in the Software without restriction, including without limitation
602  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
603  * and/or sell copies of the Software, and to permit persons to whom the
604  * Software is furnished to do so, subject to the following conditions:
605  *
606  * The above copyright notice and this permission notice (including the next
607  * paragraph) shall be included in all copies or substantial portions of the
608  * Software.
609  *
610  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
611  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
612  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
613  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
614  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
615  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
616  * DEALINGS IN THE SOFTWARE.
617  */
618
619 enum hlsl_type_class
620 {
621     HLSL_CLASS_SCALAR,
622     HLSL_CLASS_VECTOR,
623     HLSL_CLASS_MATRIX,
624     HLSL_CLASS_LAST_NUMERIC = HLSL_CLASS_MATRIX,
625     HLSL_CLASS_STRUCT,
626     HLSL_CLASS_ARRAY,
627     HLSL_CLASS_OBJECT,
628 };
629
630 enum hlsl_base_type
631 {
632     HLSL_TYPE_FLOAT,
633     HLSL_TYPE_HALF,
634     HLSL_TYPE_DOUBLE,
635     HLSL_TYPE_INT,
636     HLSL_TYPE_UINT,
637     HLSL_TYPE_BOOL,
638     HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL,
639     HLSL_TYPE_SAMPLER,
640     HLSL_TYPE_TEXTURE,
641     HLSL_TYPE_PIXELSHADER,
642     HLSL_TYPE_VERTEXSHADER,
643     HLSL_TYPE_STRING,
644     HLSL_TYPE_VOID,
645 };
646
647 enum hlsl_sampler_dim
648 {
649    HLSL_SAMPLER_DIM_GENERIC,
650    HLSL_SAMPLER_DIM_1D,
651    HLSL_SAMPLER_DIM_2D,
652    HLSL_SAMPLER_DIM_3D,
653    HLSL_SAMPLER_DIM_CUBE,
654 };
655
656 enum hlsl_matrix_majority
657 {
658     HLSL_COLUMN_MAJOR,
659     HLSL_ROW_MAJOR
660 };
661
662 struct hlsl_type
663 {
664     struct list entry;
665     struct wine_rb_entry scope_entry;
666     enum hlsl_type_class type;
667     enum hlsl_base_type base_type;
668     enum hlsl_sampler_dim sampler_dim;
669     const char *name;
670     unsigned int modifiers;
671     unsigned int dimx;
672     unsigned int dimy;
673     union
674     {
675         struct list *elements;
676         struct
677         {
678             struct hlsl_type *type;
679             unsigned int elements_count;
680         } array;
681     } e;
682 };
683
684 struct hlsl_struct_field
685 {
686     struct list entry;
687     struct hlsl_type *type;
688     const char *name;
689     const char *semantic;
690     DWORD modifiers;
691 };
692
693 struct source_location
694 {
695     const char *file;
696     unsigned int line;
697     unsigned int col;
698 };
699
700 enum hlsl_ir_node_type
701 {
702     HLSL_IR_VAR = 0,
703     HLSL_IR_ASSIGNMENT,
704     HLSL_IR_CONSTANT,
705     HLSL_IR_CONSTRUCTOR,
706     HLSL_IR_DEREF,
707     HLSL_IR_EXPR,
708     HLSL_IR_FUNCTION_DECL,
709     HLSL_IR_IF,
710     HLSL_IR_LOOP,
711     HLSL_IR_JUMP,
712     HLSL_IR_SWIZZLE,
713 };
714
715 struct hlsl_ir_node
716 {
717     struct list entry;
718     enum hlsl_ir_node_type type;
719     struct hlsl_type *data_type;
720
721     struct source_location loc;
722 };
723
724 #define HLSL_STORAGE_EXTERN          0x00000001
725 #define HLSL_STORAGE_NOINTERPOLATION 0x00000002
726 #define HLSL_MODIFIER_PRECISE        0x00000004
727 #define HLSL_STORAGE_SHARED          0x00000008
728 #define HLSL_STORAGE_GROUPSHARED     0x00000010
729 #define HLSL_STORAGE_STATIC          0x00000020
730 #define HLSL_STORAGE_UNIFORM         0x00000040
731 #define HLSL_STORAGE_VOLATILE        0x00000080
732 #define HLSL_MODIFIER_CONST          0x00000100
733 #define HLSL_MODIFIER_ROW_MAJOR      0x00000200
734 #define HLSL_MODIFIER_COLUMN_MAJOR   0x00000400
735 #define HLSL_MODIFIER_IN             0x00000800
736 #define HLSL_MODIFIER_OUT            0x00001000
737
738 #define HLSL_TYPE_MODIFIERS_MASK     (HLSL_MODIFIER_PRECISE | HLSL_STORAGE_VOLATILE | \
739                                       HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \
740                                       HLSL_MODIFIER_COLUMN_MAJOR)
741
742 #define HLSL_MODIFIERS_COMPARISON_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
743
744 struct hlsl_ir_var
745 {
746     struct hlsl_ir_node node;
747     const char *name;
748     const char *semantic;
749     unsigned int modifiers;
750     struct list scope_entry;
751
752     struct hlsl_var_allocation *allocation;
753 };
754
755 struct hlsl_ir_function_decl
756 {
757     struct hlsl_ir_node node;
758     const char *name;
759     const char *semantic;
760     struct list *parameters;
761     struct list *body;
762 };
763
764 struct hlsl_ir_if
765 {
766     struct hlsl_ir_node node;
767     struct hlsl_ir_node *condition;
768     struct list *then_instrs;
769     struct list *else_instrs;
770 };
771
772 struct hlsl_ir_loop
773 {
774     struct hlsl_ir_node node;
775     /* loop condition is stored in the body (as "if (!condition) break;") */
776     struct list *body;
777 };
778
779 struct hlsl_ir_assignment
780 {
781     struct hlsl_ir_node node;
782     struct hlsl_ir_node *lhs;
783     struct hlsl_ir_node *rhs;
784     unsigned char writemask;
785 };
786
787 enum hlsl_ir_expr_op {
788     HLSL_IR_UNOP_BIT_NOT = 0,
789     HLSL_IR_UNOP_LOGIC_NOT,
790     HLSL_IR_UNOP_NEG,
791     HLSL_IR_UNOP_ABS,
792     HLSL_IR_UNOP_SIGN,
793     HLSL_IR_UNOP_RCP,
794     HLSL_IR_UNOP_RSQ,
795     HLSL_IR_UNOP_SQRT,
796     HLSL_IR_UNOP_NRM,
797     HLSL_IR_UNOP_EXP2,
798     HLSL_IR_UNOP_LOG2,
799
800     HLSL_IR_UNOP_CAST,
801
802     HLSL_IR_UNOP_FRACT,
803
804     HLSL_IR_UNOP_SIN,
805     HLSL_IR_UNOP_COS,
806     HLSL_IR_UNOP_SIN_REDUCED,    /* Reduced range [-pi, pi] */
807     HLSL_IR_UNOP_COS_REDUCED,    /* Reduced range [-pi, pi] */
808
809     HLSL_IR_UNOP_DSX,
810     HLSL_IR_UNOP_DSY,
811
812     HLSL_IR_UNOP_SAT,
813
814     HLSL_IR_BINOP_ADD,
815     HLSL_IR_BINOP_SUB,
816     HLSL_IR_BINOP_MUL,
817     HLSL_IR_BINOP_DIV,
818
819     HLSL_IR_BINOP_MOD,
820
821     HLSL_IR_BINOP_LESS,
822     HLSL_IR_BINOP_GREATER,
823     HLSL_IR_BINOP_LEQUAL,
824     HLSL_IR_BINOP_GEQUAL,
825     HLSL_IR_BINOP_EQUAL,
826     HLSL_IR_BINOP_NEQUAL,
827
828     HLSL_IR_BINOP_LOGIC_AND,
829     HLSL_IR_BINOP_LOGIC_OR,
830
831     HLSL_IR_BINOP_LSHIFT,
832     HLSL_IR_BINOP_RSHIFT,
833     HLSL_IR_BINOP_BIT_AND,
834     HLSL_IR_BINOP_BIT_OR,
835     HLSL_IR_BINOP_BIT_XOR,
836
837     HLSL_IR_BINOP_DOT,
838     HLSL_IR_BINOP_CRS,
839     HLSL_IR_BINOP_MIN,
840     HLSL_IR_BINOP_MAX,
841
842     HLSL_IR_BINOP_POW,
843
844     HLSL_IR_BINOP_PREINC,
845     HLSL_IR_BINOP_PREDEC,
846     HLSL_IR_BINOP_POSTINC,
847     HLSL_IR_BINOP_POSTDEC,
848
849     HLSL_IR_TEROP_LERP,
850
851     HLSL_IR_SEQUENCE,
852 };
853
854 struct hlsl_ir_expr
855 {
856     struct hlsl_ir_node node;
857     enum hlsl_ir_expr_op op;
858     struct hlsl_ir_node *operands[3];
859     struct list *subexpressions;
860 };
861
862 enum hlsl_ir_jump_type
863 {
864     HLSL_IR_JUMP_BREAK,
865     HLSL_IR_JUMP_CONTINUE,
866     HLSL_IR_JUMP_DISCARD,
867     HLSL_IR_JUMP_RETURN,
868 };
869
870 struct hlsl_ir_jump
871 {
872     struct hlsl_ir_node node;
873     enum hlsl_ir_jump_type type;
874     struct hlsl_ir_node *return_value;
875 };
876
877 struct hlsl_ir_swizzle
878 {
879     struct hlsl_ir_node node;
880     struct hlsl_ir_node *val;
881     DWORD swizzle;
882 };
883
884 enum hlsl_ir_deref_type
885 {
886     HLSL_IR_DEREF_VAR,
887     HLSL_IR_DEREF_ARRAY,
888     HLSL_IR_DEREF_RECORD,
889 };
890
891 struct hlsl_ir_deref
892 {
893     struct hlsl_ir_node node;
894     enum hlsl_ir_deref_type type;
895     union
896     {
897         struct hlsl_ir_var *var;
898         struct
899         {
900             struct hlsl_ir_node *array;
901             struct hlsl_ir_node *index;
902         } array;
903         struct
904         {
905             struct hlsl_ir_node *record;
906             struct hlsl_struct_field *field;
907         } record;
908     } v;
909 };
910
911 struct hlsl_ir_constant
912 {
913     struct hlsl_ir_node node;
914     union
915     {
916         union
917         {
918             unsigned u[16];
919             int i[16];
920             float f[16];
921             double d[16];
922             BOOL b[16];
923         } value;
924         struct hlsl_ir_constant *array_elements;
925         struct list *struct_elements;
926     } v;
927 };
928
929 struct hlsl_ir_constructor
930 {
931     struct hlsl_ir_node node;
932     struct list *arguments;
933 };
934
935 struct hlsl_scope
936 {
937     struct list entry;
938     struct list vars;
939     struct wine_rb_tree types;
940     struct hlsl_scope *upper;
941 };
942
943 /* Structures used only during parsing */
944 struct parse_parameter
945 {
946     struct hlsl_type *type;
947     const char *name;
948     const char *semantic;
949     unsigned int modifiers;
950 };
951
952 struct parse_variable_def
953 {
954     struct list entry;
955     struct source_location loc;
956
957     char *name;
958     unsigned int array_size;
959     char *semantic;
960     struct list *initializer;
961 };
962
963 struct parse_if_body
964 {
965     struct list *then_instrs;
966     struct list *else_instrs;
967 };
968
969 enum parse_unary_op
970 {
971     UNARY_OP_PLUS,
972     UNARY_OP_MINUS,
973     UNARY_OP_LOGICNOT,
974     UNARY_OP_BITNOT,
975 };
976
977 enum parse_assign_op
978 {
979     ASSIGN_OP_ASSIGN,
980     ASSIGN_OP_ADD,
981     ASSIGN_OP_SUB,
982     ASSIGN_OP_MUL,
983     ASSIGN_OP_DIV,
984     ASSIGN_OP_MOD,
985     ASSIGN_OP_LSHIFT,
986     ASSIGN_OP_RSHIFT,
987     ASSIGN_OP_AND,
988     ASSIGN_OP_OR,
989     ASSIGN_OP_XOR,
990 };
991
992 struct hlsl_parse_ctx
993 {
994     const char **source_files;
995     unsigned int source_files_count;
996     const char *source_file;
997     unsigned int line_no;
998     unsigned int column;
999     enum parse_status status;
1000     struct compilation_messages messages;
1001
1002     struct hlsl_scope *cur_scope;
1003     struct hlsl_scope *globals;
1004     struct list scopes;
1005
1006     struct list types;
1007     struct list functions;
1008
1009     enum hlsl_matrix_majority matrix_majority;
1010 };
1011
1012 extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN;
1013
1014 enum hlsl_error_level
1015 {
1016     HLSL_LEVEL_ERROR = 0,
1017     HLSL_LEVEL_WARNING,
1018     HLSL_LEVEL_NOTE,
1019 };
1020
1021 void hlsl_message(const char *fmt, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN;
1022 void hlsl_report_message(const char *filename, DWORD line, DWORD column,
1023         enum hlsl_error_level level, const char *fmt, ...) PRINTF_ATTR(5,6) DECLSPEC_HIDDEN;
1024
1025 static inline struct hlsl_ir_var *var_from_node(const struct hlsl_ir_node *node)
1026 {
1027     assert(node->type == HLSL_IR_VAR);
1028     return CONTAINING_RECORD(node, struct hlsl_ir_var, node);
1029 }
1030
1031 static inline struct hlsl_ir_expr *expr_from_node(const struct hlsl_ir_node *node)
1032 {
1033     assert(node->type == HLSL_IR_EXPR);
1034     return CONTAINING_RECORD(node, struct hlsl_ir_expr, node);
1035 }
1036
1037 static inline struct hlsl_ir_deref *deref_from_node(const struct hlsl_ir_node *node)
1038 {
1039     assert(node->type == HLSL_IR_DEREF);
1040     return CONTAINING_RECORD(node, struct hlsl_ir_deref, node);
1041 }
1042
1043 static inline struct hlsl_ir_constant *constant_from_node(const struct hlsl_ir_node *node)
1044 {
1045     assert(node->type == HLSL_IR_CONSTANT);
1046     return CONTAINING_RECORD(node, struct hlsl_ir_constant, node);
1047 }
1048
1049 static inline struct hlsl_ir_jump *jump_from_node(const struct hlsl_ir_node *node)
1050 {
1051     assert(node->type == HLSL_IR_JUMP);
1052     return CONTAINING_RECORD(node, struct hlsl_ir_jump, node);
1053 }
1054
1055 static inline struct hlsl_ir_assignment *assignment_from_node(const struct hlsl_ir_node *node)
1056 {
1057     assert(node->type == HLSL_IR_ASSIGNMENT);
1058     return CONTAINING_RECORD(node, struct hlsl_ir_assignment, node);
1059 }
1060
1061 static inline struct hlsl_ir_swizzle *swizzle_from_node(const struct hlsl_ir_node *node)
1062 {
1063     assert(node->type == HLSL_IR_SWIZZLE);
1064     return CONTAINING_RECORD(node, struct hlsl_ir_swizzle, node);
1065 }
1066
1067 static inline struct hlsl_ir_constructor *constructor_from_node(const struct hlsl_ir_node *node)
1068 {
1069     assert(node->type == HLSL_IR_CONSTRUCTOR);
1070     return CONTAINING_RECORD(node, struct hlsl_ir_constructor, node);
1071 }
1072
1073 static inline struct hlsl_ir_if *if_from_node(const struct hlsl_ir_node *node)
1074 {
1075     assert(node->type == HLSL_IR_IF);
1076     return CONTAINING_RECORD(node, struct hlsl_ir_if, node);
1077 }
1078
1079 static inline struct hlsl_ir_loop *loop_from_node(const struct hlsl_ir_node *node)
1080 {
1081     assert(node->type == HLSL_IR_LOOP);
1082     return CONTAINING_RECORD(node, struct hlsl_ir_loop, node);
1083 }
1084
1085 BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN;
1086 struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
1087 void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
1088 BOOL add_func_parameter(struct list *list, struct parse_parameter *param,
1089         const struct source_location *loc) DECLSPEC_HIDDEN;
1090 struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class,
1091         enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN;
1092 struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN;
1093 struct hlsl_type *clone_hlsl_type(struct hlsl_type *old) DECLSPEC_HIDDEN;
1094 struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN;
1095 BOOL find_function(const char *name) DECLSPEC_HIDDEN;
1096 unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
1097 BOOL compatible_data_types(struct hlsl_type *s1, struct hlsl_type *s2) DECLSPEC_HIDDEN;
1098 struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands,
1099         struct source_location *loc) DECLSPEC_HIDDEN;
1100 struct hlsl_ir_expr *new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
1101         struct source_location *loc) DECLSPEC_HIDDEN;
1102 struct hlsl_ir_expr *hlsl_mul(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1103         struct source_location *loc) DECLSPEC_HIDDEN;
1104 struct hlsl_ir_expr *hlsl_div(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1105         struct source_location *loc) DECLSPEC_HIDDEN;
1106 struct hlsl_ir_expr *hlsl_mod(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1107         struct source_location *loc) DECLSPEC_HIDDEN;
1108 struct hlsl_ir_expr *hlsl_add(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1109         struct source_location *loc) DECLSPEC_HIDDEN;
1110 struct hlsl_ir_expr *hlsl_sub(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1111         struct source_location *loc) DECLSPEC_HIDDEN;
1112 struct hlsl_ir_expr *hlsl_lt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1113         struct source_location *loc) DECLSPEC_HIDDEN;
1114 struct hlsl_ir_expr *hlsl_gt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1115         struct source_location *loc) DECLSPEC_HIDDEN;
1116 struct hlsl_ir_expr *hlsl_le(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1117         struct source_location *loc) DECLSPEC_HIDDEN;
1118 struct hlsl_ir_expr *hlsl_ge(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1119         struct source_location *loc) DECLSPEC_HIDDEN;
1120 struct hlsl_ir_expr *hlsl_eq(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1121         struct source_location *loc) DECLSPEC_HIDDEN;
1122 struct hlsl_ir_expr *hlsl_ne(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1123         struct source_location *loc) DECLSPEC_HIDDEN;
1124 struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var) DECLSPEC_HIDDEN;
1125 struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assign_op assign_op,
1126         DWORD writemask, struct hlsl_ir_node *right) DECLSPEC_HIDDEN;
1127 void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
1128 BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
1129 struct hlsl_ir_function_decl *new_func_decl(const char *name, struct hlsl_type *return_type, struct list *parameters) DECLSPEC_HIDDEN;
1130 struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
1131         const char *entrypoint, char **messages) DECLSPEC_HIDDEN;
1132
1133 const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
1134 const char *debug_modifiers(DWORD modifiers) DECLSPEC_HIDDEN;
1135 void debug_dump_ir_function(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
1136
1137 void free_hlsl_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
1138 void free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
1139 void free_instr_list(struct list *list) DECLSPEC_HIDDEN;
1140 void free_function(struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
1141
1142
1143 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
1144     ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
1145     ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
1146 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
1147 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
1148 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
1149 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
1150 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
1151 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
1152 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
1153 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
1154 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
1155 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
1156 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
1157 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
1158 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
1159
1160 struct dxbc_section
1161 {
1162     DWORD tag;
1163     const char *data;
1164     DWORD data_size;
1165 };
1166
1167 struct dxbc
1168 {
1169     UINT size;
1170     UINT count;
1171     struct dxbc_section *sections;
1172 };
1173
1174 HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN;
1175 void dxbc_destroy(struct dxbc *dxbc) DECLSPEC_HIDDEN;
1176 HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) DECLSPEC_HIDDEN;
1177 HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, DWORD data_size) DECLSPEC_HIDDEN;
1178 HRESULT dxbc_init(struct dxbc *dxbc, DWORD count) DECLSPEC_HIDDEN;
1179
1180 static inline void read_dword(const char **ptr, DWORD *d)
1181 {
1182     memcpy(d, *ptr, sizeof(*d));
1183     *ptr += sizeof(*d);
1184 }
1185
1186 static inline void write_dword(char **ptr, DWORD d)
1187 {
1188     memcpy(*ptr, &d, sizeof(d));
1189     *ptr += sizeof(d);
1190 }
1191
1192 void skip_dword_unknown(const char **ptr, unsigned int count) DECLSPEC_HIDDEN;
1193
1194 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */