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