blob: cef30c9830a653f747b0638988dd9d725695b4e9 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT8:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600227 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600240 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600241 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600260 case VK_INDEX_TYPE_UINT8:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600264 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600268 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Cody Northrop293d4502015-05-05 09:38:03 -0600312static void gen6_add_scratch_space(struct intel_cmd *cmd,
313 uint32_t batch_pos,
314 const struct intel_pipeline *pipeline,
315 const struct intel_pipeline_shader *sh)
316{
317 int scratch_space;
318
319 CMD_ASSERT(cmd, 6, 7.5);
320
321 assert(sh->per_thread_scratch_size &&
322 sh->per_thread_scratch_size % 1024 == 0 &&
323 u_is_pow2(sh->per_thread_scratch_size) &&
324 sh->scratch_offset % 1024 == 0);
325 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
326
327 cmd_reserve_reloc(cmd, 1);
328 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
329 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
330}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600331
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800332static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
333{
Cody Northrop293d4502015-05-05 09:38:03 -0600334 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
335 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800336 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600337 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800338 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600339 int vue_read_len = 0;
340 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800341
Cody Northrop293d4502015-05-05 09:38:03 -0600342 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
343
344 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
345
346 // based on ilo_gpe_init_gs_cso_gen6
347 vue_read_len = (gs->in_count + 1) / 2;
348 if (!vue_read_len)
349 vue_read_len = 1;
350
351 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
352 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
353 GEN6_THREADDISP_SPF;
354
355 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
356 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
357 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
358
359 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
360 GEN6_GS_DW5_STATISTICS |
361 GEN6_GS_DW5_RENDER_ENABLE;
362
363 dw6 = GEN6_GS_DW6_GS_ENABLE;
364
365 if (gs->discard_adj)
366 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
367
368 } else {
369 dw2 = 0;
370 dw4 = 0;
371 dw5 = GEN6_GS_DW5_STATISTICS;
372 dw6 = 0;
373 }
374
375 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800376 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600377 dw[1] = cmd->bind.pipeline.gs_offset;
378 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800379 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600380 dw[4] = dw4;
381 dw[5] = dw5;
382 dw[6] = dw6;
383
384 if (gs->per_thread_scratch_size)
385 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800386}
387
Chia-I Wu62a7f252014-08-29 11:31:16 +0800388static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
389{
Cody Northrop293d4502015-05-05 09:38:03 -0600390 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
391 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800392 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600393 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800394 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600395 int vue_read_len = 0;
396 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800397
Cody Northrop293d4502015-05-05 09:38:03 -0600398 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
399
400 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
401
402 // based on upload_gs_state
403 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
404 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
405
406 vue_read_len = (gs->in_count + 1) / 2;
407 if (!vue_read_len)
408 vue_read_len = 1;
409
410 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
411 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
412 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
413 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
414 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
415
416
417 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
418 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
419 GEN7_GS_DW5_STATISTICS |
420 GEN7_GS_DW5_GS_ENABLE;
421
422 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
423 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
424
425 if (gs->include_primitive_id)
426 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
427
428 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
429 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
430 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
431 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
432 } else {
433 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
434 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
435 dw6 = 0;
436 }
437 } else {
438 dw2 = 0;
439 dw4 = 0;
440 dw5 = GEN7_GS_DW5_STATISTICS;
441 dw6 = 0;
442 }
443
444 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800445 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600446 dw[1] = cmd->bind.pipeline.gs_offset;
447 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800448 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600449 dw[4] = dw4;
450 dw[5] = dw5;
451 dw[6] = dw6;
452
453 if (gs->per_thread_scratch_size)
454 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800455}
456
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600458 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800459{
460 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800461 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800462 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800463 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800464
465 CMD_ASSERT(cmd, 6, 7.5);
466
Chia-I Wu72292b72014-09-09 10:48:33 +0800467 cmd_batch_pointer(cmd, cmd_len, &dw);
468 dw[0] = dw0;
469
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800471 dw[1] = 0;
472 dw[2] = (height - 1) << 16 |
473 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800474 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800475 dw[1] = 1;
476 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800477 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800478
479 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800480}
481
Chia-I Wu8016a172014-08-29 18:31:32 +0800482static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
483 uint32_t body[6])
484{
485 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700486 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800487 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800488
489 CMD_ASSERT(cmd, 6, 7.5);
490
491 dw1 = GEN7_SF_DW1_STATISTICS |
492 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
493 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
494 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
495 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700496 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800497
498 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
499 int format;
500
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700501 switch (pipeline->db_format) {
Tony Barbour8205d902015-04-16 15:59:00 -0600502 case VK_FORMAT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800503 format = GEN6_ZFORMAT_D16_UNORM;
504 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600505 case VK_FORMAT_D32_SFLOAT:
506 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800507 format = GEN6_ZFORMAT_D32_FLOAT;
508 break;
509 default:
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600510 assert(!cmd->bind.fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800511 format = 0;
512 break;
513 }
514
515 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
516 }
517
Tony Barbourfa6cac72015-01-16 14:27:35 -0700518 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800519
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700520 /* Scissor is always enabled */
521 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
522
Tony Barbourfa6cac72015-01-16 14:27:35 -0700523 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800524 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
525 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
526 } else {
527 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
528 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
529 }
530
Chia-I Wu8016a172014-08-29 18:31:32 +0800531 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
532 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
533 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800534 GEN7_SF_DW3_SUBPIXEL_8BITS;
535
536 if (pipeline->use_rs_point_size) {
537 int point_width;
538
539 /* in U8.3 */
540 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
541 point_width = U_CLAMP(point_width, 1, 2047);
542
543 dw3 |= GEN7_SF_DW3_USE_POINT_WIDTH | point_width;
544 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800545
546 body[0] = dw1;
547 body[1] = dw2;
548 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700549 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
550 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
551 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800552}
553
Chia-I Wu8016a172014-08-29 18:31:32 +0800554static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
555{
556 const uint8_t cmd_len = 20;
557 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
558 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800559 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800560 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800561 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800562
563 CMD_ASSERT(cmd, 6, 6);
564
565 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800566
Chia-I Wu72292b72014-09-09 10:48:33 +0800567 cmd_batch_pointer(cmd, cmd_len, &dw);
568 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800569 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800570 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800571 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800572}
573
574static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
575{
576 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800577 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800578
579 CMD_ASSERT(cmd, 7, 7.5);
580
Chia-I Wu72292b72014-09-09 10:48:33 +0800581 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800582 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
583 (cmd_len - 2);
584 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800585}
586
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800587static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
588{
589 const uint8_t cmd_len = 4;
590 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
591 (cmd_len - 2);
592 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700593 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800594 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700595 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800596 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800597
598 CMD_ASSERT(cmd, 6, 7.5);
599
600 dw1 = GEN6_CLIP_DW1_STATISTICS;
601 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
602 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
603 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700604 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800605 }
606
607 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800608 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800609 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700610 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800611 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
612 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
613 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
614
615 if (pipeline->rasterizerDiscardEnable)
616 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
617 else
618 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
619
620 if (pipeline->depthClipEnable)
621 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
622
623 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
624 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
625 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
626 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
627
628 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
629 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
630 (viewport->viewport_count - 1);
631
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600632 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600633 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600634 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
635 }
636
Chia-I Wu72292b72014-09-09 10:48:33 +0800637 cmd_batch_pointer(cmd, cmd_len, &dw);
638 dw[0] = dw0;
639 dw[1] = dw1;
640 dw[2] = dw2;
641 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800642}
643
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800644static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
645{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800646 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800647 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800648 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600649 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700650 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651
652 CMD_ASSERT(cmd, 6, 6);
653
654 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
655
656 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
657 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
658
659 dw4 = GEN6_WM_DW4_STATISTICS |
660 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
661 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700662 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800664 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700665 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
666 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667
Cody Northrope86574e2015-02-24 14:15:29 -0700668 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700669 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700670
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671 if (fs->uses & INTEL_SHADER_USE_KILL ||
672 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700673 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674
Cody Northrope238deb2015-01-26 14:41:36 -0700675 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
677 if (fs->uses & INTEL_SHADER_USE_DEPTH)
678 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
679 if (fs->uses & INTEL_SHADER_USE_W)
680 dw5 |= GEN6_WM_DW5_PS_USE_W;
681
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700682 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700683 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800684
685 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700686 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687 GEN6_WM_DW6_ZW_INTERP_PIXEL |
688 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
689 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
690
Tony Barbourfa6cac72015-01-16 14:27:35 -0700691 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800692 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
693 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
694 } else {
695 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
696 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
697 }
698
Cody Northrope86574e2015-02-24 14:15:29 -0700699 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
700
Chia-I Wu784d3042014-12-19 14:30:04 +0800701 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800702 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800703 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800704 dw[2] = dw2;
705 dw[3] = 0; /* scratch */
706 dw[4] = dw4;
707 dw[5] = dw5;
708 dw[6] = dw6;
709 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700710 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800711
712 if (fs->per_thread_scratch_size)
713 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800714}
715
716static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
717{
718 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800719 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800720 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800721 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800722
723 CMD_ASSERT(cmd, 7, 7.5);
724
725 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
726
727 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700728 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800729 GEN7_WM_DW1_ZW_INTERP_PIXEL |
730 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
731 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
732
733 if (fs->uses & INTEL_SHADER_USE_KILL ||
734 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700735 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800736
Cody Northrope238deb2015-01-26 14:41:36 -0700737 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
738
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800739 if (fs->uses & INTEL_SHADER_USE_DEPTH)
740 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
741 if (fs->uses & INTEL_SHADER_USE_W)
742 dw1 |= GEN7_WM_DW1_PS_USE_W;
743
744 dw2 = 0;
745
Tony Barbourfa6cac72015-01-16 14:27:35 -0700746 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800747 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
748 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
749 } else {
750 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
751 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
752 }
753
Chia-I Wu72292b72014-09-09 10:48:33 +0800754 cmd_batch_pointer(cmd, cmd_len, &dw);
755 dw[0] = dw0;
756 dw[1] = dw1;
757 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800758}
759
760static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
761{
762 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800763 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800764 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700765 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600766 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800767
768 CMD_ASSERT(cmd, 7, 7.5);
769
770 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
771
772 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
773 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
774
775 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700776 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800777
Cody Northrope86574e2015-02-24 14:15:29 -0700778 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700779 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700780
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800781 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800782 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700783 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800784 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800785 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800786 }
787
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800788 if (fs->in_count)
789 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
790
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700791 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800792 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
793
794 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
795 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700796 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
797
798 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800799
Chia-I Wu784d3042014-12-19 14:30:04 +0800800 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800802 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800803 dw[2] = dw2;
804 dw[3] = 0; /* scratch */
805 dw[4] = dw4;
806 dw[5] = dw5;
807 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700808 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800809
810 if (fs->per_thread_scratch_size)
811 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800812}
813
Chia-I Wu8ada4242015-03-02 11:19:33 -0700814static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
815 uint32_t sample_count)
816{
817 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
818 uint32_t dw1, dw2, dw3, *dw;
819
820 CMD_ASSERT(cmd, 6, 7.5);
821
822 switch (sample_count) {
823 case 4:
824 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
825 dw2 = cmd->dev->sample_pattern_4x;
826 dw3 = 0;
827 break;
828 case 8:
829 assert(cmd_gen(cmd) >= INTEL_GEN(7));
830 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
831 dw2 = cmd->dev->sample_pattern_8x[0];
832 dw3 = cmd->dev->sample_pattern_8x[1];
833 break;
834 default:
835 assert(sample_count <= 1);
836 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
837 dw2 = 0;
838 dw3 = 0;
839 break;
840 }
841
842 cmd_batch_pointer(cmd, cmd_len, &dw);
843
844 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
845 dw[1] = dw1;
846 dw[2] = dw2;
847 if (cmd_gen(cmd) >= INTEL_GEN(7))
848 dw[3] = dw3;
849}
850
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800851static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700852 const struct intel_ds_view *view,
853 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800854{
855 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800856 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600857 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800858
859 CMD_ASSERT(cmd, 6, 7.5);
860
861 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800862 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
863 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800864 dw0 |= (cmd_len - 2);
865
Chia-I Wu72292b72014-09-09 10:48:33 +0800866 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
867 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700868
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700870 /* note that we only enable HiZ on Gen7+ */
871 if (!optimal_ds)
872 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
873
Chia-I Wu72292b72014-09-09 10:48:33 +0800874 dw[2] = 0;
875 dw[3] = view->cmd[2];
876 dw[4] = view->cmd[3];
877 dw[5] = view->cmd[4];
878 dw[6] = view->cmd[5];
879
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600880 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 cmd_reserve_reloc(cmd, 1);
882 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
883 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600884 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800885}
886
887static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700888 const struct intel_ds_view *view,
889 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800890{
891 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600893 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800894
895 CMD_ASSERT(cmd, 6, 7.5);
896
897 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800898 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
899 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800900 dw0 |= (cmd_len - 2);
901
Chia-I Wu72292b72014-09-09 10:48:33 +0800902 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
903 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800904
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700905 if (view->has_stencil) {
906 dw[1] = view->cmd[6];
907
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 cmd_reserve_reloc(cmd, 1);
909 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
910 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700911 } else {
912 dw[1] = 0;
913 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600914 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800915}
916
917static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700918 const struct intel_ds_view *view,
919 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800920{
921 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600923 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800924
925 CMD_ASSERT(cmd, 6, 7.5);
926
927 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800928 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
929 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800930 dw0 |= (cmd_len - 2);
931
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
933 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800934
Chia-I Wu73520ac2015-02-19 11:17:45 -0700935 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700936 dw[1] = view->cmd[8];
937
Chia-I Wu72292b72014-09-09 10:48:33 +0800938 cmd_reserve_reloc(cmd, 1);
939 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
940 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700941 } else {
942 dw[1] = 0;
943 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600944 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800945}
946
Chia-I Wuf8231032014-08-25 10:44:45 +0800947static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
948 uint32_t clear_val)
949{
950 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800951 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800952 GEN6_CLEAR_PARAMS_DW0_VALID |
953 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800954 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800955
956 CMD_ASSERT(cmd, 6, 6);
957
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 cmd_batch_pointer(cmd, cmd_len, &dw);
959 dw[0] = dw0;
960 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800961}
962
963static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
964 uint32_t clear_val)
965{
966 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800967 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800968 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800969 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800970
971 CMD_ASSERT(cmd, 7, 7.5);
972
Chia-I Wu72292b72014-09-09 10:48:33 +0800973 cmd_batch_pointer(cmd, cmd_len, &dw);
974 dw[0] = dw0;
975 dw[1] = clear_val;
976 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800977}
978
Chia-I Wu302742d2014-08-22 10:28:29 +0800979static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800980 uint32_t blend_offset,
981 uint32_t ds_offset,
982 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800983{
984 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800985 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800986
987 CMD_ASSERT(cmd, 6, 6);
988
Chia-I Wu426072d2014-08-26 14:31:55 +0800989 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800990 (cmd_len - 2);
991
Chia-I Wu72292b72014-09-09 10:48:33 +0800992 cmd_batch_pointer(cmd, cmd_len, &dw);
993 dw[0] = dw0;
994 dw[1] = blend_offset | 1;
995 dw[2] = ds_offset | 1;
996 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800997}
998
Chia-I Wu1744cca2014-08-22 11:10:17 +0800999static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001000 uint32_t clip_offset,
1001 uint32_t sf_offset,
1002 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001003{
1004 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001005 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001006
1007 CMD_ASSERT(cmd, 6, 6);
1008
Chia-I Wu426072d2014-08-26 14:31:55 +08001009 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001010 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1011 GEN6_VP_PTR_DW0_SF_CHANGED |
1012 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001013 (cmd_len - 2);
1014
Chia-I Wu72292b72014-09-09 10:48:33 +08001015 cmd_batch_pointer(cmd, cmd_len, &dw);
1016 dw[0] = dw0;
1017 dw[1] = clip_offset;
1018 dw[2] = sf_offset;
1019 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001020}
1021
1022static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001023 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001024{
1025 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001026 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001027
1028 CMD_ASSERT(cmd, 6, 6);
1029
Chia-I Wu426072d2014-08-26 14:31:55 +08001030 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001031 (cmd_len - 2);
1032
Chia-I Wu72292b72014-09-09 10:48:33 +08001033 cmd_batch_pointer(cmd, cmd_len, &dw);
1034 dw[0] = dw0;
1035 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001036}
1037
Chia-I Wu42a56202014-08-23 16:47:48 +08001038static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001039 uint32_t vs_offset,
1040 uint32_t gs_offset,
1041 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001042{
1043 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001044 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001045
1046 CMD_ASSERT(cmd, 6, 6);
1047
Chia-I Wu426072d2014-08-26 14:31:55 +08001048 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001049 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1050 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1051 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001052 (cmd_len - 2);
1053
Chia-I Wu72292b72014-09-09 10:48:33 +08001054 cmd_batch_pointer(cmd, cmd_len, &dw);
1055 dw[0] = dw0;
1056 dw[1] = vs_offset;
1057 dw[2] = gs_offset;
1058 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001059}
1060
Chia-I Wu257e75e2014-08-29 14:06:35 +08001061static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001062 uint32_t vs_offset,
1063 uint32_t gs_offset,
1064 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001065{
1066 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001067 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001068
1069 CMD_ASSERT(cmd, 6, 6);
1070
1071 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001072 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1073 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1074 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001075 (cmd_len - 2);
1076
Chia-I Wu72292b72014-09-09 10:48:33 +08001077 cmd_batch_pointer(cmd, cmd_len, &dw);
1078 dw[0] = dw0;
1079 dw[1] = vs_offset;
1080 dw[2] = gs_offset;
1081 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001082}
1083
Chia-I Wu302742d2014-08-22 10:28:29 +08001084static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001085 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001086{
1087 const uint8_t cmd_len = 2;
1088 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1089 GEN6_RENDER_SUBTYPE_3D |
1090 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001091 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001092
Chia-I Wu72292b72014-09-09 10:48:33 +08001093 cmd_batch_pointer(cmd, cmd_len, &dw);
1094 dw[0] = dw0;
1095 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001096}
1097
Chia-I Wua6c4f152014-12-02 04:19:58 +08001098static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001099{
Chia-I Wue6073342014-11-30 09:43:42 +08001100 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001101 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1102 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001103
1104 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001105 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001106
Tony Barbourfa6cac72015-01-16 14:27:35 -07001107 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001108}
1109
Chia-I Wu72292b72014-09-09 10:48:33 +08001110static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001111 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001112{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001113 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001114 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001115 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001116 uint32_t dw[3];
1117
1118 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001119 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001120 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001121 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1122 (state->ds_info.stencilReadMask & 0xff) << 8 |
1123 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001124 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001125
1126 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001127
1128 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1129 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001130
Chia-I Wu00b51a82014-09-09 12:07:37 +08001131 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001132 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001133}
1134
Chia-I Wu72292b72014-09-09 10:48:33 +08001135static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001136 uint32_t stencil_ref,
1137 const uint32_t blend_color[4])
1138{
Chia-I Wue6073342014-11-30 09:43:42 +08001139 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001140 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001141 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001142
1143 CMD_ASSERT(cmd, 6, 7.5);
1144
Chia-I Wu00b51a82014-09-09 12:07:37 +08001145 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1146 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001147 dw[0] = stencil_ref;
1148 dw[1] = 0;
1149 dw[2] = blend_color[0];
1150 dw[3] = blend_color[1];
1151 dw[4] = blend_color[2];
1152 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001153
Chia-I Wu72292b72014-09-09 10:48:33 +08001154 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001155}
1156
Chia-I Wu8370b402014-08-29 12:28:37 +08001157static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001158{
Chia-I Wu8370b402014-08-29 12:28:37 +08001159 CMD_ASSERT(cmd, 6, 7.5);
1160
Chia-I Wu707a29e2014-08-27 12:51:47 +08001161 if (!cmd->bind.draw_count)
1162 return;
1163
Chia-I Wu8370b402014-08-29 12:28:37 +08001164 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001165 return;
1166
Chia-I Wu8370b402014-08-29 12:28:37 +08001167 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001168
1169 /*
1170 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1171 *
1172 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1173 * pipe-control with a post-sync op and no write-cache flushes."
1174 *
1175 * The workaround below necessitates this workaround.
1176 */
1177 gen6_PIPE_CONTROL(cmd,
1178 GEN6_PIPE_CONTROL_CS_STALL |
1179 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001180 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001181
Chia-I Wud6d079d2014-08-31 13:14:21 +08001182 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1183 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001184}
1185
Chia-I Wu8370b402014-08-29 12:28:37 +08001186static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001187{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001188 CMD_ASSERT(cmd, 6, 7.5);
1189
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001190 if (!cmd->bind.draw_count)
1191 return;
1192
Chia-I Wud6d079d2014-08-31 13:14:21 +08001193 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1194 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001195}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001196
Chia-I Wu8370b402014-08-29 12:28:37 +08001197static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1198{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001199 CMD_ASSERT(cmd, 7, 7.5);
1200
Chia-I Wu8370b402014-08-29 12:28:37 +08001201 if (!cmd->bind.draw_count)
1202 return;
1203
1204 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001205
1206 gen6_PIPE_CONTROL(cmd,
1207 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001208 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001209}
1210
Chia-I Wu8370b402014-08-29 12:28:37 +08001211static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1212{
1213 CMD_ASSERT(cmd, 7, 7.5);
1214
Chia-I Wu8370b402014-08-29 12:28:37 +08001215 /*
1216 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1217 *
1218 * "One of the following must also be set (when CS stall is set):
1219 *
1220 * * Render Target Cache Flush Enable ([12] of DW1)
1221 * * Depth Cache Flush Enable ([0] of DW1)
1222 * * Stall at Pixel Scoreboard ([1] of DW1)
1223 * * Depth Stall ([13] of DW1)
1224 * * Post-Sync Operation ([13] of DW1)"
1225 */
1226 gen6_PIPE_CONTROL(cmd,
1227 GEN6_PIPE_CONTROL_CS_STALL |
1228 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001229 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001230}
1231
1232static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1233{
1234 CMD_ASSERT(cmd, 7, 7.5);
1235
Chia-I Wu8370b402014-08-29 12:28:37 +08001236 cmd_wa_gen6_pre_depth_stall_write(cmd);
1237
Chia-I Wud6d079d2014-08-31 13:14:21 +08001238 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001239}
1240
1241static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1242{
1243 CMD_ASSERT(cmd, 6, 7.5);
1244
1245 if (!cmd->bind.draw_count)
1246 return;
1247
1248 /*
1249 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1250 *
1251 * "Driver must guarentee that all the caches in the depth pipe are
1252 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1253 * requires driver to send a PIPE_CONTROL with a CS stall along with
1254 * a Depth Flush prior to this command."
1255 *
1256 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1257 *
1258 * "Driver must ierarchi that all the caches in the depth pipe are
1259 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1260 * requires driver to send a PIPE_CONTROL with a CS stall along with
1261 * a Depth Flush prior to this command.
1262 */
1263 gen6_PIPE_CONTROL(cmd,
1264 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1265 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001266 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001267}
1268
1269static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1270{
1271 CMD_ASSERT(cmd, 6, 7.5);
1272
1273 if (!cmd->bind.draw_count)
1274 return;
1275
1276 /*
1277 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1278 *
1279 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1280 * and a post sync operation prior to the group of depth
1281 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1282 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1283 *
1284 * This workaround satifies all the conditions.
1285 */
1286 cmd_wa_gen6_pre_depth_stall_write(cmd);
1287
1288 /*
1289 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1290 *
1291 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1292 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1293 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1294 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1295 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1296 * Depth Flush Bit set, followed by another pipelined depth stall
1297 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1298 * guarantee that the pipeline from WM onwards is already flushed
1299 * (e.g., via a preceding MI_FLUSH)."
1300 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001301 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1302 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1303 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001304}
1305
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001306void cmd_batch_state_base_address(struct intel_cmd *cmd)
1307{
1308 const uint8_t cmd_len = 10;
1309 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1310 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001311 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001312 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001313 uint32_t pos;
1314 uint32_t *dw;
1315
1316 CMD_ASSERT(cmd, 6, 7.5);
1317
1318 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1319
1320 dw[0] = dw0;
1321 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001322 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001323 dw[2] = 1;
1324 dw[3] = 1;
1325 dw[4] = 1;
1326 dw[5] = 1;
1327 /* end offsets */
1328 dw[6] = 1;
1329 dw[7] = 1 + 0xfffff000;
1330 dw[8] = 1 + 0xfffff000;
1331 dw[9] = 1;
1332
1333 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001334 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1335 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1336 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1337 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1338 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1339 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001340}
1341
Chia-I Wu7c853562015-02-27 14:35:08 -07001342void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1343{
1344 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1345 const uint8_t cmd_len = 2;
1346 uint32_t offset = 0;
1347 uint32_t *dw;
1348
1349 if (cmd_gen(cmd) <= INTEL_GEN(6))
1350 return;
1351
1352 CMD_ASSERT(cmd, 7, 7.5);
1353
1354 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1355 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1356 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1357 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1358 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1359 offset += size;
1360
1361 dw += 2;
1362 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1363 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1364 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1365
1366 dw += 2;
1367 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1368 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1369 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1370
1371 dw += 2;
1372 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1373 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1374 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1375
1376 dw += 2;
1377 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1378 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1379 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1380
1381 /*
1382 *
1383 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1384 *
1385 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1386 * in the ring after this instruction
1387 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1388 */
1389 cmd_wa_gen7_post_command_cs_stall(cmd);
1390}
1391
Chia-I Wu525c6602014-08-27 10:22:34 +08001392void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1393{
Mike Stroyan552fda42015-01-30 17:21:08 -07001394 if (pipe_control_dw0 == 0)
1395 return;
1396
Chia-I Wu525c6602014-08-27 10:22:34 +08001397 if (!cmd->bind.draw_count)
1398 return;
1399
1400 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1401
Chia-I Wu8370b402014-08-29 12:28:37 +08001402 /*
1403 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1404 *
1405 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1406 * PIPE_CONTROL with any non-zero post-sync-op is required."
1407 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001408 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001409 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001410
Chia-I Wu092279a2014-08-30 19:05:30 +08001411 /*
1412 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1413 *
1414 * "One of the following must also be set (when CS stall is set):
1415 *
1416 * * Render Target Cache Flush Enable ([12] of DW1)
1417 * * Depth Cache Flush Enable ([0] of DW1)
1418 * * Stall at Pixel Scoreboard ([1] of DW1)
1419 * * Depth Stall ([13] of DW1)
1420 * * Post-Sync Operation ([13] of DW1)"
1421 */
1422 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1423 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1424 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1425 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1426 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1427 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1428
Chia-I Wud6d079d2014-08-31 13:14:21 +08001429 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001430}
1431
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001432void cmd_batch_flush_all(struct intel_cmd *cmd)
1433{
1434 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1435 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1436 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1437 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1438 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1439 GEN6_PIPE_CONTROL_CS_STALL);
1440}
1441
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001442void cmd_batch_depth_count(struct intel_cmd *cmd,
1443 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001444 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001445{
1446 cmd_wa_gen6_pre_depth_stall_write(cmd);
1447
1448 gen6_PIPE_CONTROL(cmd,
1449 GEN6_PIPE_CONTROL_DEPTH_STALL |
1450 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001451 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001452}
1453
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001454void cmd_batch_timestamp(struct intel_cmd *cmd,
1455 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001456 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001457{
1458 /* need any WA or stall? */
1459 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1460}
1461
1462void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001463 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001464 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001465 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001466 uint64_t val)
1467{
1468 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001469 gen6_PIPE_CONTROL(cmd,
1470 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1471 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001472}
1473
Chia-I Wu302742d2014-08-22 10:28:29 +08001474static void gen6_cc_states(struct intel_cmd *cmd)
1475{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001476 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1477 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001478 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001479 uint32_t stencil_ref;
1480 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001481
1482 CMD_ASSERT(cmd, 6, 6);
1483
Chia-I Wua6c4f152014-12-02 04:19:58 +08001484 blend_offset = gen6_BLEND_STATE(cmd);
1485
1486 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001487 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001488 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001489 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001490
1491 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001492 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001493 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1494 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001495 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001496 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001497 stencil_ref = 0;
1498 }
1499
Chia-I Wu72292b72014-09-09 10:48:33 +08001500 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001501
Chia-I Wu72292b72014-09-09 10:48:33 +08001502 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001503}
1504
Chia-I Wu1744cca2014-08-22 11:10:17 +08001505static void gen6_viewport_states(struct intel_cmd *cmd)
1506{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001507 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001508 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001509
1510 if (!viewport)
1511 return;
1512
Tony Barbourfa6cac72015-01-16 14:27:35 -07001513 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001514 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001515
1516 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001517 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001518 viewport->cmd);
1519
1520 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001521 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001522 &viewport->cmd[viewport->cmd_clip_pos]);
1523
1524 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001525 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001526 &viewport->cmd[viewport->cmd_cc_pos]);
1527
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001528 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1529 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1530 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001531
1532 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001533 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001534
Chia-I Wub1d450a2014-09-09 13:48:03 +08001535 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001536}
1537
Chia-I Wu302742d2014-08-22 10:28:29 +08001538static void gen7_cc_states(struct intel_cmd *cmd)
1539{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001540 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1541 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001542 uint32_t stencil_ref;
1543 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001544 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001545
1546 CMD_ASSERT(cmd, 7, 7.5);
1547
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001548 if (!blend && !ds)
1549 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001550
Chia-I Wua6c4f152014-12-02 04:19:58 +08001551 offset = gen6_BLEND_STATE(cmd);
1552 gen7_3dstate_pointer(cmd,
1553 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001554
Chia-I Wua6c4f152014-12-02 04:19:58 +08001555 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001556 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001557 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001558 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001559
1560 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001561 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001562 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1563 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001564 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001565 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1566 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001567 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1568 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001569 } else {
1570 stencil_ref = 0;
1571 }
1572
Chia-I Wu72292b72014-09-09 10:48:33 +08001573 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001574 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001576}
1577
Chia-I Wu1744cca2014-08-22 11:10:17 +08001578static void gen7_viewport_states(struct intel_cmd *cmd)
1579{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001580 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001581 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001582
1583 if (!viewport)
1584 return;
1585
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001586 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001587
Chia-I Wub1d450a2014-09-09 13:48:03 +08001588 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001589 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001590 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001591 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001592 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1593 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001594
1595 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001596 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001597 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001598 gen7_3dstate_pointer(cmd,
1599 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001600 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001601
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001602 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1603 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1604 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1605 gen7_3dstate_pointer(cmd,
1606 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1607 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001608}
1609
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001610static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001611 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001612{
1613 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001614 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001615
Chia-I Wu72292b72014-09-09 10:48:33 +08001616 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001617
1618 dw[0] = GEN6_RENDER_TYPE_RENDER |
1619 GEN6_RENDER_SUBTYPE_3D |
1620 subop | (cmd_len - 2);
1621 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001622 dw[2] = 0;
1623 dw[3] = 0;
1624 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001625}
1626
1627static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001628 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001629{
1630 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001631 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001632
Chia-I Wu72292b72014-09-09 10:48:33 +08001633 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001634
1635 dw[0] = GEN6_RENDER_TYPE_RENDER |
1636 GEN6_RENDER_SUBTYPE_3D |
1637 subop | (cmd_len - 2);
1638 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001639 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001640 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001641 dw[4] = 0;
1642 dw[5] = 0;
1643 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001644}
1645
Chia-I Wu625105f2014-10-13 15:35:29 +08001646static uint32_t emit_samplers(struct intel_cmd *cmd,
1647 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001648{
Chia-I Wu862c5572015-03-28 15:23:55 +08001649 const struct intel_desc_region *region = cmd->dev->desc_region;
1650 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001651 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1652 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001653 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001654 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001655 uint32_t surface_count;
1656 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001657
1658 CMD_ASSERT(cmd, 6, 7.5);
1659
Chia-I Wu625105f2014-10-13 15:35:29 +08001660 if (!rmap || !rmap->sampler_count)
1661 return 0;
1662
Cody Northrop40316a32014-12-09 19:08:33 -07001663 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001664
Chia-I Wudcb509d2014-12-10 08:53:10 +08001665 /*
1666 * note that we cannot call cmd_state_pointer() here as the following
1667 * cmd_state_pointer() would invalidate the pointer
1668 */
1669 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001670 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001671 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001672
1673 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001674 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001675 4 * rmap->sampler_count, &sampler_dw);
1676
Chia-I Wudcb509d2014-12-10 08:53:10 +08001677 cmd_state_update(cmd, border_offset,
1678 border_stride * rmap->sampler_count, &border_dw);
1679
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001680 for (i = 0; i < rmap->sampler_count; i++) {
1681 const struct intel_pipeline_rmap_slot *slot =
1682 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001683 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001684 const struct intel_sampler *sampler;
1685
Chia-I Wuf8385062015-01-04 16:27:24 +08001686 switch (slot->type) {
1687 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001688 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1689 &data->set_offsets[slot->index]);
1690 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001691 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001692 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001693 sampler = NULL;
1694 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001695 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001696 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001697 sampler = NULL;
1698 break;
1699 }
1700
1701 if (sampler) {
1702 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1703
1704 sampler_dw[0] = sampler->cmd[0];
1705 sampler_dw[1] = sampler->cmd[1];
1706 sampler_dw[2] = border_offset;
1707 sampler_dw[3] = sampler->cmd[2];
1708 } else {
1709 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1710 sampler_dw[1] = 0;
1711 sampler_dw[2] = 0;
1712 sampler_dw[3] = 0;
1713 }
1714
1715 border_offset += border_stride * 4;
1716 border_dw += border_stride;
1717 sampler_dw += 4;
1718 }
1719
Chia-I Wu625105f2014-10-13 15:35:29 +08001720 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001721}
1722
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001723static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001724 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001725 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001726{
Chia-I Wu862c5572015-03-28 15:23:55 +08001727 const struct intel_desc_region *region = cmd->dev->desc_region;
1728 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001729 const uint32_t sba_offset =
1730 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001731 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001732 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001733
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001734 CMD_ASSERT(cmd, 6, 7.5);
1735
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001736 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001737 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001738 if (!surface_count)
1739 return 0;
1740
Chia-I Wu42a56202014-08-23 16:47:48 +08001741 assert(surface_count <= ARRAY_SIZE(binding_table));
1742
1743 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001744 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001745 struct intel_null_view null_view;
1746 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001747
Chia-I Wuf8385062015-01-04 16:27:24 +08001748 switch (slot->type) {
1749 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001750 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001751 const struct intel_rt_view *view =
Chia-I Wu7732cb22015-03-26 15:27:55 +08001752 (slot->index < cmd->bind.fb->rt_count) ?
1753 cmd->bind.fb->rt[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001754
Chia-I Wu787a05b2014-12-05 11:02:20 +08001755 if (view) {
1756 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1757 GEN6_ALIGNMENT_SURFACE_STATE,
1758 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001759
Chia-I Wu787a05b2014-12-05 11:02:20 +08001760 cmd_reserve_reloc(cmd, 1);
1761 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1762 view->cmd[1], INTEL_RELOC_WRITE);
1763 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001764 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001765 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001766 }
1767 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001768 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001769 {
Tony Barbour22a30862015-04-22 09:02:32 -06001770 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001771 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001772 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001773 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001774 const struct intel_mem *mem;
1775 bool read_only;
1776 const uint32_t *cmd_data;
1777 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001778
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001779 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001780 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001781
Chia-I Wu862c5572015-03-28 15:23:55 +08001782 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1783 &data->set_offsets[slot->index]);
1784
1785 intel_desc_region_read_surface(region, &desc_offset, stage,
1786 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001787 if (mem) {
1788 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001789 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001790 const uint32_t reloc_flags =
1791 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001792
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001793 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001794 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001795 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001796
1797 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001798 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1799 cmd_data[1] + dynamic_offset, reloc_flags);
1800 } else {
1801 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001802 }
1803 }
1804 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001805 case INTEL_PIPELINE_RMAP_UNUSED:
1806 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001807 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001808 default:
1809 assert(!"unexpected rmap type");
1810 need_null_view = true;
1811 break;
1812 }
1813
1814 if (need_null_view) {
1815 intel_null_view_init(&null_view, cmd->dev);
1816 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1817 GEN6_ALIGNMENT_SURFACE_STATE,
1818 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001819 }
1820
Chia-I Wuf98dd882015-02-10 04:17:47 +08001821 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001822 }
1823
Chia-I Wuf98dd882015-02-10 04:17:47 +08001824 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001825 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001826 surface_count, binding_table) - sba_offset;
1827
1828 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1829 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1830
1831 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001832}
1833
Chia-I Wu1d125092014-10-08 08:49:38 +08001834static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1835{
1836 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001837 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1838 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001839 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001840
1841 CMD_ASSERT(cmd, 6, 7.5);
1842
1843 if (!pipeline->vb_count)
1844 return;
1845
1846 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1847
1848 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1849 dw++;
1850 pos++;
1851
1852 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001853 assert(pipeline->vb[i].strideInBytes <= 2048);
1854
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001855 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001856 pipeline->vb[i].strideInBytes;
1857
Chia-I Wub3686982015-02-27 09:51:16 -07001858 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001859 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1860 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001861 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001862
1863 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001864 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001865 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001866 dw[3] = 0;
1867 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001868 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001869 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001870 dw[3] = 1;
1871 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001872 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001873 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001874 dw[3] = 0;
1875 break;
1876 default:
1877 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001878 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001879 dw[3] = 0;
1880 break;
1881 }
1882
Chia-I Wu714df452015-01-01 07:55:04 +08001883 if (cmd->bind.vertex.buf[i]) {
1884 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001885 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001886
1887 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001888 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1889 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001890 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001891 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001892 dw[1] = 0;
1893 dw[2] = 0;
1894 }
1895
1896 dw += 4;
1897 pos += 4;
1898 }
1899}
1900
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001901static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1902{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001903 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1904 const struct intel_pipeline_shader *vs = &pipeline->vs;
1905 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001906 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001907 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001908 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001909 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001910
1911 CMD_ASSERT(cmd, 6, 7.5);
1912
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001913 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001914 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1915 *
1916 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1917 * 128-bit vertex elements to be passed into the payload for each
1918 * vertex."
1919 *
1920 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1921 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001922 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001923 vue_read_len = (vs->in_count + 1) / 2;
1924 if (!vue_read_len)
1925 vue_read_len = 1;
1926
1927 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1928 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1929
1930 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1931 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1932 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001933
1934 dw5 = GEN6_VS_DW5_STATISTICS |
1935 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001936
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001937 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001938 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001939 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001940 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001941
Chia-I Wube0a3d92014-09-02 13:20:59 +08001942 if (pipeline->disable_vs_cache)
1943 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1944
Chia-I Wu784d3042014-12-19 14:30:04 +08001945 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001946 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001947 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001948 dw[2] = dw2;
1949 dw[3] = 0; /* scratch */
1950 dw[4] = dw4;
1951 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001952
1953 if (vs->per_thread_scratch_size)
1954 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001955}
1956
Chia-I Wu625105f2014-10-13 15:35:29 +08001957static void emit_shader_resources(struct intel_cmd *cmd)
1958{
1959 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001960 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001961
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001962 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001963 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001964 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001965 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001966 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001967 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001968 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001969 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001970 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001971 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001972 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001973 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001974 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001975 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001976 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001977
1978 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1979 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1980 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1981 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1982 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1983
1984 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1985 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001986 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1987 binding_tables[0]);
1988 gen7_3dstate_pointer(cmd,
1989 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1990 binding_tables[1]);
1991 gen7_3dstate_pointer(cmd,
1992 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1993 binding_tables[2]);
1994 gen7_3dstate_pointer(cmd,
1995 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1996 binding_tables[3]);
1997 gen7_3dstate_pointer(cmd,
1998 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1999 binding_tables[4]);
2000
2001 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08002002 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
2003 samplers[0]);
2004 gen7_3dstate_pointer(cmd,
2005 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
2006 samplers[1]);
2007 gen7_3dstate_pointer(cmd,
2008 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2009 samplers[2]);
2010 gen7_3dstate_pointer(cmd,
2011 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2012 samplers[3]);
2013 gen7_3dstate_pointer(cmd,
2014 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2015 samplers[4]);
2016 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002017 assert(!binding_tables[1] && !binding_tables[2]);
2018 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2019 binding_tables[0], binding_tables[3], binding_tables[4]);
2020
Chia-I Wu625105f2014-10-13 15:35:29 +08002021 assert(!samplers[1] && !samplers[2]);
2022 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2023 samplers[0], samplers[3], samplers[4]);
2024 }
2025}
2026
Chia-I Wu8ada4242015-03-02 11:19:33 -07002027static void emit_msaa(struct intel_cmd *cmd)
2028{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002029 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002030
Chia-I Wubbc7d912015-02-27 14:59:50 -07002031 if (!cmd->bind.render_pass_changed)
2032 return;
2033
Chia-I Wu8ada4242015-03-02 11:19:33 -07002034 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002035 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002036
2037 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2038 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
2039}
2040
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002041static void emit_rt(struct intel_cmd *cmd)
2042{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002043 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002044
2045 if (!cmd->bind.render_pass_changed)
2046 return;
2047
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002048 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002049 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2050 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002051}
2052
2053static void emit_ds(struct intel_cmd *cmd)
2054{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002055 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002056 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002057
Chia-I Wubbc7d912015-02-27 14:59:50 -07002058 if (!cmd->bind.render_pass_changed)
2059 return;
2060
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002061 if (!ds) {
2062 /* all zeros */
2063 static const struct intel_ds_view null_ds;
2064 ds = &null_ds;
2065 }
2066
2067 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07002068 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
2069 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
2070 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002071
2072 if (cmd_gen(cmd) >= INTEL_GEN(7))
2073 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2074 else
2075 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2076}
2077
Chia-I Wua57761b2014-10-14 14:27:44 +08002078static uint32_t emit_shader(struct intel_cmd *cmd,
2079 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002080{
Chia-I Wua57761b2014-10-14 14:27:44 +08002081 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2082 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002083 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002084
Chia-I Wua57761b2014-10-14 14:27:44 +08002085 /* see if the shader is already in the cache */
2086 for (i = 0; i < cache->used; i++) {
2087 if (cache->entries[i].shader == (const void *) shader)
2088 return cache->entries[i].kernel_offset;
2089 }
2090
2091 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2092
2093 /* grow the cache if full */
2094 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002095 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002096 void *entries;
2097
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002098 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002099 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002100 if (entries) {
2101 if (cache->entries) {
2102 memcpy(entries, cache->entries,
2103 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002104 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002105 }
2106
2107 cache->entries = entries;
2108 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002109 }
2110 }
2111
Chia-I Wua57761b2014-10-14 14:27:44 +08002112 /* add the shader to the cache */
2113 if (cache->used < cache->count) {
2114 cache->entries[cache->used].shader = (const void *) shader;
2115 cache->entries[cache->used].kernel_offset = offset;
2116 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002117 }
2118
Chia-I Wua57761b2014-10-14 14:27:44 +08002119 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002120}
2121
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002122static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002123{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002124 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002125
Chia-I Wu8370b402014-08-29 12:28:37 +08002126 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2127 cmd_wa_gen6_pre_depth_stall_write(cmd);
2128 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2129 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2130 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2131 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002132
2133 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002134 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002135 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002136
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002137 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002138 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002139 }
2140 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002141 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002142 }
2143 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002144 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2145 }
2146 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2147 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2148 }
2149 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2150 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002151 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002152
Chia-I Wu8370b402014-08-29 12:28:37 +08002153 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2154 cmd_wa_gen7_post_command_cs_stall(cmd);
2155 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2156 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002157}
2158
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002159static void emit_bounded_states(struct intel_cmd *cmd)
2160{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002161 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002162
2163 emit_graphics_pipeline(cmd);
2164
2165 emit_rt(cmd);
2166 emit_ds(cmd);
2167
2168 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2169 gen7_cc_states(cmd);
2170 gen7_viewport_states(cmd);
2171
2172 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2173 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002174 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2175 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002176 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2177 &cmd->bind.pipeline.graphics->fs);
2178
Cody Northrop293d4502015-05-05 09:38:03 -06002179 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002180 gen6_3DSTATE_CLIP(cmd);
2181 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002182 gen7_3DSTATE_WM(cmd);
2183 gen7_3DSTATE_PS(cmd);
2184 } else {
2185 gen6_cc_states(cmd);
2186 gen6_viewport_states(cmd);
2187
2188 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2189 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002190 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2191 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002192 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2193 &cmd->bind.pipeline.graphics->fs);
2194
Cody Northrop293d4502015-05-05 09:38:03 -06002195 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002196 gen6_3DSTATE_CLIP(cmd);
2197 gen6_3DSTATE_SF(cmd);
2198 gen6_3DSTATE_WM(cmd);
2199 }
2200
2201 emit_shader_resources(cmd);
2202
2203 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002204
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002205 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2206 gen6_3DSTATE_VS(cmd);
2207}
2208
Tony Barbourfa6cac72015-01-16 14:27:35 -07002209static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002210 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002211{
2212 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2213 const uint8_t cmd_len = 3;
2214 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002215
2216 CMD_ASSERT(cmd, 6, 7.5);
2217
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002218 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002219 dw[0] = 0;
2220 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002221
2222 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2223 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2224 GEN6_COMPAREFUNCTION_NEVER << 27 |
2225 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2226 } else {
2227 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2228 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2229 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002230 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002231 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002232 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2233 (GEN6_STENCILOP_KEEP) << 25 |
2234 (GEN6_STENCILOP_KEEP) << 22 |
2235 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002236 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2237 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002238 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2239 (GEN6_STENCILOP_KEEP) << 9 |
2240 (GEN6_STENCILOP_KEEP) << 6 |
2241 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002242
Chia-I Wud850a392015-02-19 11:08:25 -07002243 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2244 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2245 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2246 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2247 dw[2] = 0;
2248 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002249
2250 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2251 cmd_align, cmd_len, dw);
2252}
2253
Chia-I Wu6032b892014-10-17 14:47:18 +08002254static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2255{
2256 const struct intel_cmd_meta *meta = cmd->bind.meta;
2257 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2258
2259 CMD_ASSERT(cmd, 6, 7.5);
2260
2261 blend_offset = 0;
2262 ds_offset = 0;
2263 cc_offset = 0;
2264 cc_vp_offset = 0;
2265
Chia-I Wu29e6f502014-11-24 14:27:29 +08002266 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002267 /* BLEND_STATE */
2268 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002269 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002270 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002271 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002272 }
2273
Chia-I Wu29e6f502014-11-24 14:27:29 +08002274 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002275 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002277 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2278 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002279
Chia-I Wu29e6f502014-11-24 14:27:29 +08002280 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002281 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002282
Chia-I Wu29e6f502014-11-24 14:27:29 +08002283 /* COLOR_CALC_STATE */
2284 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002285 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002286
Chia-I Wu29e6f502014-11-24 14:27:29 +08002287 /* CC_VIEWPORT */
2288 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002289 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 dw[0] = u_fui(0.0f);
2291 dw[1] = u_fui(1.0f);
2292 } else {
2293 /* DEPTH_STENCIL_STATE */
2294 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002295 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2297 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2298 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002299 }
2300
2301 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2302 gen7_3dstate_pointer(cmd,
2303 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2304 blend_offset);
2305 gen7_3dstate_pointer(cmd,
2306 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2307 ds_offset);
2308 gen7_3dstate_pointer(cmd,
2309 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2310
2311 gen7_3dstate_pointer(cmd,
2312 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2313 cc_vp_offset);
2314 } else {
2315 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002316 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002317
2318 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2319 cmd_batch_pointer(cmd, 4, &dw);
2320 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002321 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002322 dw[1] = 0;
2323 dw[2] = 0;
2324 dw[3] = cc_vp_offset;
2325 }
2326}
2327
2328static void gen6_meta_surface_states(struct intel_cmd *cmd)
2329{
2330 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002331 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002332 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002333 const uint32_t sba_offset =
2334 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002335
2336 CMD_ASSERT(cmd, 6, 7.5);
2337
Chia-I Wu29e6f502014-11-24 14:27:29 +08002338 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2339 return;
2340
Chia-I Wu005c47c2014-10-22 13:49:13 +08002341 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002342 if (meta->src.valid) {
2343 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002344 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 meta->src.surface_len, meta->src.surface);
2346
2347 cmd_reserve_reloc(cmd, 1);
2348 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2349 cmd_surface_reloc_writer(cmd, offset, 1,
2350 meta->src.reloc_target, meta->src.reloc_offset);
2351 } else {
2352 cmd_surface_reloc(cmd, offset, 1,
2353 (struct intel_bo *) meta->src.reloc_target,
2354 meta->src.reloc_offset, meta->src.reloc_flags);
2355 }
2356
Mike Stroyan9bfad482015-02-10 15:09:23 -07002357 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002358 }
2359 if (meta->dst.valid) {
2360 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002361 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002362 meta->dst.surface_len, meta->dst.surface);
2363
2364 cmd_reserve_reloc(cmd, 1);
2365 cmd_surface_reloc(cmd, offset, 1,
2366 (struct intel_bo *) meta->dst.reloc_target,
2367 meta->dst.reloc_offset, meta->dst.reloc_flags);
2368
Mike Stroyan9bfad482015-02-10 15:09:23 -07002369 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002370 }
2371
2372 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002373 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002374 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002375 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002376
2377 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002378 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2379 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2380 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002381 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002382 } else {
2383 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002384 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002385 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002386 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002387 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002388 }
2389}
2390
2391static void gen6_meta_urb(struct intel_cmd *cmd)
2392{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002393 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002394 uint32_t *dw;
2395
2396 CMD_ASSERT(cmd, 6, 6);
2397
2398 /* 3DSTATE_URB */
2399 cmd_batch_pointer(cmd, 3, &dw);
2400 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002401 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002402 dw[2] = 0;
2403}
2404
2405static void gen7_meta_urb(struct intel_cmd *cmd)
2406{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002407 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2408 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002409 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002410 uint32_t *dw;
2411
2412 CMD_ASSERT(cmd, 7, 7.5);
2413
Chia-I Wu6032b892014-10-17 14:47:18 +08002414 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2415
Chia-I Wu24aa1022014-11-25 11:53:19 +08002416 switch (cmd_gen(cmd)) {
2417 case INTEL_GEN(7.5):
2418 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2419 break;
2420 case INTEL_GEN(7):
2421 default:
2422 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2423 break;
2424 }
2425
Chia-I Wu6032b892014-10-17 14:47:18 +08002426 /* 3DSTATE_URB_x */
2427 cmd_batch_pointer(cmd, 8, &dw);
2428
2429 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002430 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002431 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002432 dw += 2;
2433
2434 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002435 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002436 dw += 2;
2437
2438 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002439 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002440 dw += 2;
2441
2442 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002443 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002444 dw += 2;
2445}
2446
2447static void gen6_meta_vf(struct intel_cmd *cmd)
2448{
2449 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002450 uint32_t vb_start, vb_end, vb_stride;
2451 int ve_format, ve_z_source;
2452 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002453 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002454
2455 CMD_ASSERT(cmd, 6, 7.5);
2456
Chia-I Wu29e6f502014-11-24 14:27:29 +08002457 switch (meta->mode) {
2458 case INTEL_CMD_META_VS_POINTS:
2459 cmd_batch_pointer(cmd, 3, &dw);
2460 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002461 dw[1] = GEN6_VE_DW0_VALID;
2462 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2463 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2464 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2465 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002466 return;
2467 break;
2468 case INTEL_CMD_META_FS_RECT:
2469 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002470 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002471
Chia-I Wu29e6f502014-11-24 14:27:29 +08002472 vertices[0][0] = meta->dst.x + meta->width;
2473 vertices[0][1] = meta->dst.y + meta->height;
2474 vertices[1][0] = meta->dst.x;
2475 vertices[1][1] = meta->dst.y + meta->height;
2476 vertices[2][0] = meta->dst.x;
2477 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002478
Chia-I Wu29e6f502014-11-24 14:27:29 +08002479 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2480 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002481
Chia-I Wu29e6f502014-11-24 14:27:29 +08002482 vb_end = vb_start + sizeof(vertices) - 1;
2483 vb_stride = sizeof(vertices[0]);
2484 ve_z_source = GEN6_VFCOMP_STORE_0;
2485 ve_format = GEN6_FORMAT_R32G32_USCALED;
2486 }
2487 break;
2488 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2489 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002490 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002491
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002492 vertices[0][0] = (float) (meta->dst.x + meta->width);
2493 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002494 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002495 vertices[1][0] = (float) meta->dst.x;
2496 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002497 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002498 vertices[2][0] = (float) meta->dst.x;
2499 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002500 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002501
Chia-I Wu29e6f502014-11-24 14:27:29 +08002502 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2503 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002504
Chia-I Wu29e6f502014-11-24 14:27:29 +08002505 vb_end = vb_start + sizeof(vertices) - 1;
2506 vb_stride = sizeof(vertices[0]);
2507 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2508 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2509 }
2510 break;
2511 default:
2512 assert(!"unknown meta mode");
2513 return;
2514 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002515 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002516
2517 /* 3DSTATE_VERTEX_BUFFERS */
2518 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002519
Chia-I Wu6032b892014-10-17 14:47:18 +08002520 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002521 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002522 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002523 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002524
2525 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002526 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2527 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002528
2529 dw[4] = 0;
2530
2531 /* 3DSTATE_VERTEX_ELEMENTS */
2532 cmd_batch_pointer(cmd, 5, &dw);
2533 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002534 dw[1] = GEN6_VE_DW0_VALID;
2535 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2536 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2537 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2538 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2539 dw[3] = GEN6_VE_DW0_VALID |
2540 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2541 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2542 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2543 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2544 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002545}
2546
Chia-I Wu29e6f502014-11-24 14:27:29 +08002547static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002548{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002549 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002550 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002551 uint32_t consts[8];
2552 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002553
2554 CMD_ASSERT(cmd, 6, 7.5);
2555
2556 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002557 case INTEL_DEV_META_VS_FILL_MEM:
2558 consts[0] = meta->dst.x;
2559 consts[1] = meta->clear_val[0];
2560 const_count = 2;
2561 break;
2562 case INTEL_DEV_META_VS_COPY_MEM:
2563 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2564 consts[0] = meta->dst.x;
2565 consts[1] = meta->src.x;
2566 const_count = 2;
2567 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002568 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2569 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2570 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2571 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2572 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2573 consts[0] = meta->src.x;
2574 consts[1] = meta->src.y;
2575 consts[2] = meta->width;
2576 consts[3] = meta->dst.x;
2577 const_count = 4;
2578 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002579 default:
2580 assert(!"unknown meta shader id");
2581 const_count = 0;
2582 break;
2583 }
2584
2585 /* this can be skipped but it makes state dumping prettier */
2586 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2587
2588 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2589}
2590
2591static void gen6_meta_vs(struct intel_cmd *cmd)
2592{
2593 const struct intel_cmd_meta *meta = cmd->bind.meta;
2594 const struct intel_pipeline_shader *sh =
2595 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2596 uint32_t offset, *dw;
2597
2598 CMD_ASSERT(cmd, 6, 7.5);
2599
2600 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002601 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002602
2603 /* 3DSTATE_CONSTANT_VS */
2604 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2605 cmd_batch_pointer(cmd, cmd_len, &dw);
2606 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2607 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2608
2609 /* 3DSTATE_VS */
2610 cmd_batch_pointer(cmd, 6, &dw);
2611 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2612 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2613
2614 return;
2615 }
2616
2617 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2618
2619 /* 3DSTATE_CONSTANT_VS */
2620 offset = gen6_meta_vs_constants(cmd);
2621 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2622 cmd_batch_pointer(cmd, 7, &dw);
2623 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002624 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002625 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002626 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002627 dw[4] = 0;
2628 dw[5] = 0;
2629 dw[6] = 0;
2630 } else {
2631 cmd_batch_pointer(cmd, 5, &dw);
2632 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002633 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002634 dw[1] = offset;
2635 dw[2] = 0;
2636 dw[3] = 0;
2637 dw[4] = 0;
2638 }
2639
2640 /* 3DSTATE_VS */
2641 offset = emit_shader(cmd, sh);
2642 cmd_batch_pointer(cmd, 6, &dw);
2643 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2644 dw[1] = offset;
2645 dw[2] = GEN6_THREADDISP_SPF |
2646 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2647 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002648 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002649 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2650 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2651
2652 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2653 GEN6_VS_DW5_VS_ENABLE;
2654 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002655 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002656 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002657 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002658
2659 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002660}
2661
2662static void gen6_meta_disabled(struct intel_cmd *cmd)
2663{
Chia-I Wu6032b892014-10-17 14:47:18 +08002664 uint32_t *dw;
2665
2666 CMD_ASSERT(cmd, 6, 6);
2667
Chia-I Wu6032b892014-10-17 14:47:18 +08002668 /* 3DSTATE_CONSTANT_GS */
2669 cmd_batch_pointer(cmd, 5, &dw);
2670 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2671 dw[1] = 0;
2672 dw[2] = 0;
2673 dw[3] = 0;
2674 dw[4] = 0;
2675
2676 /* 3DSTATE_GS */
2677 cmd_batch_pointer(cmd, 7, &dw);
2678 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2679 dw[1] = 0;
2680 dw[2] = 0;
2681 dw[3] = 0;
2682 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2683 dw[5] = GEN6_GS_DW5_STATISTICS;
2684 dw[6] = 0;
2685
Chia-I Wu6032b892014-10-17 14:47:18 +08002686 /* 3DSTATE_SF */
2687 cmd_batch_pointer(cmd, 20, &dw);
2688 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2689 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2690 memset(&dw[2], 0, 18 * sizeof(*dw));
2691}
2692
2693static void gen7_meta_disabled(struct intel_cmd *cmd)
2694{
2695 uint32_t *dw;
2696
2697 CMD_ASSERT(cmd, 7, 7.5);
2698
Chia-I Wu6032b892014-10-17 14:47:18 +08002699 /* 3DSTATE_CONSTANT_HS */
2700 cmd_batch_pointer(cmd, 7, &dw);
2701 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2702 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2703
2704 /* 3DSTATE_HS */
2705 cmd_batch_pointer(cmd, 7, &dw);
2706 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2707 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2708
2709 /* 3DSTATE_TE */
2710 cmd_batch_pointer(cmd, 4, &dw);
2711 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2712 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2713
2714 /* 3DSTATE_CONSTANT_DS */
2715 cmd_batch_pointer(cmd, 7, &dw);
2716 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2717 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2718
2719 /* 3DSTATE_DS */
2720 cmd_batch_pointer(cmd, 6, &dw);
2721 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2722 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2723
2724 /* 3DSTATE_CONSTANT_GS */
2725 cmd_batch_pointer(cmd, 7, &dw);
2726 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2727 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2728
2729 /* 3DSTATE_GS */
2730 cmd_batch_pointer(cmd, 7, &dw);
2731 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2732 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2733
2734 /* 3DSTATE_STREAMOUT */
2735 cmd_batch_pointer(cmd, 3, &dw);
2736 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2737 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2738
Chia-I Wu6032b892014-10-17 14:47:18 +08002739 /* 3DSTATE_SF */
2740 cmd_batch_pointer(cmd, 7, &dw);
2741 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2742 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2743
2744 /* 3DSTATE_SBE */
2745 cmd_batch_pointer(cmd, 14, &dw);
2746 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2747 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2748 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002749}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002750
Chia-I Wu29e6f502014-11-24 14:27:29 +08002751static void gen6_meta_clip(struct intel_cmd *cmd)
2752{
2753 const struct intel_cmd_meta *meta = cmd->bind.meta;
2754 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002755
Chia-I Wu29e6f502014-11-24 14:27:29 +08002756 /* 3DSTATE_CLIP */
2757 cmd_batch_pointer(cmd, 4, &dw);
2758 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2759 dw[1] = 0;
2760 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2761 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2762 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2763 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002764 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002765 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002766 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002767}
2768
2769static void gen6_meta_wm(struct intel_cmd *cmd)
2770{
2771 const struct intel_cmd_meta *meta = cmd->bind.meta;
2772 uint32_t *dw;
2773
2774 CMD_ASSERT(cmd, 6, 7.5);
2775
2776 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2777
2778 /* 3DSTATE_MULTISAMPLE */
2779 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2780 cmd_batch_pointer(cmd, 4, &dw);
2781 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2782 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2783 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2784 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2785 dw[2] = 0;
2786 dw[3] = 0;
2787 } else {
2788 cmd_batch_pointer(cmd, 3, &dw);
2789 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2790 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2791 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2792 dw[2] = 0;
2793 }
2794
2795 /* 3DSTATE_SAMPLE_MASK */
2796 cmd_batch_pointer(cmd, 2, &dw);
2797 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2798 dw[1] = (1 << meta->samples) - 1;
2799
2800 /* 3DSTATE_DRAWING_RECTANGLE */
2801 cmd_batch_pointer(cmd, 4, &dw);
2802 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002803 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2804 /* unused */
2805 dw[1] = 0;
2806 dw[2] = 0;
2807 } else {
2808 dw[1] = meta->dst.y << 16 | meta->dst.x;
2809 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2810 (meta->dst.x + meta->width - 1);
2811 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002812 dw[3] = 0;
2813}
2814
2815static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2816{
2817 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002818 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002819 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002820 uint32_t consts[8];
2821 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002822
2823 CMD_ASSERT(cmd, 6, 7.5);
2824
2825 /* underflow is fine here */
2826 offset_x = meta->src.x - meta->dst.x;
2827 offset_y = meta->src.y - meta->dst.y;
2828
2829 switch (meta->shader_id) {
2830 case INTEL_DEV_META_FS_COPY_MEM:
2831 case INTEL_DEV_META_FS_COPY_1D:
2832 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2833 case INTEL_DEV_META_FS_COPY_2D:
2834 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2835 case INTEL_DEV_META_FS_COPY_2D_MS:
2836 consts[0] = offset_x;
2837 consts[1] = offset_y;
2838 consts[2] = meta->src.layer;
2839 consts[3] = meta->src.lod;
2840 const_count = 4;
2841 break;
2842 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2843 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2844 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2845 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2846 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2847 consts[0] = offset_x;
2848 consts[1] = offset_y;
2849 consts[2] = meta->src.layer;
2850 consts[3] = meta->src.lod;
2851 consts[4] = meta->src.x;
2852 consts[5] = meta->width;
2853 const_count = 6;
2854 break;
2855 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2856 consts[0] = offset_x;
2857 consts[1] = offset_y;
2858 consts[2] = meta->width;
2859 const_count = 3;
2860 break;
2861 case INTEL_DEV_META_FS_CLEAR_COLOR:
2862 consts[0] = meta->clear_val[0];
2863 consts[1] = meta->clear_val[1];
2864 consts[2] = meta->clear_val[2];
2865 consts[3] = meta->clear_val[3];
2866 const_count = 4;
2867 break;
2868 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2869 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002870 consts[1] = meta->clear_val[1];
2871 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002872 break;
2873 case INTEL_DEV_META_FS_RESOLVE_2X:
2874 case INTEL_DEV_META_FS_RESOLVE_4X:
2875 case INTEL_DEV_META_FS_RESOLVE_8X:
2876 case INTEL_DEV_META_FS_RESOLVE_16X:
2877 consts[0] = offset_x;
2878 consts[1] = offset_y;
2879 const_count = 2;
2880 break;
2881 default:
2882 assert(!"unknown meta shader id");
2883 const_count = 0;
2884 break;
2885 }
2886
2887 /* this can be skipped but it makes state dumping prettier */
2888 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2889
2890 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2891}
2892
2893static void gen6_meta_ps(struct intel_cmd *cmd)
2894{
2895 const struct intel_cmd_meta *meta = cmd->bind.meta;
2896 const struct intel_pipeline_shader *sh =
2897 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2898 uint32_t offset, *dw;
2899
2900 CMD_ASSERT(cmd, 6, 6);
2901
Chia-I Wu29e6f502014-11-24 14:27:29 +08002902 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2903 /* 3DSTATE_CONSTANT_PS */
2904 cmd_batch_pointer(cmd, 5, &dw);
2905 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2906 dw[1] = 0;
2907 dw[2] = 0;
2908 dw[3] = 0;
2909 dw[4] = 0;
2910
2911 /* 3DSTATE_WM */
2912 cmd_batch_pointer(cmd, 9, &dw);
2913 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2914 dw[1] = 0;
2915 dw[2] = 0;
2916 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002917
2918 switch (meta->ds.op) {
2919 case INTEL_CMD_META_DS_HIZ_CLEAR:
2920 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2921 break;
2922 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2923 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2924 break;
2925 case INTEL_CMD_META_DS_RESOLVE:
2926 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2927 break;
2928 default:
2929 dw[4] = 0;
2930 break;
2931 }
2932
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002933 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002934 dw[6] = 0;
2935 dw[7] = 0;
2936 dw[8] = 0;
2937
Chia-I Wu3adf7212014-10-24 15:34:07 +08002938 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002939 }
2940
Chia-I Wu3adf7212014-10-24 15:34:07 +08002941 /* a normal color write */
2942 assert(meta->dst.valid && !sh->uses);
2943
Chia-I Wu6032b892014-10-17 14:47:18 +08002944 /* 3DSTATE_CONSTANT_PS */
2945 offset = gen6_meta_ps_constants(cmd);
2946 cmd_batch_pointer(cmd, 5, &dw);
2947 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002948 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002949 dw[1] = offset;
2950 dw[2] = 0;
2951 dw[3] = 0;
2952 dw[4] = 0;
2953
2954 /* 3DSTATE_WM */
2955 offset = emit_shader(cmd, sh);
2956 cmd_batch_pointer(cmd, 9, &dw);
2957 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2958 dw[1] = offset;
2959 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2960 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002961 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002962 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002963 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002964 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2965 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002966
Chia-I Wu6032b892014-10-17 14:47:18 +08002967 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002968 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002969 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2970 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2971 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2972 if (meta->samples > 1) {
2973 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2974 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2975 } else {
2976 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2977 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2978 }
2979 dw[7] = 0;
2980 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002981
2982 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002983}
2984
2985static void gen7_meta_ps(struct intel_cmd *cmd)
2986{
2987 const struct intel_cmd_meta *meta = cmd->bind.meta;
2988 const struct intel_pipeline_shader *sh =
2989 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2990 uint32_t offset, *dw;
2991
2992 CMD_ASSERT(cmd, 7, 7.5);
2993
Chia-I Wu29e6f502014-11-24 14:27:29 +08002994 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2995 /* 3DSTATE_WM */
2996 cmd_batch_pointer(cmd, 3, &dw);
2997 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002998
2999 switch (meta->ds.op) {
3000 case INTEL_CMD_META_DS_HIZ_CLEAR:
3001 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
3002 break;
3003 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3004 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
3005 break;
3006 case INTEL_CMD_META_DS_RESOLVE:
3007 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3008 break;
3009 default:
3010 dw[1] = 0;
3011 break;
3012 }
3013
3014 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003015
3016 /* 3DSTATE_CONSTANT_GS */
3017 cmd_batch_pointer(cmd, 7, &dw);
3018 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3019 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3020
3021 /* 3DSTATE_PS */
3022 cmd_batch_pointer(cmd, 8, &dw);
3023 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3024 dw[1] = 0;
3025 dw[2] = 0;
3026 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003027 /* required to avoid hangs */
3028 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003029 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003030 dw[5] = 0;
3031 dw[6] = 0;
3032 dw[7] = 0;
3033
Chia-I Wu3adf7212014-10-24 15:34:07 +08003034 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003035 }
3036
Chia-I Wu3adf7212014-10-24 15:34:07 +08003037 /* a normal color write */
3038 assert(meta->dst.valid && !sh->uses);
3039
Chia-I Wu6032b892014-10-17 14:47:18 +08003040 /* 3DSTATE_WM */
3041 cmd_batch_pointer(cmd, 3, &dw);
3042 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003043 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003044 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3045 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3046 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3047 dw[2] = 0;
3048
3049 /* 3DSTATE_CONSTANT_PS */
3050 offset = gen6_meta_ps_constants(cmd);
3051 cmd_batch_pointer(cmd, 7, &dw);
3052 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003053 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003054 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003055 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003056 dw[4] = 0;
3057 dw[5] = 0;
3058 dw[6] = 0;
3059
3060 /* 3DSTATE_PS */
3061 offset = emit_shader(cmd, sh);
3062 cmd_batch_pointer(cmd, 8, &dw);
3063 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3064 dw[1] = offset;
3065 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3066 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003067 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003068
3069 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3070 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003071 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003072
3073 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003074 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003075 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003076 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003077 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003078 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003079
3080 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3081 dw[6] = 0;
3082 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003083
3084 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003085}
3086
3087static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3088{
3089 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003090 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003091
3092 CMD_ASSERT(cmd, 6, 7.5);
3093
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003094 if (!ds) {
3095 /* all zeros */
3096 static const struct intel_ds_view null_ds;
3097 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003098 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003099
3100 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003101 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3102 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3103 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003104
3105 if (cmd_gen(cmd) >= INTEL_GEN(7))
3106 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3107 else
3108 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003109}
3110
Chia-I Wu862c5572015-03-28 15:23:55 +08003111static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3112 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003113 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003114{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003115 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003116 if (data->set_offsets)
3117 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003118
Chia-I Wu862c5572015-03-28 15:23:55 +08003119 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003120 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003121 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003122 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003123 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003124 data->set_offset_count = 0;
3125 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003126 }
3127
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003128 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003129 }
3130
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003131 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003132 if (data->dynamic_offsets)
3133 intel_free(cmd, data->dynamic_offsets);
3134
3135 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003136 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003137 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003138 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003139 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003140 data->dynamic_offset_count = 0;
3141 return false;
3142 }
3143
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003144 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003145 }
3146
3147 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003148}
3149
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003150static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3151 const struct intel_pipeline *pipeline)
3152{
3153 cmd->bind.pipeline.graphics = pipeline;
3154
3155 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003156 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003157}
3158
3159static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3160 const struct intel_pipeline *pipeline)
3161{
3162 cmd->bind.pipeline.compute = pipeline;
3163
3164 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003165 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003166}
3167
Chia-I Wu862c5572015-03-28 15:23:55 +08003168static void cmd_copy_dset_data(struct intel_cmd *cmd,
3169 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003170 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003171 uint32_t index,
3172 const struct intel_desc_set *set,
3173 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003174{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003175 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003176
Chia-I Wu862c5572015-03-28 15:23:55 +08003177 assert(index < data->set_offset_count);
3178 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003179
Chia-I Wu862c5572015-03-28 15:23:55 +08003180 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003181 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003182 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003183
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003184 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003185 dynamic_offsets,
3186 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003187 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188}
3189
Chia-I Wu3b04af52014-11-08 10:48:20 +08003190static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003191 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003192 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003193{
Chia-I Wu714df452015-01-01 07:55:04 +08003194 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003195 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003196 return;
3197 }
3198
Chia-I Wu714df452015-01-01 07:55:04 +08003199 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003200 cmd->bind.vertex.offset[binding] = offset;
3201}
3202
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003204 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003205 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003206{
Chia-I Wu714df452015-01-01 07:55:04 +08003207 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003208 cmd->bind.index.offset = offset;
3209 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003210}
3211
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003212static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003213 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003214{
3215 cmd->bind.state.viewport = state;
3216}
3217
3218static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003219 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003220{
3221 cmd->bind.state.raster = state;
3222}
3223
3224static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003225 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003226{
3227 cmd->bind.state.ds = state;
3228}
3229
3230static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003231 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003232{
3233 cmd->bind.state.blend = state;
3234}
3235
Chia-I Wuf98dd882015-02-10 04:17:47 +08003236static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3237{
3238 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3239 struct intel_pipeline_rmap *rmaps[5] = {
3240 pipeline->vs.rmap,
3241 pipeline->tcs.rmap,
3242 pipeline->tes.rmap,
3243 pipeline->gs.rmap,
3244 pipeline->fs.rmap,
3245 };
3246 uint32_t max_write;
3247 int i;
3248
3249 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3250 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3251 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3252
3253 /* pad first */
3254 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3255
3256 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3257 const struct intel_pipeline_rmap *rmap = rmaps[i];
3258 const uint32_t surface_count = (rmap) ?
3259 rmap->rt_count + rmap->texture_resource_count +
3260 rmap->resource_count + rmap->uav_count : 0;
3261
3262 if (surface_count) {
3263 /* SURFACE_STATEs */
3264 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3265
3266 /* BINDING_TABLE_STATE */
3267 max_write += u_align(sizeof(uint32_t) * surface_count,
3268 GEN6_ALIGNMENT_SURFACE_STATE);
3269 }
3270 }
3271
3272 return max_write;
3273}
3274
3275static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3276{
3277 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3278 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3279 uint32_t max_surface_write;
3280
3281 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3282 if (cmd->bind.meta)
3283 max_surface_write = 64 * sizeof(uint32_t);
3284 else
3285 max_surface_write = cmd_get_max_surface_write(cmd);
3286
3287 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3288 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3289 /* SBA expects page-aligned addresses */
3290 writer->sba_offset = writer->used & ~0xfff;
3291
3292 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3293
3294 cmd_batch_state_base_address(cmd);
3295 }
3296}
3297
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003298static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003299 uint32_t vertex_start,
3300 uint32_t vertex_count,
3301 uint32_t instance_start,
3302 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003303 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003304 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003305{
3306 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003307 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003308 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3309
3310 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003311
3312 emit_bounded_states(cmd);
3313
Chia-I Wuf98dd882015-02-10 04:17:47 +08003314 /* sanity check on cmd_get_max_surface_write() */
3315 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3316 surface_writer_used <= cmd_get_max_surface_write(cmd));
3317
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003318 if (indexed) {
3319 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003320 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003321
3322 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3323 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3324 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003325 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003326 cmd->bind.index.offset, cmd->bind.index.type,
3327 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003328 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003329 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003330 cmd->bind.index.offset, cmd->bind.index.type,
3331 p->primitive_restart);
3332 }
3333 } else {
3334 assert(!vertex_base);
3335 }
3336
3337 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3338 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3339 vertex_start, instance_count, instance_start, vertex_base);
3340 } else {
3341 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3342 vertex_start, instance_count, instance_start, vertex_base);
3343 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003344
Chia-I Wu707a29e2014-08-27 12:51:47 +08003345 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003346 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003347 /* need to re-emit all workarounds */
3348 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003349
3350 if (intel_debug & INTEL_DEBUG_NOCACHE)
3351 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003352}
3353
Chia-I Wuc14d1562014-10-17 09:49:22 +08003354void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3355{
Chia-I Wu6032b892014-10-17 14:47:18 +08003356 cmd->bind.meta = meta;
3357
Chia-I Wuf98dd882015-02-10 04:17:47 +08003358 cmd_adjust_state_base_address(cmd);
3359
Chia-I Wu6032b892014-10-17 14:47:18 +08003360 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003361 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003362
3363 gen6_meta_dynamic_states(cmd);
3364 gen6_meta_surface_states(cmd);
3365
3366 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3367 gen7_meta_urb(cmd);
3368 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003369 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003370 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003371 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003372 gen6_meta_wm(cmd);
3373 gen7_meta_ps(cmd);
3374 gen6_meta_depth_buffer(cmd);
3375
3376 cmd_wa_gen7_post_command_cs_stall(cmd);
3377 cmd_wa_gen7_post_command_depth_stall(cmd);
3378
Chia-I Wu29e6f502014-11-24 14:27:29 +08003379 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3380 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003381 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003382 } else {
3383 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3384 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003385 } else {
3386 gen6_meta_urb(cmd);
3387 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003388 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003389 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003390 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003391 gen6_meta_wm(cmd);
3392 gen6_meta_ps(cmd);
3393 gen6_meta_depth_buffer(cmd);
3394
Chia-I Wu29e6f502014-11-24 14:27:29 +08003395 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3396 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003397 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003398 } else {
3399 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3400 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003401 }
3402
3403 cmd->bind.draw_count++;
3404 /* need to re-emit all workarounds */
3405 cmd->bind.wa_flags = 0;
3406
3407 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003408
Chia-I Wubbc7d912015-02-27 14:59:50 -07003409 /* make the normal path believe the render pass has changed */
3410 cmd->bind.render_pass_changed = true;
3411
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003412 if (intel_debug & INTEL_DEBUG_NOCACHE)
3413 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003414}
3415
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003416ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003417 VkCmdBuffer cmdBuffer,
3418 VkPipelineBindPoint pipelineBindPoint,
3419 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003420{
3421 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3422
3423 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003424 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003425 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003426 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003427 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003428 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003429 break;
3430 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003431 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003432 break;
3433 }
3434}
3435
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003436ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003437 VkCmdBuffer cmdBuffer,
3438 VkStateBindPoint stateBindPoint,
3439 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003440{
3441 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3442
3443 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003444 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003445 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003446 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003447 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003448 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003449 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003450 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003451 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003452 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003453 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003454 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003455 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003456 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003457 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003458 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003459 break;
3460 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003461 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003462 break;
3463 }
3464}
3465
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003466ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003467 VkCmdBuffer cmdBuffer,
3468 VkPipelineBindPoint pipelineBindPoint,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003469 uint32_t firstSet,
3470 uint32_t setCount,
3471 const VkDescriptorSet* pDescriptorSets,
3472 uint32_t dynamicOffsetCount,
3473 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003474{
3475 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003476 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003477 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003478 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003479 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003480
3481 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003482 case VK_PIPELINE_BIND_POINT_COMPUTE:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003483 pipeline_layout = cmd->bind.pipeline.compute->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003484 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003485 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003486 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003487 pipeline_layout = cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003488 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003489 break;
3490 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003491 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003492 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003493 break;
3494 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003495
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003496 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003497 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3498
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003499 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003500 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003501 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003502 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003503 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003504 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003505 }
Chia-I Wub2755562014-08-20 13:38:52 +08003506}
3507
Tony Barbour8205d902015-04-16 15:59:00 -06003508
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003509ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3510 VkCmdBuffer cmdBuffer,
3511 uint32_t startBinding,
3512 uint32_t bindingCount,
3513 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003514 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003515{
3516 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003517
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003518 for (uint32_t i = 0; i < bindingCount; i++) {
3519 struct intel_buf *buf = intel_buf(pBuffers[i]);
3520 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3521 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003522}
3523
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003524ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003525 VkCmdBuffer cmdBuffer,
3526 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003527 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003528 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003529{
3530 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003531 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003532
Chia-I Wu714df452015-01-01 07:55:04 +08003533 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003534}
3535
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003536ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003537 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003538 uint32_t firstVertex,
3539 uint32_t vertexCount,
3540 uint32_t firstInstance,
3541 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003542{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003543 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003544
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003545 cmd_draw(cmd, firstVertex, vertexCount,
3546 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003547}
3548
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003549ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003550 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003551 uint32_t firstIndex,
3552 uint32_t indexCount,
3553 int32_t vertexOffset,
3554 uint32_t firstInstance,
3555 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003556{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003557 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003558
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003559 cmd_draw(cmd, firstIndex, indexCount,
3560 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003561}
3562
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003563ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003564 VkCmdBuffer cmdBuffer,
3565 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003566 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003567 uint32_t count,
3568 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003569{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003570 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3571
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003572 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003573}
3574
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003575ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003576 VkCmdBuffer cmdBuffer,
3577 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003578 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003579 uint32_t count,
3580 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003581{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003582 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3583
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003584 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003585}
3586
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003587ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003588 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003589 uint32_t x,
3590 uint32_t y,
3591 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003592{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003593 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3594
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003595 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003596}
3597
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003598ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003599 VkCmdBuffer cmdBuffer,
3600 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003601 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003602{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003603 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3604
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003605 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003606}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003607
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003608ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003609 VkCmdBuffer cmdBuffer,
3610 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003611{
3612 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003613 struct intel_render_pass *rp = (struct intel_render_pass *) pRenderPassBegin->renderPass;
3614 struct intel_fb *fb = (struct intel_fb *) pRenderPassBegin->framebuffer;
3615 unsigned i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003616
Chris Forbesfff9bf42015-06-15 15:26:19 +12003617 cmd_begin_render_pass(cmd, rp, fb);
3618
3619 /* issue load ops */
3620 for (i = 0; i < rp->colorAttachmentCount; i++) {
3621 if (rp->colorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3622 /* issue clear of this attachment */
3623 const struct intel_rt_view *rt = fb->rt[i];
3624
3625 VkImageSubresourceRange ranges[1] = {{
3626 VK_IMAGE_ASPECT_COLOR,
3627 rt->mipLevel,
3628 1,
3629 rt->baseArraySlice,
3630 rt->array_size
3631 }};
3632
3633 cmd_meta_clear_color_image(cmdBuffer, (VkImage) rt->img,
3634 rp->colorLayouts[i],
3635 &rp->colorClearValues[i],
3636 1,
3637 ranges);
3638 }
3639 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003640}
3641
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003642ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003643 VkCmdBuffer cmdBuffer,
3644 VkRenderPass renderPass)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003645{
3646 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3647
3648 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3649}