blob: f10c5f21746b0f7d411c2579ba4703dda78bbf78 [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_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800236 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600237 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600257 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800258 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
259 offset_align = 2;
260 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600261 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800262 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
263 offset_align = 4;
264 break;
265 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800267 return;
268 break;
269 }
270
271 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800273 return;
274 }
275
276 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800277 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800278
Chia-I Wu72292b72014-09-09 10:48:33 +0800279 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
280 dw[0] = dw0;
281
282 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800283 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
284 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285}
286
Chia-I Wu62a7f252014-08-29 11:31:16 +0800287static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
288 bool enable_cut_index,
289 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800290{
291 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800292 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800293
294 CMD_ASSERT(cmd, 7.5, 7.5);
295
Chia-I Wu426072d2014-08-26 14:31:55 +0800296 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800297 if (enable_cut_index)
298 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
299
Chia-I Wu72292b72014-09-09 10:48:33 +0800300 cmd_batch_pointer(cmd, cmd_len, &dw);
301 dw[0] = dw0;
302 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800303}
304
Cody Northrop293d4502015-05-05 09:38:03 -0600305static void gen6_add_scratch_space(struct intel_cmd *cmd,
306 uint32_t batch_pos,
307 const struct intel_pipeline *pipeline,
308 const struct intel_pipeline_shader *sh)
309{
310 int scratch_space;
311
312 CMD_ASSERT(cmd, 6, 7.5);
313
314 assert(sh->per_thread_scratch_size &&
315 sh->per_thread_scratch_size % 1024 == 0 &&
316 u_is_pow2(sh->per_thread_scratch_size) &&
317 sh->scratch_offset % 1024 == 0);
318 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
319
320 cmd_reserve_reloc(cmd, 1);
321 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
322 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
323}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600324
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800325static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
326{
Cody Northrop293d4502015-05-05 09:38:03 -0600327 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
328 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600330 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800331 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600332 int vue_read_len = 0;
333 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800334
Cody Northrop293d4502015-05-05 09:38:03 -0600335 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
336
337 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
338
339 // based on ilo_gpe_init_gs_cso_gen6
340 vue_read_len = (gs->in_count + 1) / 2;
341 if (!vue_read_len)
342 vue_read_len = 1;
343
344 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
345 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
346 GEN6_THREADDISP_SPF;
347
348 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
349 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
350 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
351
352 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
353 GEN6_GS_DW5_STATISTICS |
354 GEN6_GS_DW5_RENDER_ENABLE;
355
356 dw6 = GEN6_GS_DW6_GS_ENABLE;
357
358 if (gs->discard_adj)
359 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
360
361 } else {
362 dw2 = 0;
363 dw4 = 0;
364 dw5 = GEN6_GS_DW5_STATISTICS;
365 dw6 = 0;
366 }
367
368 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800369 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600370 dw[1] = cmd->bind.pipeline.gs_offset;
371 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800372 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600373 dw[4] = dw4;
374 dw[5] = dw5;
375 dw[6] = dw6;
376
377 if (gs->per_thread_scratch_size)
378 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800379}
380
Chia-I Wu62a7f252014-08-29 11:31:16 +0800381static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
382{
Cody Northrop293d4502015-05-05 09:38:03 -0600383 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
384 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800385 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600386 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800387 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600388 int vue_read_len = 0;
389 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800390
Cody Northrop293d4502015-05-05 09:38:03 -0600391 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
392
393 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
394
395 // based on upload_gs_state
396 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
397 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
398
399 vue_read_len = (gs->in_count + 1) / 2;
400 if (!vue_read_len)
401 vue_read_len = 1;
402
403 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
404 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
405 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
406 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
407 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
408
409
410 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
411 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
412 GEN7_GS_DW5_STATISTICS |
413 GEN7_GS_DW5_GS_ENABLE;
414
415 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
416 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
417
418 if (gs->include_primitive_id)
419 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
420
421 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
422 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
423 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
424 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
425 } else {
426 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
427 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
428 dw6 = 0;
429 }
430 } else {
431 dw2 = 0;
432 dw4 = 0;
433 dw5 = GEN7_GS_DW5_STATISTICS;
434 dw6 = 0;
435 }
436
437 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800438 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600439 dw[1] = cmd->bind.pipeline.gs_offset;
440 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800441 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600442 dw[4] = dw4;
443 dw[5] = dw5;
444 dw[6] = dw6;
445
446 if (gs->per_thread_scratch_size)
447 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800448}
449
Chia-I Wud88e02d2014-08-25 10:56:13 +0800450static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600451 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452{
453 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800454 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800455 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457
458 CMD_ASSERT(cmd, 6, 7.5);
459
Chia-I Wu72292b72014-09-09 10:48:33 +0800460 cmd_batch_pointer(cmd, cmd_len, &dw);
461 dw[0] = dw0;
462
Chia-I Wud88e02d2014-08-25 10:56:13 +0800463 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800464 dw[1] = 0;
465 dw[2] = (height - 1) << 16 |
466 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800467 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800468 dw[1] = 1;
469 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800471
472 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800473}
474
Chia-I Wu8016a172014-08-29 18:31:32 +0800475static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
476 uint32_t body[6])
477{
478 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800479 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800480 const struct intel_render_pass_subpass *subpass =
481 cmd->bind.render_pass_subpass;
Cody Northropf5bd2252015-08-17 11:10:49 -0600482 const struct intel_dynamic_raster_line *raster_line = cmd->bind.state.raster_line;
483 const struct intel_dynamic_raster_depth_bias *raster_depth_bias = cmd->bind.state.raster_depth_bias;
484 uint32_t dw1, dw2, dw3, dw4, dw5, dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800485
486 CMD_ASSERT(cmd, 6, 7.5);
487
488 dw1 = GEN7_SF_DW1_STATISTICS |
489 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
490 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
491 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
492 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800494
495 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800496 int format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800497
Chia-I Wubdeed152015-07-09 12:16:29 +0800498 if (subpass->ds_index < rp->attachment_count) {
499 switch (rp->attachments[subpass->ds_index].format) {
500 case VK_FORMAT_D16_UNORM:
501 format = GEN6_ZFORMAT_D16_UNORM;
502 break;
503 case VK_FORMAT_D32_SFLOAT:
504 case VK_FORMAT_D32_SFLOAT_S8_UINT:
505 format = GEN6_ZFORMAT_D32_FLOAT;
506 break;
507 default:
508 assert(!"unsupported depth/stencil format");
509 break;
510 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800511 }
512
513 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
514 }
515
Tony Barbourfa6cac72015-01-16 14:27:35 -0700516 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800517
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700518 /* Scissor is always enabled */
519 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
520
Cody Northropf5bd2252015-08-17 11:10:49 -0600521 // TODO: line width support
522 (void) raster_line;
523
Tony Barbourfa6cac72015-01-16 14:27:35 -0700524 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800525 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
526 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
527 } else {
528 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
529 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
530 }
531
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600532 dw3 = 2 << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
533 1 << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
534 2 << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800535 GEN7_SF_DW3_SUBPIXEL_8BITS;
536
Cody Northropf5bd2252015-08-17 11:10:49 -0600537 if (pipeline->depthBiasEnable) {
538 dw4 = u_fui((float) raster_depth_bias->raster_depth_bias_info.depthBias * 2.0f);
539 dw5 = u_fui(raster_depth_bias->raster_depth_bias_info.slopeScaledDepthBias);
540 dw6 = u_fui(raster_depth_bias->raster_depth_bias_info.depthBiasClamp);
541 } else {
542 dw4 = 0;
543 dw5 = 0;
544 dw6 = 0;
545 }
546
Chia-I Wu8016a172014-08-29 18:31:32 +0800547 body[0] = dw1;
548 body[1] = dw2;
549 body[2] = dw3;
Cody Northropf5bd2252015-08-17 11:10:49 -0600550 body[3] = dw4;
551 body[4] = dw5;
552 body[5] = dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800553}
554
Chia-I Wu8016a172014-08-29 18:31:32 +0800555static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
556{
557 const uint8_t cmd_len = 20;
558 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
559 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800560 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800561 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800562 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800563
564 CMD_ASSERT(cmd, 6, 6);
565
566 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800567
Chia-I Wu72292b72014-09-09 10:48:33 +0800568 cmd_batch_pointer(cmd, cmd_len, &dw);
569 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800570 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800571 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800572 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800573}
574
575static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
576{
577 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800578 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800579
580 CMD_ASSERT(cmd, 7, 7.5);
581
Chia-I Wu72292b72014-09-09 10:48:33 +0800582 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800583 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
584 (cmd_len - 2);
585 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800586}
587
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800588static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
589{
590 const uint8_t cmd_len = 4;
591 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
592 (cmd_len - 2);
593 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700594 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800595 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourde4124d2015-07-03 10:33:54 -0600596 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800597 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800598
599 CMD_ASSERT(cmd, 6, 7.5);
600
601 dw1 = GEN6_CLIP_DW1_STATISTICS;
602 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
603 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
604 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700605 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800606 }
607
608 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800609 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800610 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700611 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600612 2 << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
613 1 << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
614 2 << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800615
616 if (pipeline->rasterizerDiscardEnable)
617 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
618 else
619 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
620
621 if (pipeline->depthClipEnable)
622 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
623
624 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
625 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
626 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
627 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
628
629 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
630 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
631 (viewport->viewport_count - 1);
632
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600633 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600634 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600635 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
636 }
637
Chia-I Wu72292b72014-09-09 10:48:33 +0800638 cmd_batch_pointer(cmd, cmd_len, &dw);
639 dw[0] = dw0;
640 dw[1] = dw1;
641 dw[2] = dw2;
642 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800643}
644
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
646{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800648 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800649 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600650 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700651 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800652
653 CMD_ASSERT(cmd, 6, 6);
654
655 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
656
657 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
658 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
659
660 dw4 = GEN6_WM_DW4_STATISTICS |
661 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
662 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700663 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800665 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700666 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
667 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
Cody Northrope86574e2015-02-24 14:15:29 -0700669 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700670 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700671
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800672 if (fs->uses & INTEL_SHADER_USE_KILL ||
673 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700674 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800675
Cody Northrope238deb2015-01-26 14:41:36 -0700676 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800677 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
678 if (fs->uses & INTEL_SHADER_USE_DEPTH)
679 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
680 if (fs->uses & INTEL_SHADER_USE_W)
681 dw5 |= GEN6_WM_DW5_PS_USE_W;
682
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700683 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700684 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685
686 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700687 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688 GEN6_WM_DW6_ZW_INTERP_PIXEL |
689 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
690 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
691
Tony Barbourfa6cac72015-01-16 14:27:35 -0700692 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
694 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
695 } else {
696 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
697 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
698 }
699
Cody Northrope86574e2015-02-24 14:15:29 -0700700 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
701
Chia-I Wu784d3042014-12-19 14:30:04 +0800702 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800703 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800704 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 dw[2] = dw2;
706 dw[3] = 0; /* scratch */
707 dw[4] = dw4;
708 dw[5] = dw5;
709 dw[6] = dw6;
710 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700711 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800712
713 if (fs->per_thread_scratch_size)
714 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715}
716
717static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
718{
719 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800720 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800721 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800722 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723
724 CMD_ASSERT(cmd, 7, 7.5);
725
726 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
727
728 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700729 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800730 GEN7_WM_DW1_ZW_INTERP_PIXEL |
731 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
732 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
733
734 if (fs->uses & INTEL_SHADER_USE_KILL ||
735 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700736 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800737
Cody Northrope238deb2015-01-26 14:41:36 -0700738 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
739
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800740 if (fs->uses & INTEL_SHADER_USE_DEPTH)
741 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
742 if (fs->uses & INTEL_SHADER_USE_W)
743 dw1 |= GEN7_WM_DW1_PS_USE_W;
744
745 dw2 = 0;
746
Tony Barbourfa6cac72015-01-16 14:27:35 -0700747 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800748 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
749 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
750 } else {
751 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
752 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
753 }
754
Chia-I Wu72292b72014-09-09 10:48:33 +0800755 cmd_batch_pointer(cmd, cmd_len, &dw);
756 dw[0] = dw0;
757 dw[1] = dw1;
758 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800759}
760
761static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
762{
763 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800764 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800765 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700766 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600767 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800768
769 CMD_ASSERT(cmd, 7, 7.5);
770
771 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
772
773 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
774 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
775
776 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700777 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800778
Cody Northrope86574e2015-02-24 14:15:29 -0700779 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700780 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700781
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800782 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800783 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700784 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800785 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800786 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800787 }
788
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800789 if (fs->in_count)
790 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
791
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700792 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800793 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
794
795 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
796 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700797 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
798
799 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800800
Chia-I Wu784d3042014-12-19 14:30:04 +0800801 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800802 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800803 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 dw[2] = dw2;
805 dw[3] = 0; /* scratch */
806 dw[4] = dw4;
807 dw[5] = dw5;
808 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700809 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800810
811 if (fs->per_thread_scratch_size)
812 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800813}
814
Chia-I Wu8ada4242015-03-02 11:19:33 -0700815static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
816 uint32_t sample_count)
817{
818 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
819 uint32_t dw1, dw2, dw3, *dw;
820
821 CMD_ASSERT(cmd, 6, 7.5);
822
823 switch (sample_count) {
824 case 4:
825 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
826 dw2 = cmd->dev->sample_pattern_4x;
827 dw3 = 0;
828 break;
829 case 8:
830 assert(cmd_gen(cmd) >= INTEL_GEN(7));
831 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
832 dw2 = cmd->dev->sample_pattern_8x[0];
833 dw3 = cmd->dev->sample_pattern_8x[1];
834 break;
835 default:
836 assert(sample_count <= 1);
837 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
838 dw2 = 0;
839 dw3 = 0;
840 break;
841 }
842
843 cmd_batch_pointer(cmd, cmd_len, &dw);
844
845 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
846 dw[1] = dw1;
847 dw[2] = dw2;
848 if (cmd_gen(cmd) >= INTEL_GEN(7))
849 dw[3] = dw3;
850}
851
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800852static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800853 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700854 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800855{
856 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600858 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800859
860 CMD_ASSERT(cmd, 6, 7.5);
861
862 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
864 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800865 dw0 |= (cmd_len - 2);
866
Chia-I Wu72292b72014-09-09 10:48:33 +0800867 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
868 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700869
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800870 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700871 /* note that we only enable HiZ on Gen7+ */
872 if (!optimal_ds)
873 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
874
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800876 dw[3] = view->att_cmd[2];
877 dw[4] = view->att_cmd[3];
878 dw[5] = view->att_cmd[4];
879 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800880
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600881 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_reserve_reloc(cmd, 1);
883 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800884 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600885 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800886}
887
888static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800889 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700890 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800891{
892 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600894 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800895
896 CMD_ASSERT(cmd, 6, 7.5);
897
898 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800899 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
900 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800901 dw0 |= (cmd_len - 2);
902
Chia-I Wu72292b72014-09-09 10:48:33 +0800903 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
904 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800905
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700906 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800907 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700908
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 cmd_reserve_reloc(cmd, 1);
910 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800911 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700912 } else {
913 dw[1] = 0;
914 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600915 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800916}
917
918static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800919 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700920 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800921{
922 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800923 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600924 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800925
926 CMD_ASSERT(cmd, 6, 7.5);
927
928 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800929 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
930 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800931 dw0 |= (cmd_len - 2);
932
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
934 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800935
Chia-I Wu73520ac2015-02-19 11:17:45 -0700936 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800937 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700938
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 cmd_reserve_reloc(cmd, 1);
940 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800941 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700942 } else {
943 dw[1] = 0;
944 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600945 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800946}
947
Chia-I Wuf8231032014-08-25 10:44:45 +0800948static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
949 uint32_t clear_val)
950{
951 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800952 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800953 GEN6_CLEAR_PARAMS_DW0_VALID |
954 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800956
957 CMD_ASSERT(cmd, 6, 6);
958
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 cmd_batch_pointer(cmd, cmd_len, &dw);
960 dw[0] = dw0;
961 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800962}
963
964static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
965 uint32_t clear_val)
966{
967 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800968 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800969 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800971
972 CMD_ASSERT(cmd, 7, 7.5);
973
Chia-I Wu72292b72014-09-09 10:48:33 +0800974 cmd_batch_pointer(cmd, cmd_len, &dw);
975 dw[0] = dw0;
976 dw[1] = clear_val;
977 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800978}
979
Chia-I Wu302742d2014-08-22 10:28:29 +0800980static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 uint32_t blend_offset,
982 uint32_t ds_offset,
983 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800984{
985 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800986 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987
988 CMD_ASSERT(cmd, 6, 6);
989
Chia-I Wu426072d2014-08-26 14:31:55 +0800990 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800991 (cmd_len - 2);
992
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 cmd_batch_pointer(cmd, cmd_len, &dw);
994 dw[0] = dw0;
995 dw[1] = blend_offset | 1;
996 dw[2] = ds_offset | 1;
997 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800998}
999
Chia-I Wu1744cca2014-08-22 11:10:17 +08001000static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 uint32_t clip_offset,
1002 uint32_t sf_offset,
1003 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001004{
1005 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001007
1008 CMD_ASSERT(cmd, 6, 6);
1009
Chia-I Wu426072d2014-08-26 14:31:55 +08001010 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001011 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1012 GEN6_VP_PTR_DW0_SF_CHANGED |
1013 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001014 (cmd_len - 2);
1015
Chia-I Wu72292b72014-09-09 10:48:33 +08001016 cmd_batch_pointer(cmd, cmd_len, &dw);
1017 dw[0] = dw0;
1018 dw[1] = clip_offset;
1019 dw[2] = sf_offset;
1020 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001021}
1022
1023static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001024 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001025{
1026 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001027 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001028
1029 CMD_ASSERT(cmd, 6, 6);
1030
Chia-I Wu426072d2014-08-26 14:31:55 +08001031 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001032 (cmd_len - 2);
1033
Chia-I Wu72292b72014-09-09 10:48:33 +08001034 cmd_batch_pointer(cmd, cmd_len, &dw);
1035 dw[0] = dw0;
1036 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001037}
1038
Chia-I Wu42a56202014-08-23 16:47:48 +08001039static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001040 uint32_t vs_offset,
1041 uint32_t gs_offset,
1042 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001043{
1044 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001045 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001046
1047 CMD_ASSERT(cmd, 6, 6);
1048
Chia-I Wu426072d2014-08-26 14:31:55 +08001049 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001050 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1051 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1052 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001053 (cmd_len - 2);
1054
Chia-I Wu72292b72014-09-09 10:48:33 +08001055 cmd_batch_pointer(cmd, cmd_len, &dw);
1056 dw[0] = dw0;
1057 dw[1] = vs_offset;
1058 dw[2] = gs_offset;
1059 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001060}
1061
Chia-I Wu257e75e2014-08-29 14:06:35 +08001062static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001063 uint32_t vs_offset,
1064 uint32_t gs_offset,
1065 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001066{
1067 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001068 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001069
1070 CMD_ASSERT(cmd, 6, 6);
1071
1072 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001073 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1074 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1075 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001076 (cmd_len - 2);
1077
Chia-I Wu72292b72014-09-09 10:48:33 +08001078 cmd_batch_pointer(cmd, cmd_len, &dw);
1079 dw[0] = dw0;
1080 dw[1] = vs_offset;
1081 dw[2] = gs_offset;
1082 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001083}
1084
Chia-I Wu302742d2014-08-22 10:28:29 +08001085static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001086 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001087{
1088 const uint8_t cmd_len = 2;
1089 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1090 GEN6_RENDER_SUBTYPE_3D |
1091 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001092 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001093
Chia-I Wu72292b72014-09-09 10:48:33 +08001094 cmd_batch_pointer(cmd, cmd_len, &dw);
1095 dw[0] = dw0;
1096 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001097}
1098
Chia-I Wua6c4f152014-12-02 04:19:58 +08001099static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001100{
Chia-I Wue6073342014-11-30 09:43:42 +08001101 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001102 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1103 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001104
1105 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001106 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001107
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001109}
1110
Chia-I Wu72292b72014-09-09 10:48:33 +08001111static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06001112 const struct intel_dynamic_depth_stencil *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001113{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001114 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001115 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001116 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001117 uint32_t dw[3];
1118
1119 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001120 /* same read and write masks for both front and back faces */
Tony Barbourde4124d2015-07-03 10:33:54 -06001121 dw[1] = (state->depth_stencil_info.stencilReadMask & 0xff) << 24 |
1122 (state->depth_stencil_info.stencilWriteMask & 0xff) << 16 |
1123 (state->depth_stencil_info.stencilReadMask & 0xff) << 8 |
1124 (state->depth_stencil_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001125 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001126
1127 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001128
Tony Barbourde4124d2015-07-03 10:33:54 -06001129 if (state->depth_stencil_info.stencilWriteMask && pipeline->stencilTestEnable)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001130 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001131
Chia-I Wu00b51a82014-09-09 12:07:37 +08001132 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001133 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001134}
1135
Chia-I Wu72292b72014-09-09 10:48:33 +08001136static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001137 uint32_t stencil_ref,
1138 const uint32_t blend_color[4])
1139{
Chia-I Wue6073342014-11-30 09:43:42 +08001140 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001141 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001142 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001143
1144 CMD_ASSERT(cmd, 6, 7.5);
1145
Chia-I Wu00b51a82014-09-09 12:07:37 +08001146 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1147 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001148 dw[0] = stencil_ref;
1149 dw[1] = 0;
1150 dw[2] = blend_color[0];
1151 dw[3] = blend_color[1];
1152 dw[4] = blend_color[2];
1153 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001154
Chia-I Wu72292b72014-09-09 10:48:33 +08001155 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001156}
1157
Chia-I Wu8370b402014-08-29 12:28:37 +08001158static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001159{
Chia-I Wu8370b402014-08-29 12:28:37 +08001160 CMD_ASSERT(cmd, 6, 7.5);
1161
Chia-I Wu707a29e2014-08-27 12:51:47 +08001162 if (!cmd->bind.draw_count)
1163 return;
1164
Chia-I Wu8370b402014-08-29 12:28:37 +08001165 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001166 return;
1167
Chia-I Wu8370b402014-08-29 12:28:37 +08001168 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001169
1170 /*
1171 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1172 *
1173 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1174 * pipe-control with a post-sync op and no write-cache flushes."
1175 *
1176 * The workaround below necessitates this workaround.
1177 */
1178 gen6_PIPE_CONTROL(cmd,
1179 GEN6_PIPE_CONTROL_CS_STALL |
1180 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001181 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001182
Chia-I Wud6d079d2014-08-31 13:14:21 +08001183 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1184 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001185}
1186
Chia-I Wu8370b402014-08-29 12:28:37 +08001187static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001188{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001189 CMD_ASSERT(cmd, 6, 7.5);
1190
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001191 if (!cmd->bind.draw_count)
1192 return;
1193
Chia-I Wud6d079d2014-08-31 13:14:21 +08001194 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1195 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001196}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1199{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001200 CMD_ASSERT(cmd, 7, 7.5);
1201
Chia-I Wu8370b402014-08-29 12:28:37 +08001202 if (!cmd->bind.draw_count)
1203 return;
1204
1205 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001206
1207 gen6_PIPE_CONTROL(cmd,
1208 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001209 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001210}
1211
Chia-I Wu8370b402014-08-29 12:28:37 +08001212static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1213{
1214 CMD_ASSERT(cmd, 7, 7.5);
1215
Chia-I Wu8370b402014-08-29 12:28:37 +08001216 /*
1217 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1218 *
1219 * "One of the following must also be set (when CS stall is set):
1220 *
1221 * * Render Target Cache Flush Enable ([12] of DW1)
1222 * * Depth Cache Flush Enable ([0] of DW1)
1223 * * Stall at Pixel Scoreboard ([1] of DW1)
1224 * * Depth Stall ([13] of DW1)
1225 * * Post-Sync Operation ([13] of DW1)"
1226 */
1227 gen6_PIPE_CONTROL(cmd,
1228 GEN6_PIPE_CONTROL_CS_STALL |
1229 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001230 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001231}
1232
1233static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1234{
1235 CMD_ASSERT(cmd, 7, 7.5);
1236
Chia-I Wu8370b402014-08-29 12:28:37 +08001237 cmd_wa_gen6_pre_depth_stall_write(cmd);
1238
Chia-I Wud6d079d2014-08-31 13:14:21 +08001239 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001240}
1241
1242static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1243{
1244 CMD_ASSERT(cmd, 6, 7.5);
1245
1246 if (!cmd->bind.draw_count)
1247 return;
1248
1249 /*
1250 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1251 *
1252 * "Driver must guarentee that all the caches in the depth pipe are
1253 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1254 * requires driver to send a PIPE_CONTROL with a CS stall along with
1255 * a Depth Flush prior to this command."
1256 *
1257 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1258 *
1259 * "Driver must ierarchi that all the caches in the depth pipe are
1260 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1261 * requires driver to send a PIPE_CONTROL with a CS stall along with
1262 * a Depth Flush prior to this command.
1263 */
1264 gen6_PIPE_CONTROL(cmd,
1265 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1266 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001267 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001268}
1269
1270static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1271{
1272 CMD_ASSERT(cmd, 6, 7.5);
1273
1274 if (!cmd->bind.draw_count)
1275 return;
1276
1277 /*
1278 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1279 *
1280 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1281 * and a post sync operation prior to the group of depth
1282 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1283 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1284 *
1285 * This workaround satifies all the conditions.
1286 */
1287 cmd_wa_gen6_pre_depth_stall_write(cmd);
1288
1289 /*
1290 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1291 *
1292 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1293 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1294 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1295 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1296 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1297 * Depth Flush Bit set, followed by another pipelined depth stall
1298 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1299 * guarantee that the pipeline from WM onwards is already flushed
1300 * (e.g., via a preceding MI_FLUSH)."
1301 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001302 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1303 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1304 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001305}
1306
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001307void cmd_batch_state_base_address(struct intel_cmd *cmd)
1308{
1309 const uint8_t cmd_len = 10;
1310 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1311 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001312 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001313 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001314 uint32_t pos;
1315 uint32_t *dw;
1316
1317 CMD_ASSERT(cmd, 6, 7.5);
1318
1319 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1320
1321 dw[0] = dw0;
1322 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001323 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001324 dw[2] = 1;
1325 dw[3] = 1;
1326 dw[4] = 1;
1327 dw[5] = 1;
1328 /* end offsets */
1329 dw[6] = 1;
1330 dw[7] = 1 + 0xfffff000;
1331 dw[8] = 1 + 0xfffff000;
1332 dw[9] = 1;
1333
1334 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001335 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1336 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1337 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1338 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1339 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1340 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001341}
1342
Chia-I Wu7c853562015-02-27 14:35:08 -07001343void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1344{
1345 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1346 const uint8_t cmd_len = 2;
1347 uint32_t offset = 0;
1348 uint32_t *dw;
1349
1350 if (cmd_gen(cmd) <= INTEL_GEN(6))
1351 return;
1352
1353 CMD_ASSERT(cmd, 7, 7.5);
1354
1355 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1356 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1357 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1358 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1359 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1360 offset += size;
1361
1362 dw += 2;
1363 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1364 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1365 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1366
1367 dw += 2;
1368 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1369 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1370 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1371
1372 dw += 2;
1373 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1374 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1375 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1376
1377 dw += 2;
1378 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1379 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1380 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1381
1382 /*
1383 *
1384 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1385 *
1386 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1387 * in the ring after this instruction
1388 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1389 */
1390 cmd_wa_gen7_post_command_cs_stall(cmd);
1391}
1392
Chia-I Wu525c6602014-08-27 10:22:34 +08001393void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1394{
Mike Stroyan552fda42015-01-30 17:21:08 -07001395 if (pipe_control_dw0 == 0)
1396 return;
1397
Chia-I Wu525c6602014-08-27 10:22:34 +08001398 if (!cmd->bind.draw_count)
1399 return;
1400
1401 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1402
Chia-I Wu8370b402014-08-29 12:28:37 +08001403 /*
1404 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1405 *
1406 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1407 * PIPE_CONTROL with any non-zero post-sync-op is required."
1408 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001409 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001410 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001411
Chia-I Wu092279a2014-08-30 19:05:30 +08001412 /*
1413 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1414 *
1415 * "One of the following must also be set (when CS stall is set):
1416 *
1417 * * Render Target Cache Flush Enable ([12] of DW1)
1418 * * Depth Cache Flush Enable ([0] of DW1)
1419 * * Stall at Pixel Scoreboard ([1] of DW1)
1420 * * Depth Stall ([13] of DW1)
1421 * * Post-Sync Operation ([13] of DW1)"
1422 */
1423 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1424 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1425 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1426 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1427 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1428 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1429
Chia-I Wud6d079d2014-08-31 13:14:21 +08001430 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001431}
1432
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001433void cmd_batch_flush_all(struct intel_cmd *cmd)
1434{
1435 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1436 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1437 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1438 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1439 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1440 GEN6_PIPE_CONTROL_CS_STALL);
1441}
1442
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001443void cmd_batch_depth_count(struct intel_cmd *cmd,
1444 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001445 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001446{
1447 cmd_wa_gen6_pre_depth_stall_write(cmd);
1448
1449 gen6_PIPE_CONTROL(cmd,
1450 GEN6_PIPE_CONTROL_DEPTH_STALL |
1451 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001452 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001453}
1454
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001455void cmd_batch_timestamp(struct intel_cmd *cmd,
1456 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001457 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001458{
1459 /* need any WA or stall? */
1460 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1461}
1462
1463void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001464 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001465 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001466 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001467 uint64_t val)
1468{
1469 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001470 gen6_PIPE_CONTROL(cmd,
1471 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1472 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001473}
1474
Chia-I Wu302742d2014-08-22 10:28:29 +08001475static void gen6_cc_states(struct intel_cmd *cmd)
1476{
Tony Barbourde4124d2015-07-03 10:33:54 -06001477 const struct intel_dynamic_color_blend *blend = cmd->bind.state.blend;
1478 const struct intel_dynamic_depth_stencil *ds = cmd->bind.state.depth;
Chia-I Wu72292b72014-09-09 10:48:33 +08001479 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001480 uint32_t stencil_ref;
1481 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001482
1483 CMD_ASSERT(cmd, 6, 6);
1484
Chia-I Wua6c4f152014-12-02 04:19:58 +08001485 blend_offset = gen6_BLEND_STATE(cmd);
1486
1487 if (blend)
Tony Barbourde4124d2015-07-03 10:33:54 -06001488 memcpy(blend_color, blend->color_blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001489 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001490 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001491
1492 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001493 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourde4124d2015-07-03 10:33:54 -06001494 stencil_ref = (ds->depth_stencil_info.stencilFrontRef & 0xff) << 24 |
1495 (ds->depth_stencil_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001496 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001497 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001498 stencil_ref = 0;
1499 }
1500
Chia-I Wu72292b72014-09-09 10:48:33 +08001501 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001502
Chia-I Wu72292b72014-09-09 10:48:33 +08001503 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001504}
1505
Chia-I Wu1744cca2014-08-22 11:10:17 +08001506static void gen6_viewport_states(struct intel_cmd *cmd)
1507{
Tony Barbourde4124d2015-07-03 10:33:54 -06001508 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001509 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001510
1511 if (!viewport)
1512 return;
1513
Tony Barbourfa6cac72015-01-16 14:27:35 -07001514 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001515 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001516
1517 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001518 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001519 viewport->cmd);
1520
1521 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001522 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001523 &viewport->cmd[viewport->cmd_clip_pos]);
1524
1525 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001526 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001527 &viewport->cmd[viewport->cmd_cc_pos]);
1528
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001529 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1530 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1531 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001532
1533 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001534 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001535
Chia-I Wub1d450a2014-09-09 13:48:03 +08001536 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001537}
1538
Chia-I Wu302742d2014-08-22 10:28:29 +08001539static void gen7_cc_states(struct intel_cmd *cmd)
1540{
Tony Barbourde4124d2015-07-03 10:33:54 -06001541 const struct intel_dynamic_color_blend *blend = cmd->bind.state.blend;
1542 const struct intel_dynamic_depth_stencil *ds = cmd->bind.state.depth;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001543 uint32_t stencil_ref;
1544 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001546
1547 CMD_ASSERT(cmd, 7, 7.5);
1548
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001549 if (!blend && !ds)
1550 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001551
Chia-I Wua6c4f152014-12-02 04:19:58 +08001552 offset = gen6_BLEND_STATE(cmd);
1553 gen7_3dstate_pointer(cmd,
1554 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001555
Chia-I Wua6c4f152014-12-02 04:19:58 +08001556 if (blend)
Tony Barbourde4124d2015-07-03 10:33:54 -06001557 memcpy(blend_color, blend->color_blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001558 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001559 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001560
1561 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001562 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourde4124d2015-07-03 10:33:54 -06001563 stencil_ref = (ds->depth_stencil_info.stencilFrontRef & 0xff) << 24 |
1564 (ds->depth_stencil_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001565 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001566 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1567 offset);
Tony Barbourde4124d2015-07-03 10:33:54 -06001568 stencil_ref = (ds->depth_stencil_info.stencilFrontRef & 0xff) << 24 |
1569 (ds->depth_stencil_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001570 } else {
1571 stencil_ref = 0;
1572 }
1573
Chia-I Wu72292b72014-09-09 10:48:33 +08001574 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001575 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001576 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001577}
1578
Chia-I Wu1744cca2014-08-22 11:10:17 +08001579static void gen7_viewport_states(struct intel_cmd *cmd)
1580{
Tony Barbourde4124d2015-07-03 10:33:54 -06001581 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001582 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001583
1584 if (!viewport)
1585 return;
1586
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001587 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001588
Chia-I Wub1d450a2014-09-09 13:48:03 +08001589 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001590 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001591 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001592 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001593 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1594 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001595
1596 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001597 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001598 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001599 gen7_3dstate_pointer(cmd,
1600 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001601 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001602
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001603 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1604 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1605 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1606 gen7_3dstate_pointer(cmd,
1607 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1608 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001609}
1610
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001611static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001612 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001613{
1614 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001615 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001616
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001618
1619 dw[0] = GEN6_RENDER_TYPE_RENDER |
1620 GEN6_RENDER_SUBTYPE_3D |
1621 subop | (cmd_len - 2);
1622 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 dw[2] = 0;
1624 dw[3] = 0;
1625 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001626}
1627
1628static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001629 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001630{
1631 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001632 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001633
Chia-I Wu72292b72014-09-09 10:48:33 +08001634 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001635
1636 dw[0] = GEN6_RENDER_TYPE_RENDER |
1637 GEN6_RENDER_SUBTYPE_3D |
1638 subop | (cmd_len - 2);
1639 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001640 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001641 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001642 dw[4] = 0;
1643 dw[5] = 0;
1644 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001645}
1646
Chia-I Wu625105f2014-10-13 15:35:29 +08001647static uint32_t emit_samplers(struct intel_cmd *cmd,
1648 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001649{
Chia-I Wu862c5572015-03-28 15:23:55 +08001650 const struct intel_desc_region *region = cmd->dev->desc_region;
1651 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001652 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1653 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001654 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001655 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001656 uint32_t surface_count;
1657 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001658
1659 CMD_ASSERT(cmd, 6, 7.5);
1660
Chia-I Wu625105f2014-10-13 15:35:29 +08001661 if (!rmap || !rmap->sampler_count)
1662 return 0;
1663
Cody Northrop40316a32014-12-09 19:08:33 -07001664 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001665
Chia-I Wudcb509d2014-12-10 08:53:10 +08001666 /*
1667 * note that we cannot call cmd_state_pointer() here as the following
1668 * cmd_state_pointer() would invalidate the pointer
1669 */
1670 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001671 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001672 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001673
1674 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001675 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001676 4 * rmap->sampler_count, &sampler_dw);
1677
Chia-I Wudcb509d2014-12-10 08:53:10 +08001678 cmd_state_update(cmd, border_offset,
1679 border_stride * rmap->sampler_count, &border_dw);
1680
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001681 for (i = 0; i < rmap->sampler_count; i++) {
1682 const struct intel_pipeline_rmap_slot *slot =
1683 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001684 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001685 const struct intel_sampler *sampler;
1686
Chia-I Wuf8385062015-01-04 16:27:24 +08001687 switch (slot->type) {
1688 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001689 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1690 &data->set_offsets[slot->index]);
1691 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001692 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001693 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001694 sampler = NULL;
1695 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001696 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001697 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001698 sampler = NULL;
1699 break;
1700 }
1701
1702 if (sampler) {
1703 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1704
1705 sampler_dw[0] = sampler->cmd[0];
1706 sampler_dw[1] = sampler->cmd[1];
1707 sampler_dw[2] = border_offset;
1708 sampler_dw[3] = sampler->cmd[2];
1709 } else {
1710 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1711 sampler_dw[1] = 0;
1712 sampler_dw[2] = 0;
1713 sampler_dw[3] = 0;
1714 }
1715
1716 border_offset += border_stride * 4;
1717 border_dw += border_stride;
1718 sampler_dw += 4;
1719 }
1720
Chia-I Wu625105f2014-10-13 15:35:29 +08001721 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001722}
1723
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001724static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001725 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001726 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001727{
Chia-I Wu862c5572015-03-28 15:23:55 +08001728 const struct intel_desc_region *region = cmd->dev->desc_region;
1729 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001730 const uint32_t sba_offset =
1731 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001732 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001733 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001734
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001735 CMD_ASSERT(cmd, 6, 7.5);
1736
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001737 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001738 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001739 if (!surface_count)
1740 return 0;
1741
Chia-I Wu42a56202014-08-23 16:47:48 +08001742 assert(surface_count <= ARRAY_SIZE(binding_table));
1743
1744 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001745 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001746 struct intel_null_view null_view;
1747 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001748
Chia-I Wuf8385062015-01-04 16:27:24 +08001749 switch (slot->type) {
1750 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001751 {
Chia-I Wubdeed152015-07-09 12:16:29 +08001752 const struct intel_render_pass_subpass *subpass =
1753 cmd->bind.render_pass_subpass;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001754 const struct intel_fb *fb = cmd->bind.fb;
1755 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08001756 (slot->index < subpass->color_count &&
1757 subpass->color_indices[slot->index] < fb->view_count) ?
1758 fb->views[subpass->color_indices[slot->index]] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001759
Chia-I Wu787a05b2014-12-05 11:02:20 +08001760 if (view) {
1761 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1762 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001763 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001764
Chia-I Wu787a05b2014-12-05 11:02:20 +08001765 cmd_reserve_reloc(cmd, 1);
1766 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001767 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001768 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001769 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001770 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001771 }
1772 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001773 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001774 {
Tony Barbour22a30862015-04-22 09:02:32 -06001775 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001776 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001777 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001778 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001779 const struct intel_mem *mem;
1780 bool read_only;
1781 const uint32_t *cmd_data;
1782 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001783
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001784 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001785 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001786
Chia-I Wu862c5572015-03-28 15:23:55 +08001787 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1788 &data->set_offsets[slot->index]);
1789
1790 intel_desc_region_read_surface(region, &desc_offset, stage,
1791 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001792 if (mem) {
1793 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001794 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001795 const uint32_t reloc_flags =
1796 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001797
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001798 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001799 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001800 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001801
1802 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001803 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1804 cmd_data[1] + dynamic_offset, reloc_flags);
1805 } else {
1806 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001807 }
1808 }
1809 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001810 case INTEL_PIPELINE_RMAP_UNUSED:
1811 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001812 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001813 default:
1814 assert(!"unexpected rmap type");
1815 need_null_view = true;
1816 break;
1817 }
1818
1819 if (need_null_view) {
1820 intel_null_view_init(&null_view, cmd->dev);
1821 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1822 GEN6_ALIGNMENT_SURFACE_STATE,
1823 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001824 }
1825
Chia-I Wuf98dd882015-02-10 04:17:47 +08001826 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001827 }
1828
Chia-I Wuf98dd882015-02-10 04:17:47 +08001829 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001830 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001831 surface_count, binding_table) - sba_offset;
1832
1833 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1834 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1835
1836 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001837}
1838
Chia-I Wu1d125092014-10-08 08:49:38 +08001839static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1840{
1841 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001842 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1843 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001844 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001845
1846 CMD_ASSERT(cmd, 6, 7.5);
1847
1848 if (!pipeline->vb_count)
1849 return;
1850
1851 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1852
1853 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1854 dw++;
1855 pos++;
1856
1857 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001858 assert(pipeline->vb[i].strideInBytes <= 2048);
1859
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001860 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001861 pipeline->vb[i].strideInBytes;
1862
Chia-I Wub3686982015-02-27 09:51:16 -07001863 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001864 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1865 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001866 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001867
1868 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001869 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001870 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001871 dw[3] = 0;
1872 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001873 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001874 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001875 dw[3] = 1;
1876 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001877 default:
1878 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001879 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001880 dw[3] = 0;
1881 break;
1882 }
1883
Chia-I Wu714df452015-01-01 07:55:04 +08001884 if (cmd->bind.vertex.buf[i]) {
1885 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001886 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001887
1888 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001889 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1890 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001891 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001892 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001893 dw[1] = 0;
1894 dw[2] = 0;
1895 }
1896
1897 dw += 4;
1898 pos += 4;
1899 }
1900}
1901
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001902static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1903{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001904 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1905 const struct intel_pipeline_shader *vs = &pipeline->vs;
1906 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001907 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001908 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001909 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001910 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001911
1912 CMD_ASSERT(cmd, 6, 7.5);
1913
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001914 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001915 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1916 *
1917 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1918 * 128-bit vertex elements to be passed into the payload for each
1919 * vertex."
1920 *
1921 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1922 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001923 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001924 vue_read_len = (vs->in_count + 1) / 2;
1925 if (!vue_read_len)
1926 vue_read_len = 1;
1927
1928 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1929 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1930
1931 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1932 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1933 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001934
1935 dw5 = GEN6_VS_DW5_STATISTICS |
1936 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001937
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001938 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001939 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001940 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001941 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001942
Chia-I Wube0a3d92014-09-02 13:20:59 +08001943 if (pipeline->disable_vs_cache)
1944 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1945
Chia-I Wu784d3042014-12-19 14:30:04 +08001946 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001947 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001948 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001949 dw[2] = dw2;
1950 dw[3] = 0; /* scratch */
1951 dw[4] = dw4;
1952 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001953
1954 if (vs->per_thread_scratch_size)
1955 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001956}
1957
Chia-I Wu625105f2014-10-13 15:35:29 +08001958static void emit_shader_resources(struct intel_cmd *cmd)
1959{
1960 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001961 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001962
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001963 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001964 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001965 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001966 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001967 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001968 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001969 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001970 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001971 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001972 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001973 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001974 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001975 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001976 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001977 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001978
1979 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1980 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1981 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1982 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1983 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1984
1985 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1986 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001987 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1988 binding_tables[0]);
1989 gen7_3dstate_pointer(cmd,
1990 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1991 binding_tables[1]);
1992 gen7_3dstate_pointer(cmd,
1993 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1994 binding_tables[2]);
1995 gen7_3dstate_pointer(cmd,
1996 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1997 binding_tables[3]);
1998 gen7_3dstate_pointer(cmd,
1999 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2000 binding_tables[4]);
2001
2002 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08002003 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
2004 samplers[0]);
2005 gen7_3dstate_pointer(cmd,
2006 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
2007 samplers[1]);
2008 gen7_3dstate_pointer(cmd,
2009 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2010 samplers[2]);
2011 gen7_3dstate_pointer(cmd,
2012 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2013 samplers[3]);
2014 gen7_3dstate_pointer(cmd,
2015 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2016 samplers[4]);
2017 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002018 assert(!binding_tables[1] && !binding_tables[2]);
2019 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2020 binding_tables[0], binding_tables[3], binding_tables[4]);
2021
Chia-I Wu625105f2014-10-13 15:35:29 +08002022 assert(!samplers[1] && !samplers[2]);
2023 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2024 samplers[0], samplers[3], samplers[4]);
2025 }
2026}
2027
Chia-I Wu8ada4242015-03-02 11:19:33 -07002028static void emit_msaa(struct intel_cmd *cmd)
2029{
Chia-I Wuc278df82015-07-07 11:50:03 +08002030 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002031
Chia-I Wubbc7d912015-02-27 14:59:50 -07002032 if (!cmd->bind.render_pass_changed)
2033 return;
2034
Chia-I Wu8ada4242015-03-02 11:19:33 -07002035 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002036 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002037}
2038
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002039static void emit_rt(struct intel_cmd *cmd)
2040{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002041 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002042
2043 if (!cmd->bind.render_pass_changed)
2044 return;
2045
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002046 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002047 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2048 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002049}
2050
2051static void emit_ds(struct intel_cmd *cmd)
2052{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002053 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002054 const struct intel_render_pass_subpass *subpass =
2055 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002056 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002057 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002058 (subpass->ds_index < rp->attachment_count) ?
2059 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002060
Chia-I Wubbc7d912015-02-27 14:59:50 -07002061 if (!cmd->bind.render_pass_changed)
2062 return;
2063
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002064 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002065 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002066 static const struct intel_att_view null_view;
2067 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002068 }
2069
2070 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002071 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2072 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2073 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002074
2075 if (cmd_gen(cmd) >= INTEL_GEN(7))
2076 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2077 else
2078 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2079}
2080
Chia-I Wua57761b2014-10-14 14:27:44 +08002081static uint32_t emit_shader(struct intel_cmd *cmd,
2082 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002083{
Chia-I Wua57761b2014-10-14 14:27:44 +08002084 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2085 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002086 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002087
Chia-I Wua57761b2014-10-14 14:27:44 +08002088 /* see if the shader is already in the cache */
2089 for (i = 0; i < cache->used; i++) {
2090 if (cache->entries[i].shader == (const void *) shader)
2091 return cache->entries[i].kernel_offset;
2092 }
2093
2094 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2095
2096 /* grow the cache if full */
2097 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002098 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002099 void *entries;
2100
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002101 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002102 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002103 if (entries) {
2104 if (cache->entries) {
2105 memcpy(entries, cache->entries,
2106 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002107 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002108 }
2109
2110 cache->entries = entries;
2111 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002112 }
2113 }
2114
Chia-I Wua57761b2014-10-14 14:27:44 +08002115 /* add the shader to the cache */
2116 if (cache->used < cache->count) {
2117 cache->entries[cache->used].shader = (const void *) shader;
2118 cache->entries[cache->used].kernel_offset = offset;
2119 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002120 }
2121
Chia-I Wua57761b2014-10-14 14:27:44 +08002122 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002123}
2124
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002125static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002126{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002127 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002128
Chia-I Wu8370b402014-08-29 12:28:37 +08002129 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2130 cmd_wa_gen6_pre_depth_stall_write(cmd);
2131 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2132 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2133 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2134 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002135
2136 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002137 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002138 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002139
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002140 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002141 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002142 }
2143 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002144 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002145 }
2146 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002147 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2148 }
2149 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2150 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2151 }
2152 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2153 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002154 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002155
Chia-I Wu8370b402014-08-29 12:28:37 +08002156 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2157 cmd_wa_gen7_post_command_cs_stall(cmd);
2158 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2159 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002160}
2161
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002162static void emit_bounded_states(struct intel_cmd *cmd)
2163{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002164 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002165
2166 emit_graphics_pipeline(cmd);
2167
2168 emit_rt(cmd);
2169 emit_ds(cmd);
2170
2171 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2172 gen7_cc_states(cmd);
2173 gen7_viewport_states(cmd);
2174
2175 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2176 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002177 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2178 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002179 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2180 &cmd->bind.pipeline.graphics->fs);
2181
Cody Northrop293d4502015-05-05 09:38:03 -06002182 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002183 gen6_3DSTATE_CLIP(cmd);
2184 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002185 gen7_3DSTATE_WM(cmd);
2186 gen7_3DSTATE_PS(cmd);
2187 } else {
2188 gen6_cc_states(cmd);
2189 gen6_viewport_states(cmd);
2190
2191 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2192 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002193 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2194 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002195 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2196 &cmd->bind.pipeline.graphics->fs);
2197
Cody Northrop293d4502015-05-05 09:38:03 -06002198 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002199 gen6_3DSTATE_CLIP(cmd);
2200 gen6_3DSTATE_SF(cmd);
2201 gen6_3DSTATE_WM(cmd);
2202 }
2203
2204 emit_shader_resources(cmd);
2205
2206 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002207
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002208 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2209 gen6_3DSTATE_VS(cmd);
2210}
2211
Tony Barbourfa6cac72015-01-16 14:27:35 -07002212static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002213 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002214{
2215 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2216 const uint8_t cmd_len = 3;
2217 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002218
2219 CMD_ASSERT(cmd, 6, 7.5);
2220
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002221 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002222 dw[0] = 0;
2223 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002224
2225 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2226 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2227 GEN6_COMPAREFUNCTION_NEVER << 27 |
2228 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2229 } else {
2230 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2231 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2232 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002233 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002234 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002235 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2236 (GEN6_STENCILOP_KEEP) << 25 |
2237 (GEN6_STENCILOP_KEEP) << 22 |
2238 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002239 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2240 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002241 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2242 (GEN6_STENCILOP_KEEP) << 9 |
2243 (GEN6_STENCILOP_KEEP) << 6 |
2244 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002245
Chia-I Wud850a392015-02-19 11:08:25 -07002246 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2247 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2248 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2249 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2250 dw[2] = 0;
2251 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002252
2253 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2254 cmd_align, cmd_len, dw);
2255}
2256
Chia-I Wu6032b892014-10-17 14:47:18 +08002257static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2258{
2259 const struct intel_cmd_meta *meta = cmd->bind.meta;
2260 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2261
2262 CMD_ASSERT(cmd, 6, 7.5);
2263
2264 blend_offset = 0;
2265 ds_offset = 0;
2266 cc_offset = 0;
2267 cc_vp_offset = 0;
2268
Chia-I Wu29e6f502014-11-24 14:27:29 +08002269 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002270 /* BLEND_STATE */
2271 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002272 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002273 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002274 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002275 }
2276
Chia-I Wu29e6f502014-11-24 14:27:29 +08002277 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002278 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002280 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2281 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002282
Chia-I Wu29e6f502014-11-24 14:27:29 +08002283 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002284 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 /* COLOR_CALC_STATE */
2287 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002288 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002289
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 /* CC_VIEWPORT */
2291 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002292 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002293 dw[0] = u_fui(0.0f);
2294 dw[1] = u_fui(1.0f);
2295 } else {
2296 /* DEPTH_STENCIL_STATE */
2297 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002298 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002299 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2300 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2301 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002302 }
2303
2304 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2305 gen7_3dstate_pointer(cmd,
2306 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2307 blend_offset);
2308 gen7_3dstate_pointer(cmd,
2309 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2310 ds_offset);
2311 gen7_3dstate_pointer(cmd,
2312 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2313
2314 gen7_3dstate_pointer(cmd,
2315 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2316 cc_vp_offset);
2317 } else {
2318 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002319 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002320
2321 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2322 cmd_batch_pointer(cmd, 4, &dw);
2323 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002324 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002325 dw[1] = 0;
2326 dw[2] = 0;
2327 dw[3] = cc_vp_offset;
2328 }
2329}
2330
2331static void gen6_meta_surface_states(struct intel_cmd *cmd)
2332{
2333 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002334 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002335 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002336 const uint32_t sba_offset =
2337 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002338
2339 CMD_ASSERT(cmd, 6, 7.5);
2340
Chia-I Wu29e6f502014-11-24 14:27:29 +08002341 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2342 return;
2343
Chia-I Wu005c47c2014-10-22 13:49:13 +08002344 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 if (meta->src.valid) {
2346 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002347 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002348 meta->src.surface_len, meta->src.surface);
2349
2350 cmd_reserve_reloc(cmd, 1);
2351 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2352 cmd_surface_reloc_writer(cmd, offset, 1,
2353 meta->src.reloc_target, meta->src.reloc_offset);
2354 } else {
2355 cmd_surface_reloc(cmd, offset, 1,
2356 (struct intel_bo *) meta->src.reloc_target,
2357 meta->src.reloc_offset, meta->src.reloc_flags);
2358 }
2359
Mike Stroyan9bfad482015-02-10 15:09:23 -07002360 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002361 }
2362 if (meta->dst.valid) {
2363 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002364 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002365 meta->dst.surface_len, meta->dst.surface);
2366
2367 cmd_reserve_reloc(cmd, 1);
2368 cmd_surface_reloc(cmd, offset, 1,
2369 (struct intel_bo *) meta->dst.reloc_target,
2370 meta->dst.reloc_offset, meta->dst.reloc_flags);
2371
Mike Stroyan9bfad482015-02-10 15:09:23 -07002372 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002373 }
2374
2375 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002376 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002377 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002378 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002379
2380 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002381 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2382 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2383 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002384 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002385 } else {
2386 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002387 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002388 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002389 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002390 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002391 }
2392}
2393
2394static void gen6_meta_urb(struct intel_cmd *cmd)
2395{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002396 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002397 uint32_t *dw;
2398
2399 CMD_ASSERT(cmd, 6, 6);
2400
2401 /* 3DSTATE_URB */
2402 cmd_batch_pointer(cmd, 3, &dw);
2403 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002404 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002405 dw[2] = 0;
2406}
2407
2408static void gen7_meta_urb(struct intel_cmd *cmd)
2409{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002410 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2411 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002412 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002413 uint32_t *dw;
2414
2415 CMD_ASSERT(cmd, 7, 7.5);
2416
Chia-I Wu6032b892014-10-17 14:47:18 +08002417 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2418
Chia-I Wu24aa1022014-11-25 11:53:19 +08002419 switch (cmd_gen(cmd)) {
2420 case INTEL_GEN(7.5):
2421 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2422 break;
2423 case INTEL_GEN(7):
2424 default:
2425 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2426 break;
2427 }
2428
Chia-I Wu6032b892014-10-17 14:47:18 +08002429 /* 3DSTATE_URB_x */
2430 cmd_batch_pointer(cmd, 8, &dw);
2431
2432 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002433 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002434 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002435 dw += 2;
2436
2437 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002438 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002439 dw += 2;
2440
2441 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002442 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002443 dw += 2;
2444
2445 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002446 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002447 dw += 2;
2448}
2449
2450static void gen6_meta_vf(struct intel_cmd *cmd)
2451{
2452 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002453 uint32_t vb_start, vb_end, vb_stride;
2454 int ve_format, ve_z_source;
2455 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002456 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002457
2458 CMD_ASSERT(cmd, 6, 7.5);
2459
Chia-I Wu29e6f502014-11-24 14:27:29 +08002460 switch (meta->mode) {
2461 case INTEL_CMD_META_VS_POINTS:
2462 cmd_batch_pointer(cmd, 3, &dw);
2463 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002464 dw[1] = GEN6_VE_DW0_VALID;
2465 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2466 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2467 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2468 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002469 return;
2470 break;
2471 case INTEL_CMD_META_FS_RECT:
2472 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002473 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002474
Chia-I Wu29e6f502014-11-24 14:27:29 +08002475 vertices[0][0] = meta->dst.x + meta->width;
2476 vertices[0][1] = meta->dst.y + meta->height;
2477 vertices[1][0] = meta->dst.x;
2478 vertices[1][1] = meta->dst.y + meta->height;
2479 vertices[2][0] = meta->dst.x;
2480 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002481
Chia-I Wu29e6f502014-11-24 14:27:29 +08002482 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2483 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002484
Chia-I Wu29e6f502014-11-24 14:27:29 +08002485 vb_end = vb_start + sizeof(vertices) - 1;
2486 vb_stride = sizeof(vertices[0]);
2487 ve_z_source = GEN6_VFCOMP_STORE_0;
2488 ve_format = GEN6_FORMAT_R32G32_USCALED;
2489 }
2490 break;
2491 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2492 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002493 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002494
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002495 vertices[0][0] = (float) (meta->dst.x + meta->width);
2496 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002497 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002498 vertices[1][0] = (float) meta->dst.x;
2499 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002500 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002501 vertices[2][0] = (float) meta->dst.x;
2502 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002503 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002504
Chia-I Wu29e6f502014-11-24 14:27:29 +08002505 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2506 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002507
Chia-I Wu29e6f502014-11-24 14:27:29 +08002508 vb_end = vb_start + sizeof(vertices) - 1;
2509 vb_stride = sizeof(vertices[0]);
2510 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2511 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2512 }
2513 break;
2514 default:
2515 assert(!"unknown meta mode");
2516 return;
2517 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002518 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002519
2520 /* 3DSTATE_VERTEX_BUFFERS */
2521 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002522
Chia-I Wu6032b892014-10-17 14:47:18 +08002523 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002524 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002525 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002526 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002527
2528 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002529 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2530 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002531
2532 dw[4] = 0;
2533
2534 /* 3DSTATE_VERTEX_ELEMENTS */
2535 cmd_batch_pointer(cmd, 5, &dw);
2536 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002537 dw[1] = GEN6_VE_DW0_VALID;
2538 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2539 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2540 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2541 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2542 dw[3] = GEN6_VE_DW0_VALID |
2543 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2544 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2545 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2546 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2547 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002548}
2549
Chia-I Wu29e6f502014-11-24 14:27:29 +08002550static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002551{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002552 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002553 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002554 uint32_t consts[8];
2555 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002556
2557 CMD_ASSERT(cmd, 6, 7.5);
2558
2559 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002560 case INTEL_DEV_META_VS_FILL_MEM:
2561 consts[0] = meta->dst.x;
2562 consts[1] = meta->clear_val[0];
2563 const_count = 2;
2564 break;
2565 case INTEL_DEV_META_VS_COPY_MEM:
2566 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2567 consts[0] = meta->dst.x;
2568 consts[1] = meta->src.x;
2569 const_count = 2;
2570 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002571 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2572 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2573 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2574 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2575 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2576 consts[0] = meta->src.x;
2577 consts[1] = meta->src.y;
2578 consts[2] = meta->width;
2579 consts[3] = meta->dst.x;
2580 const_count = 4;
2581 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002582 default:
2583 assert(!"unknown meta shader id");
2584 const_count = 0;
2585 break;
2586 }
2587
2588 /* this can be skipped but it makes state dumping prettier */
2589 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2590
2591 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2592}
2593
2594static void gen6_meta_vs(struct intel_cmd *cmd)
2595{
2596 const struct intel_cmd_meta *meta = cmd->bind.meta;
2597 const struct intel_pipeline_shader *sh =
2598 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2599 uint32_t offset, *dw;
2600
2601 CMD_ASSERT(cmd, 6, 7.5);
2602
2603 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002604 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002605
2606 /* 3DSTATE_CONSTANT_VS */
2607 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2608 cmd_batch_pointer(cmd, cmd_len, &dw);
2609 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2610 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2611
2612 /* 3DSTATE_VS */
2613 cmd_batch_pointer(cmd, 6, &dw);
2614 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2615 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2616
2617 return;
2618 }
2619
2620 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2621
2622 /* 3DSTATE_CONSTANT_VS */
2623 offset = gen6_meta_vs_constants(cmd);
2624 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2625 cmd_batch_pointer(cmd, 7, &dw);
2626 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002627 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002628 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002629 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002630 dw[4] = 0;
2631 dw[5] = 0;
2632 dw[6] = 0;
2633 } else {
2634 cmd_batch_pointer(cmd, 5, &dw);
2635 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002636 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002637 dw[1] = offset;
2638 dw[2] = 0;
2639 dw[3] = 0;
2640 dw[4] = 0;
2641 }
2642
2643 /* 3DSTATE_VS */
2644 offset = emit_shader(cmd, sh);
2645 cmd_batch_pointer(cmd, 6, &dw);
2646 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2647 dw[1] = offset;
2648 dw[2] = GEN6_THREADDISP_SPF |
2649 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2650 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002651 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002652 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2653 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2654
2655 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2656 GEN6_VS_DW5_VS_ENABLE;
2657 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002658 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002659 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002660 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002661
2662 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002663}
2664
2665static void gen6_meta_disabled(struct intel_cmd *cmd)
2666{
Chia-I Wu6032b892014-10-17 14:47:18 +08002667 uint32_t *dw;
2668
2669 CMD_ASSERT(cmd, 6, 6);
2670
Chia-I Wu6032b892014-10-17 14:47:18 +08002671 /* 3DSTATE_CONSTANT_GS */
2672 cmd_batch_pointer(cmd, 5, &dw);
2673 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2674 dw[1] = 0;
2675 dw[2] = 0;
2676 dw[3] = 0;
2677 dw[4] = 0;
2678
2679 /* 3DSTATE_GS */
2680 cmd_batch_pointer(cmd, 7, &dw);
2681 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2682 dw[1] = 0;
2683 dw[2] = 0;
2684 dw[3] = 0;
2685 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2686 dw[5] = GEN6_GS_DW5_STATISTICS;
2687 dw[6] = 0;
2688
Chia-I Wu6032b892014-10-17 14:47:18 +08002689 /* 3DSTATE_SF */
2690 cmd_batch_pointer(cmd, 20, &dw);
2691 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2692 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2693 memset(&dw[2], 0, 18 * sizeof(*dw));
2694}
2695
2696static void gen7_meta_disabled(struct intel_cmd *cmd)
2697{
2698 uint32_t *dw;
2699
2700 CMD_ASSERT(cmd, 7, 7.5);
2701
Chia-I Wu6032b892014-10-17 14:47:18 +08002702 /* 3DSTATE_CONSTANT_HS */
2703 cmd_batch_pointer(cmd, 7, &dw);
2704 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2705 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2706
2707 /* 3DSTATE_HS */
2708 cmd_batch_pointer(cmd, 7, &dw);
2709 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2710 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2711
2712 /* 3DSTATE_TE */
2713 cmd_batch_pointer(cmd, 4, &dw);
2714 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2715 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2716
2717 /* 3DSTATE_CONSTANT_DS */
2718 cmd_batch_pointer(cmd, 7, &dw);
2719 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2720 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2721
2722 /* 3DSTATE_DS */
2723 cmd_batch_pointer(cmd, 6, &dw);
2724 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2725 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2726
2727 /* 3DSTATE_CONSTANT_GS */
2728 cmd_batch_pointer(cmd, 7, &dw);
2729 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2730 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2731
2732 /* 3DSTATE_GS */
2733 cmd_batch_pointer(cmd, 7, &dw);
2734 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2735 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2736
2737 /* 3DSTATE_STREAMOUT */
2738 cmd_batch_pointer(cmd, 3, &dw);
2739 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2740 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2741
Chia-I Wu6032b892014-10-17 14:47:18 +08002742 /* 3DSTATE_SF */
2743 cmd_batch_pointer(cmd, 7, &dw);
2744 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2745 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2746
2747 /* 3DSTATE_SBE */
2748 cmd_batch_pointer(cmd, 14, &dw);
2749 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2750 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2751 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002752}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002753
Chia-I Wu29e6f502014-11-24 14:27:29 +08002754static void gen6_meta_clip(struct intel_cmd *cmd)
2755{
2756 const struct intel_cmd_meta *meta = cmd->bind.meta;
2757 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002758
Chia-I Wu29e6f502014-11-24 14:27:29 +08002759 /* 3DSTATE_CLIP */
2760 cmd_batch_pointer(cmd, 4, &dw);
2761 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2762 dw[1] = 0;
2763 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2764 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2765 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2766 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002767 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002768 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002769 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002770}
2771
2772static void gen6_meta_wm(struct intel_cmd *cmd)
2773{
2774 const struct intel_cmd_meta *meta = cmd->bind.meta;
2775 uint32_t *dw;
2776
2777 CMD_ASSERT(cmd, 6, 7.5);
2778
2779 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2780
2781 /* 3DSTATE_MULTISAMPLE */
2782 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2783 cmd_batch_pointer(cmd, 4, &dw);
2784 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2785 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2786 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2787 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2788 dw[2] = 0;
2789 dw[3] = 0;
2790 } else {
2791 cmd_batch_pointer(cmd, 3, &dw);
2792 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2793 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2794 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2795 dw[2] = 0;
2796 }
2797
2798 /* 3DSTATE_SAMPLE_MASK */
2799 cmd_batch_pointer(cmd, 2, &dw);
2800 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2801 dw[1] = (1 << meta->samples) - 1;
2802
2803 /* 3DSTATE_DRAWING_RECTANGLE */
2804 cmd_batch_pointer(cmd, 4, &dw);
2805 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002806 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2807 /* unused */
2808 dw[1] = 0;
2809 dw[2] = 0;
2810 } else {
2811 dw[1] = meta->dst.y << 16 | meta->dst.x;
2812 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2813 (meta->dst.x + meta->width - 1);
2814 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002815 dw[3] = 0;
2816}
2817
2818static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2819{
2820 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002821 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002822 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002823 uint32_t consts[8];
2824 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002825
2826 CMD_ASSERT(cmd, 6, 7.5);
2827
2828 /* underflow is fine here */
2829 offset_x = meta->src.x - meta->dst.x;
2830 offset_y = meta->src.y - meta->dst.y;
2831
2832 switch (meta->shader_id) {
2833 case INTEL_DEV_META_FS_COPY_MEM:
2834 case INTEL_DEV_META_FS_COPY_1D:
2835 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2836 case INTEL_DEV_META_FS_COPY_2D:
2837 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2838 case INTEL_DEV_META_FS_COPY_2D_MS:
2839 consts[0] = offset_x;
2840 consts[1] = offset_y;
2841 consts[2] = meta->src.layer;
2842 consts[3] = meta->src.lod;
2843 const_count = 4;
2844 break;
2845 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2846 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2847 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2848 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2849 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2850 consts[0] = offset_x;
2851 consts[1] = offset_y;
2852 consts[2] = meta->src.layer;
2853 consts[3] = meta->src.lod;
2854 consts[4] = meta->src.x;
2855 consts[5] = meta->width;
2856 const_count = 6;
2857 break;
2858 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2859 consts[0] = offset_x;
2860 consts[1] = offset_y;
2861 consts[2] = meta->width;
2862 const_count = 3;
2863 break;
2864 case INTEL_DEV_META_FS_CLEAR_COLOR:
2865 consts[0] = meta->clear_val[0];
2866 consts[1] = meta->clear_val[1];
2867 consts[2] = meta->clear_val[2];
2868 consts[3] = meta->clear_val[3];
2869 const_count = 4;
2870 break;
2871 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2872 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002873 consts[1] = meta->clear_val[1];
2874 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002875 break;
2876 case INTEL_DEV_META_FS_RESOLVE_2X:
2877 case INTEL_DEV_META_FS_RESOLVE_4X:
2878 case INTEL_DEV_META_FS_RESOLVE_8X:
2879 case INTEL_DEV_META_FS_RESOLVE_16X:
2880 consts[0] = offset_x;
2881 consts[1] = offset_y;
2882 const_count = 2;
2883 break;
2884 default:
2885 assert(!"unknown meta shader id");
2886 const_count = 0;
2887 break;
2888 }
2889
2890 /* this can be skipped but it makes state dumping prettier */
2891 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2892
2893 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2894}
2895
2896static void gen6_meta_ps(struct intel_cmd *cmd)
2897{
2898 const struct intel_cmd_meta *meta = cmd->bind.meta;
2899 const struct intel_pipeline_shader *sh =
2900 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2901 uint32_t offset, *dw;
2902
2903 CMD_ASSERT(cmd, 6, 6);
2904
Chia-I Wu29e6f502014-11-24 14:27:29 +08002905 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2906 /* 3DSTATE_CONSTANT_PS */
2907 cmd_batch_pointer(cmd, 5, &dw);
2908 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2909 dw[1] = 0;
2910 dw[2] = 0;
2911 dw[3] = 0;
2912 dw[4] = 0;
2913
2914 /* 3DSTATE_WM */
2915 cmd_batch_pointer(cmd, 9, &dw);
2916 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2917 dw[1] = 0;
2918 dw[2] = 0;
2919 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002920
2921 switch (meta->ds.op) {
2922 case INTEL_CMD_META_DS_HIZ_CLEAR:
2923 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2924 break;
2925 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2926 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2927 break;
2928 case INTEL_CMD_META_DS_RESOLVE:
2929 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2930 break;
2931 default:
2932 dw[4] = 0;
2933 break;
2934 }
2935
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002936 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002937 dw[6] = 0;
2938 dw[7] = 0;
2939 dw[8] = 0;
2940
Chia-I Wu3adf7212014-10-24 15:34:07 +08002941 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002942 }
2943
Chia-I Wu3adf7212014-10-24 15:34:07 +08002944 /* a normal color write */
2945 assert(meta->dst.valid && !sh->uses);
2946
Chia-I Wu6032b892014-10-17 14:47:18 +08002947 /* 3DSTATE_CONSTANT_PS */
2948 offset = gen6_meta_ps_constants(cmd);
2949 cmd_batch_pointer(cmd, 5, &dw);
2950 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002951 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002952 dw[1] = offset;
2953 dw[2] = 0;
2954 dw[3] = 0;
2955 dw[4] = 0;
2956
2957 /* 3DSTATE_WM */
2958 offset = emit_shader(cmd, sh);
2959 cmd_batch_pointer(cmd, 9, &dw);
2960 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2961 dw[1] = offset;
2962 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2963 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002964 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002965 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002966 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002967 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2968 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002969
Chia-I Wu6032b892014-10-17 14:47:18 +08002970 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002971 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002972 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2973 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2974 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2975 if (meta->samples > 1) {
2976 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2977 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2978 } else {
2979 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2980 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2981 }
2982 dw[7] = 0;
2983 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002984
2985 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002986}
2987
2988static void gen7_meta_ps(struct intel_cmd *cmd)
2989{
2990 const struct intel_cmd_meta *meta = cmd->bind.meta;
2991 const struct intel_pipeline_shader *sh =
2992 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2993 uint32_t offset, *dw;
2994
2995 CMD_ASSERT(cmd, 7, 7.5);
2996
Chia-I Wu29e6f502014-11-24 14:27:29 +08002997 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2998 /* 3DSTATE_WM */
2999 cmd_batch_pointer(cmd, 3, &dw);
3000 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003001
3002 switch (meta->ds.op) {
3003 case INTEL_CMD_META_DS_HIZ_CLEAR:
3004 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
3005 break;
3006 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3007 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
3008 break;
3009 case INTEL_CMD_META_DS_RESOLVE:
3010 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3011 break;
3012 default:
3013 dw[1] = 0;
3014 break;
3015 }
3016
3017 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003018
3019 /* 3DSTATE_CONSTANT_GS */
3020 cmd_batch_pointer(cmd, 7, &dw);
3021 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3022 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3023
3024 /* 3DSTATE_PS */
3025 cmd_batch_pointer(cmd, 8, &dw);
3026 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3027 dw[1] = 0;
3028 dw[2] = 0;
3029 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003030 /* required to avoid hangs */
3031 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003032 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003033 dw[5] = 0;
3034 dw[6] = 0;
3035 dw[7] = 0;
3036
Chia-I Wu3adf7212014-10-24 15:34:07 +08003037 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003038 }
3039
Chia-I Wu3adf7212014-10-24 15:34:07 +08003040 /* a normal color write */
3041 assert(meta->dst.valid && !sh->uses);
3042
Chia-I Wu6032b892014-10-17 14:47:18 +08003043 /* 3DSTATE_WM */
3044 cmd_batch_pointer(cmd, 3, &dw);
3045 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003046 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003047 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3048 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3049 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3050 dw[2] = 0;
3051
3052 /* 3DSTATE_CONSTANT_PS */
3053 offset = gen6_meta_ps_constants(cmd);
3054 cmd_batch_pointer(cmd, 7, &dw);
3055 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003056 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003057 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003058 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003059 dw[4] = 0;
3060 dw[5] = 0;
3061 dw[6] = 0;
3062
3063 /* 3DSTATE_PS */
3064 offset = emit_shader(cmd, sh);
3065 cmd_batch_pointer(cmd, 8, &dw);
3066 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3067 dw[1] = offset;
3068 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3069 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003070 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003071
3072 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3073 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003074 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003075
3076 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003077 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003078 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003079 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003080 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003081 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003082
3083 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3084 dw[6] = 0;
3085 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003086
3087 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003088}
3089
3090static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3091{
3092 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003093 const struct intel_att_view *view = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003094
3095 CMD_ASSERT(cmd, 6, 7.5);
3096
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003097 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003098 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003099 static const struct intel_att_view null_view;
3100 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003101 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003102
3103 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003104 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3105 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3106 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003107
3108 if (cmd_gen(cmd) >= INTEL_GEN(7))
3109 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3110 else
3111 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003112}
3113
Chia-I Wu862c5572015-03-28 15:23:55 +08003114static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3115 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003116 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003117{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003118 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003119 if (data->set_offsets)
3120 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003121
Chia-I Wu862c5572015-03-28 15:23:55 +08003122 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003123 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003124 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003125 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003126 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003127 data->set_offset_count = 0;
3128 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003129 }
3130
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003131 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003132 }
3133
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003134 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003135 if (data->dynamic_offsets)
3136 intel_free(cmd, data->dynamic_offsets);
3137
3138 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003139 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003140 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003141 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003142 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003143 data->dynamic_offset_count = 0;
3144 return false;
3145 }
3146
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003147 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003148 }
3149
3150 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003151}
3152
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003153static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3154 const struct intel_pipeline *pipeline)
3155{
3156 cmd->bind.pipeline.graphics = pipeline;
3157
3158 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003159 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003160}
3161
3162static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3163 const struct intel_pipeline *pipeline)
3164{
3165 cmd->bind.pipeline.compute = pipeline;
3166
3167 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003168 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003169}
3170
Chia-I Wu862c5572015-03-28 15:23:55 +08003171static void cmd_copy_dset_data(struct intel_cmd *cmd,
3172 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003173 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003174 uint32_t index,
3175 const struct intel_desc_set *set,
3176 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003177{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003178 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003179
Chia-I Wu862c5572015-03-28 15:23:55 +08003180 assert(index < data->set_offset_count);
3181 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003182
Chia-I Wu862c5572015-03-28 15:23:55 +08003183 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003184 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003185 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003186
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003187 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003188 dynamic_offsets,
3189 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003190 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003191}
3192
Chia-I Wu3b04af52014-11-08 10:48:20 +08003193static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003194 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003195 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003196{
Chia-I Wu714df452015-01-01 07:55:04 +08003197 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003198 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003199 return;
3200 }
3201
Chia-I Wu714df452015-01-01 07:55:04 +08003202 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003203 cmd->bind.vertex.offset[binding] = offset;
3204}
3205
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003206static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003207 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003208 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003209{
Chia-I Wu714df452015-01-01 07:55:04 +08003210 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003211 cmd->bind.index.offset = offset;
3212 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213}
3214
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003216 const struct intel_dynamic_viewport *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217{
3218 cmd->bind.state.viewport = state;
3219}
3220
Cody Northropf5bd2252015-08-17 11:10:49 -06003221static void cmd_bind_raster_line_state(struct intel_cmd *cmd,
3222 const struct intel_dynamic_raster_line *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003223{
Cody Northropf5bd2252015-08-17 11:10:49 -06003224 cmd->bind.state.raster_line = state;
3225}
3226
3227static void cmd_bind_raster_depth_bias_state(struct intel_cmd *cmd,
3228 const struct intel_dynamic_raster_depth_bias *state)
3229{
3230 cmd->bind.state.raster_depth_bias = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003231}
3232
Tony Barbourde4124d2015-07-03 10:33:54 -06003233static void cmd_bind_depth_stencil_state(struct intel_cmd *cmd,
3234 const struct intel_dynamic_depth_stencil *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003235{
Tony Barbourde4124d2015-07-03 10:33:54 -06003236 cmd->bind.state.depth = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003237}
3238
3239static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003240 const struct intel_dynamic_color_blend *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003241{
3242 cmd->bind.state.blend = state;
3243}
3244
Chia-I Wuf98dd882015-02-10 04:17:47 +08003245static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3246{
3247 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3248 struct intel_pipeline_rmap *rmaps[5] = {
3249 pipeline->vs.rmap,
3250 pipeline->tcs.rmap,
3251 pipeline->tes.rmap,
3252 pipeline->gs.rmap,
3253 pipeline->fs.rmap,
3254 };
3255 uint32_t max_write;
3256 int i;
3257
3258 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3259 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3260 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3261
3262 /* pad first */
3263 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3264
3265 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3266 const struct intel_pipeline_rmap *rmap = rmaps[i];
3267 const uint32_t surface_count = (rmap) ?
3268 rmap->rt_count + rmap->texture_resource_count +
3269 rmap->resource_count + rmap->uav_count : 0;
3270
3271 if (surface_count) {
3272 /* SURFACE_STATEs */
3273 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3274
3275 /* BINDING_TABLE_STATE */
3276 max_write += u_align(sizeof(uint32_t) * surface_count,
3277 GEN6_ALIGNMENT_SURFACE_STATE);
3278 }
3279 }
3280
3281 return max_write;
3282}
3283
3284static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3285{
3286 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3287 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3288 uint32_t max_surface_write;
3289
3290 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3291 if (cmd->bind.meta)
3292 max_surface_write = 64 * sizeof(uint32_t);
3293 else
3294 max_surface_write = cmd_get_max_surface_write(cmd);
3295
3296 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3297 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3298 /* SBA expects page-aligned addresses */
3299 writer->sba_offset = writer->used & ~0xfff;
3300
3301 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3302
3303 cmd_batch_state_base_address(cmd);
3304 }
3305}
3306
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003307static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003308 uint32_t vertex_start,
3309 uint32_t vertex_count,
3310 uint32_t instance_start,
3311 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003312 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003313 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003314{
3315 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003316 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003317 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3318
3319 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003320
3321 emit_bounded_states(cmd);
3322
Chia-I Wuf98dd882015-02-10 04:17:47 +08003323 /* sanity check on cmd_get_max_surface_write() */
3324 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3325 surface_writer_used <= cmd_get_max_surface_write(cmd));
3326
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003327 if (indexed) {
3328 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003329 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003330
3331 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3332 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3333 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003334 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003335 cmd->bind.index.offset, cmd->bind.index.type,
3336 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003337 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003338 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003339 cmd->bind.index.offset, cmd->bind.index.type,
3340 p->primitive_restart);
3341 }
3342 } else {
3343 assert(!vertex_base);
3344 }
3345
3346 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3347 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3348 vertex_start, instance_count, instance_start, vertex_base);
3349 } else {
3350 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3351 vertex_start, instance_count, instance_start, vertex_base);
3352 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003353
Chia-I Wu707a29e2014-08-27 12:51:47 +08003354 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003355 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003356 /* need to re-emit all workarounds */
3357 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003358
3359 if (intel_debug & INTEL_DEBUG_NOCACHE)
3360 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003361}
3362
Chia-I Wuc14d1562014-10-17 09:49:22 +08003363void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3364{
Chia-I Wu6032b892014-10-17 14:47:18 +08003365 cmd->bind.meta = meta;
3366
Chia-I Wuf98dd882015-02-10 04:17:47 +08003367 cmd_adjust_state_base_address(cmd);
3368
Chia-I Wu6032b892014-10-17 14:47:18 +08003369 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003370 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003371
3372 gen6_meta_dynamic_states(cmd);
3373 gen6_meta_surface_states(cmd);
3374
3375 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3376 gen7_meta_urb(cmd);
3377 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003378 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003379 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003380 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003381 gen6_meta_wm(cmd);
3382 gen7_meta_ps(cmd);
3383 gen6_meta_depth_buffer(cmd);
3384
3385 cmd_wa_gen7_post_command_cs_stall(cmd);
3386 cmd_wa_gen7_post_command_depth_stall(cmd);
3387
Chia-I Wu29e6f502014-11-24 14:27:29 +08003388 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3389 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003390 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003391 } else {
3392 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3393 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003394 } else {
3395 gen6_meta_urb(cmd);
3396 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003397 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003398 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003399 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003400 gen6_meta_wm(cmd);
3401 gen6_meta_ps(cmd);
3402 gen6_meta_depth_buffer(cmd);
3403
Chia-I Wu29e6f502014-11-24 14:27:29 +08003404 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3405 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003406 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003407 } else {
3408 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3409 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003410 }
3411
3412 cmd->bind.draw_count++;
3413 /* need to re-emit all workarounds */
3414 cmd->bind.wa_flags = 0;
3415
3416 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003417
Chia-I Wubbc7d912015-02-27 14:59:50 -07003418 /* make the normal path believe the render pass has changed */
3419 cmd->bind.render_pass_changed = true;
3420
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003421 if (intel_debug & INTEL_DEBUG_NOCACHE)
3422 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003423}
3424
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003425static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3426{
3427 const uint8_t cmd_len = 2;
3428 uint32_t *dw;
3429 uint32_t pos;
3430
3431 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3432 cmd->result = VK_ERROR_UNKNOWN;
3433 return;
3434 }
3435
3436 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3437 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3438 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3439 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3440 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3441
3442 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3443}
3444
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003445ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003446 VkCmdBuffer cmdBuffer,
3447 VkPipelineBindPoint pipelineBindPoint,
3448 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003449{
3450 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3451
3452 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003453 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003454 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003455 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003456 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003457 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003458 break;
3459 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003460 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003461 break;
3462 }
3463}
3464
Tony Barbourde4124d2015-07-03 10:33:54 -06003465ICD_EXPORT void VKAPI vkCmdBindDynamicViewportState(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003466 VkCmdBuffer cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003467 VkDynamicViewportState state)
Chia-I Wub2755562014-08-20 13:38:52 +08003468{
3469 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3470
Tony Barbourde4124d2015-07-03 10:33:54 -06003471 cmd_bind_viewport_state(cmd,
3472 intel_dynamic_viewport(state));
3473}
3474
Cody Northropf5bd2252015-08-17 11:10:49 -06003475ICD_EXPORT void VKAPI vkCmdBindDynamicRasterLineState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003476 VkCmdBuffer cmdBuffer,
Cody Northropf5bd2252015-08-17 11:10:49 -06003477 VkDynamicRasterLineState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003478{
3479 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3480
Cody Northropf5bd2252015-08-17 11:10:49 -06003481 cmd_bind_raster_line_state(cmd,
3482 intel_dynamic_raster_line(state));
3483}
3484
3485ICD_EXPORT void VKAPI vkCmdBindDynamicRasterDepthBiasState(
3486 VkCmdBuffer cmdBuffer,
3487 VkDynamicRasterDepthBiasState state)
3488{
3489 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3490
3491 cmd_bind_raster_depth_bias_state(cmd,
3492 intel_dynamic_raster_depth_bias(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003493}
3494
3495ICD_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(
3496 VkCmdBuffer cmdBuffer,
3497 VkDynamicColorBlendState state)
3498{
3499 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3500
3501 cmd_bind_blend_state(cmd,
3502 intel_dynamic_color_blend(state));
3503}
3504
3505ICD_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(
3506 VkCmdBuffer cmdBuffer,
3507 VkDynamicDepthStencilState state)
3508{
3509 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3510
3511 cmd_bind_depth_stencil_state(cmd,
3512 intel_dynamic_depth_stencil(state));
Chia-I Wub2755562014-08-20 13:38:52 +08003513}
3514
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003515ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003516 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003517 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003518 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003519 uint32_t firstSet,
3520 uint32_t setCount,
3521 const VkDescriptorSet* pDescriptorSets,
3522 uint32_t dynamicOffsetCount,
3523 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003524{
3525 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003526 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003527 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003528 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003529 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003530
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003531 pipeline_layout = intel_pipeline_layout(layout);
3532
Chia-I Wub2755562014-08-20 13:38:52 +08003533 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003534 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003535 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003536 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003537 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003538 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003539 break;
3540 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003541 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003542 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003543 break;
3544 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003545
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003546 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003547 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3548
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003549 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003550 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003551 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003552 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003553 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003554 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003555 }
Chia-I Wub2755562014-08-20 13:38:52 +08003556}
3557
Tony Barbour8205d902015-04-16 15:59:00 -06003558
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003559ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3560 VkCmdBuffer cmdBuffer,
3561 uint32_t startBinding,
3562 uint32_t bindingCount,
3563 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003564 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003565{
3566 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003567
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003568 for (uint32_t i = 0; i < bindingCount; i++) {
3569 struct intel_buf *buf = intel_buf(pBuffers[i]);
3570 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3571 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003572}
3573
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003574ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003575 VkCmdBuffer cmdBuffer,
3576 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003577 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003578 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003579{
3580 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003581 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003582
Chia-I Wu714df452015-01-01 07:55:04 +08003583 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003584}
3585
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003586ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003587 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003588 uint32_t firstVertex,
3589 uint32_t vertexCount,
3590 uint32_t firstInstance,
3591 uint32_t instanceCount)
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);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003594
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003595 cmd_draw(cmd, firstVertex, vertexCount,
3596 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003597}
3598
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003599ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003600 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003601 uint32_t firstIndex,
3602 uint32_t indexCount,
3603 int32_t vertexOffset,
3604 uint32_t firstInstance,
3605 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003606{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003607 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003608
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003609 cmd_draw(cmd, firstIndex, indexCount,
3610 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003611}
3612
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003613ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003614 VkCmdBuffer cmdBuffer,
3615 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003616 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003617 uint32_t count,
3618 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003619{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003620 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3621
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003622 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003623}
3624
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003625ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003626 VkCmdBuffer cmdBuffer,
3627 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003628 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003629 uint32_t count,
3630 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003631{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003632 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3633
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003634 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003635}
3636
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003637ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003638 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003639 uint32_t x,
3640 uint32_t y,
3641 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003642{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003643 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3644
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003645 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003646}
3647
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003648ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003649 VkCmdBuffer cmdBuffer,
3650 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003651 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003652{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003653 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3654
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003655 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003656}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003657
Courtney Goeltzenleuchtera375b622015-07-27 14:04:01 -06003658void VKAPI vkCmdPushConstants(
3659 VkCmdBuffer cmdBuffer,
3660 VkPipelineLayout layout,
3661 VkShaderStageFlags stageFlags,
3662 uint32_t start,
3663 uint32_t length,
3664 const void* values)
3665{
3666 /* TODO: Implement */
3667}
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003668
3669VkResult VKAPI vkGetRenderAreaGranularity(
3670 VkDevice device,
3671 VkRenderPass renderPass,
3672 VkExtent2D* pGranularity)
3673{
3674 pGranularity->height = 1;
3675 pGranularity->width = 1;
3676
3677 return VK_SUCCESS;
3678}
3679
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003680ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003681 VkCmdBuffer cmdBuffer,
3682 const VkRenderPassBeginInfo* pRenderPassBegin,
3683 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003684{
Chia-I Wubdeed152015-07-09 12:16:29 +08003685 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3686 const struct intel_render_pass *rp =
3687 intel_render_pass(pRenderPassBegin->renderPass);
3688 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3689 const struct intel_att_view *view;
3690 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003691
Chia-I Wubdeed152015-07-09 12:16:29 +08003692 if (!cmd->primary || rp->attachment_count != fb->view_count) {
3693 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3694 return;
3695 }
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003696
Cody Northrop16898b02015-08-11 11:35:58 -06003697 cmd_begin_render_pass(cmd, rp, fb, 0, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003698
Chia-I Wubdeed152015-07-09 12:16:29 +08003699 for (i = 0; i < rp->attachment_count; i++) {
3700 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003701 const VkClearValue *clear_val =
Cody Northropc332eef2015-08-04 11:51:03 -06003702 &pRenderPassBegin->pClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003703 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003704
Chia-I Wubdeed152015-07-09 12:16:29 +08003705 if (!att->clear_on_load)
3706 continue;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003707
Chia-I Wubdeed152015-07-09 12:16:29 +08003708 view = fb->views[i];
3709 range.baseMipLevel = view->mipLevel;
3710 range.mipLevels = 1;
3711 range.baseArraySlice = view->baseArraySlice;
3712 range.arraySize = view->array_size;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003713
Chia-I Wubdeed152015-07-09 12:16:29 +08003714 if (view->is_rt) {
3715 range.aspect = VK_IMAGE_ASPECT_COLOR;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003716
Tony Barbourde4124d2015-07-03 10:33:54 -06003717 cmd_meta_clear_color_image(cmdBuffer, view->img,
Chia-I Wuc278df82015-07-07 11:50:03 +08003718 att->initial_layout, &clear_val->color, 1, &range);
Chia-I Wubdeed152015-07-09 12:16:29 +08003719 } else {
3720 range.aspect = VK_IMAGE_ASPECT_DEPTH;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003721
Chia-I Wubdeed152015-07-09 12:16:29 +08003722 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003723 view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003724 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003725 1, &range);
Chris Forbes4cf9d102015-06-22 18:46:05 +12003726
Chia-I Wubdeed152015-07-09 12:16:29 +08003727 if (att->stencil_clear_on_load) {
3728 range.aspect = VK_IMAGE_ASPECT_STENCIL;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003729
Chia-I Wubdeed152015-07-09 12:16:29 +08003730 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003731 view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003732 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003733 1, &range);
3734 }
3735 }
3736 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003737}
3738
Chia-I Wuc278df82015-07-07 11:50:03 +08003739ICD_EXPORT void VKAPI vkCmdNextSubpass(
3740 VkCmdBuffer cmdBuffer,
3741 VkRenderPassContents contents)
3742{
3743 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3744 const struct intel_render_pass *rp = cmd->bind.render_pass;
3745
3746 if (cmd->bind.render_pass_subpass >= rp->subpasses +
3747 rp->subpass_count - 1) {
3748 cmd->result = VK_ERROR_UNKNOWN;
3749 return;
3750 }
3751
3752 cmd->bind.render_pass_changed = true;
3753 cmd->bind.render_pass_subpass++;
3754 cmd->bind.render_pass_contents = contents;
3755}
3756
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003757ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003758 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003759{
3760 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3761
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003762 cmd_end_render_pass(cmd);
3763}
3764
3765ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3766 VkCmdBuffer cmdBuffer,
3767 uint32_t cmdBuffersCount,
3768 const VkCmdBuffer* pCmdBuffers)
3769{
3770 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003771 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003772
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003773 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3774 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3775 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3776 return;
3777 }
3778
3779 for (i = 0; i < cmdBuffersCount; i++) {
3780 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3781
3782 if (secondary->primary) {
3783 cmd->result = VK_ERROR_INVALID_VALUE;
3784 break;
3785 }
3786
3787 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3788 }
3789
3790 if (i)
3791 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003792}