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