Assorted typo, spelling, wording and case fixes.
[wine] / dlls / 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 /*
37  * This doesn't belong here, but for some functions it is possible to return that value,
38  * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
39  * The original definition is in D3DX10core.h.
40  */
41 #define D3DERR_INVALIDCALL 0x8876086c
42
43 /* TRACE helper functions */
44 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part) DECLSPEC_HIDDEN;
45 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c) DECLSPEC_HIDDEN;
46 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t) DECLSPEC_HIDDEN;
47
48 enum shader_type
49 {
50     ST_VERTEX,
51     ST_PIXEL,
52 };
53
54 typedef enum BWRITER_COMPARISON_TYPE {
55     BWRITER_COMPARISON_NONE,
56     BWRITER_COMPARISON_GT,
57     BWRITER_COMPARISON_EQ,
58     BWRITER_COMPARISON_GE,
59     BWRITER_COMPARISON_LT,
60     BWRITER_COMPARISON_NE,
61     BWRITER_COMPARISON_LE
62 } BWRITER_COMPARISON_TYPE;
63
64 struct constant {
65     DWORD                   regnum;
66     union {
67         float               f;
68         INT                 i;
69         BOOL                b;
70         DWORD               d;
71     }                       value[4];
72 };
73
74 struct shader_reg {
75     DWORD                   type;
76     DWORD                   regnum;
77     struct shader_reg       *rel_reg;
78     DWORD                   srcmod;
79     union {
80         DWORD               swizzle;
81         DWORD               writemask;
82     } u;
83 };
84
85 struct instruction {
86     DWORD                   opcode;
87     DWORD                   dstmod;
88     DWORD                   shift;
89     BWRITER_COMPARISON_TYPE comptype;
90     BOOL                    has_dst;
91     struct shader_reg       dst;
92     struct shader_reg       *src;
93     unsigned int            num_srcs; /* For freeing the rel_regs */
94     BOOL                    has_predicate;
95     struct shader_reg       predicate;
96     BOOL                    coissue;
97 };
98
99 struct declaration {
100     DWORD                   usage, usage_idx;
101     DWORD                   regnum;
102     DWORD                   mod;
103     DWORD                   writemask;
104     BOOL                    builtin;
105 };
106
107 struct samplerdecl {
108     DWORD                   type;
109     DWORD                   regnum;
110     DWORD                   mod;
111 };
112
113 #define INSTRARRAY_INITIAL_SIZE 8
114 struct bwriter_shader {
115     enum shader_type        type;
116
117     /* Shader version selected */
118     DWORD                   version;
119
120     /* Local constants. Every constant that is not defined below is loaded from
121      * the global constant set at shader runtime
122      */
123     struct constant         **constF;
124     struct constant         **constI;
125     struct constant         **constB;
126     unsigned int            num_cf, num_ci, num_cb;
127
128     /* Declared input and output varyings */
129     struct declaration      *inputs, *outputs;
130     unsigned int            num_inputs, num_outputs;
131     struct samplerdecl      *samplers;
132     unsigned int            num_samplers;
133
134     /* Are special pixel shader 3.0 registers declared? */
135     BOOL                    vPos, vFace;
136
137     /* Array of shader instructions - The shader code itself */
138     struct instruction      **instr;
139     unsigned int            num_instrs, instr_alloc_size;
140 };
141
142 static inline void *d3dcompiler_alloc(SIZE_T size)
143 {
144     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
145 }
146
147 static inline void *d3dcompiler_realloc(void *ptr, SIZE_T size)
148 {
149     return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
150 }
151
152 static inline BOOL d3dcompiler_free(void *ptr)
153 {
154     return HeapFree(GetProcessHeap(), 0, ptr);
155 }
156
157 struct asm_parser;
158
159 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
160  * too it has to know it as well
161  */
162 struct rel_reg {
163     BOOL            has_rel_reg;
164     DWORD           type;
165     DWORD           additional_offset;
166     DWORD           rel_regnum;
167     DWORD           swizzle;
168 };
169
170 #define MAX_SRC_REGS 4
171
172 struct src_regs {
173     struct shader_reg reg[MAX_SRC_REGS];
174     unsigned int      count;
175 };
176
177 struct asmparser_backend {
178     void (*constF)(struct asm_parser *This, DWORD reg, float x, float y, float z, float w);
179     void (*constI)(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w);
180     void (*constB)(struct asm_parser *This, DWORD reg, BOOL x);
181
182     void (*dstreg)(struct asm_parser *This, struct instruction *instr,
183                    const struct shader_reg *dst);
184     void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num,
185                    const struct shader_reg *src);
186
187     void (*predicate)(struct asm_parser *This,
188                       const struct shader_reg *predicate);
189     void (*coissue)(struct asm_parser *This);
190
191     void (*dcl_output)(struct asm_parser *This, DWORD usage, DWORD num,
192                        const struct shader_reg *reg);
193     void (*dcl_input)(struct asm_parser *This, DWORD usage, DWORD num,
194                       DWORD mod, const struct shader_reg *reg);
195     void (*dcl_sampler)(struct asm_parser *This, DWORD samptype, DWORD mod,
196                         DWORD regnum, unsigned int line_no);
197
198     void (*end)(struct asm_parser *This);
199
200     void (*instr)(struct asm_parser *This, DWORD opcode, DWORD mod, DWORD shift,
201                   BWRITER_COMPARISON_TYPE comp, const struct shader_reg *dst,
202                   const struct src_regs *srcs, int expectednsrcs);
203 };
204
205 struct instruction *alloc_instr(unsigned int srcs) DECLSPEC_HIDDEN;
206 BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr) DECLSPEC_HIDDEN;
207 BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w) DECLSPEC_HIDDEN;
208 BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w) DECLSPEC_HIDDEN;
209 BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x) DECLSPEC_HIDDEN;
210 BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, DWORD usage_idx,
211         DWORD mod, BOOL output, DWORD regnum, DWORD writemask, BOOL builtin) DECLSPEC_HIDDEN;
212 BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype, DWORD mod, DWORD regnum) DECLSPEC_HIDDEN;
213
214 #define MESSAGEBUFFER_INITIAL_SIZE 256
215
216 enum parse_status
217 {
218     PARSE_SUCCESS = 0,
219     PARSE_WARN = 1,
220     PARSE_ERR = 2
221 };
222
223 struct compilation_messages
224 {
225     char *string;
226     unsigned int size;
227     unsigned int capacity;
228 };
229
230 struct asm_parser
231 {
232     /* The function table of the parser implementation */
233     const struct asmparser_backend *funcs;
234
235     /* Private data follows */
236     struct bwriter_shader *shader;
237     unsigned int m3x3pad_count;
238
239     enum parse_status status;
240     struct compilation_messages messages;
241     unsigned int line_no;
242 };
243
244 extern struct asm_parser asm_ctx DECLSPEC_HIDDEN;
245
246 void create_vs10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
247 void create_vs11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
248 void create_vs20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
249 void create_vs2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
250 void create_vs30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
251 void create_ps10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
252 void create_ps11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
253 void create_ps12_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
254 void create_ps13_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
255 void create_ps14_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
256 void create_ps20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
257 void create_ps2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
258 void create_ps30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
259
260 struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN;
261
262 #ifdef __GNUC__
263 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
264 #else
265 #define PRINTF_ATTR(fmt,args)
266 #endif
267
268 void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args) DECLSPEC_HIDDEN;
269 void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
270 static inline void set_parse_status(enum parse_status *current, enum parse_status update)
271 {
272     if (update == PARSE_ERR)
273         *current = PARSE_ERR;
274     else if (update == PARSE_WARN && *current == PARSE_SUCCESS)
275         *current = PARSE_WARN;
276 }
277
278 /* A reasonable value as initial size */
279 #define BYTECODEBUFFER_INITIAL_SIZE 32
280 struct bytecode_buffer {
281     DWORD *data;
282     DWORD size;
283     DWORD alloc_size;
284     /* For tracking rare out of memory situations without passing
285      * return values around everywhere
286      */
287     HRESULT state;
288 };
289
290 struct bc_writer; /* Predeclaration for use in vtable parameters */
291
292 typedef void (*instr_writer)(struct bc_writer *This,
293                              const struct instruction *instr,
294                              struct bytecode_buffer *buffer);
295
296 struct bytecode_backend {
297     void (*header)(struct bc_writer *This, const struct bwriter_shader *shader,
298                    struct bytecode_buffer *buffer);
299     void (*end)(struct bc_writer *This, const struct bwriter_shader *shader,
300                 struct bytecode_buffer *buffer);
301     void (*srcreg)(struct bc_writer *This, const struct shader_reg *reg,
302                    struct bytecode_buffer *buffer);
303     void (*dstreg)(struct bc_writer *This, const struct shader_reg *reg,
304                    struct bytecode_buffer *buffer, DWORD shift, DWORD mod);
305     void (*opcode)(struct bc_writer *This, const struct instruction *instr,
306                    DWORD token, struct bytecode_buffer *buffer);
307
308     const struct instr_handler_table {
309         DWORD opcode;
310         instr_writer func;
311     } *instructions;
312 };
313
314 /* Bytecode writing stuff */
315 struct bc_writer {
316     const struct bytecode_backend *funcs;
317
318     /* Avoid result checking */
319     HRESULT                       state;
320
321     DWORD                         version;
322
323     /* Vertex shader varying mapping */
324     DWORD                         oPos_regnum;
325     DWORD                         oD_regnum[2];
326     DWORD                         oT_regnum[8];
327     DWORD                         oFog_regnum;
328     DWORD                         oFog_mask;
329     DWORD                         oPts_regnum;
330     DWORD                         oPts_mask;
331
332     /* Pixel shader specific members */
333     DWORD                         t_regnum[8];
334     DWORD                         v_regnum[2];
335 };
336
337 /* Debug utility routines */
338 const char *debug_print_srcmod(DWORD mod) DECLSPEC_HIDDEN;
339 const char *debug_print_dstmod(DWORD mod) DECLSPEC_HIDDEN;
340 const char *debug_print_shift(DWORD shift) DECLSPEC_HIDDEN;
341 const char *debug_print_dstreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
342 const char *debug_print_srcreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
343 const char *debug_print_comp(DWORD comp) DECLSPEC_HIDDEN;
344 const char *debug_print_opcode(DWORD opcode) DECLSPEC_HIDDEN;
345
346 /* Used to signal an incorrect swizzle/writemask */
347 #define SWIZZLE_ERR ~0U
348
349 /*
350   Enumerations and defines used in the bytecode writer
351   intermediate representation
352 */
353 typedef enum _BWRITERSHADER_INSTRUCTION_OPCODE_TYPE {
354     BWRITERSIO_NOP,
355     BWRITERSIO_MOV,
356     BWRITERSIO_ADD,
357     BWRITERSIO_SUB,
358     BWRITERSIO_MAD,
359     BWRITERSIO_MUL,
360     BWRITERSIO_RCP,
361     BWRITERSIO_RSQ,
362     BWRITERSIO_DP3,
363     BWRITERSIO_DP4,
364     BWRITERSIO_MIN,
365     BWRITERSIO_MAX,
366     BWRITERSIO_SLT,
367     BWRITERSIO_SGE,
368     BWRITERSIO_EXP,
369     BWRITERSIO_LOG,
370     BWRITERSIO_LIT,
371     BWRITERSIO_DST,
372     BWRITERSIO_LRP,
373     BWRITERSIO_FRC,
374     BWRITERSIO_M4x4,
375     BWRITERSIO_M4x3,
376     BWRITERSIO_M3x4,
377     BWRITERSIO_M3x3,
378     BWRITERSIO_M3x2,
379     BWRITERSIO_CALL,
380     BWRITERSIO_CALLNZ,
381     BWRITERSIO_LOOP,
382     BWRITERSIO_RET,
383     BWRITERSIO_ENDLOOP,
384     BWRITERSIO_LABEL,
385     BWRITERSIO_DCL,
386     BWRITERSIO_POW,
387     BWRITERSIO_CRS,
388     BWRITERSIO_SGN,
389     BWRITERSIO_ABS,
390     BWRITERSIO_NRM,
391     BWRITERSIO_SINCOS,
392     BWRITERSIO_REP,
393     BWRITERSIO_ENDREP,
394     BWRITERSIO_IF,
395     BWRITERSIO_IFC,
396     BWRITERSIO_ELSE,
397     BWRITERSIO_ENDIF,
398     BWRITERSIO_BREAK,
399     BWRITERSIO_BREAKC,
400     BWRITERSIO_MOVA,
401     BWRITERSIO_DEFB,
402     BWRITERSIO_DEFI,
403
404     BWRITERSIO_TEXCOORD,
405     BWRITERSIO_TEXKILL,
406     BWRITERSIO_TEX,
407     BWRITERSIO_TEXBEM,
408     BWRITERSIO_TEXBEML,
409     BWRITERSIO_TEXREG2AR,
410     BWRITERSIO_TEXREG2GB,
411     BWRITERSIO_TEXM3x2PAD,
412     BWRITERSIO_TEXM3x2TEX,
413     BWRITERSIO_TEXM3x3PAD,
414     BWRITERSIO_TEXM3x3TEX,
415     BWRITERSIO_TEXM3x3SPEC,
416     BWRITERSIO_TEXM3x3VSPEC,
417     BWRITERSIO_EXPP,
418     BWRITERSIO_LOGP,
419     BWRITERSIO_CND,
420     BWRITERSIO_DEF,
421     BWRITERSIO_TEXREG2RGB,
422     BWRITERSIO_TEXDP3TEX,
423     BWRITERSIO_TEXM3x2DEPTH,
424     BWRITERSIO_TEXDP3,
425     BWRITERSIO_TEXM3x3,
426     BWRITERSIO_TEXDEPTH,
427     BWRITERSIO_CMP,
428     BWRITERSIO_BEM,
429     BWRITERSIO_DP2ADD,
430     BWRITERSIO_DSX,
431     BWRITERSIO_DSY,
432     BWRITERSIO_TEXLDD,
433     BWRITERSIO_SETP,
434     BWRITERSIO_TEXLDL,
435     BWRITERSIO_BREAKP,
436     BWRITERSIO_TEXLDP,
437     BWRITERSIO_TEXLDB,
438
439     BWRITERSIO_PHASE,
440     BWRITERSIO_COMMENT,
441     BWRITERSIO_END,
442 } BWRITERSHADER_INSTRUCTION_OPCODE_TYPE;
443
444 typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE {
445     BWRITERSPR_TEMP,
446     BWRITERSPR_INPUT,
447     BWRITERSPR_CONST,
448     BWRITERSPR_ADDR,
449     BWRITERSPR_TEXTURE,
450     BWRITERSPR_RASTOUT,
451     BWRITERSPR_ATTROUT,
452     BWRITERSPR_TEXCRDOUT,
453     BWRITERSPR_OUTPUT,
454     BWRITERSPR_CONSTINT,
455     BWRITERSPR_COLOROUT,
456     BWRITERSPR_DEPTHOUT,
457     BWRITERSPR_SAMPLER,
458     BWRITERSPR_CONSTBOOL,
459     BWRITERSPR_LOOP,
460     BWRITERSPR_MISCTYPE,
461     BWRITERSPR_LABEL,
462     BWRITERSPR_PREDICATE
463 } BWRITERSHADER_PARAM_REGISTER_TYPE;
464
465 typedef enum _BWRITERVS_RASTOUT_OFFSETS
466 {
467     BWRITERSRO_POSITION,
468     BWRITERSRO_FOG,
469     BWRITERSRO_POINT_SIZE
470 } BWRITERVS_RASTOUT_OFFSETS;
471
472 #define BWRITERSP_WRITEMASK_0   0x1 /* .x r */
473 #define BWRITERSP_WRITEMASK_1   0x2 /* .y g */
474 #define BWRITERSP_WRITEMASK_2   0x4 /* .z b */
475 #define BWRITERSP_WRITEMASK_3   0x8 /* .w a */
476 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
477
478 typedef enum _BWRITERSHADER_PARAM_DSTMOD_TYPE {
479     BWRITERSPDM_NONE = 0,
480     BWRITERSPDM_SATURATE = 1,
481     BWRITERSPDM_PARTIALPRECISION = 2,
482     BWRITERSPDM_MSAMPCENTROID = 4,
483 } BWRITERSHADER_PARAM_DSTMOD_TYPE;
484
485 typedef enum _BWRITERSAMPLER_TEXTURE_TYPE {
486     BWRITERSTT_UNKNOWN = 0,
487     BWRITERSTT_1D = 1,
488     BWRITERSTT_2D = 2,
489     BWRITERSTT_CUBE = 3,
490     BWRITERSTT_VOLUME = 4,
491 } BWRITERSAMPLER_TEXTURE_TYPE;
492
493 #define BWRITERSI_TEXLD_PROJECT 1
494 #define BWRITERSI_TEXLD_BIAS    2
495
496 typedef enum _BWRITERSHADER_PARAM_SRCMOD_TYPE {
497     BWRITERSPSM_NONE = 0,
498     BWRITERSPSM_NEG,
499     BWRITERSPSM_BIAS,
500     BWRITERSPSM_BIASNEG,
501     BWRITERSPSM_SIGN,
502     BWRITERSPSM_SIGNNEG,
503     BWRITERSPSM_COMP,
504     BWRITERSPSM_X2,
505     BWRITERSPSM_X2NEG,
506     BWRITERSPSM_DZ,
507     BWRITERSPSM_DW,
508     BWRITERSPSM_ABS,
509     BWRITERSPSM_ABSNEG,
510     BWRITERSPSM_NOT,
511 } BWRITERSHADER_PARAM_SRCMOD_TYPE;
512
513 #define BWRITER_SM1_VS  0xfffe
514 #define BWRITER_SM1_PS  0xffff
515
516 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
517 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
518
519 #define BWRITERVS_SWIZZLE_SHIFT      16
520 #define BWRITERVS_SWIZZLE_MASK       (0xFF << BWRITERVS_SWIZZLE_SHIFT)
521
522 #define BWRITERVS_X_X       (0 << BWRITERVS_SWIZZLE_SHIFT)
523 #define BWRITERVS_X_Y       (1 << BWRITERVS_SWIZZLE_SHIFT)
524 #define BWRITERVS_X_Z       (2 << BWRITERVS_SWIZZLE_SHIFT)
525 #define BWRITERVS_X_W       (3 << BWRITERVS_SWIZZLE_SHIFT)
526
527 #define BWRITERVS_Y_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 2))
528 #define BWRITERVS_Y_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 2))
529 #define BWRITERVS_Y_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 2))
530 #define BWRITERVS_Y_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
531
532 #define BWRITERVS_Z_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 4))
533 #define BWRITERVS_Z_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 4))
534 #define BWRITERVS_Z_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 4))
535 #define BWRITERVS_Z_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
536
537 #define BWRITERVS_W_X       (0 << (BWRITERVS_SWIZZLE_SHIFT + 6))
538 #define BWRITERVS_W_Y       (1 << (BWRITERVS_SWIZZLE_SHIFT + 6))
539 #define BWRITERVS_W_Z       (2 << (BWRITERVS_SWIZZLE_SHIFT + 6))
540 #define BWRITERVS_W_W       (3 << (BWRITERVS_SWIZZLE_SHIFT + 6))
541
542 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
543
544 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
545 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
546 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
547 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
548
549 typedef enum _BWRITERDECLUSAGE {
550     BWRITERDECLUSAGE_POSITION,
551     BWRITERDECLUSAGE_BLENDWEIGHT,
552     BWRITERDECLUSAGE_BLENDINDICES,
553     BWRITERDECLUSAGE_NORMAL,
554     BWRITERDECLUSAGE_PSIZE,
555     BWRITERDECLUSAGE_TEXCOORD,
556     BWRITERDECLUSAGE_TANGENT,
557     BWRITERDECLUSAGE_BINORMAL,
558     BWRITERDECLUSAGE_TESSFACTOR,
559     BWRITERDECLUSAGE_POSITIONT,
560     BWRITERDECLUSAGE_COLOR,
561     BWRITERDECLUSAGE_FOG,
562     BWRITERDECLUSAGE_DEPTH,
563     BWRITERDECLUSAGE_SAMPLE
564 } BWRITERDECLUSAGE;
565
566 /* ps 1.x texture registers mappings */
567 #define T0_REG          2
568 #define T1_REG          3
569 #define T2_REG          4
570 #define T3_REG          5
571
572 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) DECLSPEC_HIDDEN;
573 DWORD SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result) DECLSPEC_HIDDEN;
574 void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN;
575
576 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
577     ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
578     ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
579 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
580 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
581 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
582 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
583 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
584 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
585 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
586 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
587 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
588 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
589 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
590 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
591 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
592
593 struct dxbc_section
594 {
595     DWORD tag;
596     const char *data;
597     DWORD data_size;
598 };
599
600 struct dxbc
601 {
602     UINT size;
603     UINT count;
604     struct dxbc_section *sections;
605 };
606
607 HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN;
608 void dxbc_destroy(struct dxbc *dxbc) DECLSPEC_HIDDEN;
609 HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) DECLSPEC_HIDDEN;
610 HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, DWORD data_size) DECLSPEC_HIDDEN;
611 HRESULT dxbc_init(struct dxbc *dxbc, DWORD count) DECLSPEC_HIDDEN;
612
613 static inline void read_dword(const char **ptr, DWORD *d)
614 {
615     memcpy(d, *ptr, sizeof(*d));
616     *ptr += sizeof(*d);
617 }
618
619 static inline void write_dword(char **ptr, DWORD d)
620 {
621     memcpy(*ptr, &d, sizeof(d));
622     *ptr += sizeof(d);
623 }
624
625 void skip_dword_unknown(const char **ptr, unsigned int count) DECLSPEC_HIDDEN;
626
627 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */