818ff6c72a3c6fe7807b79085d0645cb95e97dfc
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_tgsi_action.h
1 /*
2 * Copyright 2011-2012 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 **************************************************************************/
26
27 /**
28 *
29 * @author Tom Stellard <thomas.stellard@amd.com>
30 *
31 */
32
33
34 #ifndef LP_BLD_TGSI_ACTION_H
35 #define LP_BLD_TGSI_ACTION_H
36
37 #include <llvm-c/Core.h>
38
39 struct lp_build_tgsi_context;
40
41 struct lp_build_emit_data {
42 /** Arguments that are passed to lp_build_tgsi_action::emit. The
43 * order of the arguments should be as follows:
44 * SOA: s0.x, s0.y, s0.z, s0.w, s1.x, s1.y, s1.z, s1.w, s2.x, s2.y, s2.x, s2.w
45 * AOS: s0.xyzw, s1.xyzw, s2.xyzw
46 * TEXTURE Instructions: coord.xyzw
47 *
48 * Arguments should be packed into the args array. For example an SOA
49 * instructions that reads s0.x and s1.x args should look like this:
50 * args[0] = s0.x;
51 * args[1] = s1.x;
52 */
53 LLVMValueRef args[12];
54
55 /**
56 * Number of arguments in the args array.
57 */
58 unsigned arg_count;
59
60 /**
61 * The type output type of the opcode. This should be set in the
62 * lp_build_tgsi_action::fetch_args function.
63 */
64 LLVMTypeRef dst_type;
65
66 /** This is used by the lp_build_tgsi_action::fetch_args function to
67 * determine which channel to read from the opcode arguments. It also
68 * specifies which index of the output array should be written to by
69 * the lp_build_tgsi_action::emit function. However, this value is
70 * usually ignored by any opcodes that are not TGSI_OUTPUT_COMPONENTWISE.
71 */
72 unsigned chan;
73
74 /** The lp_build_tgsi_action::emit 'executes' the opcode and writes the
75 * results to this array.
76 */
77 LLVMValueRef output[4];
78
79 /**
80 * The current instruction that is being 'executed'.
81 */
82 const struct tgsi_full_instruction * inst;
83 const struct tgsi_opcode_info * info;
84 };
85
86 struct lp_build_tgsi_action
87 {
88
89 /**
90 * This function is responsible for doing 2-3 things:
91 * 1. Fetching the instruction arguments into the emit_data->args array.
92 * 2. Setting the number of arguments in emit_data->arg_count.
93 * 3. Setting the destination type in emit_data->dst_type (usually only
94 * necessary for opcodes that are TGSI_OUTPUT_COMPONENTWISE).
95 */
96 void (*fetch_args)(struct lp_build_tgsi_context *,
97 struct lp_build_emit_data *);
98
99
100 /**
101 * This function is responsible for emitting LLVM IR for a TGSI opcode.
102 * It should store the values it generates in the emit_data->output array
103 * and for TGSI_OUTPUT_COMPONENTWISE and TGSI_OUTPUT_REPLICATE instructions
104 * (and possibly others depending on the specific implementation), it should
105 * make sure to store the values in the array slot indexed by emit_data->chan.
106 */
107 void (*emit)(const struct lp_build_tgsi_action *,
108 struct lp_build_tgsi_context *,
109 struct lp_build_emit_data *);
110
111 /**
112 * This variable can be used to store an intrinsic name, in case the TGSI
113 * opcode will be replaced by a target specific intrinsic. (There is a
114 * convenience function in lp_bld_tgsi.c called lp_build_tgsi_intrinsic()
115 * that can be assigned to lp_build_tgsi_action::emit and used for
116 * generating intrinsics).
117 */
118 const char * intr_name;
119 };
120
121 /**
122 * This function initializes the bld_base->op_actions array with some
123 * generic operand actions.
124 */
125 void
126 lp_set_default_actions(
127 struct lp_build_tgsi_context * bld_base);
128
129 /*
130 * This function initialize the bld_base->op_actions array with some
131 * operand actions that are intended only for use when generating
132 * instructions to be executed on a CPU.
133 */
134 void
135 lp_set_default_actions_cpu(
136 struct lp_build_tgsi_context * bld_base);
137
138 #endif /* LP_BLD_TGSI_ACTION_H */