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