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