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