2 * Copyright (C) 2002 Raphael Junqueira
3 * Copyright (C) 2008 David Adam
4 * Copyright (C) 2008 Tony Wasserka
5 * Copyright (C) 2008 Stefan Dösinger
6 * Copyright (C) 2009 Matteo Bruni
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #ifndef __WINE_D3DX9_36_PRIVATE_H
25 #define __WINE_D3DX9_36_PRIVATE_H
35 /* for internal use */
36 typedef enum _FormatType
{
37 FORMAT_ARGB
, /* unsigned */
41 typedef struct _PixelFormatDesc
{
49 HRESULT
map_view_of_file(LPCWSTR filename
, LPVOID
*buffer
, DWORD
*length
);
50 HRESULT
load_resource_into_memory(HMODULE module
, HRSRC resinfo
, LPVOID
*buffer
, DWORD
*length
);
52 const PixelFormatDesc
*get_format_info(D3DFORMAT format
);
55 extern const ID3DXBufferVtbl D3DXBuffer_Vtbl
;
58 typedef struct ID3DXBufferImpl
61 const ID3DXBufferVtbl
*lpVtbl
;
64 /* ID3DXBuffer fields */
71 typedef struct ID3DXFontImpl
74 const ID3DXFontVtbl
*lpVtbl
;
77 /* ID3DXFont fields */
78 IDirect3DDevice9
*device
;
85 /* ID3DXMatrixStack */
86 typedef struct ID3DXMatrixStackImpl
89 const ID3DXMatrixStackVtbl
*lpVtbl
;
92 /* ID3DXMatrixStack fields */
94 unsigned int stack_size
;
96 } ID3DXMatrixStackImpl
;
99 typedef struct _SPRITE
{
100 LPDIRECT3DTEXTURE9 texture
;
108 typedef struct ID3DXSpriteImpl
110 /* IUnknown fields */
111 const ID3DXSpriteVtbl
*lpVtbl
;
114 /* ID3DXSprite fields */
115 IDirect3DDevice9
*device
;
116 IDirect3DVertexDeclaration9
*vdecl
;
117 IDirect3DStateBlock9
*stateblock
;
118 D3DXMATRIX transform
;
123 /* Store the relevant caps to prevent multiple GetDeviceCaps calls */
124 DWORD texfilter_caps
;
129 int sprite_count
; /* number of sprites to be drawn */
130 int allocated_sprites
; /* number of (pre-)allocated sprites */
133 /* Shader assembler definitions */
134 typedef enum _shader_type
{
139 typedef enum BWRITER_COMPARISON_TYPE
{
140 BWRITER_COMPARISON_NONE
,
141 BWRITER_COMPARISON_GT
,
142 BWRITER_COMPARISON_EQ
,
143 BWRITER_COMPARISON_GE
,
144 BWRITER_COMPARISON_LT
,
145 BWRITER_COMPARISON_NE
,
146 BWRITER_COMPARISON_LE
147 } BWRITER_COMPARISON_TYPE
;
162 struct shader_reg
*rel_reg
;
174 BWRITER_COMPARISON_TYPE comptype
;
176 struct shader_reg dst
;
177 struct shader_reg
*src
;
178 unsigned int num_srcs
; /* For freeing the rel_regs */
180 struct shader_reg predicate
;
185 DWORD usage
, usage_idx
;
198 #define INSTRARRAY_INITIAL_SIZE 8
199 struct bwriter_shader
{
202 /* Shader version selected */
205 /* Local constants. Every constant that is not defined below is loaded from
206 * the global constant set at shader runtime
208 struct constant
**constF
;
209 struct constant
**constI
;
210 struct constant
**constB
;
211 unsigned int num_cf
, num_ci
, num_cb
;
213 /* Declared input and output varyings */
214 struct declaration
*inputs
, *outputs
;
215 unsigned int num_inputs
, num_outputs
;
216 struct samplerdecl
*samplers
;
217 unsigned int num_samplers
;
219 /* Are special pixel shader 3.0 registers declared? */
222 /* Array of shader instructions - The shader code itself */
223 struct instruction
**instr
;
224 unsigned int num_instrs
, instr_alloc_size
;
227 static inline LPVOID
asm_alloc(SIZE_T size
) {
228 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
231 static inline LPVOID
asm_realloc(LPVOID ptr
, SIZE_T size
) {
232 return HeapReAlloc(GetProcessHeap(), 0, ptr
, size
);
235 static inline BOOL
asm_free(LPVOID ptr
) {
236 return HeapFree(GetProcessHeap(), 0, ptr
);
241 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
242 * too it has to know it as well
247 DWORD additional_offset
;
252 #define MAX_SRC_REGS 4
255 struct shader_reg reg
[MAX_SRC_REGS
];
259 struct asmparser_backend
{
260 void (*constF
)(struct asm_parser
*This
, DWORD reg
, float x
, float y
, float z
, float w
);
261 void (*constI
)(struct asm_parser
*This
, DWORD reg
, INT x
, INT y
, INT z
, INT w
);
262 void (*constB
)(struct asm_parser
*This
, DWORD reg
, BOOL x
);
264 void (*dstreg
)(struct asm_parser
*This
, struct instruction
*instr
,
265 const struct shader_reg
*dst
);
266 void (*srcreg
)(struct asm_parser
*This
, struct instruction
*instr
, int num
,
267 const struct shader_reg
*src
);
269 void (*predicate
)(struct asm_parser
*This
,
270 const struct shader_reg
*predicate
);
271 void (*coissue
)(struct asm_parser
*This
);
273 void (*dcl_output
)(struct asm_parser
*This
, DWORD usage
, DWORD num
,
274 const struct shader_reg
*reg
);
275 void (*dcl_input
)(struct asm_parser
*This
, DWORD usage
, DWORD num
,
276 DWORD mod
, const struct shader_reg
*reg
);
277 void (*dcl_sampler
)(struct asm_parser
*This
, DWORD samptype
, DWORD mod
,
278 DWORD regnum
, unsigned int line_no
);
280 void (*end
)(struct asm_parser
*This
);
282 void (*instr
)(struct asm_parser
*This
, DWORD opcode
, DWORD mod
, DWORD shift
,
283 BWRITER_COMPARISON_TYPE comp
, const struct shader_reg
*dst
,
284 const struct src_regs
*srcs
, int expectednsrcs
);
287 struct instruction
*alloc_instr(unsigned int srcs
);
288 BOOL
add_instruction(struct bwriter_shader
*shader
, struct instruction
*instr
);
289 BOOL
add_constF(struct bwriter_shader
*shader
, DWORD reg
, float x
, float y
, float z
, float w
);
290 BOOL
add_constI(struct bwriter_shader
*shader
, DWORD reg
, INT x
, INT y
, INT z
, INT w
);
291 BOOL
add_constB(struct bwriter_shader
*shader
, DWORD reg
, BOOL x
);
292 BOOL
record_declaration(struct bwriter_shader
*shader
, DWORD usage
,
293 DWORD usage_idx
, DWORD mod
, BOOL output
,
294 DWORD regnum
, DWORD writemask
, BOOL builtin
);
295 BOOL
record_sampler(struct bwriter_shader
*shader
, DWORD samptype
,
296 DWORD mod
, DWORD regnum
);
298 #define MESSAGEBUFFER_INITIAL_SIZE 256
301 /* The function table of the parser implementation */
302 const struct asmparser_backend
*funcs
;
304 /* Private data follows */
305 struct bwriter_shader
*shader
;
306 unsigned int m3x3pad_count
;
314 unsigned int messagesize
;
315 unsigned int messagecapacity
;
316 unsigned int line_no
;
319 extern struct asm_parser asm_ctx
;
321 void create_vs10_parser(struct asm_parser
*ret
);
322 void create_vs11_parser(struct asm_parser
*ret
);
323 void create_vs20_parser(struct asm_parser
*ret
);
324 void create_vs2x_parser(struct asm_parser
*ret
);
325 void create_vs30_parser(struct asm_parser
*ret
);
326 void create_ps20_parser(struct asm_parser
*ret
);
327 void create_ps2x_parser(struct asm_parser
*ret
);
328 void create_ps30_parser(struct asm_parser
*ret
);
330 struct bwriter_shader
*parse_asm_shader(char **messages
);
333 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
335 #define PRINTF_ATTR(fmt,args)
338 void asmparser_message(struct asm_parser
*ctx
, const char *fmt
, ...) PRINTF_ATTR(2,3);
339 void set_parse_status(struct asm_parser
*ctx
, enum parse_status status
);
341 /* A reasonable value as initial size */
342 #define BYTECODEBUFFER_INITIAL_SIZE 32
343 struct bytecode_buffer
{
347 /* For tracking rare out of memory situations without passing
348 * return values around everywhere
353 struct bc_writer
; /* Predeclaration for use in vtable parameters */
355 typedef void (*instr_writer
)(struct bc_writer
*This
,
356 const struct instruction
*instr
,
357 struct bytecode_buffer
*buffer
);
359 struct bytecode_backend
{
360 void (*header
)(struct bc_writer
*This
, const struct bwriter_shader
*shader
,
361 struct bytecode_buffer
*buffer
);
362 void (*end
)(struct bc_writer
*This
, const struct bwriter_shader
*shader
,
363 struct bytecode_buffer
*buffer
);
364 void (*srcreg
)(struct bc_writer
*This
, const struct shader_reg
*reg
,
365 struct bytecode_buffer
*buffer
);
366 void (*dstreg
)(struct bc_writer
*This
, const struct shader_reg
*reg
,
367 struct bytecode_buffer
*buffer
, DWORD shift
, DWORD mod
);
368 void (*opcode
)(struct bc_writer
*This
, const struct instruction
*instr
,
369 DWORD token
, struct bytecode_buffer
*buffer
);
371 const struct instr_handler_table
{
377 /* Bytecode writing stuff */
379 const struct bytecode_backend
*funcs
;
381 /* Avoid result checking */
386 /* Vertex shader varying mapping */
395 /* Pixel shader specific members */
400 /* Debug utility routines */
401 const char *debug_print_srcmod(DWORD mod
);
402 const char *debug_print_dstmod(DWORD mod
);
403 const char *debug_print_dstreg(const struct shader_reg
*reg
, shader_type st
);
404 const char *debug_print_srcreg(const struct shader_reg
*reg
, shader_type st
);
405 const char *debug_print_swizzle(DWORD swizzle
);
406 const char *debug_print_writemask(DWORD mask
);
407 const char *debug_print_comp(DWORD comp
);
408 const char *debug_print_opcode(DWORD opcode
);
410 /* Utilities for internal->d3d constant mapping */
411 DWORD
d3d9_swizzle(DWORD bwriter_swizzle
);
412 DWORD
d3d9_writemask(DWORD bwriter_writemask
);
413 DWORD
d3d9_srcmod(DWORD bwriter_srcmod
);
414 DWORD
d3d9_dstmod(DWORD bwriter_mod
);
415 DWORD
d3d9_comparetype(DWORD bwriter_comparetype
);
416 DWORD
d3d9_sampler(DWORD bwriter_sampler
);
417 DWORD
d3d9_register(DWORD bwriter_register
);
418 DWORD
d3d9_opcode(DWORD bwriter_opcode
);
420 /* Used to signal an incorrect swizzle/writemask */
421 #define SWIZZLE_ERR ~0U
424 Enumerations and defines used in the bytecode writer
425 intermediate representation
427 typedef enum _BWRITERSHADER_INSTRUCTION_OPCODE_TYPE
{
496 } BWRITERSHADER_INSTRUCTION_OPCODE_TYPE
;
498 typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE
{
506 BWRITERSPR_TEXCRDOUT
,
512 BWRITERSPR_CONSTBOOL
,
517 } BWRITERSHADER_PARAM_REGISTER_TYPE
;
519 typedef enum _BWRITERVS_RASTOUT_OFFSETS
523 BWRITERSRO_POINT_SIZE
524 } BWRITERVS_RASTOUT_OFFSETS
;
526 #define BWRITERSP_WRITEMASK_0 0x1 /* .x r */
527 #define BWRITERSP_WRITEMASK_1 0x2 /* .y g */
528 #define BWRITERSP_WRITEMASK_2 0x4 /* .z b */
529 #define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
530 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
532 typedef enum _BWRITERSHADER_PARAM_DSTMOD_TYPE
{
533 BWRITERSPDM_NONE
= 0,
534 BWRITERSPDM_SATURATE
= 1,
535 BWRITERSPDM_PARTIALPRECISION
= 2,
536 BWRITERSPDM_MSAMPCENTROID
= 4,
537 } BWRITERSHADER_PARAM_DSTMOD_TYPE
;
539 typedef enum _BWRITERSAMPLER_TEXTURE_TYPE
{
540 BWRITERSTT_UNKNOWN
= 0,
544 BWRITERSTT_VOLUME
= 4,
545 } BWRITERSAMPLER_TEXTURE_TYPE
;
547 #define BWRITERSI_TEXLD_PROJECT 1
548 #define BWRITERSI_TEXLD_BIAS 2
550 typedef enum _BWRITERSHADER_PARAM_SRCMOD_TYPE
{
551 BWRITERSPSM_NONE
= 0,
565 } BWRITERSHADER_PARAM_SRCMOD_TYPE
;
567 #define BWRITER_SM1_VS 0xfffe
568 #define BWRITER_SM1_PS 0xffff
570 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
571 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
573 #define BWRITERVS_SWIZZLE_SHIFT 16
574 #define BWRITERVS_SWIZZLE_MASK (0xFF << BWRITERVS_SWIZZLE_SHIFT)
576 #define BWRITERVS_X_X (0 << BWRITERVS_SWIZZLE_SHIFT)
577 #define BWRITERVS_X_Y (1 << BWRITERVS_SWIZZLE_SHIFT)
578 #define BWRITERVS_X_Z (2 << BWRITERVS_SWIZZLE_SHIFT)
579 #define BWRITERVS_X_W (3 << BWRITERVS_SWIZZLE_SHIFT)
581 #define BWRITERVS_Y_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 2))
582 #define BWRITERVS_Y_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 2))
583 #define BWRITERVS_Y_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 2))
584 #define BWRITERVS_Y_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
586 #define BWRITERVS_Z_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 4))
587 #define BWRITERVS_Z_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 4))
588 #define BWRITERVS_Z_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 4))
589 #define BWRITERVS_Z_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
591 #define BWRITERVS_W_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 6))
592 #define BWRITERVS_W_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 6))
593 #define BWRITERVS_W_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 6))
594 #define BWRITERVS_W_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 6))
596 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
598 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
599 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
600 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
601 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
603 typedef enum _BWRITERDECLUSAGE
{
604 BWRITERDECLUSAGE_POSITION
,
605 BWRITERDECLUSAGE_BLENDWEIGHT
,
606 BWRITERDECLUSAGE_BLENDINDICES
,
607 BWRITERDECLUSAGE_NORMAL
,
608 BWRITERDECLUSAGE_PSIZE
,
609 BWRITERDECLUSAGE_TEXCOORD
,
610 BWRITERDECLUSAGE_TANGENT
,
611 BWRITERDECLUSAGE_BINORMAL
,
612 BWRITERDECLUSAGE_TESSFACTOR
,
613 BWRITERDECLUSAGE_POSITIONT
,
614 BWRITERDECLUSAGE_COLOR
,
615 BWRITERDECLUSAGE_FOG
,
616 BWRITERDECLUSAGE_DEPTH
,
617 BWRITERDECLUSAGE_SAMPLE
620 struct bwriter_shader
*SlAssembleShader(const char *text
, char **messages
);
621 DWORD
SlWriteBytecode(const struct bwriter_shader
*shader
, int dxversion
, DWORD
**result
);
622 void SlDeleteShader(struct bwriter_shader
*shader
);
624 #endif /* __WINE_D3DX9_36_PRIVATE_H */