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"
35 #include "d3dcompiler.h"
40 * This doesn't belong here, but for some functions it is possible to return that value,
41 * see http://msdn.microsoft.com/en-us/library/bb205278%28v=VS.85%29.aspx
42 * The original definition is in D3DX10core.h.
44 #define D3DERR_INVALIDCALL 0x8876086c
46 /* TRACE helper functions */
47 const char *debug_d3dcompiler_d3d_blob_part(D3D_BLOB_PART part
) DECLSPEC_HIDDEN
;
48 const char *debug_d3dcompiler_shader_variable_class(D3D_SHADER_VARIABLE_CLASS c
) DECLSPEC_HIDDEN
;
49 const char *debug_d3dcompiler_shader_variable_type(D3D_SHADER_VARIABLE_TYPE t
) DECLSPEC_HIDDEN
;
58 enum bwriter_comparison_type
60 BWRITER_COMPARISON_NONE
,
61 BWRITER_COMPARISON_GT
,
62 BWRITER_COMPARISON_EQ
,
63 BWRITER_COMPARISON_GE
,
64 BWRITER_COMPARISON_LT
,
65 BWRITER_COMPARISON_NE
,
82 struct shader_reg
*rel_reg
;
94 enum bwriter_comparison_type comptype
;
96 struct shader_reg dst
;
97 struct shader_reg
*src
;
98 unsigned int num_srcs
; /* For freeing the rel_regs */
100 struct shader_reg predicate
;
105 DWORD usage
, usage_idx
;
118 struct bwriter_shader
{
119 enum shader_type type
;
120 unsigned char major_version
, minor_version
;
122 /* Local constants. Every constant that is not defined below is loaded from
123 * the global constant set at shader runtime
125 struct constant
**constF
;
126 struct constant
**constI
;
127 struct constant
**constB
;
128 unsigned int num_cf
, num_ci
, num_cb
;
130 /* Declared input and output varyings */
131 struct declaration
*inputs
, *outputs
;
132 unsigned int num_inputs
, num_outputs
;
133 struct samplerdecl
*samplers
;
134 unsigned int num_samplers
;
136 /* Are special pixel shader 3.0 registers declared? */
139 /* Array of shader instructions - The shader code itself */
140 struct instruction
**instr
;
141 unsigned int num_instrs
, instr_alloc_size
;
144 static inline void *d3dcompiler_alloc(SIZE_T size
)
146 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
149 static inline void *d3dcompiler_realloc(void *ptr
, SIZE_T size
)
152 return d3dcompiler_alloc(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
, __ms_va_list args
) DECLSPEC_HIDDEN
;
288 void WINAPIV
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 /* Debug utility routines */
298 const char *debug_print_srcmod(DWORD mod
) DECLSPEC_HIDDEN
;
299 const char *debug_print_dstmod(DWORD mod
) DECLSPEC_HIDDEN
;
300 const char *debug_print_shift(DWORD shift
) DECLSPEC_HIDDEN
;
301 const char *debug_print_dstreg(const struct shader_reg
*reg
) DECLSPEC_HIDDEN
;
302 const char *debug_print_srcreg(const struct shader_reg
*reg
) DECLSPEC_HIDDEN
;
303 const char *debug_print_comp(DWORD comp
) DECLSPEC_HIDDEN
;
304 const char *debug_print_opcode(DWORD opcode
) DECLSPEC_HIDDEN
;
306 /* Used to signal an incorrect swizzle/writemask */
307 #define SWIZZLE_ERR ~0U
309 /* Enumerations and defines used in the bytecode writer intermediate
311 enum bwritershader_instruction_opcode_type
368 BWRITERSIO_TEXREG2AR
,
369 BWRITERSIO_TEXREG2GB
,
370 BWRITERSIO_TEXM3x2PAD
,
371 BWRITERSIO_TEXM3x2TEX
,
372 BWRITERSIO_TEXM3x3PAD
,
373 BWRITERSIO_TEXM3x3TEX
,
374 BWRITERSIO_TEXM3x3SPEC
,
375 BWRITERSIO_TEXM3x3VSPEC
,
380 BWRITERSIO_TEXREG2RGB
,
381 BWRITERSIO_TEXDP3TEX
,
382 BWRITERSIO_TEXM3x2DEPTH
,
403 enum bwritershader_param_register_type
412 BWRITERSPR_TEXCRDOUT
,
418 BWRITERSPR_CONSTBOOL
,
425 enum bwritervs_rastout_offsets
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,
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,
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 */
533 struct bwriter_shader
*SlAssembleShader(const char *text
, char **messages
) DECLSPEC_HIDDEN
;
534 HRESULT
shader_write_bytecode(const struct bwriter_shader
*shader
, DWORD
**result
, DWORD
*size
) DECLSPEC_HIDDEN
;
535 void SlDeleteShader(struct bwriter_shader
*shader
) DECLSPEC_HIDDEN
;
537 /* The general IR structure is inspired by Mesa GLSL hir, even though the code
538 * ends up being quite different in practice. Anyway, here comes the relevant
539 * licensing information.
541 * Copyright © 2010 Intel Corporation
543 * Permission is hereby granted, free of charge, to any person obtaining a
544 * copy of this software and associated documentation files (the "Software"),
545 * to deal in the Software without restriction, including without limitation
546 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
547 * and/or sell copies of the Software, and to permit persons to whom the
548 * Software is furnished to do so, subject to the following conditions:
550 * The above copyright notice and this permission notice (including the next
551 * paragraph) shall be included in all copies or substantial portions of the
554 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
555 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
556 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
557 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
558 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
559 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
560 * DEALINGS IN THE SOFTWARE.
568 HLSL_CLASS_LAST_NUMERIC
= HLSL_CLASS_MATRIX
,
582 HLSL_TYPE_LAST_SCALAR
= HLSL_TYPE_BOOL
,
585 HLSL_TYPE_PIXELSHADER
,
586 HLSL_TYPE_VERTEXSHADER
,
591 enum hlsl_sampler_dim
593 HLSL_SAMPLER_DIM_GENERIC
,
597 HLSL_SAMPLER_DIM_CUBE
,
598 HLSL_SAMPLER_DIM_MAX
= HLSL_SAMPLER_DIM_CUBE
601 enum hlsl_matrix_majority
610 struct wine_rb_entry scope_entry
;
611 enum hlsl_type_class type
;
612 enum hlsl_base_type base_type
;
613 enum hlsl_sampler_dim sampler_dim
;
615 unsigned int modifiers
;
618 unsigned int reg_size
;
621 struct list
*elements
;
624 struct hlsl_type
*type
;
625 unsigned int elements_count
;
630 struct hlsl_struct_field
633 struct hlsl_type
*type
;
635 const char *semantic
;
637 unsigned int reg_offset
;
640 struct source_location
647 enum hlsl_ir_node_type
649 HLSL_IR_ASSIGNMENT
= 0,
662 enum hlsl_ir_node_type type
;
663 struct hlsl_type
*data_type
;
667 struct source_location loc
;
669 /* Liveness ranges. "index" is the index of this instruction. Since this is
670 * essentially an SSA value, the earliest live point is the index. This is
671 * true even for loops, since currently we can't have a reference to a
672 * value generated in an earlier iteration of the loop. */
673 unsigned int index
, last_read
;
678 struct hlsl_ir_node
*node
;
682 #define HLSL_STORAGE_EXTERN 0x00000001
683 #define HLSL_STORAGE_NOINTERPOLATION 0x00000002
684 #define HLSL_MODIFIER_PRECISE 0x00000004
685 #define HLSL_STORAGE_SHARED 0x00000008
686 #define HLSL_STORAGE_GROUPSHARED 0x00000010
687 #define HLSL_STORAGE_STATIC 0x00000020
688 #define HLSL_STORAGE_UNIFORM 0x00000040
689 #define HLSL_STORAGE_VOLATILE 0x00000080
690 #define HLSL_MODIFIER_CONST 0x00000100
691 #define HLSL_MODIFIER_ROW_MAJOR 0x00000200
692 #define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400
693 #define HLSL_STORAGE_IN 0x00000800
694 #define HLSL_STORAGE_OUT 0x00001000
696 #define HLSL_TYPE_MODIFIERS_MASK (HLSL_MODIFIER_PRECISE | HLSL_STORAGE_VOLATILE | \
697 HLSL_MODIFIER_CONST | HLSL_MODIFIER_ROW_MAJOR | \
698 HLSL_MODIFIER_COLUMN_MAJOR)
700 #define HLSL_MODIFIERS_MAJORITY_MASK (HLSL_MODIFIER_ROW_MAJOR | HLSL_MODIFIER_COLUMN_MAJOR)
702 struct reg_reservation
704 enum bwritershader_param_register_type type
;
710 struct hlsl_type
*data_type
;
711 struct source_location loc
;
713 const char *semantic
;
714 unsigned int modifiers
;
715 const struct reg_reservation
*reg_reservation
;
716 struct list scope_entry
, param_entry
;
718 unsigned int first_write
, last_read
;
721 struct hlsl_ir_function
723 struct wine_rb_entry entry
;
725 struct wine_rb_tree overloads
;
729 struct hlsl_ir_function_decl
731 struct hlsl_type
*return_type
;
732 struct hlsl_ir_var
*return_var
;
733 struct source_location loc
;
734 struct wine_rb_entry entry
;
735 struct hlsl_ir_function
*func
;
736 const char *semantic
;
737 struct list
*parameters
;
743 struct hlsl_ir_node node
;
744 struct hlsl_src condition
;
745 struct list then_instrs
;
746 struct list else_instrs
;
751 struct hlsl_ir_node node
;
752 /* loop condition is stored in the body (as "if (!condition) break;") */
754 unsigned int next_index
; /* liveness index of the end of the loop */
757 enum hlsl_ir_expr_op
{
758 HLSL_IR_UNOP_BIT_NOT
= 0,
759 HLSL_IR_UNOP_LOGIC_NOT
,
776 HLSL_IR_UNOP_SIN_REDUCED
, /* Reduced range [-pi, pi] */
777 HLSL_IR_UNOP_COS_REDUCED
, /* Reduced range [-pi, pi] */
786 HLSL_IR_UNOP_POSTINC
,
787 HLSL_IR_UNOP_POSTDEC
,
797 HLSL_IR_BINOP_GREATER
,
798 HLSL_IR_BINOP_LEQUAL
,
799 HLSL_IR_BINOP_GEQUAL
,
801 HLSL_IR_BINOP_NEQUAL
,
803 HLSL_IR_BINOP_LOGIC_AND
,
804 HLSL_IR_BINOP_LOGIC_OR
,
806 HLSL_IR_BINOP_LSHIFT
,
807 HLSL_IR_BINOP_RSHIFT
,
808 HLSL_IR_BINOP_BIT_AND
,
809 HLSL_IR_BINOP_BIT_OR
,
810 HLSL_IR_BINOP_BIT_XOR
,
826 struct hlsl_ir_node node
;
827 enum hlsl_ir_expr_op op
;
828 struct hlsl_src operands
[3];
831 enum hlsl_ir_jump_type
834 HLSL_IR_JUMP_CONTINUE
,
835 HLSL_IR_JUMP_DISCARD
,
841 struct hlsl_ir_node node
;
842 enum hlsl_ir_jump_type type
;
845 struct hlsl_ir_swizzle
847 struct hlsl_ir_node node
;
854 struct hlsl_ir_var
*var
;
855 struct hlsl_src offset
;
860 struct hlsl_ir_node node
;
861 struct hlsl_deref src
;
864 struct hlsl_ir_assignment
866 struct hlsl_ir_node node
;
867 struct hlsl_deref lhs
;
869 unsigned char writemask
;
872 struct hlsl_ir_constant
874 struct hlsl_ir_node node
;
889 struct wine_rb_tree types
;
890 struct hlsl_scope
*upper
;
893 /* Structures used only during parsing */
894 struct parse_parameter
896 struct hlsl_type
*type
;
898 const char *semantic
;
899 const struct reg_reservation
*reg_reservation
;
900 unsigned int modifiers
;
903 struct parse_colon_attribute
905 const char *semantic
;
906 struct reg_reservation
*reg_reservation
;
909 struct parse_initializer
911 struct hlsl_ir_node
**args
;
912 unsigned int args_count
;
916 struct parse_variable_def
919 struct source_location loc
;
922 unsigned int array_size
;
923 const char *semantic
;
924 struct reg_reservation
*reg_reservation
;
925 struct parse_initializer initializer
;
928 struct parse_function
931 struct hlsl_ir_function_decl
*decl
;
936 struct list
*then_instrs
;
937 struct list
*else_instrs
;
963 struct hlsl_parse_ctx
965 const char **source_files
;
966 unsigned int source_files_count
;
967 const char *source_file
;
968 unsigned int line_no
;
970 enum parse_status status
;
971 struct compilation_messages messages
;
973 struct hlsl_scope
*cur_scope
;
974 struct hlsl_scope
*globals
;
978 struct wine_rb_tree functions
;
979 const struct hlsl_ir_function_decl
*cur_function
;
981 enum hlsl_matrix_majority matrix_majority
;
985 struct hlsl_type
*scalar
[HLSL_TYPE_LAST_SCALAR
+ 1];
986 struct hlsl_type
*vector
[HLSL_TYPE_LAST_SCALAR
+ 1][4];
987 struct hlsl_type
*sampler
[HLSL_SAMPLER_DIM_MAX
+ 1];
988 struct hlsl_type
*Void
;
991 struct list static_initializers
;
994 extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN
;
996 enum hlsl_error_level
998 HLSL_LEVEL_ERROR
= 0,
1003 void WINAPIV
hlsl_message(const char *fmt
, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN
;
1004 void WINAPIV
hlsl_report_message(const struct source_location loc
,
1005 enum hlsl_error_level level
, const char *fmt
, ...) PRINTF_ATTR(3,4) DECLSPEC_HIDDEN
;
1007 static inline struct hlsl_ir_expr
*expr_from_node(const struct hlsl_ir_node
*node
)
1009 assert(node
->type
== HLSL_IR_EXPR
);
1010 return CONTAINING_RECORD(node
, struct hlsl_ir_expr
, node
);
1013 static inline struct hlsl_ir_load
*load_from_node(const struct hlsl_ir_node
*node
)
1015 assert(node
->type
== HLSL_IR_LOAD
);
1016 return CONTAINING_RECORD(node
, struct hlsl_ir_load
, node
);
1019 static inline struct hlsl_ir_constant
*constant_from_node(const struct hlsl_ir_node
*node
)
1021 assert(node
->type
== HLSL_IR_CONSTANT
);
1022 return CONTAINING_RECORD(node
, struct hlsl_ir_constant
, node
);
1025 static inline struct hlsl_ir_jump
*jump_from_node(const struct hlsl_ir_node
*node
)
1027 assert(node
->type
== HLSL_IR_JUMP
);
1028 return CONTAINING_RECORD(node
, struct hlsl_ir_jump
, node
);
1031 static inline struct hlsl_ir_assignment
*assignment_from_node(const struct hlsl_ir_node
*node
)
1033 assert(node
->type
== HLSL_IR_ASSIGNMENT
);
1034 return CONTAINING_RECORD(node
, struct hlsl_ir_assignment
, node
);
1037 static inline struct hlsl_ir_swizzle
*swizzle_from_node(const struct hlsl_ir_node
*node
)
1039 assert(node
->type
== HLSL_IR_SWIZZLE
);
1040 return CONTAINING_RECORD(node
, struct hlsl_ir_swizzle
, node
);
1043 static inline struct hlsl_ir_if
*if_from_node(const struct hlsl_ir_node
*node
)
1045 assert(node
->type
== HLSL_IR_IF
);
1046 return CONTAINING_RECORD(node
, struct hlsl_ir_if
, node
);
1049 static inline struct hlsl_ir_loop
*loop_from_node(const struct hlsl_ir_node
*node
)
1051 assert(node
->type
== HLSL_IR_LOOP
);
1052 return CONTAINING_RECORD(node
, struct hlsl_ir_loop
, node
);
1055 static inline struct hlsl_ir_node
*node_from_list(struct list
*list
)
1057 return LIST_ENTRY(list_tail(list
), struct hlsl_ir_node
, entry
);
1060 static inline void init_node(struct hlsl_ir_node
*node
, enum hlsl_ir_node_type type
,
1061 struct hlsl_type
*data_type
, struct source_location loc
)
1064 node
->data_type
= data_type
;
1066 list_init(&node
->uses
);
1069 static inline void hlsl_src_from_node(struct hlsl_src
*src
, struct hlsl_ir_node
*node
)
1073 list_add_tail(&node
->uses
, &src
->entry
);
1076 static inline void hlsl_src_remove(struct hlsl_src
*src
)
1079 list_remove(&src
->entry
);
1083 struct hlsl_ir_node
*add_assignment(struct list
*instrs
, struct hlsl_ir_node
*lhs
,
1084 enum parse_assign_op assign_op
, struct hlsl_ir_node
*rhs
) DECLSPEC_HIDDEN
;
1085 struct hlsl_ir_expr
*add_expr(struct list
*instrs
, enum hlsl_ir_expr_op op
, struct hlsl_ir_node
*operands
[3],
1086 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1087 struct hlsl_ir_node
*add_implicit_conversion(struct list
*instrs
, struct hlsl_ir_node
*node
, struct hlsl_type
*type
,
1088 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1090 struct hlsl_ir_expr
*new_cast(struct hlsl_ir_node
*node
, struct hlsl_type
*type
,
1091 struct source_location
*loc
) DECLSPEC_HIDDEN
;
1092 struct hlsl_ir_node
*new_binary_expr(enum hlsl_ir_expr_op op
, struct hlsl_ir_node
*arg1
,
1093 struct hlsl_ir_node
*arg2
) DECLSPEC_HIDDEN
;
1094 struct hlsl_ir_node
*new_unary_expr(enum hlsl_ir_expr_op op
, struct hlsl_ir_node
*arg
,
1095 struct source_location loc
) DECLSPEC_HIDDEN
;
1097 BOOL
add_declaration(struct hlsl_scope
*scope
, struct hlsl_ir_var
*decl
, BOOL local_var
) DECLSPEC_HIDDEN
;
1098 struct hlsl_ir_var
*get_variable(struct hlsl_scope
*scope
, const char *name
) DECLSPEC_HIDDEN
;
1099 void free_declaration(struct hlsl_ir_var
*decl
) DECLSPEC_HIDDEN
;
1100 struct hlsl_type
*new_hlsl_type(const char *name
, enum hlsl_type_class type_class
,
1101 enum hlsl_base_type base_type
, unsigned dimx
, unsigned dimy
) DECLSPEC_HIDDEN
;
1102 struct hlsl_type
*new_array_type(struct hlsl_type
*basic_type
, unsigned int array_size
) DECLSPEC_HIDDEN
;
1103 struct hlsl_type
*clone_hlsl_type(struct hlsl_type
*old
, unsigned int default_majority
) DECLSPEC_HIDDEN
;
1104 struct hlsl_type
*get_type(struct hlsl_scope
*scope
, const char *name
, BOOL recursive
) DECLSPEC_HIDDEN
;
1105 BOOL
is_row_major(const struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1106 BOOL
find_function(const char *name
) DECLSPEC_HIDDEN
;
1107 unsigned int components_count_type(struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1108 BOOL
compare_hlsl_types(const struct hlsl_type
*t1
, const struct hlsl_type
*t2
) DECLSPEC_HIDDEN
;
1109 BOOL
compatible_data_types(struct hlsl_type
*s1
, struct hlsl_type
*s2
) DECLSPEC_HIDDEN
;
1110 void push_scope(struct hlsl_parse_ctx
*ctx
) DECLSPEC_HIDDEN
;
1111 BOOL
pop_scope(struct hlsl_parse_ctx
*ctx
) DECLSPEC_HIDDEN
;
1112 void init_functions_tree(struct wine_rb_tree
*funcs
) DECLSPEC_HIDDEN
;
1113 void add_function_decl(struct wine_rb_tree
*funcs
, char *name
, struct hlsl_ir_function_decl
*decl
,
1114 BOOL intrinsic
) DECLSPEC_HIDDEN
;
1115 HRESULT
parse_hlsl_shader(const char *text
, enum shader_type type
, DWORD major
, DWORD minor
,
1116 const char *entrypoint
, ID3D10Blob
**shader
, char **messages
) DECLSPEC_HIDDEN
;
1118 const char *debug_base_type(const struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1119 const char *debug_hlsl_type(const struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1120 const char *debug_modifiers(DWORD modifiers
) DECLSPEC_HIDDEN
;
1121 const char *debug_node_type(enum hlsl_ir_node_type type
) DECLSPEC_HIDDEN
;
1122 void debug_dump_ir_function_decl(const struct hlsl_ir_function_decl
*func
) DECLSPEC_HIDDEN
;
1124 void free_hlsl_type(struct hlsl_type
*type
) DECLSPEC_HIDDEN
;
1125 void free_instr(struct hlsl_ir_node
*node
) DECLSPEC_HIDDEN
;
1126 void free_instr_list(struct list
*list
) DECLSPEC_HIDDEN
;
1127 void free_function_rb(struct wine_rb_entry
*entry
, void *context
) DECLSPEC_HIDDEN
;
1129 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
1130 ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
1131 ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
1132 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
1133 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
1134 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
1135 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
1136 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
1137 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
1138 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
1139 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
1140 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
1141 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
1142 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
1143 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
1144 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
1157 struct dxbc_section
*sections
;
1160 HRESULT
dxbc_write_blob(struct dxbc
*dxbc
, ID3DBlob
**blob
) DECLSPEC_HIDDEN
;
1161 void dxbc_destroy(struct dxbc
*dxbc
) DECLSPEC_HIDDEN
;
1162 HRESULT
dxbc_parse(const char *data
, SIZE_T data_size
, struct dxbc
*dxbc
) DECLSPEC_HIDDEN
;
1163 HRESULT
dxbc_add_section(struct dxbc
*dxbc
, DWORD tag
, const char *data
, DWORD data_size
) DECLSPEC_HIDDEN
;
1164 HRESULT
dxbc_init(struct dxbc
*dxbc
, unsigned int size
) DECLSPEC_HIDDEN
;
1166 static inline void read_dword(const char **ptr
, DWORD
*d
)
1168 memcpy(d
, *ptr
, sizeof(*d
));
1172 static inline void write_dword(char **ptr
, DWORD d
)
1174 memcpy(*ptr
, &d
, sizeof(d
));
1178 void skip_dword_unknown(const char **ptr
, unsigned int count
) DECLSPEC_HIDDEN
;
1180 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */