initial code to get texture sampling limping along
[mesa.git] / src / mesa / shader / slang / slang_assemble.h
index d93755c7e7bb2b207d798e8a37f21e7ee33dd5cc..8aafeb012ff1fbbba3b1caaaa28b2efd569a6367 100644 (file)
-/*\r
- * Mesa 3-D graphics library\r
- * Version:  6.3\r
- *\r
- * Copyright (C) 2005  Brian Paul   All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-#if !defined SLANG_ASSEMBLE_H\r
-#define SLANG_ASSEMBLE_H\r
-\r
-#include "slang_compile.h"\r
-\r
-#if defined __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-typedef enum slang_assembly_type_\r
-{\r
-       /* core */\r
-       slang_asm_none,\r
-       slang_asm_float_copy,\r
-       slang_asm_float_move,\r
-       slang_asm_float_push,\r
-       slang_asm_float_deref,\r
-       slang_asm_float_add,\r
-       slang_asm_float_multiply,\r
-       slang_asm_float_divide,\r
-       slang_asm_float_negate,\r
-       slang_asm_float_less,\r
-       slang_asm_float_equal,\r
-       slang_asm_float_to_int,\r
-       slang_asm_int_copy,\r
-       slang_asm_int_move,\r
-       slang_asm_int_push,\r
-       slang_asm_int_deref,\r
-       slang_asm_int_to_float,\r
-       slang_asm_int_to_addr,\r
-       slang_asm_bool_copy,\r
-       slang_asm_bool_move,\r
-       slang_asm_bool_push,\r
-       slang_asm_bool_deref,\r
-       slang_asm_addr_copy,\r
-       slang_asm_addr_push,\r
-       slang_asm_addr_deref,\r
-       slang_asm_addr_add,\r
-       slang_asm_addr_multiply,\r
-       slang_asm_jump,\r
-       slang_asm_jump_if_zero,\r
-       slang_asm_enter,\r
-       slang_asm_leave,\r
-       slang_asm_local_alloc,\r
-       slang_asm_local_free,\r
-       slang_asm_local_addr,\r
-       slang_asm_call,\r
-       slang_asm_return,\r
-       slang_asm_discard,\r
-       slang_asm_exit,\r
-       slang_asm__last\r
-} slang_assembly_type;\r
-\r
-typedef struct slang_assembly_\r
-{\r
-       slang_assembly_type type;\r
-       GLfloat literal;\r
-       GLuint param[2];\r
-} slang_assembly;\r
-\r
-typedef struct slang_assembly_file_\r
-{\r
-       slang_assembly *code;\r
-       unsigned int count;\r
-} slang_assembly_file;\r
-\r
-void slang_assembly_file_construct (slang_assembly_file *);\r
-void slang_assembly_file_destruct (slang_assembly_file *);\r
-int slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);\r
-int slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);\r
-int slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);\r
-int slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);\r
-\r
-typedef struct slang_assembly_flow_control_\r
-{\r
-       unsigned int loop_start;                        /* for "continue" statement */\r
-       unsigned int loop_end;                          /* for "break" statement */\r
-       unsigned int function_end;                      /* for "return" statement */\r
-} slang_assembly_flow_control;\r
-\r
-typedef struct slang_assembly_name_space_\r
-{\r
-       struct slang_function_scope_ *funcs;\r
-       struct slang_struct_scope_ *structs;\r
-       struct slang_variable_scope_ *vars;\r
-} slang_assembly_name_space;\r
-\r
-slang_function *_slang_locate_function (const char *name, slang_operation *params,\r
-       unsigned int num_params, slang_assembly_name_space *space);\r
-\r
-int _slang_assemble_function (slang_assembly_file *, struct slang_function_ *,\r
-       slang_assembly_name_space *);\r
-\r
-typedef struct slang_assembly_stack_info_\r
-{\r
-       unsigned int swizzle_mask;\r
-} slang_assembly_stack_info;\r
-\r
-int _slang_cleanup_stack (slang_assembly_file *, slang_operation *, int ref,\r
-       slang_assembly_name_space *);\r
-\r
-typedef struct slang_assembly_local_info_\r
-{\r
-       unsigned int ret_size;\r
-       unsigned int addr_tmp;\r
-       unsigned int swizzle_tmp;\r
-} slang_assembly_local_info;\r
-\r
-int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, int reference,\r
-       slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,\r
-       slang_assembly_stack_info *);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
-\r
+/*
+ * Mesa 3-D graphics library
+ * Version:  6.5.2
+ *
+ * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef SLANG_ASSEMBLE_H
+#define SLANG_ASSEMBLE_H
+
+#include "imports.h"
+#include "mtypes.h"
+#include "slang_utility.h"
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+
+struct slang_operation_;
+
+typedef enum slang_assembly_type_
+{
+   /* core */
+   slang_asm_none,
+   slang_asm_float_copy,
+   slang_asm_float_move,
+   slang_asm_float_push,
+   slang_asm_float_deref,
+   slang_asm_float_add,       /* a = pop(); b = pop(); push(a + b); */
+   slang_asm_float_subtract,
+   slang_asm_float_multiply,
+   slang_asm_float_divide,
+   slang_asm_float_negate,    /* push(-pop()) */
+   slang_asm_float_less,      /* a = pop(); b = pop(); push(a < b); */
+   slang_asm_float_equal_exp,
+   slang_asm_float_equal_int,
+   slang_asm_float_to_int,    /* push(floatToInt(pop())) */
+   slang_asm_float_sine,      /* push(sin(pop()) */
+   slang_asm_float_cosine,
+   slang_asm_float_arcsine,
+   slang_asm_float_arctan,
+   slang_asm_float_power,     /* push(pow(pop(), pop())) */
+   slang_asm_float_exp,
+   slang_asm_float_exp2,
+   slang_asm_float_rsq,
+   slang_asm_float_rcp,
+   slang_asm_float_log2,
+   slang_asm_float_min,
+   slang_asm_float_max,
+   slang_asm_float_ceil,
+   slang_asm_float_noise1,    /* push(noise1(pop()) */
+   slang_asm_float_noise2,    /* push(noise2(pop(), pop())) */
+   slang_asm_float_noise3,
+   slang_asm_float_noise4,
+
+   slang_asm_int_copy,
+   slang_asm_int_move,
+   slang_asm_int_push,
+   slang_asm_int_deref,
+   slang_asm_int_to_float,
+   slang_asm_int_to_addr,
+
+   slang_asm_bool_copy,
+   slang_asm_bool_move,
+   slang_asm_bool_push,
+   slang_asm_bool_deref,
+
+   slang_asm_addr_copy,
+   slang_asm_addr_push,
+   slang_asm_addr_deref,
+   slang_asm_addr_add,
+   slang_asm_addr_multiply,
+
+   slang_asm_vec4_tex1d,
+   slang_asm_vec4_tex2d,
+   slang_asm_vec4_tex3d,
+   slang_asm_vec4_texcube,
+   slang_asm_vec4_shad1d,
+   slang_asm_vec4_shad2d,
+
+   slang_asm_jump,
+   slang_asm_jump_if_zero,
+
+   slang_asm_enter,
+   slang_asm_leave,
+
+   slang_asm_local_alloc,
+   slang_asm_local_free,
+   slang_asm_local_addr,
+   slang_asm_global_addr,
+
+   slang_asm_call,          /* push(ip); jump(inst->param[0]); */
+   slang_asm_return,
+
+   slang_asm_discard,
+   slang_asm_exit,
+   /* GL_MESA_shader_debug */
+   slang_asm_float_print,
+   slang_asm_int_print,
+   slang_asm_bool_print,
+   /* vec4 */
+   slang_asm_float_to_vec4,
+   slang_asm_vec4_add,
+   slang_asm_vec4_subtract,
+   slang_asm_vec4_multiply,
+   slang_asm_vec4_divide,
+   slang_asm_vec4_negate,
+   slang_asm_vec4_min,
+   slang_asm_vec4_max,
+   slang_asm_vec4_seq,
+   slang_asm_vec4_sne,
+   slang_asm_vec4_sge,
+   slang_asm_vec4_sgt,
+   slang_asm_vec4_dot,
+   slang_asm_vec3_dot,
+   slang_asm_vec3_cross,
+   slang_asm_vec4_floor,
+   slang_asm_vec4_frac,
+   slang_asm_vec4_abs,
+
+   slang_asm_vec4_copy,
+   slang_asm_vec4_deref,
+   slang_asm_vec4_equal_int,
+   /* not a real assembly instruction */
+   slang_asm__last
+} slang_assembly_type;
+
+
+/**
+ * An assembly-level shader instruction.
+ */
+typedef struct slang_assembly_
+{
+   slang_assembly_type type;  /**< The instruction opcode */
+   GLfloat literal;           /**< float literal */
+   GLuint param[2];           /**< Two integer/address parameters */
+} slang_assembly;
+
+
+/**
+ * A list of slang_assembly instructions
+ */
+typedef struct slang_assembly_file_
+{
+   slang_assembly *code;
+   GLuint count;
+   GLuint capacity;
+} slang_assembly_file;
+
+
+extern GLvoid
+_slang_assembly_file_ctr(slang_assembly_file *);
+
+extern GLvoid
+slang_assembly_file_destruct(slang_assembly_file *);
+
+extern GLboolean
+slang_assembly_file_push(slang_assembly_file *, slang_assembly_type);
+
+extern GLboolean
+slang_assembly_file_push_label(slang_assembly_file *,
+                               slang_assembly_type, GLuint);
+
+extern GLboolean
+slang_assembly_file_push_label2(slang_assembly_file *, slang_assembly_type,
+                                GLuint, GLuint);
+
+extern GLboolean
+slang_assembly_file_push_literal(slang_assembly_file *,
+                                 slang_assembly_type, GLfloat);
+
+
+typedef struct slang_assembly_file_restore_point_
+{
+   GLuint count;
+} slang_assembly_file_restore_point;
+
+
+extern GLboolean
+slang_assembly_file_restore_point_save(slang_assembly_file *,
+                                       slang_assembly_file_restore_point *);
+
+extern GLboolean
+slang_assembly_file_restore_point_load(slang_assembly_file *,
+                                       slang_assembly_file_restore_point *);
+
+
+typedef struct slang_assembly_flow_control_
+{
+   GLuint loop_start;           /**< for "continue" statement */
+   GLuint loop_end;             /**< for "break" statement */
+   GLuint function_end;         /**< for "return" statement */
+} slang_assembly_flow_control;
+
+typedef struct slang_assembly_local_info_
+{
+   GLuint ret_size;
+   GLuint addr_tmp;
+   GLuint swizzle_tmp;
+} slang_assembly_local_info;
+
+typedef enum
+{
+   slang_ref_force,
+   slang_ref_forbid             /**< slang_ref_freelance */
+} slang_ref_type;
+
+/**
+ * Holds complete information about vector swizzle - the <swizzle>
+ * array contains vector component source indices, where 0 is "x", 1
+ * is "y", 2 is "z" and 3 is "w".
+ * Example: "xwz" --> { 3, { 0, 3, 2, not used } }.
+ */
+typedef struct slang_swizzle_
+{
+   GLuint num_components;
+   GLuint swizzle[4];
+} slang_swizzle;
+
+typedef struct slang_assembly_name_space_
+{
+   struct slang_function_scope_ *funcs;
+   struct slang_struct_scope_ *structs;
+   struct slang_variable_scope_ *vars;
+} slang_assembly_name_space;
+
+
+typedef struct {
+   GLboolean TempUsed[MAX_PROGRAM_TEMPS];
+   GLuint NumSamplers;
+} slang_gen_context;
+
+
+typedef struct slang_assemble_ctx_
+{
+   slang_assembly_file *file;
+   struct slang_machine_ *mach;
+   slang_atom_pool *atoms;
+   slang_assembly_name_space space;
+   slang_assembly_flow_control flow;
+   slang_assembly_local_info local;
+   slang_ref_type ref;
+   slang_swizzle swz;
+   struct gl_program *program;
+   slang_gen_context *codegen;
+} slang_assemble_ctx;
+
+extern struct slang_function_ *
+_slang_locate_function(const struct slang_function_scope_ *funcs,
+                       slang_atom name, const struct slang_operation_ *params,
+                       GLuint num_params,
+                       const slang_assembly_name_space *space,
+                       slang_atom_pool *);
+
+extern GLboolean
+_slang_assemble_function(slang_assemble_ctx *, struct slang_function_ *);
+
+extern GLboolean
+_slang_cleanup_stack(slang_assemble_ctx *, struct slang_operation_ *);
+
+extern GLboolean
+_slang_dereference(slang_assemble_ctx *, struct slang_operation_ *);
+
+extern GLboolean
+_slang_assemble_function_call(slang_assemble_ctx *, struct slang_function_ *,
+                              struct slang_operation_ *, GLuint, GLboolean);
+
+extern GLboolean
+_slang_assemble_function_call_name(slang_assemble_ctx *, const char *,
+                                   struct slang_operation_ *, GLuint,
+                                   GLboolean);
+
+extern GLboolean
+_slang_assemble_operation(slang_assemble_ctx *, struct slang_operation_ *,
+                          slang_ref_type);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#include "slang_assemble_assignment.h"
+#include "slang_assemble_typeinfo.h"
+#include "slang_assemble_constructor.h"
+#include "slang_assemble_conditional.h"
+
+#endif