iris: Move get_command_space to iris_batch.c
[mesa.git] / src / gallium / drivers / iris / iris_batch.h
1 /*
2 * Copyright © 2017 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef IRIS_BATCH_DOT_H
25 #define IRIS_BATCH_DOT_H
26
27 #include <stdint.h>
28 #include <stdbool.h>
29 #include "common/gen_decoder.h"
30
31 /* The kernel assumes batchbuffers are smaller than 256kB. */
32 #define MAX_BATCH_SIZE (256 * 1024)
33
34 struct iris_address {
35 struct iris_bo *bo;
36 uint64_t offset;
37 bool write;
38 };
39
40 struct iris_batch_buffer {
41 struct iris_bo *bo;
42 void *map;
43 void *map_next;
44
45 struct iris_bo *partial_bo;
46 unsigned partial_bytes;
47 };
48
49 struct iris_batch {
50 struct iris_screen *screen;
51 struct pipe_debug_callback *dbg;
52
53 /** Current batchbuffer being queued up. */
54 struct iris_batch_buffer cmdbuf;
55
56 /** Last BO submitted to the hardware. Used for glFinish(). */
57 struct iris_bo *last_cmd_bo;
58
59 uint32_t hw_ctx_id;
60
61 /** Which ring this batch targets - a I915_EXEC_RING_MASK value */
62 uint8_t ring;
63
64 bool no_wrap;
65
66 /** The validation list */
67 struct drm_i915_gem_exec_object2 *validation_list;
68 struct iris_bo **exec_bos;
69 int exec_count;
70 int exec_array_size;
71
72 /** The amount of aperture space (in bytes) used by all exec_bos */
73 int aperture_space;
74
75 #if DEBUG
76 /** Map from batch offset to iris_alloc_state data (with DEBUG_BATCH) */
77 // XXX: unused
78 struct hash_table *state_sizes;
79 struct gen_batch_decode_ctx decoder;
80 #endif
81 };
82
83 void iris_init_batch(struct iris_batch *batch,
84 struct iris_screen *screen,
85 struct pipe_debug_callback *dbg,
86 uint8_t ring);
87 void iris_batch_free(struct iris_batch *batch);
88 void iris_require_command_space(struct iris_batch *batch, unsigned size);
89 void *iris_get_command_space(struct iris_batch *batch, unsigned bytes);
90 void iris_batch_emit(struct iris_batch *batch, const void *data, unsigned size);
91
92 int _iris_batch_flush_fence(struct iris_batch *batch,
93 int in_fence_fd, int *out_fence_fd,
94 const char *file, int line);
95
96
97 #define iris_batch_flush_fence(batch, in_fence_fd, out_fence_fd) \
98 _iris_batch_flush_fence((batch), (in_fence_fd), (out_fence_fd), \
99 __FILE__, __LINE__)
100
101 #define iris_batch_flush(batch) iris_batch_flush_fence((batch), -1, NULL)
102
103 bool iris_batch_references(struct iris_batch *batch, struct iris_bo *bo);
104
105 #define RELOC_WRITE EXEC_OBJECT_WRITE
106
107 void iris_use_pinned_bo(struct iris_batch *batch, struct iris_bo *bo,
108 bool writable);
109
110 #endif