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;
56 typedef enum BWRITER_COMPARISON_TYPE {
57 BWRITER_COMPARISON_NONE,
58 BWRITER_COMPARISON_GT,
59 BWRITER_COMPARISON_EQ,
60 BWRITER_COMPARISON_GE,
61 BWRITER_COMPARISON_LT,
62 BWRITER_COMPARISON_NE,
64 } BWRITER_COMPARISON_TYPE;
79 struct shader_reg *rel_reg;
91 BWRITER_COMPARISON_TYPE comptype;
93 struct shader_reg dst;
94 struct shader_reg *src;
95 unsigned int num_srcs; /* For freeing the rel_regs */
97 struct shader_reg predicate;
102 DWORD usage, usage_idx;
115 #define INSTRARRAY_INITIAL_SIZE 8
116 struct bwriter_shader {
117 enum shader_type type;
119 /* Shader version selected */
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)
151 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
154 static inline BOOL d3dcompiler_free(void *ptr)
156 return HeapFree(GetProcessHeap(), 0, ptr);
159 static inline char *d3dcompiler_strdup(const char *string)
167 len = strlen(string);
168 copy = d3dcompiler_alloc(len + 1);
170 memcpy(copy, string, len + 1);
176 /* This structure is only used in asmshader.y, but since the .l file accesses the semantic types
177 * too it has to know it as well
182 DWORD additional_offset;
187 #define MAX_SRC_REGS 4
190 struct shader_reg reg[MAX_SRC_REGS];
194 struct asmparser_backend {
195 void (*constF)(struct asm_parser *This, DWORD reg, float x, float y, float z, float w);
196 void (*constI)(struct asm_parser *This, DWORD reg, INT x, INT y, INT z, INT w);
197 void (*constB)(struct asm_parser *This, DWORD reg, BOOL x);
199 void (*dstreg)(struct asm_parser *This, struct instruction *instr,
200 const struct shader_reg *dst);
201 void (*srcreg)(struct asm_parser *This, struct instruction *instr, int num,
202 const struct shader_reg *src);
204 void (*predicate)(struct asm_parser *This,
205 const struct shader_reg *predicate);
206 void (*coissue)(struct asm_parser *This);
208 void (*dcl_output)(struct asm_parser *This, DWORD usage, DWORD num,
209 const struct shader_reg *reg);
210 void (*dcl_input)(struct asm_parser *This, DWORD usage, DWORD num,
211 DWORD mod, const struct shader_reg *reg);
212 void (*dcl_sampler)(struct asm_parser *This, DWORD samptype, DWORD mod,
213 DWORD regnum, unsigned int line_no);
215 void (*end)(struct asm_parser *This);
217 void (*instr)(struct asm_parser *This, DWORD opcode, DWORD mod, DWORD shift,
218 BWRITER_COMPARISON_TYPE comp, const struct shader_reg *dst,
219 const struct src_regs *srcs, int expectednsrcs);
222 struct instruction *alloc_instr(unsigned int srcs) DECLSPEC_HIDDEN;
223 BOOL add_instruction(struct bwriter_shader *shader, struct instruction *instr) DECLSPEC_HIDDEN;
224 BOOL add_constF(struct bwriter_shader *shader, DWORD reg, float x, float y, float z, float w) DECLSPEC_HIDDEN;
225 BOOL add_constI(struct bwriter_shader *shader, DWORD reg, INT x, INT y, INT z, INT w) DECLSPEC_HIDDEN;
226 BOOL add_constB(struct bwriter_shader *shader, DWORD reg, BOOL x) DECLSPEC_HIDDEN;
227 BOOL record_declaration(struct bwriter_shader *shader, DWORD usage, DWORD usage_idx,
228 DWORD mod, BOOL output, DWORD regnum, DWORD writemask, BOOL builtin) DECLSPEC_HIDDEN;
229 BOOL record_sampler(struct bwriter_shader *shader, DWORD samptype, DWORD mod, DWORD regnum) DECLSPEC_HIDDEN;
231 #define MESSAGEBUFFER_INITIAL_SIZE 256
240 struct compilation_messages
244 unsigned int capacity;
249 /* The function table of the parser implementation */
250 const struct asmparser_backend *funcs;
252 /* Private data follows */
253 struct bwriter_shader *shader;
254 unsigned int m3x3pad_count;
256 enum parse_status status;
257 struct compilation_messages messages;
258 unsigned int line_no;
261 extern struct asm_parser asm_ctx DECLSPEC_HIDDEN;
263 void create_vs10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
264 void create_vs11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
265 void create_vs20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
266 void create_vs2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
267 void create_vs30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
268 void create_ps10_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
269 void create_ps11_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
270 void create_ps12_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
271 void create_ps13_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
272 void create_ps14_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
273 void create_ps20_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
274 void create_ps2x_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
275 void create_ps30_parser(struct asm_parser *ret) DECLSPEC_HIDDEN;
277 struct bwriter_shader *parse_asm_shader(char **messages) DECLSPEC_HIDDEN;
280 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
282 #define PRINTF_ATTR(fmt,args)
285 void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args) DECLSPEC_HIDDEN;
286 void asmparser_message(struct asm_parser *ctx, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
287 static inline void set_parse_status(enum parse_status *current, enum parse_status update)
289 if (update == PARSE_ERR)
290 *current = PARSE_ERR;
291 else if (update == PARSE_WARN && *current == PARSE_SUCCESS)
292 *current = PARSE_WARN;
295 /* A reasonable value as initial size */
296 #define BYTECODEBUFFER_INITIAL_SIZE 32
297 struct bytecode_buffer {
301 /* For tracking rare out of memory situations without passing
302 * return values around everywhere
307 struct bc_writer; /* Predeclaration for use in vtable parameters */
309 typedef void (*instr_writer)(struct bc_writer *This,
310 const struct instruction *instr,
311 struct bytecode_buffer *buffer);
313 struct bytecode_backend {
314 void (*header)(struct bc_writer *This, const struct bwriter_shader *shader,
315 struct bytecode_buffer *buffer);
316 void (*end)(struct bc_writer *This, const struct bwriter_shader *shader,
317 struct bytecode_buffer *buffer);
318 void (*srcreg)(struct bc_writer *This, const struct shader_reg *reg,
319 struct bytecode_buffer *buffer);
320 void (*dstreg)(struct bc_writer *This, const struct shader_reg *reg,
321 struct bytecode_buffer *buffer, DWORD shift, DWORD mod);
322 void (*opcode)(struct bc_writer *This, const struct instruction *instr,
323 DWORD token, struct bytecode_buffer *buffer);
325 const struct instr_handler_table {
331 /* Bytecode writing stuff */
333 const struct bytecode_backend *funcs;
335 /* Avoid result checking */
340 /* Vertex shader varying mapping */
349 /* Pixel shader specific members */
354 /* Debug utility routines */
355 const char *debug_print_srcmod(DWORD mod) DECLSPEC_HIDDEN;
356 const char *debug_print_dstmod(DWORD mod) DECLSPEC_HIDDEN;
357 const char *debug_print_shift(DWORD shift) DECLSPEC_HIDDEN;
358 const char *debug_print_dstreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
359 const char *debug_print_srcreg(const struct shader_reg *reg) DECLSPEC_HIDDEN;
360 const char *debug_print_comp(DWORD comp) DECLSPEC_HIDDEN;
361 const char *debug_print_opcode(DWORD opcode) DECLSPEC_HIDDEN;
363 /* Used to signal an incorrect swizzle/writemask */
364 #define SWIZZLE_ERR ~0U
367 Enumerations and defines used in the bytecode writer
368 intermediate representation
370 typedef enum _BWRITERSHADER_INSTRUCTION_OPCODE_TYPE {
426 BWRITERSIO_TEXREG2AR,
427 BWRITERSIO_TEXREG2GB,
428 BWRITERSIO_TEXM3x2PAD,
429 BWRITERSIO_TEXM3x2TEX,
430 BWRITERSIO_TEXM3x3PAD,
431 BWRITERSIO_TEXM3x3TEX,
432 BWRITERSIO_TEXM3x3SPEC,
433 BWRITERSIO_TEXM3x3VSPEC,
438 BWRITERSIO_TEXREG2RGB,
439 BWRITERSIO_TEXDP3TEX,
440 BWRITERSIO_TEXM3x2DEPTH,
459 } BWRITERSHADER_INSTRUCTION_OPCODE_TYPE;
461 typedef enum _BWRITERSHADER_PARAM_REGISTER_TYPE {
469 BWRITERSPR_TEXCRDOUT,
475 BWRITERSPR_CONSTBOOL,
480 } BWRITERSHADER_PARAM_REGISTER_TYPE;
482 typedef enum _BWRITERVS_RASTOUT_OFFSETS
486 BWRITERSRO_POINT_SIZE
487 } BWRITERVS_RASTOUT_OFFSETS;
489 #define BWRITERSP_WRITEMASK_0 0x1 /* .x r */
490 #define BWRITERSP_WRITEMASK_1 0x2 /* .y g */
491 #define BWRITERSP_WRITEMASK_2 0x4 /* .z b */
492 #define BWRITERSP_WRITEMASK_3 0x8 /* .w a */
493 #define BWRITERSP_WRITEMASK_ALL 0xf /* all */
495 typedef enum _BWRITERSHADER_PARAM_DSTMOD_TYPE {
496 BWRITERSPDM_NONE = 0,
497 BWRITERSPDM_SATURATE = 1,
498 BWRITERSPDM_PARTIALPRECISION = 2,
499 BWRITERSPDM_MSAMPCENTROID = 4,
500 } BWRITERSHADER_PARAM_DSTMOD_TYPE;
502 typedef enum _BWRITERSAMPLER_TEXTURE_TYPE {
503 BWRITERSTT_UNKNOWN = 0,
507 BWRITERSTT_VOLUME = 4,
508 } BWRITERSAMPLER_TEXTURE_TYPE;
510 #define BWRITERSI_TEXLD_PROJECT 1
511 #define BWRITERSI_TEXLD_BIAS 2
513 typedef enum _BWRITERSHADER_PARAM_SRCMOD_TYPE {
514 BWRITERSPSM_NONE = 0,
528 } BWRITERSHADER_PARAM_SRCMOD_TYPE;
530 #define BWRITER_SM1_VS 0xfffe
531 #define BWRITER_SM1_PS 0xffff
533 #define BWRITERPS_VERSION(major, minor) ((BWRITER_SM1_PS << 16) | ((major) << 8) | (minor))
534 #define BWRITERVS_VERSION(major, minor) ((BWRITER_SM1_VS << 16) | ((major) << 8) | (minor))
536 #define BWRITERVS_SWIZZLE_SHIFT 16
537 #define BWRITERVS_SWIZZLE_MASK (0xFF << BWRITERVS_SWIZZLE_SHIFT)
539 #define BWRITERVS_X_X (0 << BWRITERVS_SWIZZLE_SHIFT)
540 #define BWRITERVS_X_Y (1 << BWRITERVS_SWIZZLE_SHIFT)
541 #define BWRITERVS_X_Z (2 << BWRITERVS_SWIZZLE_SHIFT)
542 #define BWRITERVS_X_W (3 << BWRITERVS_SWIZZLE_SHIFT)
544 #define BWRITERVS_Y_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 2))
545 #define BWRITERVS_Y_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 2))
546 #define BWRITERVS_Y_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 2))
547 #define BWRITERVS_Y_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 2))
549 #define BWRITERVS_Z_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 4))
550 #define BWRITERVS_Z_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 4))
551 #define BWRITERVS_Z_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 4))
552 #define BWRITERVS_Z_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 4))
554 #define BWRITERVS_W_X (0 << (BWRITERVS_SWIZZLE_SHIFT + 6))
555 #define BWRITERVS_W_Y (1 << (BWRITERVS_SWIZZLE_SHIFT + 6))
556 #define BWRITERVS_W_Z (2 << (BWRITERVS_SWIZZLE_SHIFT + 6))
557 #define BWRITERVS_W_W (3 << (BWRITERVS_SWIZZLE_SHIFT + 6))
559 #define BWRITERVS_NOSWIZZLE (BWRITERVS_X_X | BWRITERVS_Y_Y | BWRITERVS_Z_Z | BWRITERVS_W_W)
561 #define BWRITERVS_SWIZZLE_X (BWRITERVS_X_X | BWRITERVS_Y_X | BWRITERVS_Z_X | BWRITERVS_W_X)
562 #define BWRITERVS_SWIZZLE_Y (BWRITERVS_X_Y | BWRITERVS_Y_Y | BWRITERVS_Z_Y | BWRITERVS_W_Y)
563 #define BWRITERVS_SWIZZLE_Z (BWRITERVS_X_Z | BWRITERVS_Y_Z | BWRITERVS_Z_Z | BWRITERVS_W_Z)
564 #define BWRITERVS_SWIZZLE_W (BWRITERVS_X_W | BWRITERVS_Y_W | BWRITERVS_Z_W | BWRITERVS_W_W)
566 typedef enum _BWRITERDECLUSAGE {
567 BWRITERDECLUSAGE_POSITION,
568 BWRITERDECLUSAGE_BLENDWEIGHT,
569 BWRITERDECLUSAGE_BLENDINDICES,
570 BWRITERDECLUSAGE_NORMAL,
571 BWRITERDECLUSAGE_PSIZE,
572 BWRITERDECLUSAGE_TEXCOORD,
573 BWRITERDECLUSAGE_TANGENT,
574 BWRITERDECLUSAGE_BINORMAL,
575 BWRITERDECLUSAGE_TESSFACTOR,
576 BWRITERDECLUSAGE_POSITIONT,
577 BWRITERDECLUSAGE_COLOR,
578 BWRITERDECLUSAGE_FOG,
579 BWRITERDECLUSAGE_DEPTH,
580 BWRITERDECLUSAGE_SAMPLE
583 /* ps 1.x texture registers mappings */
589 struct bwriter_shader *SlAssembleShader(const char *text, char **messages) DECLSPEC_HIDDEN;
590 HRESULT SlWriteBytecode(const struct bwriter_shader *shader, int dxversion, DWORD **result, DWORD *size) DECLSPEC_HIDDEN;
591 void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN;
593 /* The general IR structure is inspired by Mesa GLSL hir, even though the code
594 * ends up being quite different in practice. Anyway, here comes the relevant
595 * licensing information.
597 * Copyright © 2010 Intel Corporation
599 * Permission is hereby granted, free of charge, to any person obtaining a
600 * copy of this software and associated documentation files (the "Software"),
601 * to deal in the Software without restriction, including without limitation
602 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
603 * and/or sell copies of the Software, and to permit persons to whom the
604 * Software is furnished to do so, subject to the following conditions:
606 * The above copyright notice and this permission notice (including the next
607 * paragraph) shall be included in all copies or substantial portions of the
610 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
611 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
612 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
613 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
614 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
615 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
616 * DEALINGS IN THE SOFTWARE.
624 HLSL_CLASS_LAST_NUMERIC = HLSL_CLASS_MATRIX,
638 HLSL_TYPE_LAST_SCALAR = HLSL_TYPE_BOOL,
641 HLSL_TYPE_PIXELSHADER,
642 HLSL_TYPE_VERTEXSHADER,
647 enum hlsl_sampler_dim
649 HLSL_SAMPLER_DIM_GENERIC,
653 HLSL_SAMPLER_DIM_CUBE,
656 enum hlsl_matrix_majority
665 struct list scope_entry;
666 enum hlsl_type_class type;
667 enum hlsl_base_type base_type;
668 enum hlsl_sampler_dim sampler_dim;
670 unsigned int modifiers;
675 struct list *elements;
678 struct hlsl_type *type;
679 unsigned int elements_count;
684 struct hlsl_struct_field
687 struct hlsl_type *type;
689 const char *semantic;
693 struct source_location
700 enum hlsl_ir_node_type
708 HLSL_IR_FUNCTION_DECL,
714 enum hlsl_ir_node_type type;
715 struct hlsl_type *data_type;
717 struct source_location loc;
720 #define HLSL_STORAGE_EXTERN 0x00000001
721 #define HLSL_STORAGE_NOINTERPOLATION 0x00000002
722 #define HLSL_MODIFIER_PRECISE 0x00000004
723 #define HLSL_STORAGE_SHARED 0x00000008
724 #define HLSL_STORAGE_GROUPSHARED 0x00000010
725 #define HLSL_STORAGE_STATIC 0x00000020
726 #define HLSL_STORAGE_UNIFORM 0x00000040
727 #define HLSL_STORAGE_VOLATILE 0x00000080
728 #define HLSL_MODIFIER_CONST 0x00000100
729 #define HLSL_MODIFIER_ROW_MAJOR 0x00000200
730 #define HLSL_MODIFIER_COLUMN_MAJOR 0x00000400
731 #define HLSL_MODIFIER_IN 0x00000800
732 #define HLSL_MODIFIER_OUT 0x00001000
736 struct hlsl_ir_node node;
738 const char *semantic;
739 unsigned int modifiers;
740 struct list scope_entry;
742 struct hlsl_var_allocation *allocation;
745 struct hlsl_ir_function_decl
747 struct hlsl_ir_node node;
749 const char *semantic;
750 struct list *parameters;
754 struct hlsl_ir_assignment
756 struct hlsl_ir_node node;
757 struct hlsl_ir_node *lhs;
758 struct hlsl_ir_node *rhs;
759 unsigned char writemask;
762 enum hlsl_ir_expr_op {
763 HLSL_IR_UNOP_BIT_NOT = 0,
764 HLSL_IR_UNOP_LOGIC_NOT,
781 HLSL_IR_UNOP_SIN_REDUCED, /* Reduced range [-pi, pi] */
782 HLSL_IR_UNOP_COS_REDUCED, /* Reduced range [-pi, pi] */
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,
819 HLSL_IR_BINOP_PREINC,
820 HLSL_IR_BINOP_PREDEC,
821 HLSL_IR_BINOP_POSTINC,
822 HLSL_IR_BINOP_POSTDEC,
831 struct hlsl_ir_node node;
832 enum hlsl_ir_expr_op op;
833 struct hlsl_ir_node *operands[3];
834 struct list *subexpressions;
837 enum hlsl_ir_deref_type
841 HLSL_IR_DEREF_RECORD,
846 struct hlsl_ir_node node;
847 enum hlsl_ir_deref_type type;
850 struct hlsl_ir_var *var;
853 struct hlsl_ir_node *array;
854 struct hlsl_ir_node *index;
858 struct hlsl_ir_node *record;
864 struct hlsl_ir_constant
866 struct hlsl_ir_node node;
877 struct hlsl_ir_constant *array_elements;
878 struct list *struct_elements;
882 struct hlsl_ir_constructor
884 struct hlsl_ir_node node;
885 struct list *arguments;
893 struct hlsl_scope *upper;
896 /* Structures used only during parsing */
897 struct parse_parameter
899 struct hlsl_type *type;
901 const char *semantic;
902 unsigned int modifiers;
905 struct parse_variable_def
908 struct source_location loc;
911 unsigned int array_size;
913 struct list *initializer;
939 struct hlsl_parse_ctx
941 const char **source_files;
942 unsigned int source_files_count;
943 const char *source_file;
944 unsigned int line_no;
946 enum parse_status status;
947 struct compilation_messages messages;
949 struct hlsl_scope *cur_scope;
950 struct hlsl_scope *globals;
954 struct list functions;
956 enum hlsl_matrix_majority matrix_majority;
959 extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN;
961 enum hlsl_error_level
963 HLSL_LEVEL_ERROR = 0,
968 void hlsl_message(const char *fmt, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN;
969 void hlsl_report_message(const char *filename, DWORD line, DWORD column,
970 enum hlsl_error_level level, const char *fmt, ...) PRINTF_ATTR(5,6) DECLSPEC_HIDDEN;
972 static inline struct hlsl_ir_var *var_from_node(const struct hlsl_ir_node *node)
974 assert(node->type == HLSL_IR_VAR);
975 return CONTAINING_RECORD(node, struct hlsl_ir_var, node);
978 static inline struct hlsl_ir_expr *expr_from_node(const struct hlsl_ir_node *node)
980 assert(node->type == HLSL_IR_EXPR);
981 return CONTAINING_RECORD(node, struct hlsl_ir_expr, node);
984 static inline struct hlsl_ir_deref *deref_from_node(const struct hlsl_ir_node *node)
986 assert(node->type == HLSL_IR_DEREF);
987 return CONTAINING_RECORD(node, struct hlsl_ir_deref, node);
990 static inline struct hlsl_ir_constant *constant_from_node(const struct hlsl_ir_node *node)
992 assert(node->type == HLSL_IR_CONSTANT);
993 return CONTAINING_RECORD(node, struct hlsl_ir_constant, node);
996 static inline struct hlsl_ir_assignment *assignment_from_node(const struct hlsl_ir_node *node)
998 assert(node->type == HLSL_IR_ASSIGNMENT);
999 return CONTAINING_RECORD(node, struct hlsl_ir_assignment, node);
1002 static inline struct hlsl_ir_constructor *constructor_from_node(const struct hlsl_ir_node *node)
1004 assert(node->type == HLSL_IR_CONSTRUCTOR);
1005 return CONTAINING_RECORD(node, struct hlsl_ir_constructor, node);
1008 BOOL add_declaration(struct hlsl_scope *scope, struct hlsl_ir_var *decl, BOOL local_var) DECLSPEC_HIDDEN;
1009 struct hlsl_ir_var *get_variable(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
1010 void free_declaration(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
1011 BOOL add_func_parameter(struct list *list, struct parse_parameter *param,
1012 const struct source_location *loc) DECLSPEC_HIDDEN;
1013 struct hlsl_type *new_hlsl_type(const char *name, enum hlsl_type_class type_class,
1014 enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN;
1015 struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int array_size) DECLSPEC_HIDDEN;
1016 struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive) DECLSPEC_HIDDEN;
1017 BOOL find_function(const char *name) DECLSPEC_HIDDEN;
1018 unsigned int components_count_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
1019 struct hlsl_ir_expr *new_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node **operands,
1020 struct source_location *loc) DECLSPEC_HIDDEN;
1021 struct hlsl_ir_expr *hlsl_mul(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1022 struct source_location *loc) DECLSPEC_HIDDEN;
1023 struct hlsl_ir_expr *hlsl_div(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1024 struct source_location *loc) DECLSPEC_HIDDEN;
1025 struct hlsl_ir_expr *hlsl_mod(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1026 struct source_location *loc) DECLSPEC_HIDDEN;
1027 struct hlsl_ir_expr *hlsl_add(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1028 struct source_location *loc) DECLSPEC_HIDDEN;
1029 struct hlsl_ir_expr *hlsl_sub(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1030 struct source_location *loc) DECLSPEC_HIDDEN;
1031 struct hlsl_ir_expr *hlsl_lt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1032 struct source_location *loc) DECLSPEC_HIDDEN;
1033 struct hlsl_ir_expr *hlsl_gt(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1034 struct source_location *loc) DECLSPEC_HIDDEN;
1035 struct hlsl_ir_expr *hlsl_le(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1036 struct source_location *loc) DECLSPEC_HIDDEN;
1037 struct hlsl_ir_expr *hlsl_ge(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1038 struct source_location *loc) DECLSPEC_HIDDEN;
1039 struct hlsl_ir_expr *hlsl_eq(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1040 struct source_location *loc) DECLSPEC_HIDDEN;
1041 struct hlsl_ir_expr *hlsl_ne(struct hlsl_ir_node *op1, struct hlsl_ir_node *op2,
1042 struct source_location *loc) DECLSPEC_HIDDEN;
1043 struct hlsl_ir_deref *new_var_deref(struct hlsl_ir_var *var) DECLSPEC_HIDDEN;
1044 struct hlsl_ir_node *make_assignment(struct hlsl_ir_node *left, enum parse_assign_op assign_op,
1045 DWORD writemask, struct hlsl_ir_node *right) DECLSPEC_HIDDEN;
1046 void push_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
1047 BOOL pop_scope(struct hlsl_parse_ctx *ctx) DECLSPEC_HIDDEN;
1048 struct hlsl_ir_function_decl *new_func_decl(const char *name, struct hlsl_type *return_type, struct list *parameters) DECLSPEC_HIDDEN;
1049 struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
1050 const char *entrypoint, char **messages) DECLSPEC_HIDDEN;
1052 const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
1053 const char *debug_modifiers(DWORD modifiers) DECLSPEC_HIDDEN;
1054 void debug_dump_ir_function(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
1056 void free_hlsl_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
1057 void free_instr(struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
1058 void free_instr_list(struct list *list) DECLSPEC_HIDDEN;
1059 void free_function(struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
1062 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
1063 ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
1064 ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
1065 #define TAG_Aon9 MAKE_TAG('A', 'o', 'n', '9')
1066 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
1067 #define TAG_ISGN MAKE_TAG('I', 'S', 'G', 'N')
1068 #define TAG_OSGN MAKE_TAG('O', 'S', 'G', 'N')
1069 #define TAG_OSG5 MAKE_TAG('O', 'S', 'G', '5')
1070 #define TAG_PCSG MAKE_TAG('P', 'C', 'S', 'G')
1071 #define TAG_RDEF MAKE_TAG('R', 'D', 'E', 'F')
1072 #define TAG_SDBG MAKE_TAG('S', 'D', 'B', 'G')
1073 #define TAG_SHDR MAKE_TAG('S', 'H', 'D', 'R')
1074 #define TAG_SHEX MAKE_TAG('S', 'H', 'E', 'X')
1075 #define TAG_STAT MAKE_TAG('S', 'T', 'A', 'T')
1076 #define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
1077 #define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
1090 struct dxbc_section *sections;
1093 HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN;
1094 void dxbc_destroy(struct dxbc *dxbc) DECLSPEC_HIDDEN;
1095 HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) DECLSPEC_HIDDEN;
1096 HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, DWORD data_size) DECLSPEC_HIDDEN;
1097 HRESULT dxbc_init(struct dxbc *dxbc, DWORD count) DECLSPEC_HIDDEN;
1099 static inline void read_dword(const char **ptr, DWORD *d)
1101 memcpy(d, *ptr, sizeof(*d));
1105 static inline void write_dword(char **ptr, DWORD d)
1107 memcpy(*ptr, &d, sizeof(d));
1111 void skip_dword_unknown(const char **ptr, unsigned int count) DECLSPEC_HIDDEN;
1113 #endif /* __WINE_D3DCOMPILER_PRIVATE_H */