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"
34 #include "d3dcompiler.h"
39 * This doesn't belong here, but for some functions it is possible to return that value,
40 * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
41 * The original definition is in D3DX10core.h.
43 #define D3DERR_INVALIDCALL 0x8876086c
45 /* TRACE helper functions */
46 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part
) DECLSPEC_HIDDEN
;
47 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c
) DECLSPEC_HIDDEN
;
48 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t
) DECLSPEC_HIDDEN
;
57 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
,
81 struct shader_reg
*rel_reg
;
93 enum 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
{
119 enum shader_type type
;
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 void *d3dcompiler_alloc(SIZE_T size
)
148 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
151 static inline void *d3dcompiler_realloc(void *ptr
, SIZE_T size
)
153 return HeapReAlloc(GetProcessHeap(), 0, ptr
, size
);
156 static inline BOOL
d3dcompiler_free(void *ptr
)
158 return HeapFree(GetProcessHeap(), 0, ptr
);
161 static inline char *d3dcompiler_strdup(const char *string
)
169 len
= strlen(string
);
170 copy
= d3dcompiler_alloc(len
+ 1);
172 memcpy(copy
, string
, len
+ 1);
178 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
179 * too it has to know it as well
184 DWORD additional_offset
;
189 #define MAX_SRC_REGS 4
192 struct shader_reg reg
[MAX_SRC_REGS
];
196 struct asmparser_backend
{
197 void (*constF
)(struct asm_parser
*This
, DWORD reg
, float x
, float y
, float z
, float w
);
198 void (*constI
)(struct asm_parser
*This
, DWORD reg
, INT x
, INT y
, INT z
, INT w
);
199 void (*constB
)(struct asm_parser
*This
, DWORD 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
, DWORD usage
, DWORD num
,
211 const struct shader_reg
*reg
);
212 void (*dcl_input
)(struct asm_parser
*This
, DWORD usage
, DWORD num
,
213 DWORD mod
, const struct shader_reg
*reg
);
214 void (*dcl_sampler
)(struct asm_parser
*This
, DWORD samptype
, DWORD mod
,
215 DWORD regnum
, unsigned int line_no
);
217 void (*end
)(struct asm_parser
*This
);
219 void (*instr
)(struct asm_parser
*parser
, DWORD opcode
, DWORD mod
, DWORD 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
) DECLSPEC_HIDDEN
;
225 BOOL
add_instruction(struct bwriter_shader
*shader
, struct instruction
*instr
) DECLSPEC_HIDDEN
;
226 BOOL
add_constF(struct bwriter_shader
*shader
, DWORD reg
, float x
, float y
, float z
, float w
) DECLSPEC_HIDDEN
;
227 BOOL
add_constI(struct bwriter_shader
*shader
, DWORD reg
, INT x
, INT y
, INT z
, INT w
) DECLSPEC_HIDDEN
;
228 BOOL
add_constB(struct bwriter_shader
*shader
, DWORD reg
, BOOL x
) DECLSPEC_HIDDEN
;
229 BOOL
record_declaration(struct bwriter_shader
*shader
, DWORD usage
, DWORD usage_idx
,
230 DWORD mod
, BOOL output
, DWORD regnum
, DWORD writemask
, BOOL builtin
) DECLSPEC_HIDDEN
;
231 BOOL
record_sampler(struct bwriter_shader
*shader
, DWORD samptype
, DWORD mod
, DWORD regnum
) DECLSPEC_HIDDEN
;
233 #define MESSAGEBUFFER_INITIAL_SIZE 256
242 struct compilation_messages
246 unsigned int capacity
;
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 DECLSPEC_HIDDEN
;
265 void create_vs10_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
266 void create_vs11_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
267 void create_vs20_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
268 void create_vs2x_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
269 void create_vs30_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
270 void create_ps10_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
271 void create_ps11_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
272 void create_ps12_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
273 void create_ps13_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
274 void create_ps14_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
275 void create_ps20_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
276 void create_ps2x_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
277 void create_ps30_parser(struct asm_parser
*ret
) DECLSPEC_HIDDEN
;
279 struct bwriter_shader
*parse_asm_shader(char **messages
) DECLSPEC_HIDDEN
;
282 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
284 #define PRINTF_ATTR(fmt,args)
287 void compilation_message(struct compilation_messages
*msg
, const char *fmt
, va_list args
) DECLSPEC_HIDDEN
;
288 void asmparser_message(struct asm_parser
*ctx
, const char *fmt
, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN
;
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 /* A reasonable value as initial size */
298 #define BYTECODEBUFFER_INITIAL_SIZE 32
299 struct bytecode_buffer
{
303 /* For tracking rare out of memory situations without passing
304 * return values around everywhere
309 struct bc_writer
; /* Predeclaration for use in vtable parameters */
311 typedef void (*instr_writer
)(struct bc_writer
*This
,
312 const struct instruction
*instr
,
313 struct bytecode_buffer
*buffer
);
315 struct bytecode_backend
{
316 void (*header
)(struct bc_writer
*This
, const struct bwriter_shader
*shader
,
317 struct bytecode_buffer
*buffer
);
318 void (*end
)(struct bc_writer
*This
, const struct bwriter_shader
*shader
,
319 struct bytecode_buffer
*buffer
);
320 void (*srcreg
)(struct bc_writer
*This
, const struct shader_reg
*reg
,
321 struct bytecode_buffer
*buffer
);
322 void (*dstreg
)(struct bc_writer
*This
, const struct shader_reg
*reg
,
323 struct bytecode_buffer
*buffer
, DWORD shift
, DWORD mod
);
324 void (*opcode
)(struct bc_writer
*This
, const struct instruction
*instr
,
325 DWORD token
, struct bytecode_buffer
*buffer
);
327 const struct instr_handler_table
{
333 /* Bytecode writing stuff */
335 const struct bytecode_backend
*funcs
;
337 /* Avoid result checking */
342 /* Vertex shader varying mapping */
351 /* Pixel shader specific members */
356 /* Debug utility routines */
357 const char *debug_print_srcmod(DWORD mod
) DECLSPEC_HIDDEN
;
358 const char *debug_print_dstmod(DWORD mod
) DECLSPEC_HIDDEN
;
359 const char *debug_print_shift(DWORD shift
) DECLSPEC_HIDDEN
;
360 const char *debug_print_dstreg(const struct shader_reg
*reg
) DECLSPEC_HIDDEN
;
361 const char *debug_print_srcreg(const struct shader_reg
*reg
) DECLSPEC_HIDDEN
;
362 const char *debug_print_comp(DWORD comp
) DECLSPEC_HIDDEN
;
363 const char *debug_print_opcode(DWORD opcode
) DECLSPEC_HIDDEN
;
365 /* Used to signal an incorrect swizzle/writemask */
366 #define SWIZZLE_ERR ~0U
368 /* Enumerations and defines used in the bytecode writer intermediate
370 enum bwritershader_instruction_opcode_type
427 BWRITERSIO_TEXREG2AR
,
428 BWRITERSIO_TEXREG2GB
,
429 BWRITERSIO_TEXM3x2PAD
,
430 BWRITERSIO_TEXM3x2TEX
,
431 BWRITERSIO_TEXM3x3PAD
,
432 BWRITERSIO_TEXM3x3TEX
,
433 BWRITERSIO_TEXM3x3SPEC
,
434 BWRITERSIO_TEXM3x3VSPEC
,
439 BWRITERSIO_TEXREG2RGB
,
440 BWRITERSIO_TEXDP3TEX
,
441 BWRITERSIO_TEXM3x2DEPTH
,
462 enum bwritershader_param_register_type
471 BWRITERSPR_TEXCRDOUT
,
477 BWRITERSPR_CONSTBOOL
,
484 enum bwritervs_rastout_offsets
488 BWRITERSRO_POINT_SIZE
491 #define BWRITERSP_WRITEMASK_0 0x1 /* .x r */
492 #define BWRITERSP_WRITEMASK_1 0x2 /* .y g */
493 #define BWRITERSP_WRITEMASK_2 0x4 /* .z b */
494 #define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
495 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
497 enum bwritershader_param_dstmod_type
499 BWRITERSPDM_NONE
= 0,
500 BWRITERSPDM_SATURATE
= 1,
501 BWRITERSPDM_PARTIALPRECISION
= 2,
502 BWRITERSPDM_MSAMPCENTROID
= 4,
505 enum bwritersampler_texture_type
507 BWRITERSTT_UNKNOWN
= 0,
511 BWRITERSTT_VOLUME
= 4,
514 #define BWRITERSI_TEXLD_PROJECT 1
515 #define BWRITERSI_TEXLD_BIAS 2
517 enum bwritershader_param_srcmod_type
519 BWRITERSPSM_NONE
= 0,
535 #define BWRITER_SM1_VS 0xfffe
536 #define BWRITER_SM1_PS 0xffff
538 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
539 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
541 #define BWRITERVS_SWIZZLE_SHIFT 16
542 #define BWRITERVS_SWIZZLE_MASK (0xFF << BWRITERVS_SWIZZLE_SHIFT)
544 #define BWRITERVS_X_X (0 << BWRITERVS_SWIZZLE_SHIFT)
545 #define BWRITERVS_X_Y (1 << BWRITERVS_SWIZZLE_SHIFT)
546 #define BWRITERVS_X_Z (2 << BWRITERVS_SWIZZLE_SHIFT)
547 #define BWRITERVS_X_W (3 << BWRITERVS_SWIZZLE_SHIFT)
549 #define BWRITERVS_Y_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 2))
550 #define BWRITERVS_Y_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 2))
551 #define BWRITERVS_Y_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 2))
552 #define BWRITERVS_Y_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
554 #define BWRITERVS_Z_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 4))
555 #define BWRITERVS_Z_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 4))
556 #define BWRITERVS_Z_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 4))
557 #define BWRITERVS_Z_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
559 #define BWRITERVS_W_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 6))
560 #define BWRITERVS_W_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 6))
561 #define BWRITERVS_W_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 6))
562 #define BWRITERVS_W_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 6))
564 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
566 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
567 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
568 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
569 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
571 enum bwriterdeclusage
573 BWRITERDECLUSAGE_POSITION
,
574 BWRITERDECLUSAGE_BLENDWEIGHT
,
575 BWRITERDECLUSAGE_BLENDINDICES
,
576 BWRITERDECLUSAGE_NORMAL
,
577 BWRITERDECLUSAGE_PSIZE
,
578 BWRITERDECLUSAGE_TEXCOORD
,
579 BWRITERDECLUSAGE_TANGENT
,
580 BWRITERDECLUSAGE_BINORMAL
,
581 BWRITERDECLUSAGE_TESSFACTOR
,
582 BWRITERDECLUSAGE_POSITIONT
,
583 BWRITERDECLUSAGE_COLOR
,
584 BWRITERDECLUSAGE_FOG
,
585 BWRITERDECLUSAGE_DEPTH
,
586 BWRITERDECLUSAGE_SAMPLE
589 /* ps 1.x texture registers mappings */
595 struct bwriter_shader
*SlAssembleShader(const char *text
, char **messages
) DECLSPEC_HIDDEN
;
596 HRESULT
SlWriteBytecode(const struct bwriter_shader
*shader
, int dxversion
, DWORD
**result
, DWORD
*size
) DECLSPEC_HIDDEN
;
597 void SlDeleteShader(struct bwriter_shader
*shader
) DECLSPEC_HIDDEN
;
599 /* The general IR structure is inspired by Mesa GLSL hir, even though the code
600 * ends up being quite different in practice. Anyway, here comes the relevant
601 * licensing information.
603 * Copyright © 2010 Intel Corporation
605 * Permission is hereby granted, free of charge, to any person obtaining a
606 * copy of this software and associated documentation files (the "Software"),
607 * to deal in the Software without restriction, including without limitation
608 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
609 * and/or sell copies of the Software, and to permit persons to whom the
610 * Software is furnished to do so, subject to the following conditions:
612 * The above copyright notice and this permission notice (including the next
613 * paragraph) shall be included in all copies or substantial portions of the
616 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
617 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
618 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
619 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
620 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
621 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
622 * DEALINGS IN THE SOFTWARE.
630 HLSL_CLASS_LAST_NUMERIC
= HLSL_CLASS_MATRIX
,
644 HLSL_TYPE_LAST_SCALAR
= HLSL_TYPE_BOOL
,
647 HLSL_TYPE_PIXELSHADER
,
648 HLSL_TYPE_VERTEXSHADER
,
653 enum hlsl_sampler_dim
655 HLSL_SAMPLER_DIM_GENERIC
,
659 HLSL_SAMPLER_DIM_CUBE
,
662 enum hlsl_matrix_majority
671 struct wine_rb_entry scope_entry
;
672 enum hlsl_type_class type
;
673 enum hlsl_base_type base_type
;
674 enum hlsl_sampler_dim sampler_dim
;
676 unsigned int modifiers
;
681 struct list
*elements
;
684 struct hlsl_type
*type
;
685 unsigned int elements_count
;
690 struct hlsl_struct_field
693 struct hlsl_type
*type
;
695 const char *semantic
;
699 struct source_location
706 enum hlsl_ir_node_type
714 HLSL_IR_FUNCTION_DECL
,
724 enum hlsl_ir_node_type type
;
725 struct hlsl_type
*data_type
;
727 struct source_location loc
;
730 #define HLSL_STORAGE_EXTERN 0x00000001
731 #define HLSL_STORAGE_NOINTERPOLATION 0x00000002
732 #define HLSL_MODIFIER_PRECISE 0x00000004
733 #define HLSL_STORAGE_SHARED 0x00000008
734 #define HLSL_STORAGE_GROUPSHARED 0x00000010
735 #define HLSL_STORAGE_STATIC 0x00000020
736 #define HLSL_STORAGE_UNIFORM 0x00000040
737 #define HLSL_STORAGE_VOLATILE 0x00000080
738 #define HLSL_MODIFIER_CONST 0x00000100
739 #define HLSL_MODIFIER_ROW_MAJOR 0x00000200
740 #define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400
741 #define HLSL_MODIFIER_IN 0x00000800
742 #define HLSL_MODIFIER_OUT 0x00001000
744 #define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_STORAGE_VOLATILE | \
745 HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \
746 HLSL_MODIFIER_COLUMN_MAJOR)
748 #define HLSL_MODIFIERS_COMPARISON_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
752 struct hlsl_ir_node node
;
754 const char *semantic
;
755 unsigned int modifiers
;
756 struct list scope_entry
;
758 struct hlsl_var_allocation
*allocation
;
761 struct hlsl_ir_function
763 struct wine_rb_entry entry
;
765 struct wine_rb_tree overloads
;
769 struct hlsl_ir_function_decl
771 struct hlsl_ir_node node
;
772 struct wine_rb_entry entry
;
773 struct hlsl_ir_function
*func
;
774 const char *semantic
;
775 struct list
*parameters
;
781 struct hlsl_ir_node node
;
782 struct hlsl_ir_node
*condition
;
783 struct list
*then_instrs
;
784 struct list
*else_instrs
;
789 struct hlsl_ir_node node
;
790 /* loop condition is stored in the body (as "if (!condition) break;") */
794 struct hlsl_ir_assignment
796 struct hlsl_ir_node node
;
797 struct hlsl_ir_node
*lhs
;
798 struct hlsl_ir_node
*rhs
;
799 unsigned char writemask
;
802 enum hlsl_ir_expr_op
{
803 HLSL_IR_UNOP_BIT_NOT
= 0,
804 HLSL_IR_UNOP_LOGIC_NOT
,
821 HLSL_IR_UNOP_SIN_REDUCED
, /* Reduced range [-pi, pi] */
822 HLSL_IR_UNOP_COS_REDUCED
, /* Reduced range [-pi, pi] */
831 HLSL_IR_UNOP_POSTINC
,
832 HLSL_IR_UNOP_POSTDEC
,
842 HLSL_IR_BINOP_GREATER
,
843 HLSL_IR_BINOP_LEQUAL
,
844 HLSL_IR_BINOP_GEQUAL
,
846 HLSL_IR_BINOP_NEQUAL
,
848 HLSL_IR_BINOP_LOGIC_AND
,
849 HLSL_IR_BINOP_LOGIC_OR
,
851 HLSL_IR_BINOP_LSHIFT
,
852 HLSL_IR_BINOP_RSHIFT
,
853 HLSL_IR_BINOP_BIT_AND
,
854 HLSL_IR_BINOP_BIT_OR
,
855 HLSL_IR_BINOP_BIT_XOR
,
871 struct hlsl_ir_node node
;
872 enum hlsl_ir_expr_op op
;
873 struct hlsl_ir_node
*operands
[3];
874 struct list
*subexpressions
;
877 enum hlsl_ir_jump_type
880 HLSL_IR_JUMP_CONTINUE
,
881 HLSL_IR_JUMP_DISCARD
,
887 struct hlsl_ir_node node
;
888 enum hlsl_ir_jump_type type
;
889 struct hlsl_ir_node
*return_value
;
892 struct hlsl_ir_swizzle
894 struct hlsl_ir_node node
;
895 struct hlsl_ir_node
*val
;
899 enum hlsl_ir_deref_type
903 HLSL_IR_DEREF_RECORD
,
908 struct hlsl_ir_node node
;
909 enum hlsl_ir_deref_type type
;
912 struct hlsl_ir_var
*var
;
915 struct hlsl_ir_node
*array
;
916 struct hlsl_ir_node
*index
;
920 struct hlsl_ir_node
*record
;
921 struct hlsl_struct_field
*field
;
926 struct hlsl_ir_constant
928 struct hlsl_ir_node node
;
939 struct hlsl_ir_constant
*array_elements
;
940 struct list
*struct_elements
;
944 struct hlsl_ir_constructor
946 struct hlsl_ir_node node
;
947 struct list
*arguments
;
954 struct wine_rb_tree types
;
955 struct hlsl_scope
*upper
;
958 /* Structures used only during parsing */
959 struct parse_parameter
961 struct hlsl_type
*type
;
963 const char *semantic
;
964 unsigned int modifiers
;
967 struct parse_variable_def
970 struct source_location loc
;
973 unsigned int array_size
;
975 struct list
*initializer
;
978 struct parse_function
981 struct hlsl_ir_function_decl
*decl
;
986 struct list
*then_instrs
;
987 struct list
*else_instrs
;
1013 struct hlsl_parse_ctx
1015 const char **source_files
;
1016 unsigned int source_files_count
;
1017 const char *source_file
;
1018 unsigned int line_no
;
1019 unsigned int column
;
1020 enum parse_status status
;
1021 struct compilation_messages messages
;
1023 struct hlsl_scope
*cur_scope
;
1024 struct hlsl_scope
*globals
;
1028 struct wine_rb_tree functions
;
1030 enum hlsl_matrix_majority matrix_majority
;
1033 extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN
;
1035 enum hlsl_error_level
1037 HLSL_LEVEL_ERROR
= 0,
1042 void hlsl_message(const char *fmt
, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN
;
1043 void hlsl_report_message(const char *filename
, DWORD line
, DWORD column
,
1044 enum hlsl_error_level level
, const char *fmt
, ...) PRINTF_ATTR(5,6) DECLSPEC_HIDDEN
;
1046 static inline struct hlsl_ir_var
*var_from_node(const struct hlsl_ir_node
*node
)
1048 assert(node
->type
== HLSL_IR_VAR
);
1049 return CONTAINING_RECORD(node
, struct hlsl_ir_var
, node
);
1052 static inline struct hlsl_ir_expr
*expr_from_node(const struct hlsl_ir_node
*node
)
1054 assert(node
->type
== HLSL_IR_EXPR
);
1055 return CONTAINING_RECORD(node
, struct hlsl_ir_expr
, node
);
1058 static inline struct hlsl_ir_deref
*deref_from_node(const struct hlsl_ir_node
*node
)
1060 assert(node
->type
== HLSL_IR_DEREF
);
1061 return CONTAINING_RECORD(node
, struct hlsl_ir_deref
, node
);
1064 static inline struct hlsl_ir_constant
*constant_from_node(const struct hlsl_ir_node
*node
)
1066 assert(node
->type
== HLSL_IR_CONSTANT
);
1067 return CONTAINING_RECORD(node
, struct hlsl_ir_constant
, node
);
1070 static inline struct hlsl_ir_jump
*jump_from_node(const struct hlsl_ir_node
*node
)
1072 assert(node
->type
== HLSL_IR_JUMP
);
1073 return CONTAINING_RECORD(node
, struct hlsl_ir_jump
, node
);
1076 static inline struct hlsl_ir_assignment
*assignment_from_node(const struct hlsl_ir_node
*node
)
1078 assert(node
->type
== HLSL_IR_ASSIGNMENT
);
1079 return CONTAINING_RECORD(node
, struct hlsl_ir_assignment
, node
);
1082 static inline struct hlsl_ir_swizzle
*swizzle_from_node(const struct hlsl_ir_node
*node
)
1084 assert(node
->type
== HLSL_IR_SWIZZLE
);
1085 return CONTAINING_RECORD(node
, struct hlsl_ir_swizzle
, node
);
1088 static inline struct hlsl_ir_constructor
*constructor_from_node(const struct hlsl_ir_node
*node
)
1090 assert(node
->type
== HLSL_IR_CONSTRUCTOR
);
1091 return CONTAINING_RECORD(node
, struct hlsl_ir_constructor
, node
);
1094 static inline struct hlsl_ir_if
*if_from_node(const struct hlsl_ir_node
*node
)
1096 assert(node
->type
== HLSL_IR_IF
);
1097 return CONTAINING_RECORD(node
, struct hlsl_ir_if
, node
);
1100 static inline struct hlsl_ir_loop
*loop_from_node(const struct hlsl_ir_node
*node
)
1102 assert(node
->type
== HLSL_IR_LOOP
);
1103 return CONTAINING_RECORD(node
, struct hlsl_ir_loop
, node
);
1106 BOOL
add_declaration(struct hlsl_scope
*scope
, struct hlsl_ir_var
*decl
, BOOL local_var
) DECLSPEC_HIDDEN
;
1107 struct hlsl_ir_var
*get_variable(struct hlsl_scope
*scope
, const char *name
) DECLSPEC_HIDDEN
;
1108 void free_declaration(struct hlsl_ir_var
*decl
) DECLSPEC_HIDDEN
;
1109 struct hlsl_type
*new_hlsl_type(const char *name
, enum hlsl_type_class type_class
,
1110 enum hlsl_base_type base_type
, unsigned dimx
, unsigned dimy
) DECLSPEC_HIDDEN
;
1111 struct hlsl_type
*new_array_type(struct hlsl_type
*basic_type
, unsigned int array_size
) DECLSPEC_HIDDEN
;
1112 struct hlsl_type
*clone_hlsl_type(struct hlsl_type
*old
) DECLSPEC_HIDDEN
;
1113 struct hlsl_type
*get_type(struct hlsl_scope
*scope
, const char *name
, BOOL recursive
) DECLSPEC_HIDDEN
;
1114 BOOL
find_function(const char *name
) DECLSPEC_HIDDEN
;
1115 unsigned int components_count_type(struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1116 BOOL
compare_hlsl_types(const struct hlsl_type
*t1
, const struct hlsl_type
*t2
) DECLSPEC_HIDDEN
;
1117 BOOL
compatible_data_types(struct hlsl_type
*s1
, struct hlsl_type
*s2
) DECLSPEC_HIDDEN
;
1118 struct hlsl_ir_expr
*new_expr(enum hlsl_ir_expr_op op
, struct hlsl_ir_node
**operands
,
1119 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1120 struct hlsl_ir_expr
*new_cast(struct hlsl_ir_node
*node
, struct hlsl_type
*type
,
1121 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1122 struct hlsl_ir_expr
*hlsl_mul(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1123 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1124 struct hlsl_ir_expr
*hlsl_div(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1125 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1126 struct hlsl_ir_expr
*hlsl_mod(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1127 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1128 struct hlsl_ir_expr
*hlsl_add(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1129 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1130 struct hlsl_ir_expr
*hlsl_sub(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1131 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1132 struct hlsl_ir_expr
*hlsl_lt(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1133 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1134 struct hlsl_ir_expr
*hlsl_gt(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1135 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1136 struct hlsl_ir_expr
*hlsl_le(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1137 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1138 struct hlsl_ir_expr
*hlsl_ge(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1139 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1140 struct hlsl_ir_expr
*hlsl_eq(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1141 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1142 struct hlsl_ir_expr
*hlsl_ne(struct hlsl_ir_node
*op1
, struct hlsl_ir_node
*op2
,
1143 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1144 struct hlsl_ir_deref
*new_var_deref(struct hlsl_ir_var
*var
) DECLSPEC_HIDDEN
;
1145 struct hlsl_ir_deref
*new_record_deref(struct hlsl_ir_node
*record
, struct hlsl_struct_field
*field
) DECLSPEC_HIDDEN
;
1146 struct hlsl_ir_node
*make_assignment(struct hlsl_ir_node
*left
, enum parse_assign_op assign_op
,
1147 DWORD writemask
, struct hlsl_ir_node
*right
) DECLSPEC_HIDDEN
;
1148 void push_scope(struct hlsl_parse_ctx
*ctx
) DECLSPEC_HIDDEN
;
1149 BOOL
pop_scope(struct hlsl_parse_ctx
*ctx
) DECLSPEC_HIDDEN
;
1150 struct hlsl_ir_function_decl
*new_func_decl(struct hlsl_type
*return_type
, struct list
*parameters
) DECLSPEC_HIDDEN
;
1151 void init_functions_tree(struct wine_rb_tree
*funcs
) DECLSPEC_HIDDEN
;
1152 void add_function_decl(struct wine_rb_tree
*funcs
, char *name
, struct hlsl_ir_function_decl
*decl
,
1153 BOOL intrinsic
) DECLSPEC_HIDDEN
;
1154 struct bwriter_shader
*parse_hlsl_shader(const char *text
, enum shader_type type
, DWORD major
, DWORD minor
,
1155 const char *entrypoint
, char **messages
) DECLSPEC_HIDDEN
;
1157 const char *debug_hlsl_type(const struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1158 const char *debug_modifiers(DWORD modifiers
) DECLSPEC_HIDDEN
;
1159 void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl
*func
) DECLSPEC_HIDDEN
;
1161 void free_hlsl_type(struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1162 void free_instr(struct hlsl_ir_node
*node
) DECLSPEC_HIDDEN
;
1163 void free_instr_list(struct list
*list
) DECLSPEC_HIDDEN
;
1164 void free_function_rb(struct wine_rb_entry
*entry
, void *context
) DECLSPEC_HIDDEN
;
1167 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
1168 ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
1169 ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
1170 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
1171 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
1172 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
1173 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
1174 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
1175 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
1176 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
1177 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
1178 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
1179 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
1180 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
1181 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
1182 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
1195 struct dxbc_section
*sections
;
1198 HRESULT
dxbc_write_blob(struct dxbc
*dxbc
, ID3DBlob
**blob
) DECLSPEC_HIDDEN
;
1199 void dxbc_destroy(struct dxbc
*dxbc
) DECLSPEC_HIDDEN
;
1200 HRESULT
dxbc_parse(const char *data
, SIZE_T data_size
, struct dxbc
*dxbc
) DECLSPEC_HIDDEN
;
1201 HRESULT
dxbc_add_section(struct dxbc
*dxbc
, DWORD tag
, const char *data
, DWORD data_size
) DECLSPEC_HIDDEN
;
1202 HRESULT
dxbc_init(struct dxbc
*dxbc
, DWORD count
) DECLSPEC_HIDDEN
;
1204 static inline void read_dword(const char **ptr
, DWORD
*d
)
1206 memcpy(d
, *ptr
, sizeof(*d
));
1210 static inline void write_dword(char **ptr
, DWORD d
)
1212 memcpy(*ptr
, &d
, sizeof(d
));
1216 void skip_dword_unknown(const char **ptr
, unsigned int count
) DECLSPEC_HIDDEN
;
1218 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */