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