blob: c5d12245992ba79f93ca4b256505db68052c1aa1 [file] [log] [blame]
Chia-I Wu09142132014-08-11 15:42:55 +08001/*
2 * XGL
3 *
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.
23 */
24
25#ifndef CMD_H
26#define CMD_H
27
28#include "intel.h"
29#include "obj.h"
Chia-I Wub2755562014-08-20 13:38:52 +080030#include "view.h"
31
32struct intel_pipeline;
33struct intel_pipeline_delta;
34struct intel_viewport_state;
35struct intel_raster_state;
36struct intel_msaa_state;
37struct intel_blend_state;
38struct intel_ds_state;
39struct intel_dset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -060040struct intel_pipe_shader;
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu958d1b72014-08-21 11:28:11 +080042struct intel_cmd_reloc;
43
Chia-I Wu8370b402014-08-29 12:28:37 +080044/*
45 * We know what workarounds are needed for intel_pipeline. These are mostly
46 * for intel_pipeline_delta.
47 */
48enum intel_cmd_wa_flags {
49 /*
50 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
51 *
52 * "Before any depth stall flush (including those produced by
53 * non-pipelined state commands), software needs to first send a
54 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
55 */
56 INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE = 1 << 0,
57
58 /*
59 * From the Sandy Bridge PRM, volume 2 part 1, page 274:
60 *
61 * "A PIPE_CONTROL command, with only the Stall At Pixel Scoreboard
62 * field set (DW1 Bit 1), must be issued prior to any change to the
63 * value in this field (Maximum Number of Threads in 3DSTATE_WM)"
64 *
65 * From the Ivy Bridge PRM, volume 2 part 1, page 286:
66 *
67 * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed
68 * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
69 * Pixel Scoreboard set is required to be issued."
70 */
71 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL = 1 << 1,
72
73 /*
74 * From the Ivy Bridge PRM, volume 2 part 1, page 106:
75 *
76 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
77 * stall needs to be sent just prior to any 3DSTATE_VS,
78 * 3DSTATE_URB_VS, 3DSTATE_CONSTANT_VS,
79 * 3DSTATE_BINDING_TABLE_POINTER_VS, 3DSTATE_SAMPLER_STATE_POINTER_VS
80 * command. Only one PIPE_CONTROL needs to be sent before any
81 * combination of VS associated 3DSTATE."
82 */
83 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE = 1 << 2,
84
85 /*
86 * From the Ivy Bridge PRM, volume 2 part 1, page 258:
87 *
88 * "Due to an HW issue driver needs to send a pipe control with stall
89 * when ever there is state change in depth bias related state"
90 *
91 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
92 *
93 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
94 * in the ring after this instruction
95 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
96 */
97 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL = 1 << 3,
98
99 /*
100 * From the Ivy Bridge PRM, volume 2 part 1, page 276:
101 *
102 * "The driver must make sure a PIPE_CONTROL with the Depth Stall
103 * Enable bit set after all the following states are programmed:
104 *
105 * - 3DSTATE_PS
106 * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC
107 * - 3DSTATE_CONSTANT_PS
108 * - 3DSTATE_BINDING_TABLE_POINTERS_PS
109 * - 3DSTATE_SAMPLER_STATE_POINTERS_PS
110 * - 3DSTATE_CC_STATE_POINTERS
111 * - 3DSTATE_BLEND_STATE_POINTERS
112 * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
113 */
114 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL = 1 << 4,
115};
116
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600117struct intel_cmd_shader {
Chia-I Wu338fe642014-08-28 10:43:04 +0800118 const struct intel_pipe_shader *shader;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600119 XGL_UINT kernel_pos;
120};
121
Chia-I Wub2755562014-08-20 13:38:52 +0800122/*
123 * States bounded to the command buffer. We want to write states directly to
124 * the command buffer when possible, and reduce this struct.
125 */
126struct intel_cmd_bind {
127 struct {
128 const struct intel_pipeline *graphics;
129 const struct intel_pipeline *compute;
130 const struct intel_pipeline_delta *graphics_delta;
131 const struct intel_pipeline_delta *compute_delta;
132 } pipeline;
133
Courtney Goeltzenleuchterba305812014-08-28 17:27:47 -0600134 /*
135 * Currently active shaders for this command buffer.
136 * Provides data only available after shaders are bound to
137 * a command buffer, such as the kernel position in the kernel BO
138 */
139 struct intel_cmd_shader vs;
140 struct intel_cmd_shader fs;
141 struct intel_cmd_shader gs;
142 struct intel_cmd_shader tess_control;
143 struct intel_cmd_shader tess_eval;
144 struct intel_cmd_shader compute;
145
Chia-I Wub2755562014-08-20 13:38:52 +0800146 struct {
Chia-I Wu338fe642014-08-28 10:43:04 +0800147 XGL_UINT count;
148 XGL_UINT used;
149 struct intel_cmd_shader *shaderArray;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600150 } shaderCache;
151
152 struct {
Chia-I Wub2755562014-08-20 13:38:52 +0800153 const struct intel_viewport_state *viewport;
154 const struct intel_raster_state *raster;
155 const struct intel_msaa_state *msaa;
156 const struct intel_blend_state *blend;
157 const struct intel_ds_state *ds;
158 } state;
159
160 struct {
161 const struct intel_dset *graphics;
162 XGL_UINT graphics_offset;
163 const struct intel_dset *compute;
164 XGL_UINT compute_offset;
165 } dset;
166
167 struct {
168 struct intel_mem_view graphics;
169 struct intel_mem_view compute;
Chia-I Wu9f1722c2014-08-25 10:17:58 +0800170 } dyn_view;
Chia-I Wub2755562014-08-20 13:38:52 +0800171
172 struct {
173 const struct intel_mem *mem;
174 XGL_GPU_SIZE offset;
175 XGL_INDEX_TYPE type;
176 } index;
177
178 struct {
179 const struct intel_rt_view *rt[XGL_MAX_COLOR_ATTACHMENTS];
180 XGL_UINT rt_count;
181
182 const struct intel_ds_view *ds;
183 } att;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800184
Chia-I Wu707a29e2014-08-27 12:51:47 +0800185 XGL_UINT draw_count;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800186 uint32_t wa_flags;
Chia-I Wub2755562014-08-20 13:38:52 +0800187};
Chia-I Wu09142132014-08-11 15:42:55 +0800188
Chia-I Wue24c3292014-08-21 14:05:23 +0800189struct intel_cmd_writer {
190 struct intel_bo *bo;
191 void *ptr_opaque;
192
193 /* in DWords */
194 XGL_UINT size;
195 XGL_UINT used;
196};
197
Chia-I Wu730e5362014-08-19 12:15:09 +0800198struct intel_cmd {
199 struct intel_obj obj;
200
201 struct intel_dev *dev;
Chia-I Wu0b784442014-08-25 22:54:16 +0800202 struct intel_bo *scratch_bo;
Chia-I Wu63883292014-08-25 13:50:26 +0800203 int pipeline_select;
Chia-I Wu730e5362014-08-19 12:15:09 +0800204
Chia-I Wu343b1372014-08-20 16:39:20 +0800205 struct intel_cmd_reloc *relocs;
206 XGL_UINT reloc_count;
207
Chia-I Wu730e5362014-08-19 12:15:09 +0800208 XGL_FLAGS flags;
209
Chia-I Wue24c3292014-08-21 14:05:23 +0800210 struct intel_cmd_writer batch;
Chia-I Wu24565ee2014-08-21 20:24:31 +0800211 struct intel_cmd_writer state;
Chia-I Wu1cbc0052014-08-25 09:50:12 +0800212 struct intel_cmd_writer kernel;
Chia-I Wu730e5362014-08-19 12:15:09 +0800213
Chia-I Wu343b1372014-08-20 16:39:20 +0800214 XGL_UINT reloc_used;
Chia-I Wu04966702014-08-20 15:05:03 +0800215 XGL_RESULT result;
Chia-I Wub2755562014-08-20 13:38:52 +0800216
217 struct intel_cmd_bind bind;
Chia-I Wu730e5362014-08-19 12:15:09 +0800218};
219
220static inline struct intel_cmd *intel_cmd(XGL_CMD_BUFFER cmd)
221{
222 return (struct intel_cmd *) cmd;
223}
224
225static inline struct intel_cmd *intel_cmd_from_obj(struct intel_obj *obj)
226{
227 return (struct intel_cmd *) obj;
228}
229
230XGL_RESULT intel_cmd_create(struct intel_dev *dev,
231 const XGL_CMD_BUFFER_CREATE_INFO *info,
232 struct intel_cmd **cmd_ret);
233void intel_cmd_destroy(struct intel_cmd *cmd);
234
235XGL_RESULT intel_cmd_begin(struct intel_cmd *cmd, XGL_FLAGS flags);
236XGL_RESULT intel_cmd_end(struct intel_cmd *cmd);
237
Chia-I Wue24c3292014-08-21 14:05:23 +0800238static inline struct intel_bo *intel_cmd_get_batch(const struct intel_cmd *cmd,
239 XGL_GPU_SIZE *used)
240{
241 const struct intel_cmd_writer *writer = &cmd->batch;
242
243 if (used)
244 *used = sizeof(uint32_t) * writer->used;
245
246 return writer->bo;
247}
248
Chia-I Wu09142132014-08-11 15:42:55 +0800249XGL_RESULT XGLAPI intelCreateCommandBuffer(
250 XGL_DEVICE device,
251 const XGL_CMD_BUFFER_CREATE_INFO* pCreateInfo,
252 XGL_CMD_BUFFER* pCmdBuffer);
253
254XGL_RESULT XGLAPI intelBeginCommandBuffer(
255 XGL_CMD_BUFFER cmdBuffer,
256 XGL_FLAGS flags);
257
258XGL_RESULT XGLAPI intelEndCommandBuffer(
259 XGL_CMD_BUFFER cmdBuffer);
260
261XGL_RESULT XGLAPI intelResetCommandBuffer(
262 XGL_CMD_BUFFER cmdBuffer);
263
264XGL_VOID XGLAPI intelCmdBindPipeline(
265 XGL_CMD_BUFFER cmdBuffer,
266 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
267 XGL_PIPELINE pipeline);
268
269XGL_VOID XGLAPI intelCmdBindPipelineDelta(
270 XGL_CMD_BUFFER cmdBuffer,
271 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
272 XGL_PIPELINE_DELTA delta);
273
274XGL_VOID XGLAPI intelCmdBindStateObject(
275 XGL_CMD_BUFFER cmdBuffer,
276 XGL_STATE_BIND_POINT stateBindPoint,
277 XGL_STATE_OBJECT state);
278
279XGL_VOID XGLAPI intelCmdBindDescriptorSet(
280 XGL_CMD_BUFFER cmdBuffer,
281 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
282 XGL_UINT index,
283 XGL_DESCRIPTOR_SET descriptorSet,
284 XGL_UINT slotOffset);
285
286XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
287 XGL_CMD_BUFFER cmdBuffer,
288 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
289 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView);
290
291XGL_VOID XGLAPI intelCmdBindIndexData(
292 XGL_CMD_BUFFER cmdBuffer,
293 XGL_GPU_MEMORY mem,
294 XGL_GPU_SIZE offset,
295 XGL_INDEX_TYPE indexType);
296
297XGL_VOID XGLAPI intelCmdBindAttachments(
298 XGL_CMD_BUFFER cmdBuffer,
299 XGL_UINT colorAttachmentCount,
300 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
301 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment);
302
303XGL_VOID XGLAPI intelCmdPrepareMemoryRegions(
304 XGL_CMD_BUFFER cmdBuffer,
305 XGL_UINT transitionCount,
306 const XGL_MEMORY_STATE_TRANSITION* pStateTransitions);
307
308XGL_VOID XGLAPI intelCmdPrepareImages(
309 XGL_CMD_BUFFER cmdBuffer,
310 XGL_UINT transitionCount,
311 const XGL_IMAGE_STATE_TRANSITION* pStateTransitions);
312
313XGL_VOID XGLAPI intelCmdDraw(
314 XGL_CMD_BUFFER cmdBuffer,
315 XGL_UINT firstVertex,
316 XGL_UINT vertexCount,
317 XGL_UINT firstInstance,
318 XGL_UINT instanceCount);
319
320XGL_VOID XGLAPI intelCmdDrawIndexed(
321 XGL_CMD_BUFFER cmdBuffer,
322 XGL_UINT firstIndex,
323 XGL_UINT indexCount,
324 XGL_INT vertexOffset,
325 XGL_UINT firstInstance,
326 XGL_UINT instanceCount);
327
328XGL_VOID XGLAPI intelCmdDrawIndirect(
329 XGL_CMD_BUFFER cmdBuffer,
330 XGL_GPU_MEMORY mem,
331 XGL_GPU_SIZE offset,
332 XGL_UINT32 count,
333 XGL_UINT32 stride);
334
335XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
336 XGL_CMD_BUFFER cmdBuffer,
337 XGL_GPU_MEMORY mem,
338 XGL_GPU_SIZE offset,
339 XGL_UINT32 count,
340 XGL_UINT32 stride);
341
342XGL_VOID XGLAPI intelCmdDispatch(
343 XGL_CMD_BUFFER cmdBuffer,
344 XGL_UINT x,
345 XGL_UINT y,
346 XGL_UINT z);
347
348XGL_VOID XGLAPI intelCmdDispatchIndirect(
349 XGL_CMD_BUFFER cmdBuffer,
350 XGL_GPU_MEMORY mem,
351 XGL_GPU_SIZE offset);
352
353XGL_VOID XGLAPI intelCmdCopyMemory(
354 XGL_CMD_BUFFER cmdBuffer,
355 XGL_GPU_MEMORY srcMem,
356 XGL_GPU_MEMORY destMem,
357 XGL_UINT regionCount,
358 const XGL_MEMORY_COPY* pRegions);
359
360XGL_VOID XGLAPI intelCmdCopyImage(
361 XGL_CMD_BUFFER cmdBuffer,
362 XGL_IMAGE srcImage,
363 XGL_IMAGE destImage,
364 XGL_UINT regionCount,
365 const XGL_IMAGE_COPY* pRegions);
366
367XGL_VOID XGLAPI intelCmdCopyMemoryToImage(
368 XGL_CMD_BUFFER cmdBuffer,
369 XGL_GPU_MEMORY srcMem,
370 XGL_IMAGE destImage,
371 XGL_UINT regionCount,
372 const XGL_MEMORY_IMAGE_COPY* pRegions);
373
374XGL_VOID XGLAPI intelCmdCopyImageToMemory(
375 XGL_CMD_BUFFER cmdBuffer,
376 XGL_IMAGE srcImage,
377 XGL_GPU_MEMORY destMem,
378 XGL_UINT regionCount,
379 const XGL_MEMORY_IMAGE_COPY* pRegions);
380
381XGL_VOID XGLAPI intelCmdCloneImageData(
382 XGL_CMD_BUFFER cmdBuffer,
383 XGL_IMAGE srcImage,
384 XGL_IMAGE_STATE srcImageState,
385 XGL_IMAGE destImage,
386 XGL_IMAGE_STATE destImageState);
387
388XGL_VOID XGLAPI intelCmdUpdateMemory(
389 XGL_CMD_BUFFER cmdBuffer,
390 XGL_GPU_MEMORY destMem,
391 XGL_GPU_SIZE destOffset,
392 XGL_GPU_SIZE dataSize,
393 const XGL_UINT32* pData);
394
395XGL_VOID XGLAPI intelCmdFillMemory(
396 XGL_CMD_BUFFER cmdBuffer,
397 XGL_GPU_MEMORY destMem,
398 XGL_GPU_SIZE destOffset,
399 XGL_GPU_SIZE fillSize,
400 XGL_UINT32 data);
401
402XGL_VOID XGLAPI intelCmdClearColorImage(
403 XGL_CMD_BUFFER cmdBuffer,
404 XGL_IMAGE image,
405 const XGL_FLOAT color[4],
406 XGL_UINT rangeCount,
407 const XGL_IMAGE_SUBRESOURCE_RANGE* pRanges);
408
409XGL_VOID XGLAPI intelCmdClearColorImageRaw(
410 XGL_CMD_BUFFER cmdBuffer,
411 XGL_IMAGE image,
412 const XGL_UINT32 color[4],
413 XGL_UINT rangeCount,
414 const XGL_IMAGE_SUBRESOURCE_RANGE* pRanges);
415
416XGL_VOID XGLAPI intelCmdClearDepthStencil(
417 XGL_CMD_BUFFER cmdBuffer,
418 XGL_IMAGE image,
419 XGL_FLOAT depth,
420 XGL_UINT32 stencil,
421 XGL_UINT rangeCount,
422 const XGL_IMAGE_SUBRESOURCE_RANGE* pRanges);
423
424XGL_VOID XGLAPI intelCmdResolveImage(
425 XGL_CMD_BUFFER cmdBuffer,
426 XGL_IMAGE srcImage,
427 XGL_IMAGE destImage,
428 XGL_UINT rectCount,
429 const XGL_IMAGE_RESOLVE* pRects);
430
431XGL_VOID XGLAPI intelCmdSetEvent(
432 XGL_CMD_BUFFER cmdBuffer,
433 XGL_EVENT event);
434
435XGL_VOID XGLAPI intelCmdResetEvent(
436 XGL_CMD_BUFFER cmdBuffer,
437 XGL_EVENT event);
438
439XGL_VOID XGLAPI intelCmdMemoryAtomic(
440 XGL_CMD_BUFFER cmdBuffer,
441 XGL_GPU_MEMORY destMem,
442 XGL_GPU_SIZE destOffset,
443 XGL_UINT64 srcData,
444 XGL_ATOMIC_OP atomicOp);
445
446XGL_VOID XGLAPI intelCmdBeginQuery(
447 XGL_CMD_BUFFER cmdBuffer,
448 XGL_QUERY_POOL queryPool,
449 XGL_UINT slot,
450 XGL_FLAGS flags);
451
452XGL_VOID XGLAPI intelCmdEndQuery(
453 XGL_CMD_BUFFER cmdBuffer,
454 XGL_QUERY_POOL queryPool,
455 XGL_UINT slot);
456
457XGL_VOID XGLAPI intelCmdResetQueryPool(
458 XGL_CMD_BUFFER cmdBuffer,
459 XGL_QUERY_POOL queryPool,
460 XGL_UINT startQuery,
461 XGL_UINT queryCount);
462
463XGL_VOID XGLAPI intelCmdWriteTimestamp(
464 XGL_CMD_BUFFER cmdBuffer,
465 XGL_TIMESTAMP_TYPE timestampType,
466 XGL_GPU_MEMORY destMem,
467 XGL_GPU_SIZE destOffset);
468
469XGL_VOID XGLAPI intelCmdInitAtomicCounters(
470 XGL_CMD_BUFFER cmdBuffer,
471 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
472 XGL_UINT startCounter,
473 XGL_UINT counterCount,
474 const XGL_UINT32* pData);
475
476XGL_VOID XGLAPI intelCmdLoadAtomicCounters(
477 XGL_CMD_BUFFER cmdBuffer,
478 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
479 XGL_UINT startCounter,
480 XGL_UINT counterCount,
481 XGL_GPU_MEMORY srcMem,
482 XGL_GPU_SIZE srcOffset);
483
484XGL_VOID XGLAPI intelCmdSaveAtomicCounters(
485 XGL_CMD_BUFFER cmdBuffer,
486 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
487 XGL_UINT startCounter,
488 XGL_UINT counterCount,
489 XGL_GPU_MEMORY destMem,
490 XGL_GPU_SIZE destOffset);
491
492XGL_VOID XGLAPI intelCmdDbgMarkerBegin(
493 XGL_CMD_BUFFER cmdBuffer,
494 const XGL_CHAR* pMarker);
495
496XGL_VOID XGLAPI intelCmdDbgMarkerEnd(
497 XGL_CMD_BUFFER cmdBuffer);
498
499#endif /* CMD_H */