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