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