freedreno/a3xx: add ARB_instanced_arrays support
[mesa.git] / src / gallium / drivers / ilo / ilo_cp.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 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 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #ifndef ILO_CP_H
29 #define ILO_CP_H
30
31 #include "intel_winsys.h"
32
33 #include "ilo_builder.h"
34 #include "ilo_common.h"
35
36 struct ilo_cp;
37 struct ilo_shader_cache;
38
39 typedef void (*ilo_cp_callback)(struct ilo_cp *cp, void *data);
40
41 /**
42 * Parser owners are notified when they gain or lose the ownership of the
43 * parser. This gives owners a chance to emit prolog or epilog.
44 */
45 struct ilo_cp_owner {
46 ilo_cp_callback own;
47 ilo_cp_callback release;
48 void *data;
49
50 /*
51 * Space reserved for release(). This can be modified at any time, as long
52 * as it is never increased by more than ilo_cp_space().
53 */
54 int reserve;
55 };
56
57 /**
58 * Command parser.
59 */
60 struct ilo_cp {
61 struct intel_winsys *winsys;
62 struct ilo_shader_cache *shader_cache;
63 struct intel_context *render_ctx;
64
65 ilo_cp_callback submit_callback;
66 void *submit_callback_data;
67
68 enum intel_ring_type ring;
69 const struct ilo_cp_owner *owner;
70
71 unsigned one_off_flags;
72
73 struct ilo_builder builder;
74 struct intel_bo *last_submitted_bo;
75 };
76
77 struct ilo_cp *
78 ilo_cp_create(const struct ilo_dev_info *dev,
79 struct intel_winsys *winsys,
80 struct ilo_shader_cache *shc);
81
82 void
83 ilo_cp_destroy(struct ilo_cp *cp);
84
85 void
86 ilo_cp_submit_internal(struct ilo_cp *cp);
87
88 static inline void
89 ilo_cp_submit(struct ilo_cp *cp, const char *reason)
90 {
91 if (ilo_debug & ILO_DEBUG_SUBMIT) {
92 ilo_printf("submit batch buffer to %s ring because of %s: ",
93 (cp->ring == INTEL_RING_RENDER) ? "render" : "unknown", reason);
94 ilo_builder_batch_print_stats(&cp->builder);
95 }
96
97 ilo_cp_submit_internal(cp);
98 }
99
100 void
101 ilo_cp_set_owner(struct ilo_cp *cp, enum intel_ring_type ring,
102 const struct ilo_cp_owner *owner);
103
104 /**
105 * Return the remaining space (in dwords) in the parser buffer.
106 */
107 static inline int
108 ilo_cp_space(struct ilo_cp *cp)
109 {
110 const int space = ilo_builder_batch_space(&cp->builder);
111 const int mi_batch_buffer_end_space = 2;
112
113 assert(space >= cp->owner->reserve + mi_batch_buffer_end_space);
114
115 return space - cp->owner->reserve - mi_batch_buffer_end_space;
116 }
117
118 /**
119 * Set one-off flags. They will be cleared after submission.
120 */
121 static inline void
122 ilo_cp_set_one_off_flags(struct ilo_cp *cp, unsigned flags)
123 {
124 cp->one_off_flags |= flags;
125 }
126
127 /**
128 * Set submit callback. The callback is invoked after the bo has been
129 * successfully submitted, and before the bo is reallocated.
130 */
131 static inline void
132 ilo_cp_set_submit_callback(struct ilo_cp *cp, ilo_cp_callback callback,
133 void *data)
134 {
135 cp->submit_callback = callback;
136 cp->submit_callback_data = data;
137 }
138
139 #endif /* ILO_CP_H */