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