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