r600g: remove unused definitions
[mesa.git] / src / gallium / drivers / r600 / r600.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #ifndef R600_H
27 #define R600_H
28
29 #include "../../winsys/radeon/drm/radeon_winsys.h"
30 #include "util/u_double_list.h"
31 #include "util/u_vbuf.h"
32
33 #define R600_ERR(fmt, args...) \
34 fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
35
36 struct winsys_handle;
37
38 enum radeon_family {
39 CHIP_UNKNOWN,
40 CHIP_R600,
41 CHIP_RV610,
42 CHIP_RV630,
43 CHIP_RV670,
44 CHIP_RV620,
45 CHIP_RV635,
46 CHIP_RS780,
47 CHIP_RS880,
48 CHIP_RV770,
49 CHIP_RV730,
50 CHIP_RV710,
51 CHIP_RV740,
52 CHIP_CEDAR,
53 CHIP_REDWOOD,
54 CHIP_JUNIPER,
55 CHIP_CYPRESS,
56 CHIP_HEMLOCK,
57 CHIP_PALM,
58 CHIP_SUMO,
59 CHIP_SUMO2,
60 CHIP_BARTS,
61 CHIP_TURKS,
62 CHIP_CAICOS,
63 CHIP_CAYMAN,
64 CHIP_LAST,
65 };
66
67 enum chip_class {
68 R600,
69 R700,
70 EVERGREEN,
71 CAYMAN,
72 };
73
74 struct r600_tiling_info {
75 unsigned num_channels;
76 unsigned num_banks;
77 unsigned group_bytes;
78 };
79
80 struct r600_resource {
81 struct u_vbuf_resource b;
82
83 /* Winsys objects. */
84 struct pb_buffer *buf;
85 struct radeon_winsys_cs_handle *cs_buf;
86
87 /* Resource state. */
88 unsigned domains;
89 };
90
91 #define R600_BLOCK_MAX_BO 32
92 #define R600_BLOCK_MAX_REG 128
93
94 /* each range covers 9 bits of dword space = 512 dwords = 2k bytes */
95 /* there is a block entry for each register so 512 blocks */
96 /* we have no registers to read/write below 0x8000 (0x2000 in dw space) */
97 /* we use some fake offsets at 0x40000 to do evergreen sampler borders so take 0x42000 as a max bound*/
98 #define RANGE_OFFSET_START 0x8000
99 #define HASH_SHIFT 9
100 #define NUM_RANGES (0x42000 - RANGE_OFFSET_START) / (4 << HASH_SHIFT) /* 128 << 9 = 64k */
101
102 #define CTX_RANGE_ID(offset) ((((offset - RANGE_OFFSET_START) >> 2) >> HASH_SHIFT) & 255)
103 #define CTX_BLOCK_ID(offset) (((offset - RANGE_OFFSET_START) >> 2) & ((1 << HASH_SHIFT) - 1))
104
105 struct r600_pipe_reg {
106 uint32_t value;
107 struct r600_block *block;
108 struct r600_resource *bo;
109 enum radeon_bo_usage bo_usage;
110 uint32_t id;
111 };
112
113 struct r600_pipe_state {
114 unsigned id;
115 unsigned nregs;
116 struct r600_pipe_reg regs[R600_BLOCK_MAX_REG];
117 };
118
119 struct r600_pipe_resource_state {
120 unsigned id;
121 uint32_t val[8];
122 struct r600_resource *bo[2];
123 enum radeon_bo_usage bo_usage[2];
124 };
125
126 #define R600_BLOCK_STATUS_ENABLED (1 << 0)
127 #define R600_BLOCK_STATUS_DIRTY (1 << 1)
128 #define R600_BLOCK_STATUS_RESOURCE_DIRTY (1 << 2)
129
130 #define R600_BLOCK_STATUS_RESOURCE_VERTEX (1 << 3)
131
132 struct r600_block_reloc {
133 struct r600_resource *bo;
134 enum radeon_bo_usage bo_usage;
135 unsigned bo_pm4_index;
136 };
137
138 struct r600_block {
139 struct list_head list;
140 struct list_head enable_list;
141 unsigned status;
142 unsigned flags;
143 unsigned start_offset;
144 unsigned pm4_ndwords;
145 unsigned nbo;
146 uint16_t nreg;
147 uint16_t nreg_dirty;
148 uint32_t *reg;
149 uint32_t pm4[R600_BLOCK_MAX_REG];
150 unsigned pm4_bo_index[R600_BLOCK_MAX_REG];
151 struct r600_block_reloc reloc[R600_BLOCK_MAX_BO];
152 };
153
154 struct r600_range {
155 struct r600_block **blocks;
156 };
157
158 struct r600_query_buffer {
159 /* The buffer where query results are stored. */
160 struct r600_resource *buf;
161 /* Offset of the next free result after current query data */
162 unsigned results_end;
163 /* If a query buffer is full, a new buffer is created and the old one
164 * is put in here. When we calculate the result, we sum up the samples
165 * from all buffers. */
166 struct r600_query_buffer *previous;
167 };
168
169 union r600_query_result {
170 uint64_t u64;
171 boolean b;
172 struct pipe_query_data_so_statistics so;
173 };
174
175 struct r600_query {
176 /* The query buffer and how many results are in it. */
177 struct r600_query_buffer buffer;
178 /* The type of query */
179 unsigned type;
180 /* Size of the result in memory for both begin_query and end_query,
181 * this can be one or two numbers, or it could even be a size of a structure. */
182 unsigned result_size;
183 /* The number of dwords for begin_query or end_query. */
184 unsigned num_cs_dw;
185 /* linked list of queries */
186 struct list_head list;
187 };
188
189 struct r600_so_target {
190 struct pipe_stream_output_target b;
191
192 /* The buffer where BUFFER_FILLED_SIZE is stored. */
193 struct r600_resource *filled_size;
194 unsigned stride_in_dw;
195 unsigned so_index;
196 };
197
198 #define R600_CONTEXT_DRAW_PENDING (1 << 0)
199 #define R600_CONTEXT_DST_CACHES_DIRTY (1 << 1)
200
201 struct r600_context;
202 struct r600_screen;
203
204 void r600_get_backend_mask(struct r600_context *ctx);
205 int r600_context_init(struct r600_context *ctx);
206 void r600_context_fini(struct r600_context *ctx);
207 void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state);
208 void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
209 void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
210 void r600_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
211 void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
212 void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
213 void r600_context_flush(struct r600_context *ctx, unsigned flags);
214
215 void r600_context_emit_fence(struct r600_context *ctx, struct r600_resource *fence,
216 unsigned offset, unsigned value);
217 void r600_inval_shader_cache(struct r600_context *ctx);
218 void r600_inval_texture_cache(struct r600_context *ctx);
219 void r600_inval_vertex_cache(struct r600_context *ctx);
220 void r600_flush_framebuffer(struct r600_context *ctx, bool flush_now);
221
222 void r600_context_streamout_begin(struct r600_context *ctx);
223 void r600_context_streamout_end(struct r600_context *ctx);
224 void r600_context_draw_opaque_count(struct r600_context *ctx, struct r600_so_target *t);
225 void r600_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in);
226 void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block);
227 void r600_context_block_resource_emit_dirty(struct r600_context *ctx, struct r600_block *block);
228
229 int evergreen_context_init(struct r600_context *ctx);
230 void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
231 void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
232
233 void _r600_pipe_state_add_reg(struct r600_context *ctx,
234 struct r600_pipe_state *state,
235 uint32_t offset, uint32_t value,
236 uint32_t range_id, uint32_t block_id,
237 struct r600_resource *bo,
238 enum radeon_bo_usage usage);
239
240 void r600_pipe_state_add_reg_noblock(struct r600_pipe_state *state,
241 uint32_t offset, uint32_t value,
242 struct r600_resource *bo,
243 enum radeon_bo_usage usage);
244
245 #define r600_pipe_state_add_reg(state, offset, value, bo, usage) _r600_pipe_state_add_reg(rctx, state, offset, value, CTX_RANGE_ID(offset), CTX_BLOCK_ID(offset), bo, usage)
246
247 static inline void r600_pipe_state_mod_reg(struct r600_pipe_state *state,
248 uint32_t value)
249 {
250 state->regs[state->nregs].value = value;
251 state->nregs++;
252 }
253
254 static inline void r600_pipe_state_mod_reg_bo(struct r600_pipe_state *state,
255 uint32_t value, struct r600_resource *bo,
256 enum radeon_bo_usage usage)
257 {
258 state->regs[state->nregs].value = value;
259 state->regs[state->nregs].bo = bo;
260 state->regs[state->nregs].bo_usage = usage;
261 state->nregs++;
262 }
263
264 #endif