winegstreamer: Remove support for flushing the wg_parser object.
[wine.git] / dlls / d3dcompiler_43 / d3dcompiler_private.h
blob6dea5a08a85cc9e877deab29376193fc97d73a11
1 /*
2 * Copyright 2008 Stefan Dösinger
3 * Copyright 2009 Matteo Bruni
4 * Copyright 2010 Rico Schüller
5 * Copyright 2012 Matteo Bruni for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifndef __WINE_D3DCOMPILER_PRIVATE_H
23 #define __WINE_D3DCOMPILER_PRIVATE_H
25 #include "wine/debug.h"
26 #include "wine/list.h"
27 #include "wine/rbtree.h"
28 #include "wine/heap.h"
30 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "objbase.h"
35 #include "d3dcompiler.h"
36 #include "utils.h"
38 #include <assert.h>
39 #include <stdint.h>
42 * This doesn't belong here, but for some functions it is possible to return that value,
43 * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
44 * The original definition is in D3DX10core.h.
46 #define D3DERR_INVALIDCALL 0x8876086c
48 /* TRACE helper functions */
49 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part) DECLSPEC_HIDDEN;
50 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c) DECLSPEC_HIDDEN;
51 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t) DECLSPEC_HIDDEN;
53 enum shader_type
55 ST_UNKNOWN,
56 ST_VERTEX,
57 ST_PIXEL
60 enum bwriter_comparison_type
62 BWRITER_COMPARISON_NONE,
63 BWRITER_COMPARISON_GT,
64 BWRITER_COMPARISON_EQ,
65 BWRITER_COMPARISON_GE,
66 BWRITER_COMPARISON_LT,
67 BWRITER_COMPARISON_NE,
68 BWRITER_COMPARISON_LE
71 struct constant
73 unsigned int regnum;
74 union
76 float f;
77 int i;
78 BOOL b;
79 uint32_t d;
80 } value[4];
83 struct shader_reg
85 uint32_t type;
86 unsigned int regnum;
87 struct shader_reg *rel_reg;
88 uint32_t srcmod;
89 union
91 uint32_t swizzle;
92 uint32_t writemask;
96 struct instruction
98 uint32_t opcode;
99 uint32_t dstmod;
100 uint32_t shift;
101 enum bwriter_comparison_type comptype;
102 BOOL has_dst;
103 struct shader_reg dst;
104 struct shader_reg *src;
105 unsigned int num_srcs; /* For freeing the rel_regs */
106 BOOL has_predicate;
107 struct shader_reg predicate;
108 BOOL coissue;
111 struct declaration
113 uint32_t usage, usage_idx;
114 uint32_t regnum;
115 uint32_t mod;
116 uint32_t writemask;
117 BOOL builtin;
120 struct samplerdecl
122 uint32_t type;
123 uint32_t regnum;
124 uint32_t mod;
127 struct bwriter_shader
129 enum shader_type type;
130 unsigned char major_version, minor_version;
132 /* Local constants. Every constant that is not defined below is loaded from
133 * the global constant set at shader runtime
135 struct constant **constF;
136 struct constant **constI;
137 struct constant **constB;
138 unsigned int num_cf, num_ci, num_cb;
140 /* Declared input and output varyings */
141 struct declaration *inputs, *outputs;
142 unsigned int num_inputs, num_outputs;
143 struct samplerdecl *samplers;
144 unsigned int num_samplers;
146 /* Are special pixel shader 3.0 registers declared? */
147 BOOL vPos, vFace;
149 /* Array of shader instructions - The shader code itself */
150 struct instruction **instr;
151 unsigned int num_instrs, instr_alloc_size;
154 static inline void *d3dcompiler_alloc(SIZE_T size)
156 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
159 static inline void *d3dcompiler_realloc(void *ptr, SIZE_T size)
161 if (!ptr)
162 return d3dcompiler_alloc(size);
163 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
166 static inline BOOL d3dcompiler_free(void *ptr)
168 return HeapFree(GetProcessHeap(), 0, ptr);
171 struct asm_parser;
173 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
174 * too it has to know it as well
176 struct rel_reg
178 BOOL has_rel_reg;
179 uint32_t type;
180 uint32_t additional_offset;
181 uint32_t rel_regnum;
182 uint32_t swizzle;
185 #define MAX_SRC_REGS 4
187 struct src_regs
189 struct shader_reg reg[MAX_SRC_REGS];
190 unsigned int count;
193 struct asmparser_backend
195 void (*constF)(struct asm_parser *This, uint32_t reg, float x, float y, float z, float w);
196 void (*constI)(struct asm_parser *This, uint32_t reg, int x, int y, int z, int w);
197 void (*constB)(struct asm_parser *This, uint32_t reg, BOOL x);
199 void (*dstreg)(struct asm_parser *This, struct instruction *instr,
200 const struct shader_reg *dst);
201 void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num,
202 const struct shader_reg *src);
204 void (*predicate)(struct asm_parser *This,
205 const struct shader_reg *predicate);
206 void (*coissue)(struct asm_parser *This);
208 void (*dcl_output)(struct asm_parser *This, uint32_t usage, uint32_t num,
209 const struct shader_reg *reg);
210 void (*dcl_input)(struct asm_parser *This, uint32_t usage, uint32_t num,
211 uint32_t mod, const struct shader_reg *reg);
212 void (*dcl_sampler)(struct asm_parser *This, uint32_t samptype, uint32_t mod,
213 uint32_t regnum, unsigned int line_no);
215 void (*end)(struct asm_parser *This);
217 void (*instr)(struct asm_parser *parser, uint32_t opcode, uint32_t mod, uint32_t shift,
218 enum bwriter_comparison_type comp, const struct shader_reg *dst,
219 const struct src_regs *srcs, int expectednsrcs);
222 struct instruction *alloc_instr(unsigned int srcs) DECLSPEC_HIDDEN;
223 BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr) DECLSPEC_HIDDEN;
224 BOOL add_constF(struct bwriter_shader *shader, uint32_t reg, float x, float y, float z, float w) DECLSPEC_HIDDEN;
225 BOOL add_constI(struct bwriter_shader *shader, uint32_t reg, int x, int y, int z, int w) DECLSPEC_HIDDEN;
226 BOOL add_constB(struct bwriter_shader *shader, uint32_t reg, BOOL x) DECLSPEC_HIDDEN;
227 BOOL record_declaration(struct bwriter_shader *shader, uint32_t usage, uint32_t usage_idx,
228 uint32_t mod, BOOL output, uint32_t regnum, uint32_t writemask, BOOL builtin) DECLSPEC_HIDDEN;
229 BOOL record_sampler(struct bwriter_shader *shader, uint32_t samptype, uint32_t mod, uint32_t regnum) DECLSPEC_HIDDEN;
231 #define MESSAGEBUFFER_INITIAL_SIZE 256
233 enum parse_status
235 PARSE_SUCCESS = 0,
236 PARSE_WARN = 1,
237 PARSE_ERR = 2
240 struct compilation_messages
242 char *string;
243 unsigned int size;
244 unsigned int capacity;
247 struct asm_parser
249 /* The function table of the parser implementation */
250 const struct asmparser_backend *funcs;
252 /* Private data follows */
253 struct bwriter_shader *shader;
254 unsigned int m3x3pad_count;
256 enum parse_status status;
257 struct compilation_messages messages;
258 unsigned int line_no;
261 extern struct asm_parser asm_ctx DECLSPEC_HIDDEN;
263 void create_vs10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
264 void create_vs11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
265 void create_vs20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
266 void create_vs2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
267 void create_vs30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
268 void create_ps10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
269 void create_ps11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
270 void create_ps12_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
271 void create_ps13_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
272 void create_ps14_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
273 void create_ps20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
274 void create_ps2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
275 void create_ps30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
277 struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN;
279 #ifdef __GNUC__
280 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
281 #else
282 #define PRINTF_ATTR(fmt,args)
283 #endif
285 void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args) DECLSPEC_HIDDEN;
286 void WINAPIV asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
287 static inline void set_parse_status(enum parse_status *current, enum parse_status update)
289 if (update == PARSE_ERR)
290 *current = PARSE_ERR;
291 else if (update == PARSE_WARN && *current == PARSE_SUCCESS)
292 *current = PARSE_WARN;
295 /* Debug utility routines */
296 const char *debug_print_srcmod(uint32_t mod) DECLSPEC_HIDDEN;
297 const char *debug_print_dstmod(uint32_t mod) DECLSPEC_HIDDEN;
298 const char *debug_print_shift(uint32_t shift) DECLSPEC_HIDDEN;
299 const char *debug_print_dstreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
300 const char *debug_print_srcreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
301 const char *debug_print_comp(uint32_t comp) DECLSPEC_HIDDEN;
302 const char *debug_print_opcode(uint32_t opcode) DECLSPEC_HIDDEN;
304 /* Used to signal an incorrect swizzle/writemask */
305 #define SWIZZLE_ERR ~0U
307 /* Enumerations and defines used in the bytecode writer intermediate
308 * representation. */
309 enum bwritershader_instruction_opcode_type
311 BWRITERSIO_NOP,
312 BWRITERSIO_MOV,
313 BWRITERSIO_ADD,
314 BWRITERSIO_SUB,
315 BWRITERSIO_MAD,
316 BWRITERSIO_MUL,
317 BWRITERSIO_RCP,
318 BWRITERSIO_RSQ,
319 BWRITERSIO_DP3,
320 BWRITERSIO_DP4,
321 BWRITERSIO_MIN,
322 BWRITERSIO_MAX,
323 BWRITERSIO_SLT,
324 BWRITERSIO_SGE,
325 BWRITERSIO_EXP,
326 BWRITERSIO_LOG,
327 BWRITERSIO_LIT,
328 BWRITERSIO_DST,
329 BWRITERSIO_LRP,
330 BWRITERSIO_FRC,
331 BWRITERSIO_M4x4,
332 BWRITERSIO_M4x3,
333 BWRITERSIO_M3x4,
334 BWRITERSIO_M3x3,
335 BWRITERSIO_M3x2,
336 BWRITERSIO_CALL,
337 BWRITERSIO_CALLNZ,
338 BWRITERSIO_LOOP,
339 BWRITERSIO_RET,
340 BWRITERSIO_ENDLOOP,
341 BWRITERSIO_LABEL,
342 BWRITERSIO_DCL,
343 BWRITERSIO_POW,
344 BWRITERSIO_CRS,
345 BWRITERSIO_SGN,
346 BWRITERSIO_ABS,
347 BWRITERSIO_NRM,
348 BWRITERSIO_SINCOS,
349 BWRITERSIO_REP,
350 BWRITERSIO_ENDREP,
351 BWRITERSIO_IF,
352 BWRITERSIO_IFC,
353 BWRITERSIO_ELSE,
354 BWRITERSIO_ENDIF,
355 BWRITERSIO_BREAK,
356 BWRITERSIO_BREAKC,
357 BWRITERSIO_MOVA,
358 BWRITERSIO_DEFB,
359 BWRITERSIO_DEFI,
361 BWRITERSIO_TEXCOORD,
362 BWRITERSIO_TEXKILL,
363 BWRITERSIO_TEX,
364 BWRITERSIO_TEXBEM,
365 BWRITERSIO_TEXBEML,
366 BWRITERSIO_TEXREG2AR,
367 BWRITERSIO_TEXREG2GB,
368 BWRITERSIO_TEXM3x2PAD,
369 BWRITERSIO_TEXM3x2TEX,
370 BWRITERSIO_TEXM3x3PAD,
371 BWRITERSIO_TEXM3x3TEX,
372 BWRITERSIO_TEXM3x3SPEC,
373 BWRITERSIO_TEXM3x3VSPEC,
374 BWRITERSIO_EXPP,
375 BWRITERSIO_LOGP,
376 BWRITERSIO_CND,
377 BWRITERSIO_DEF,
378 BWRITERSIO_TEXREG2RGB,
379 BWRITERSIO_TEXDP3TEX,
380 BWRITERSIO_TEXM3x2DEPTH,
381 BWRITERSIO_TEXDP3,
382 BWRITERSIO_TEXM3x3,
383 BWRITERSIO_TEXDEPTH,
384 BWRITERSIO_CMP,
385 BWRITERSIO_BEM,
386 BWRITERSIO_DP2ADD,
387 BWRITERSIO_DSX,
388 BWRITERSIO_DSY,
389 BWRITERSIO_TEXLDD,
390 BWRITERSIO_SETP,
391 BWRITERSIO_TEXLDL,
392 BWRITERSIO_BREAKP,
393 BWRITERSIO_TEXLDP,
394 BWRITERSIO_TEXLDB,
396 BWRITERSIO_PHASE,
397 BWRITERSIO_COMMENT,
398 BWRITERSIO_END,
401 enum bwritershader_param_register_type
403 BWRITERSPR_TEMP,
404 BWRITERSPR_INPUT,
405 BWRITERSPR_CONST,
406 BWRITERSPR_ADDR,
407 BWRITERSPR_TEXTURE,
408 BWRITERSPR_RASTOUT,
409 BWRITERSPR_ATTROUT,
410 BWRITERSPR_TEXCRDOUT,
411 BWRITERSPR_OUTPUT,
412 BWRITERSPR_CONSTINT,
413 BWRITERSPR_COLOROUT,
414 BWRITERSPR_DEPTHOUT,
415 BWRITERSPR_SAMPLER,
416 BWRITERSPR_CONSTBOOL,
417 BWRITERSPR_LOOP,
418 BWRITERSPR_MISCTYPE,
419 BWRITERSPR_LABEL,
420 BWRITERSPR_PREDICATE
423 enum bwritervs_rastout_offsets
425 BWRITERSRO_POSITION,
426 BWRITERSRO_FOG,
427 BWRITERSRO_POINT_SIZE
430 #define BWRITERSP_WRITEMASK_0 0x1 /* .x r */
431 #define BWRITERSP_WRITEMASK_1 0x2 /* .y g */
432 #define BWRITERSP_WRITEMASK_2 0x4 /* .z b */
433 #define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
434 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
436 enum bwritershader_param_dstmod_type
438 BWRITERSPDM_NONE = 0,
439 BWRITERSPDM_SATURATE = 1,
440 BWRITERSPDM_PARTIALPRECISION = 2,
441 BWRITERSPDM_MSAMPCENTROID = 4,
444 enum bwritersampler_texture_type
446 BWRITERSTT_UNKNOWN = 0,
447 BWRITERSTT_1D = 1,
448 BWRITERSTT_2D = 2,
449 BWRITERSTT_CUBE = 3,
450 BWRITERSTT_VOLUME = 4,
453 #define BWRITERSI_TEXLD_PROJECT 1
454 #define BWRITERSI_TEXLD_BIAS 2
456 enum bwritershader_param_srcmod_type
458 BWRITERSPSM_NONE = 0,
459 BWRITERSPSM_NEG,
460 BWRITERSPSM_BIAS,
461 BWRITERSPSM_BIASNEG,
462 BWRITERSPSM_SIGN,
463 BWRITERSPSM_SIGNNEG,
464 BWRITERSPSM_COMP,
465 BWRITERSPSM_X2,
466 BWRITERSPSM_X2NEG,
467 BWRITERSPSM_DZ,
468 BWRITERSPSM_DW,
469 BWRITERSPSM_ABS,
470 BWRITERSPSM_ABSNEG,
471 BWRITERSPSM_NOT,
474 #define BWRITER_SM1_VS 0xfffeu
475 #define BWRITER_SM1_PS 0xffffu
477 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
478 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
480 #define BWRITERVS_X_X (0)
481 #define BWRITERVS_X_Y (1)
482 #define BWRITERVS_X_Z (2)
483 #define BWRITERVS_X_W (3)
485 #define BWRITERVS_Y_X (0 << 2)
486 #define BWRITERVS_Y_Y (1 << 2)
487 #define BWRITERVS_Y_Z (2 << 2)
488 #define BWRITERVS_Y_W (3 << 2)
490 #define BWRITERVS_Z_X (0 << 4)
491 #define BWRITERVS_Z_Y (1 << 4)
492 #define BWRITERVS_Z_Z (2 << 4)
493 #define BWRITERVS_Z_W (3 << 4)
495 #define BWRITERVS_W_X (0 << 6)
496 #define BWRITERVS_W_Y (1 << 6)
497 #define BWRITERVS_W_Z (2 << 6)
498 #define BWRITERVS_W_W (3 << 6)
500 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
502 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
503 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
504 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
505 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
507 enum bwriterdeclusage
509 BWRITERDECLUSAGE_POSITION,
510 BWRITERDECLUSAGE_BLENDWEIGHT,
511 BWRITERDECLUSAGE_BLENDINDICES,
512 BWRITERDECLUSAGE_NORMAL,
513 BWRITERDECLUSAGE_PSIZE,
514 BWRITERDECLUSAGE_TEXCOORD,
515 BWRITERDECLUSAGE_TANGENT,
516 BWRITERDECLUSAGE_BINORMAL,
517 BWRITERDECLUSAGE_TESSFACTOR,
518 BWRITERDECLUSAGE_POSITIONT,
519 BWRITERDECLUSAGE_COLOR,
520 BWRITERDECLUSAGE_FOG,
521 BWRITERDECLUSAGE_DEPTH,
522 BWRITERDECLUSAGE_SAMPLE
525 /* ps 1.x texture registers mappings */
526 #define T0_REG 2
527 #define T1_REG 3
528 #define T2_REG 4
529 #define T3_REG 5
531 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) DECLSPEC_HIDDEN;
532 HRESULT shader_write_bytecode(const struct bwriter_shader *shader, uint32_t **result, uint32_t *size) DECLSPEC_HIDDEN;
533 void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN;
535 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
536 ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
537 ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
538 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
539 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
540 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
541 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
542 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
543 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
544 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
545 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
546 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
547 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
548 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
549 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
550 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
552 struct dxbc_section
554 DWORD tag;
555 const char *data;
556 DWORD data_size;
559 struct dxbc
561 UINT size;
562 UINT count;
563 struct dxbc_section *sections;
566 HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN;
567 void dxbc_destroy(struct dxbc *dxbc) DECLSPEC_HIDDEN;
568 HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) DECLSPEC_HIDDEN;
569 HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, size_t data_size) DECLSPEC_HIDDEN;
570 HRESULT dxbc_init(struct dxbc *dxbc, unsigned int size) DECLSPEC_HIDDEN;
572 static inline void write_u32(char **ptr, uint32_t u32)
574 memcpy(*ptr, &u32, sizeof(u32));
575 *ptr += sizeof(u32);
578 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */