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
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
41 struct d3dcompiler_blob
43 const struct ID3D10BlobVtbl
*vtbl
;
50 HRESULT
d3dcompiler_blob_init(struct d3dcompiler_blob
*blob
, SIZE_T data_size
) DECLSPEC_HIDDEN
;
52 /* Shader assembler definitions */
53 typedef enum _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
,
66 } BWRITER_COMPARISON_TYPE
;
81 struct shader_reg
*rel_reg
;
93 BWRITER_COMPARISON_TYPE comptype
;
95 struct shader_reg dst
;
96 struct shader_reg
*src
;
97 unsigned int num_srcs
; /* For freeing the rel_regs */
99 struct shader_reg predicate
;
104 DWORD usage
, usage_idx
;
117 #define INSTRARRAY_INITIAL_SIZE 8
118 struct bwriter_shader
{
121 /* Shader version selected */
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? */
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
);
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
166 DWORD additional_offset
;
171 #define MAX_SRC_REGS 4
174 struct shader_reg reg
[MAX_SRC_REGS
];
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
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
;
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
);
257 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
259 #define PRINTF_ATTR(fmt,args)
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
{
271 /* For tracking rare out of memory situations without passing
272 * return values around everywhere
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
{
301 /* Bytecode writing stuff */
303 const struct bytecode_backend
*funcs
;
305 /* Avoid result checking */
310 /* Vertex shader varying mapping */
319 /* Pixel shader specific members */
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
{
406 BWRITERSIO_TEXREG2AR
,
407 BWRITERSIO_TEXREG2GB
,
408 BWRITERSIO_TEXM3x2PAD
,
409 BWRITERSIO_TEXM3x2TEX
,
410 BWRITERSIO_TEXM3x3PAD
,
411 BWRITERSIO_TEXM3x3TEX
,
412 BWRITERSIO_TEXM3x3SPEC
,
413 BWRITERSIO_TEXM3x3VSPEC
,
418 BWRITERSIO_TEXREG2RGB
,
419 BWRITERSIO_TEXDP3TEX
,
420 BWRITERSIO_TEXM3x2DEPTH
,
439 } BWRITERSHADER_INSTRUCTION_OPCODE_TYPE
;
441 typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE
{
449 BWRITERSPR_TEXCRDOUT
,
455 BWRITERSPR_CONSTBOOL
,
460 } BWRITERSHADER_PARAM_REGISTER_TYPE
;
462 typedef enum _BWRITERVS_RASTOUT_OFFSETS
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,
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,
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
563 /* ps 1.x texture registers mappings */
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 */