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