shdoclc: Remove a space before an ellipsis in the Italian translation.
[wine/hramrach.git] / dlls / d3dcompiler_43 / d3dcompiler_private.h
blob929e635710af5bcd586d3b6a35c30c96c8441452
1 /*
2 * Copyright 2008 Stefan Dösinger
3 * Copyright 2009 Matteo Bruni
4 * Copyright 2010 Rico Schüller
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.
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.
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
21 #ifndef __WINE_D3DCOMPILER_PRIVATE_H
22 #define __WINE_D3DCOMPILER_PRIVATE_H
24 #include <stdarg.h>
26 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "objbase.h"
31 #include "d3dcompiler.h"
34 * This doesn't belong here, but for some functions it is possible to return that value,
35 * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
36 * The original definition is in D3DX10core.h.
38 #define D3DERR_INVALIDCALL 0x8876086c
40 /* ID3DBlob */
41 struct d3dcompiler_blob
43 const struct ID3D10BlobVtbl *vtbl;
44 LONG refcount;
46 SIZE_T size;
47 void *data;
50 HRESULT d3dcompiler_blob_init(struct d3dcompiler_blob *blob, SIZE_T data_size) DECLSPEC_HIDDEN;
52 /* Shader assembler definitions */
53 typedef enum _shader_type {
54 ST_VERTEX,
55 ST_PIXEL,
56 } shader_type;
58 typedef enum BWRITER_COMPARISON_TYPE {
59 BWRITER_COMPARISON_NONE,
60 BWRITER_COMPARISON_GT,
61 BWRITER_COMPARISON_EQ,
62 BWRITER_COMPARISON_GE,
63 BWRITER_COMPARISON_LT,
64 BWRITER_COMPARISON_NE,
65 BWRITER_COMPARISON_LE
66 } BWRITER_COMPARISON_TYPE;
68 struct constant {
69 DWORD regnum;
70 union {
71 float f;
72 INT i;
73 BOOL b;
74 DWORD d;
75 } value[4];
78 struct shader_reg {
79 DWORD type;
80 DWORD regnum;
81 struct shader_reg *rel_reg;
82 DWORD srcmod;
83 union {
84 DWORD swizzle;
85 DWORD writemask;
89 struct instruction {
90 DWORD opcode;
91 DWORD dstmod;
92 DWORD shift;
93 BWRITER_COMPARISON_TYPE comptype;
94 BOOL has_dst;
95 struct shader_reg dst;
96 struct shader_reg *src;
97 unsigned int num_srcs; /* For freeing the rel_regs */
98 BOOL has_predicate;
99 struct shader_reg predicate;
100 BOOL coissue;
103 struct declaration {
104 DWORD usage, usage_idx;
105 DWORD regnum;
106 DWORD mod;
107 DWORD writemask;
108 BOOL builtin;
111 struct samplerdecl {
112 DWORD type;
113 DWORD regnum;
114 DWORD mod;
117 #define INSTRARRAY_INITIAL_SIZE 8
118 struct bwriter_shader {
119 shader_type type;
121 /* Shader version selected */
122 DWORD version;
124 /* Local constants. Every constant that is not defined below is loaded from
125 * the global constant set at shader runtime
127 struct constant **constF;
128 struct constant **constI;
129 struct constant **constB;
130 unsigned int num_cf, num_ci, num_cb;
132 /* Declared input and output varyings */
133 struct declaration *inputs, *outputs;
134 unsigned int num_inputs, num_outputs;
135 struct samplerdecl *samplers;
136 unsigned int num_samplers;
138 /* Are special pixel shader 3.0 registers declared? */
139 BOOL vPos, vFace;
141 /* Array of shader instructions - The shader code itself */
142 struct instruction **instr;
143 unsigned int num_instrs, instr_alloc_size;
146 static inline LPVOID asm_alloc(SIZE_T size) {
147 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
150 static inline LPVOID asm_realloc(LPVOID ptr, SIZE_T size) {
151 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
154 static inline BOOL asm_free(LPVOID ptr) {
155 return HeapFree(GetProcessHeap(), 0, ptr);
158 struct asm_parser;
160 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
161 * too it has to know it as well
163 struct rel_reg {
164 BOOL has_rel_reg;
165 DWORD type;
166 DWORD additional_offset;
167 DWORD rel_regnum;
168 DWORD swizzle;
171 #define MAX_SRC_REGS 4
173 struct src_regs {
174 struct shader_reg reg[MAX_SRC_REGS];
175 unsigned int count;
178 struct asmparser_backend {
179 void (*constF)(struct asm_parser *This, DWORD reg, float x, float y, float z, float w);
180 void (*constI)(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w);
181 void (*constB)(struct asm_parser *This, DWORD reg, BOOL x);
183 void (*dstreg)(struct asm_parser *This, struct instruction *instr,
184 const struct shader_reg *dst);
185 void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num,
186 const struct shader_reg *src);
188 void (*predicate)(struct asm_parser *This,
189 const struct shader_reg *predicate);
190 void (*coissue)(struct asm_parser *This);
192 void (*dcl_output)(struct asm_parser *This, DWORD usage, DWORD num,
193 const struct shader_reg *reg);
194 void (*dcl_input)(struct asm_parser *This, DWORD usage, DWORD num,
195 DWORD mod, const struct shader_reg *reg);
196 void (*dcl_sampler)(struct asm_parser *This, DWORD samptype, DWORD mod,
197 DWORD regnum, unsigned int line_no);
199 void (*end)(struct asm_parser *This);
201 void (*instr)(struct asm_parser *This, DWORD opcode, DWORD mod, DWORD shift,
202 BWRITER_COMPARISON_TYPE comp, const struct shader_reg *dst,
203 const struct src_regs *srcs, int expectednsrcs);
206 struct instruction *alloc_instr(unsigned int srcs);
207 BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr);
208 BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w);
209 BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w);
210 BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x);
211 BOOL record_declaration(struct bwriter_shader *shader, DWORD usage,
212 DWORD usage_idx, DWORD mod, BOOL output,
213 DWORD regnum, DWORD writemask, BOOL builtin);
214 BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype,
215 DWORD mod, DWORD regnum);
217 #define MESSAGEBUFFER_INITIAL_SIZE 256
219 struct asm_parser {
220 /* The function table of the parser implementation */
221 const struct asmparser_backend *funcs;
223 /* Private data follows */
224 struct bwriter_shader *shader;
225 unsigned int m3x3pad_count;
227 enum parse_status {
228 PARSE_SUCCESS = 0,
229 PARSE_WARN = 1,
230 PARSE_ERR = 2
231 } status;
232 char *messages;
233 unsigned int messagesize;
234 unsigned int messagecapacity;
235 unsigned int line_no;
238 extern struct asm_parser asm_ctx;
240 void create_vs10_parser(struct asm_parser *ret);
241 void create_vs11_parser(struct asm_parser *ret);
242 void create_vs20_parser(struct asm_parser *ret);
243 void create_vs2x_parser(struct asm_parser *ret);
244 void create_vs30_parser(struct asm_parser *ret);
245 void create_ps10_parser(struct asm_parser *ret);
246 void create_ps11_parser(struct asm_parser *ret);
247 void create_ps12_parser(struct asm_parser *ret);
248 void create_ps13_parser(struct asm_parser *ret);
249 void create_ps14_parser(struct asm_parser *ret);
250 void create_ps20_parser(struct asm_parser *ret);
251 void create_ps2x_parser(struct asm_parser *ret);
252 void create_ps30_parser(struct asm_parser *ret);
254 struct bwriter_shader *parse_asm_shader(char **messages);
256 #ifdef __GNUC__
257 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
258 #else
259 #define PRINTF_ATTR(fmt,args)
260 #endif
262 void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3);
263 void set_parse_status(struct asm_parser *ctx, enum parse_status status);
265 /* A reasonable value as initial size */
266 #define BYTECODEBUFFER_INITIAL_SIZE 32
267 struct bytecode_buffer {
268 DWORD *data;
269 DWORD size;
270 DWORD alloc_size;
271 /* For tracking rare out of memory situations without passing
272 * return values around everywhere
274 HRESULT state;
277 struct bc_writer; /* Predeclaration for use in vtable parameters */
279 typedef void (*instr_writer)(struct bc_writer *This,
280 const struct instruction *instr,
281 struct bytecode_buffer *buffer);
283 struct bytecode_backend {
284 void (*header)(struct bc_writer *This, const struct bwriter_shader *shader,
285 struct bytecode_buffer *buffer);
286 void (*end)(struct bc_writer *This, const struct bwriter_shader *shader,
287 struct bytecode_buffer *buffer);
288 void (*srcreg)(struct bc_writer *This, const struct shader_reg *reg,
289 struct bytecode_buffer *buffer);
290 void (*dstreg)(struct bc_writer *This, const struct shader_reg *reg,
291 struct bytecode_buffer *buffer, DWORD shift, DWORD mod);
292 void (*opcode)(struct bc_writer *This, const struct instruction *instr,
293 DWORD token, struct bytecode_buffer *buffer);
295 const struct instr_handler_table {
296 DWORD opcode;
297 instr_writer func;
298 } *instructions;
301 /* Bytecode writing stuff */
302 struct bc_writer {
303 const struct bytecode_backend *funcs;
305 /* Avoid result checking */
306 HRESULT state;
308 DWORD version;
310 /* Vertex shader varying mapping */
311 DWORD oPos_regnum;
312 DWORD oD_regnum[2];
313 DWORD oT_regnum[8];
314 DWORD oFog_regnum;
315 DWORD oFog_mask;
316 DWORD oPts_regnum;
317 DWORD oPts_mask;
319 /* Pixel shader specific members */
320 DWORD t_regnum[8];
321 DWORD v_regnum[2];
324 /* Debug utility routines */
325 const char *debug_print_srcmod(DWORD mod);
326 const char *debug_print_dstmod(DWORD mod);
327 const char *debug_print_shift(DWORD shift);
328 const char *debug_print_dstreg(const struct shader_reg *reg);
329 const char *debug_print_srcreg(const struct shader_reg *reg);
330 const char *debug_print_comp(DWORD comp);
331 const char *debug_print_opcode(DWORD opcode);
333 /* Utilities for internal->d3d constant mapping */
334 DWORD d3d9_swizzle(DWORD bwriter_swizzle);
335 DWORD d3d9_writemask(DWORD bwriter_writemask);
336 DWORD d3d9_srcmod(DWORD bwriter_srcmod);
337 DWORD d3d9_dstmod(DWORD bwriter_mod);
338 DWORD d3d9_comparetype(DWORD bwriter_comparetype);
339 DWORD d3d9_sampler(DWORD bwriter_sampler);
340 DWORD d3d9_register(DWORD bwriter_register);
341 DWORD d3d9_opcode(DWORD bwriter_opcode);
343 /* Used to signal an incorrect swizzle/writemask */
344 #define SWIZZLE_ERR ~0U
347 Enumerations and defines used in the bytecode writer
348 intermediate representation
350 typedef enum _BWRITERSHADER_INSTRUCTION_OPCODE_TYPE {
351 BWRITERSIO_NOP,
352 BWRITERSIO_MOV,
353 BWRITERSIO_ADD,
354 BWRITERSIO_SUB,
355 BWRITERSIO_MAD,
356 BWRITERSIO_MUL,
357 BWRITERSIO_RCP,
358 BWRITERSIO_RSQ,
359 BWRITERSIO_DP3,
360 BWRITERSIO_DP4,
361 BWRITERSIO_MIN,
362 BWRITERSIO_MAX,
363 BWRITERSIO_SLT,
364 BWRITERSIO_SGE,
365 BWRITERSIO_EXP,
366 BWRITERSIO_LOG,
367 BWRITERSIO_LIT,
368 BWRITERSIO_DST,
369 BWRITERSIO_LRP,
370 BWRITERSIO_FRC,
371 BWRITERSIO_M4x4,
372 BWRITERSIO_M4x3,
373 BWRITERSIO_M3x4,
374 BWRITERSIO_M3x3,
375 BWRITERSIO_M3x2,
376 BWRITERSIO_CALL,
377 BWRITERSIO_CALLNZ,
378 BWRITERSIO_LOOP,
379 BWRITERSIO_RET,
380 BWRITERSIO_ENDLOOP,
381 BWRITERSIO_LABEL,
382 BWRITERSIO_DCL,
383 BWRITERSIO_POW,
384 BWRITERSIO_CRS,
385 BWRITERSIO_SGN,
386 BWRITERSIO_ABS,
387 BWRITERSIO_NRM,
388 BWRITERSIO_SINCOS,
389 BWRITERSIO_REP,
390 BWRITERSIO_ENDREP,
391 BWRITERSIO_IF,
392 BWRITERSIO_IFC,
393 BWRITERSIO_ELSE,
394 BWRITERSIO_ENDIF,
395 BWRITERSIO_BREAK,
396 BWRITERSIO_BREAKC,
397 BWRITERSIO_MOVA,
398 BWRITERSIO_DEFB,
399 BWRITERSIO_DEFI,
401 BWRITERSIO_TEXCOORD,
402 BWRITERSIO_TEXKILL,
403 BWRITERSIO_TEX,
404 BWRITERSIO_TEXBEM,
405 BWRITERSIO_TEXBEML,
406 BWRITERSIO_TEXREG2AR,
407 BWRITERSIO_TEXREG2GB,
408 BWRITERSIO_TEXM3x2PAD,
409 BWRITERSIO_TEXM3x2TEX,
410 BWRITERSIO_TEXM3x3PAD,
411 BWRITERSIO_TEXM3x3TEX,
412 BWRITERSIO_TEXM3x3SPEC,
413 BWRITERSIO_TEXM3x3VSPEC,
414 BWRITERSIO_EXPP,
415 BWRITERSIO_LOGP,
416 BWRITERSIO_CND,
417 BWRITERSIO_DEF,
418 BWRITERSIO_TEXREG2RGB,
419 BWRITERSIO_TEXDP3TEX,
420 BWRITERSIO_TEXM3x2DEPTH,
421 BWRITERSIO_TEXDP3,
422 BWRITERSIO_TEXM3x3,
423 BWRITERSIO_TEXDEPTH,
424 BWRITERSIO_CMP,
425 BWRITERSIO_BEM,
426 BWRITERSIO_DP2ADD,
427 BWRITERSIO_DSX,
428 BWRITERSIO_DSY,
429 BWRITERSIO_TEXLDD,
430 BWRITERSIO_SETP,
431 BWRITERSIO_TEXLDL,
432 BWRITERSIO_BREAKP,
433 BWRITERSIO_TEXLDP,
434 BWRITERSIO_TEXLDB,
436 BWRITERSIO_PHASE,
437 BWRITERSIO_COMMENT,
438 BWRITERSIO_END,
439 } BWRITERSHADER_INSTRUCTION_OPCODE_TYPE;
441 typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE {
442 BWRITERSPR_TEMP,
443 BWRITERSPR_INPUT,
444 BWRITERSPR_CONST,
445 BWRITERSPR_ADDR,
446 BWRITERSPR_TEXTURE,
447 BWRITERSPR_RASTOUT,
448 BWRITERSPR_ATTROUT,
449 BWRITERSPR_TEXCRDOUT,
450 BWRITERSPR_OUTPUT,
451 BWRITERSPR_CONSTINT,
452 BWRITERSPR_COLOROUT,
453 BWRITERSPR_DEPTHOUT,
454 BWRITERSPR_SAMPLER,
455 BWRITERSPR_CONSTBOOL,
456 BWRITERSPR_LOOP,
457 BWRITERSPR_MISCTYPE,
458 BWRITERSPR_LABEL,
459 BWRITERSPR_PREDICATE
460 } BWRITERSHADER_PARAM_REGISTER_TYPE;
462 typedef enum _BWRITERVS_RASTOUT_OFFSETS
464 BWRITERSRO_POSITION,
465 BWRITERSRO_FOG,
466 BWRITERSRO_POINT_SIZE
467 } BWRITERVS_RASTOUT_OFFSETS;
469 #define BWRITERSP_WRITEMASK_0 0x1 /* .x r */
470 #define BWRITERSP_WRITEMASK_1 0x2 /* .y g */
471 #define BWRITERSP_WRITEMASK_2 0x4 /* .z b */
472 #define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
473 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
475 typedef enum _BWRITERSHADER_PARAM_DSTMOD_TYPE {
476 BWRITERSPDM_NONE = 0,
477 BWRITERSPDM_SATURATE = 1,
478 BWRITERSPDM_PARTIALPRECISION = 2,
479 BWRITERSPDM_MSAMPCENTROID = 4,
480 } BWRITERSHADER_PARAM_DSTMOD_TYPE;
482 typedef enum _BWRITERSAMPLER_TEXTURE_TYPE {
483 BWRITERSTT_UNKNOWN = 0,
484 BWRITERSTT_1D = 1,
485 BWRITERSTT_2D = 2,
486 BWRITERSTT_CUBE = 3,
487 BWRITERSTT_VOLUME = 4,
488 } BWRITERSAMPLER_TEXTURE_TYPE;
490 #define BWRITERSI_TEXLD_PROJECT 1
491 #define BWRITERSI_TEXLD_BIAS 2
493 typedef enum _BWRITERSHADER_PARAM_SRCMOD_TYPE {
494 BWRITERSPSM_NONE = 0,
495 BWRITERSPSM_NEG,
496 BWRITERSPSM_BIAS,
497 BWRITERSPSM_BIASNEG,
498 BWRITERSPSM_SIGN,
499 BWRITERSPSM_SIGNNEG,
500 BWRITERSPSM_COMP,
501 BWRITERSPSM_X2,
502 BWRITERSPSM_X2NEG,
503 BWRITERSPSM_DZ,
504 BWRITERSPSM_DW,
505 BWRITERSPSM_ABS,
506 BWRITERSPSM_ABSNEG,
507 BWRITERSPSM_NOT,
508 } BWRITERSHADER_PARAM_SRCMOD_TYPE;
510 #define BWRITER_SM1_VS 0xfffe
511 #define BWRITER_SM1_PS 0xffff
513 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
514 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
516 #define BWRITERVS_SWIZZLE_SHIFT 16
517 #define BWRITERVS_SWIZZLE_MASK (0xFF << BWRITERVS_SWIZZLE_SHIFT)
519 #define BWRITERVS_X_X (0 << BWRITERVS_SWIZZLE_SHIFT)
520 #define BWRITERVS_X_Y (1 << BWRITERVS_SWIZZLE_SHIFT)
521 #define BWRITERVS_X_Z (2 << BWRITERVS_SWIZZLE_SHIFT)
522 #define BWRITERVS_X_W (3 << BWRITERVS_SWIZZLE_SHIFT)
524 #define BWRITERVS_Y_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 2))
525 #define BWRITERVS_Y_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 2))
526 #define BWRITERVS_Y_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 2))
527 #define BWRITERVS_Y_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
529 #define BWRITERVS_Z_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 4))
530 #define BWRITERVS_Z_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 4))
531 #define BWRITERVS_Z_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 4))
532 #define BWRITERVS_Z_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
534 #define BWRITERVS_W_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 6))
535 #define BWRITERVS_W_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 6))
536 #define BWRITERVS_W_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 6))
537 #define BWRITERVS_W_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 6))
539 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
541 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
542 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
543 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
544 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
546 typedef enum _BWRITERDECLUSAGE {
547 BWRITERDECLUSAGE_POSITION,
548 BWRITERDECLUSAGE_BLENDWEIGHT,
549 BWRITERDECLUSAGE_BLENDINDICES,
550 BWRITERDECLUSAGE_NORMAL,
551 BWRITERDECLUSAGE_PSIZE,
552 BWRITERDECLUSAGE_TEXCOORD,
553 BWRITERDECLUSAGE_TANGENT,
554 BWRITERDECLUSAGE_BINORMAL,
555 BWRITERDECLUSAGE_TESSFACTOR,
556 BWRITERDECLUSAGE_POSITIONT,
557 BWRITERDECLUSAGE_COLOR,
558 BWRITERDECLUSAGE_FOG,
559 BWRITERDECLUSAGE_DEPTH,
560 BWRITERDECLUSAGE_SAMPLE
561 } BWRITERDECLUSAGE;
563 /* ps 1.x texture registers mappings */
564 #define T0_REG 2
565 #define T1_REG 3
566 #define T2_REG 4
567 #define T3_REG 5
569 struct bwriter_shader *SlAssembleShader(const char *text, char **messages);
570 DWORD SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result);
571 void SlDeleteShader(struct bwriter_shader *shader);
573 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */