2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
31 #include "toy_compiler.h"
34 * Transpose a dst operand.
36 * Instead of processing a single vertex with each of its attributes in one
39 * r0 = [x0, y0, z0, w0]
41 * we want to process four vertices at a time
43 * r0 = [x0, y0, z0, w0]
44 * r1 = [x1, y1, z1, w1]
45 * r2 = [x2, y2, z2, w2]
46 * r3 = [x3, y3, z3, w3]
48 * but with the attribute data "transposed"
50 * r0 = [x0, x1, x2, x3]
51 * r1 = [y0, y1, y2, y3]
52 * r2 = [z0, z1, z2, z3]
53 * r3 = [w0, w1, w2, w3]
55 * This is also known as the SoA form.
58 tdst_transpose(struct toy_dst dst
, struct toy_dst
*trans
)
64 assert(!dst
.indirect
);
65 for (i
= 0; i
< 4; i
++) {
66 if (dst
.writemask
& (1 << i
)) {
67 trans
[i
] = tdst_offset(dst
, i
, 0);
68 trans
[i
].writemask
= TOY_WRITEMASK_XYZW
;
71 trans
[i
] = tdst_null();
76 assert(tdst_is_null(dst
));
77 for (i
= 0; i
< 4; i
++)
84 assert(!"unexpected file in dst transposition");
85 for (i
= 0; i
< 4; i
++)
86 trans
[i
] = tdst_null();
92 * Transpose a src operand.
95 tsrc_transpose(struct toy_src src
, struct toy_src
*trans
)
97 const enum toy_swizzle swizzle
[4] = {
98 src
.swizzle_x
, src
.swizzle_y
,
99 src
.swizzle_z
, src
.swizzle_w
,
105 assert(!src
.indirect
);
106 for (i
= 0; i
< 4; i
++) {
107 trans
[i
] = tsrc_offset(src
, swizzle
[i
], 0);
108 trans
[i
].swizzle_x
= TOY_SWIZZLE_X
;
109 trans
[i
].swizzle_y
= TOY_SWIZZLE_Y
;
110 trans
[i
].swizzle_z
= TOY_SWIZZLE_Z
;
111 trans
[i
].swizzle_w
= TOY_SWIZZLE_W
;
115 assert(tsrc_is_null(src
));
118 for (i
= 0; i
< 4; i
++)
124 assert(!"unexpected file in src transposition");
125 for (i
= 0; i
< 4; i
++)
126 trans
[i
] = tsrc_null();
131 static inline struct toy_src
132 tsrc_imm_mdesc(const struct toy_compiler
*tc
,
134 unsigned message_length
,
135 unsigned response_length
,
137 uint32_t function_control
)
141 assert(message_length
>= 1 && message_length
<= 15);
142 assert(response_length
>= 0 && response_length
<= 16);
143 assert(function_control
< 1 << 19);
146 message_length
<< 25 |
147 response_length
<< 20 |
148 header_present
<< 19 |
151 return tsrc_imm_ud(desc
);
154 static inline struct toy_src
155 tsrc_imm_mdesc_sampler(const struct toy_compiler
*tc
,
156 unsigned message_length
,
157 unsigned response_length
,
160 unsigned message_type
,
161 unsigned sampler_index
,
162 unsigned binding_table_index
)
164 const bool eot
= false;
167 assert(simd_mode
< 4);
168 assert(sampler_index
< 16);
169 assert(binding_table_index
< 256);
171 if (tc
->dev
->gen
>= ILO_GEN(7)) {
172 ctrl
= simd_mode
<< 17 |
178 ctrl
= simd_mode
<< 16 |
184 return tsrc_imm_mdesc(tc
, eot
, message_length
,
185 response_length
, header_present
, ctrl
);
188 static inline struct toy_src
189 tsrc_imm_mdesc_data_port(const struct toy_compiler
*tc
,
191 unsigned message_length
,
192 unsigned response_length
,
194 bool send_write_commit_message
,
195 unsigned message_type
,
196 unsigned message_specific_control
,
197 unsigned binding_table_index
)
201 if (tc
->dev
->gen
>= ILO_GEN(7)) {
202 assert(!send_write_commit_message
);
203 assert((message_specific_control
& 0x3f00) == message_specific_control
);
205 ctrl
= message_type
<< 14 |
206 (message_specific_control
& 0x3f00) |
210 assert(!send_write_commit_message
||
211 message_type
== GEN6_DATAPORT_WRITE_MESSAGE_STREAMED_VB_WRITE
);
212 assert((message_specific_control
& 0x1f00) == message_specific_control
);
214 ctrl
= send_write_commit_message
<< 17 |
216 (message_specific_control
& 0x1f00) |
220 return tsrc_imm_mdesc(tc
, eot
, message_length
,
221 response_length
, header_present
, ctrl
);
224 static inline struct toy_src
225 tsrc_imm_mdesc_data_port_scratch(const struct toy_compiler
*tc
,
226 unsigned message_length
,
227 unsigned response_length
,
230 bool invalidate_after_read
,
234 const bool eot
= false;
235 const bool header_present
= true;
238 assert(tc
->dev
->gen
>= ILO_GEN(7));
239 assert(num_registers
== 1 || num_registers
== 2 || num_registers
== 4);
244 invalidate_after_read
<< 15 |
245 (num_registers
- 1) << 12 |
248 return tsrc_imm_mdesc(tc
, eot
, message_length
,
249 response_length
, header_present
, ctrl
);
252 static inline struct toy_src
253 tsrc_imm_mdesc_urb(const struct toy_compiler
*tc
,
255 unsigned message_length
,
256 unsigned response_length
,
260 unsigned swizzle_control
,
261 unsigned global_offset
,
264 const bool header_present
= true;
267 if (tc
->dev
->gen
>= ILO_GEN(7)) {
268 const bool per_slot_offset
= false;
270 ctrl
= per_slot_offset
<< 16 |
272 swizzle_control
<< 14 |
277 ctrl
= complete
<< 15 |
280 swizzle_control
<< 10 |
285 return tsrc_imm_mdesc(tc
, eot
, message_length
,
286 response_length
, header_present
, ctrl
);
289 #endif /* TOY_HELPERS_H */