d3dcompiler_43: Remove DECLSPEC_HIDDEN usage.
[wine.git] / dlls / d3dcompiler_43 / d3dcompiler_private.h
blobc1349fbfc4dfbe53bbd33a30287aba1b90b7c360
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>
41 #include <vkd3d_shader.h>
44 * This doesn't belong here, but for some functions it is possible to return that value,
45 * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
46 * The original definition is in D3DX10core.h.
48 #define D3DERR_INVALIDCALL 0x8876086c
50 /* TRACE helper functions */
51 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part);
52 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c);
53 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t);
55 enum shader_type
57 ST_UNKNOWN,
58 ST_VERTEX,
59 ST_PIXEL
62 enum bwriter_comparison_type
64 BWRITER_COMPARISON_NONE,
65 BWRITER_COMPARISON_GT,
66 BWRITER_COMPARISON_EQ,
67 BWRITER_COMPARISON_GE,
68 BWRITER_COMPARISON_LT,
69 BWRITER_COMPARISON_NE,
70 BWRITER_COMPARISON_LE
73 struct constant
75 unsigned int regnum;
76 union
78 float f;
79 int i;
80 BOOL b;
81 uint32_t d;
82 } value[4];
85 struct shader_reg
87 uint32_t type;
88 unsigned int regnum;
89 struct shader_reg *rel_reg;
90 uint32_t srcmod;
91 union
93 uint32_t swizzle;
94 uint32_t writemask;
98 struct instruction
100 uint32_t opcode;
101 uint32_t dstmod;
102 uint32_t shift;
103 enum bwriter_comparison_type comptype;
104 BOOL has_dst;
105 struct shader_reg dst;
106 struct shader_reg *src;
107 unsigned int num_srcs; /* For freeing the rel_regs */
108 BOOL has_predicate;
109 struct shader_reg predicate;
110 BOOL coissue;
113 struct declaration
115 uint32_t usage, usage_idx;
116 uint32_t regnum;
117 uint32_t mod;
118 uint32_t writemask;
119 BOOL builtin;
122 struct samplerdecl
124 uint32_t type;
125 uint32_t regnum;
126 uint32_t mod;
129 struct bwriter_shader
131 enum shader_type type;
132 unsigned char major_version, minor_version;
134 /* Local constants. Every constant that is not defined below is loaded from
135 * the global constant set at shader runtime
137 struct constant **constF;
138 struct constant **constI;
139 struct constant **constB;
140 unsigned int num_cf, num_ci, num_cb;
142 /* Declared input and output varyings */
143 struct declaration *inputs, *outputs;
144 unsigned int num_inputs, num_outputs;
145 struct samplerdecl *samplers;
146 unsigned int num_samplers;
148 /* Are special pixel shader 3.0 registers declared? */
149 BOOL vPos, vFace;
151 /* Array of shader instructions - The shader code itself */
152 struct instruction **instr;
153 unsigned int num_instrs, instr_alloc_size;
156 static inline void *d3dcompiler_alloc(SIZE_T size)
158 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
161 static inline void *d3dcompiler_realloc(void *ptr, SIZE_T size)
163 if (!ptr)
164 return d3dcompiler_alloc(size);
165 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
168 static inline BOOL d3dcompiler_free(void *ptr)
170 return HeapFree(GetProcessHeap(), 0, ptr);
173 struct asm_parser;
175 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
176 * too it has to know it as well
178 struct rel_reg
180 BOOL has_rel_reg;
181 uint32_t type;
182 uint32_t additional_offset;
183 uint32_t rel_regnum;
184 uint32_t swizzle;
187 #define MAX_SRC_REGS 4
189 struct src_regs
191 struct shader_reg reg[MAX_SRC_REGS];
192 unsigned int count;
195 struct asmparser_backend
197 void (*constF)(struct asm_parser *This, uint32_t reg, float x, float y, float z, float w);
198 void (*constI)(struct asm_parser *This, uint32_t reg, int x, int y, int z, int w);
199 void (*constB)(struct asm_parser *This, uint32_t reg, BOOL x);
201 void (*dstreg)(struct asm_parser *This, struct instruction *instr,
202 const struct shader_reg *dst);
203 void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num,
204 const struct shader_reg *src);
206 void (*predicate)(struct asm_parser *This,
207 const struct shader_reg *predicate);
208 void (*coissue)(struct asm_parser *This);
210 void (*dcl_output)(struct asm_parser *This, uint32_t usage, uint32_t num,
211 const struct shader_reg *reg);
212 void (*dcl_input)(struct asm_parser *This, uint32_t usage, uint32_t num,
213 uint32_t mod, const struct shader_reg *reg);
214 void (*dcl_sampler)(struct asm_parser *This, uint32_t samptype, uint32_t mod,
215 uint32_t regnum, unsigned int line_no);
217 void (*end)(struct asm_parser *This);
219 void (*instr)(struct asm_parser *parser, uint32_t opcode, uint32_t mod, uint32_t shift,
220 enum bwriter_comparison_type comp, const struct shader_reg *dst,
221 const struct src_regs *srcs, int expectednsrcs);
224 struct instruction *alloc_instr(unsigned int srcs);
225 BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr);
226 BOOL add_constF(struct bwriter_shader *shader, uint32_t reg, float x, float y, float z, float w);
227 BOOL add_constI(struct bwriter_shader *shader, uint32_t reg, int x, int y, int z, int w);
228 BOOL add_constB(struct bwriter_shader *shader, uint32_t reg, BOOL x);
229 BOOL record_declaration(struct bwriter_shader *shader, uint32_t usage, uint32_t usage_idx,
230 uint32_t mod, BOOL output, uint32_t regnum, uint32_t writemask, BOOL builtin);
231 BOOL record_sampler(struct bwriter_shader *shader, uint32_t samptype, uint32_t mod, uint32_t regnum);
233 #define MESSAGEBUFFER_INITIAL_SIZE 256
235 enum parse_status
237 PARSE_SUCCESS = 0,
238 PARSE_WARN = 1,
239 PARSE_ERR = 2
242 struct compilation_messages
244 char *string;
245 unsigned int size;
246 unsigned int capacity;
249 struct asm_parser
251 /* The function table of the parser implementation */
252 const struct asmparser_backend *funcs;
254 /* Private data follows */
255 struct bwriter_shader *shader;
256 unsigned int m3x3pad_count;
258 enum parse_status status;
259 struct compilation_messages messages;
260 unsigned int line_no;
263 extern struct asm_parser asm_ctx;
265 void create_vs10_parser(struct asm_parser *ret);
266 void create_vs11_parser(struct asm_parser *ret);
267 void create_vs20_parser(struct asm_parser *ret);
268 void create_vs2x_parser(struct asm_parser *ret);
269 void create_vs30_parser(struct asm_parser *ret);
270 void create_ps10_parser(struct asm_parser *ret);
271 void create_ps11_parser(struct asm_parser *ret);
272 void create_ps12_parser(struct asm_parser *ret);
273 void create_ps13_parser(struct asm_parser *ret);
274 void create_ps14_parser(struct asm_parser *ret);
275 void create_ps20_parser(struct asm_parser *ret);
276 void create_ps2x_parser(struct asm_parser *ret);
277 void create_ps30_parser(struct asm_parser *ret);
279 struct bwriter_shader *parse_asm_shader(char **messages);
281 #ifdef __GNUC__
282 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
283 #else
284 #define PRINTF_ATTR(fmt,args)
285 #endif
287 void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args);
288 void WINAPIV asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3);
289 static inline void set_parse_status(enum parse_status *current, enum parse_status update)
291 if (update == PARSE_ERR)
292 *current = PARSE_ERR;
293 else if (update == PARSE_WARN && *current == PARSE_SUCCESS)
294 *current = PARSE_WARN;
297 /* Debug utility routines */
298 const char *debug_print_srcmod(uint32_t mod);
299 const char *debug_print_dstmod(uint32_t mod);
300 const char *debug_print_shift(uint32_t shift);
301 const char *debug_print_dstreg(const struct shader_reg *reg);
302 const char *debug_print_srcreg(const struct shader_reg *reg);
303 const char *debug_print_comp(uint32_t comp);
304 const char *debug_print_opcode(uint32_t opcode);
306 /* Used to signal an incorrect swizzle/writemask */
307 #define SWIZZLE_ERR ~0U
309 /* Enumerations and defines used in the bytecode writer intermediate
310 * representation. */
311 enum bwritershader_instruction_opcode_type
313 BWRITERSIO_NOP,
314 BWRITERSIO_MOV,
315 BWRITERSIO_ADD,
316 BWRITERSIO_SUB,
317 BWRITERSIO_MAD,
318 BWRITERSIO_MUL,
319 BWRITERSIO_RCP,
320 BWRITERSIO_RSQ,
321 BWRITERSIO_DP3,
322 BWRITERSIO_DP4,
323 BWRITERSIO_MIN,
324 BWRITERSIO_MAX,
325 BWRITERSIO_SLT,
326 BWRITERSIO_SGE,
327 BWRITERSIO_EXP,
328 BWRITERSIO_LOG,
329 BWRITERSIO_LIT,
330 BWRITERSIO_DST,
331 BWRITERSIO_LRP,
332 BWRITERSIO_FRC,
333 BWRITERSIO_M4x4,
334 BWRITERSIO_M4x3,
335 BWRITERSIO_M3x4,
336 BWRITERSIO_M3x3,
337 BWRITERSIO_M3x2,
338 BWRITERSIO_CALL,
339 BWRITERSIO_CALLNZ,
340 BWRITERSIO_LOOP,
341 BWRITERSIO_RET,
342 BWRITERSIO_ENDLOOP,
343 BWRITERSIO_LABEL,
344 BWRITERSIO_DCL,
345 BWRITERSIO_POW,
346 BWRITERSIO_CRS,
347 BWRITERSIO_SGN,
348 BWRITERSIO_ABS,
349 BWRITERSIO_NRM,
350 BWRITERSIO_SINCOS,
351 BWRITERSIO_REP,
352 BWRITERSIO_ENDREP,
353 BWRITERSIO_IF,
354 BWRITERSIO_IFC,
355 BWRITERSIO_ELSE,
356 BWRITERSIO_ENDIF,
357 BWRITERSIO_BREAK,
358 BWRITERSIO_BREAKC,
359 BWRITERSIO_MOVA,
360 BWRITERSIO_DEFB,
361 BWRITERSIO_DEFI,
363 BWRITERSIO_TEXCOORD,
364 BWRITERSIO_TEXKILL,
365 BWRITERSIO_TEX,
366 BWRITERSIO_TEXBEM,
367 BWRITERSIO_TEXBEML,
368 BWRITERSIO_TEXREG2AR,
369 BWRITERSIO_TEXREG2GB,
370 BWRITERSIO_TEXM3x2PAD,
371 BWRITERSIO_TEXM3x2TEX,
372 BWRITERSIO_TEXM3x3PAD,
373 BWRITERSIO_TEXM3x3TEX,
374 BWRITERSIO_TEXM3x3SPEC,
375 BWRITERSIO_TEXM3x3VSPEC,
376 BWRITERSIO_EXPP,
377 BWRITERSIO_LOGP,
378 BWRITERSIO_CND,
379 BWRITERSIO_DEF,
380 BWRITERSIO_TEXREG2RGB,
381 BWRITERSIO_TEXDP3TEX,
382 BWRITERSIO_TEXM3x2DEPTH,
383 BWRITERSIO_TEXDP3,
384 BWRITERSIO_TEXM3x3,
385 BWRITERSIO_TEXDEPTH,
386 BWRITERSIO_CMP,
387 BWRITERSIO_BEM,
388 BWRITERSIO_DP2ADD,
389 BWRITERSIO_DSX,
390 BWRITERSIO_DSY,
391 BWRITERSIO_TEXLDD,
392 BWRITERSIO_SETP,
393 BWRITERSIO_TEXLDL,
394 BWRITERSIO_BREAKP,
395 BWRITERSIO_TEXLDP,
396 BWRITERSIO_TEXLDB,
398 BWRITERSIO_PHASE,
399 BWRITERSIO_COMMENT,
400 BWRITERSIO_END,
403 enum bwritershader_param_register_type
405 BWRITERSPR_TEMP,
406 BWRITERSPR_INPUT,
407 BWRITERSPR_CONST,
408 BWRITERSPR_ADDR,
409 BWRITERSPR_TEXTURE,
410 BWRITERSPR_RASTOUT,
411 BWRITERSPR_ATTROUT,
412 BWRITERSPR_TEXCRDOUT,
413 BWRITERSPR_OUTPUT,
414 BWRITERSPR_CONSTINT,
415 BWRITERSPR_COLOROUT,
416 BWRITERSPR_DEPTHOUT,
417 BWRITERSPR_SAMPLER,
418 BWRITERSPR_CONSTBOOL,
419 BWRITERSPR_LOOP,
420 BWRITERSPR_MISCTYPE,
421 BWRITERSPR_LABEL,
422 BWRITERSPR_PREDICATE
425 enum bwritervs_rastout_offsets
427 BWRITERSRO_POSITION,
428 BWRITERSRO_FOG,
429 BWRITERSRO_POINT_SIZE
432 #define BWRITERSP_WRITEMASK_0 0x1 /* .x r */
433 #define BWRITERSP_WRITEMASK_1 0x2 /* .y g */
434 #define BWRITERSP_WRITEMASK_2 0x4 /* .z b */
435 #define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
436 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
438 enum bwritershader_param_dstmod_type
440 BWRITERSPDM_NONE = 0,
441 BWRITERSPDM_SATURATE = 1,
442 BWRITERSPDM_PARTIALPRECISION = 2,
443 BWRITERSPDM_MSAMPCENTROID = 4,
446 enum bwritersampler_texture_type
448 BWRITERSTT_UNKNOWN = 0,
449 BWRITERSTT_1D = 1,
450 BWRITERSTT_2D = 2,
451 BWRITERSTT_CUBE = 3,
452 BWRITERSTT_VOLUME = 4,
455 #define BWRITERSI_TEXLD_PROJECT 1
456 #define BWRITERSI_TEXLD_BIAS 2
458 enum bwritershader_param_srcmod_type
460 BWRITERSPSM_NONE = 0,
461 BWRITERSPSM_NEG,
462 BWRITERSPSM_BIAS,
463 BWRITERSPSM_BIASNEG,
464 BWRITERSPSM_SIGN,
465 BWRITERSPSM_SIGNNEG,
466 BWRITERSPSM_COMP,
467 BWRITERSPSM_X2,
468 BWRITERSPSM_X2NEG,
469 BWRITERSPSM_DZ,
470 BWRITERSPSM_DW,
471 BWRITERSPSM_ABS,
472 BWRITERSPSM_ABSNEG,
473 BWRITERSPSM_NOT,
476 #define BWRITER_SM1_VS 0xfffeu
477 #define BWRITER_SM1_PS 0xffffu
479 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
480 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
482 #define BWRITERVS_X_X (0)
483 #define BWRITERVS_X_Y (1)
484 #define BWRITERVS_X_Z (2)
485 #define BWRITERVS_X_W (3)
487 #define BWRITERVS_Y_X (0 << 2)
488 #define BWRITERVS_Y_Y (1 << 2)
489 #define BWRITERVS_Y_Z (2 << 2)
490 #define BWRITERVS_Y_W (3 << 2)
492 #define BWRITERVS_Z_X (0 << 4)
493 #define BWRITERVS_Z_Y (1 << 4)
494 #define BWRITERVS_Z_Z (2 << 4)
495 #define BWRITERVS_Z_W (3 << 4)
497 #define BWRITERVS_W_X (0 << 6)
498 #define BWRITERVS_W_Y (1 << 6)
499 #define BWRITERVS_W_Z (2 << 6)
500 #define BWRITERVS_W_W (3 << 6)
502 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
504 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
505 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
506 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
507 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
509 enum bwriterdeclusage
511 BWRITERDECLUSAGE_POSITION,
512 BWRITERDECLUSAGE_BLENDWEIGHT,
513 BWRITERDECLUSAGE_BLENDINDICES,
514 BWRITERDECLUSAGE_NORMAL,
515 BWRITERDECLUSAGE_PSIZE,
516 BWRITERDECLUSAGE_TEXCOORD,
517 BWRITERDECLUSAGE_TANGENT,
518 BWRITERDECLUSAGE_BINORMAL,
519 BWRITERDECLUSAGE_TESSFACTOR,
520 BWRITERDECLUSAGE_POSITIONT,
521 BWRITERDECLUSAGE_COLOR,
522 BWRITERDECLUSAGE_FOG,
523 BWRITERDECLUSAGE_DEPTH,
524 BWRITERDECLUSAGE_SAMPLE
527 /* ps 1.x texture registers mappings */
528 #define T0_REG 2
529 #define T1_REG 3
530 #define T2_REG 4
531 #define T3_REG 5
533 struct bwriter_shader *SlAssembleShader(const char *text, char **messages);
534 HRESULT shader_write_bytecode(const struct bwriter_shader *shader, uint32_t **result, uint32_t *size);
535 void SlDeleteShader(struct bwriter_shader *shader);
537 #define DXBC_HEADER_SIZE (8 * sizeof(uint32_t))
539 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
540 ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
541 ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
542 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
543 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
544 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
545 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
546 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
547 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
548 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
549 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
550 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
551 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
552 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
553 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
554 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
556 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */