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