7cbacea89a1321a7b6705e8ffbad18acc2055509
[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 <stdint.h>
30 #include <stdio.h>
31
32 #define RADEON_CTX_MAX_PM4 (64 * 1024 / 4)
33
34 #define R600_ERR(fmt, args...) \
35 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
36
37 typedef uint64_t u64;
38 typedef uint32_t u32;
39 typedef uint16_t u16;
40 typedef uint8_t u8;
41
42 struct radeon;
43
44 enum radeon_family {
45 CHIP_UNKNOWN,
46 CHIP_R100,
47 CHIP_RV100,
48 CHIP_RS100,
49 CHIP_RV200,
50 CHIP_RS200,
51 CHIP_R200,
52 CHIP_RV250,
53 CHIP_RS300,
54 CHIP_RV280,
55 CHIP_R300,
56 CHIP_R350,
57 CHIP_RV350,
58 CHIP_RV380,
59 CHIP_R420,
60 CHIP_R423,
61 CHIP_RV410,
62 CHIP_RS400,
63 CHIP_RS480,
64 CHIP_RS600,
65 CHIP_RS690,
66 CHIP_RS740,
67 CHIP_RV515,
68 CHIP_R520,
69 CHIP_RV530,
70 CHIP_RV560,
71 CHIP_RV570,
72 CHIP_R580,
73 CHIP_R600,
74 CHIP_RV610,
75 CHIP_RV630,
76 CHIP_RV670,
77 CHIP_RV620,
78 CHIP_RV635,
79 CHIP_RS780,
80 CHIP_RS880,
81 CHIP_RV770,
82 CHIP_RV730,
83 CHIP_RV710,
84 CHIP_RV740,
85 CHIP_CEDAR,
86 CHIP_REDWOOD,
87 CHIP_JUNIPER,
88 CHIP_CYPRESS,
89 CHIP_HEMLOCK,
90 CHIP_LAST,
91 };
92
93 enum radeon_family r600_get_family(struct radeon *rw);
94
95 /* lowlevel WS bo */
96 struct radeon_ws_bo;
97 struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon,
98 unsigned size, unsigned alignment, unsigned usage);
99 struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon,
100 unsigned handle);
101 void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo, unsigned usage, void *ctx);
102 void radeon_ws_bo_unmap(struct radeon *radeon, struct radeon_ws_bo *bo);
103 void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst,
104 struct radeon_ws_bo *src);
105
106 /* R600/R700 STATES */
107 #define R600_GROUP_MAX 16
108 #define R600_BLOCK_MAX_BO 32
109 #define R600_BLOCK_MAX_REG 128
110
111 enum r600_group_id {
112 R600_GROUP_CONFIG = 0,
113 R600_GROUP_CONTEXT,
114 R600_GROUP_ALU_CONST,
115 R600_GROUP_RESOURCE,
116 R600_GROUP_SAMPLER,
117 R600_GROUP_CTL_CONST,
118 R600_GROUP_LOOP_CONST,
119 R600_GROUP_BOOL_CONST,
120 R600_NGROUPS
121 };
122
123 struct r600_pipe_reg {
124 unsigned group_id;
125 u32 offset;
126 u32 mask;
127 u32 value;
128 struct radeon_ws_bo *bo;
129 };
130
131 struct r600_pipe_state {
132 unsigned id;
133 unsigned nregs;
134 struct r600_pipe_reg regs[R600_BLOCK_MAX_REG];
135 };
136
137 static inline void r600_pipe_state_add_reg(struct r600_pipe_state *state,
138 unsigned group_id, u32 offset,
139 u32 value, u32 mask,
140 struct radeon_ws_bo *bo)
141 {
142 state->regs[state->nregs].group_id = group_id;
143 state->regs[state->nregs].offset = offset;
144 state->regs[state->nregs].value = value;
145 state->regs[state->nregs].mask = mask;
146 state->regs[state->nregs].bo = bo;
147 state->nregs++;
148 assert(state->nregs < R600_BLOCK_MAX_REG);
149 }
150
151 #define R600_BLOCK_STATUS_ENABLED (1 << 0)
152 #define R600_BLOCK_STATUS_DIRTY (1 << 1)
153
154 struct r600_block_reloc {
155 struct radeon_ws_bo *bo;
156 unsigned nreloc;
157 unsigned bo_pm4_index[R600_BLOCK_MAX_BO];
158 };
159
160 struct r600_group_block {
161 unsigned status;
162 unsigned start_offset;
163 unsigned pm4_ndwords;
164 unsigned nbo;
165 unsigned nreg;
166 u32 pm4[R600_BLOCK_MAX_REG];
167 unsigned pm4_bo_index[R600_BLOCK_MAX_REG];
168 struct r600_block_reloc reloc[R600_BLOCK_MAX_BO];
169 };
170
171 struct r600_group {
172 unsigned start_offset;
173 unsigned end_offset;
174 unsigned nblocks;
175 struct r600_group_block *blocks;
176 unsigned *offset_block_id;
177 };
178
179 #pragma pack(1)
180 struct r600_reloc {
181 uint32_t handle;
182 uint32_t read_domain;
183 uint32_t write_domain;
184 uint32_t flags;
185 };
186 #pragma pack()
187
188 struct r600_context {
189 struct radeon *radeon;
190 unsigned ngroups;
191 struct r600_group groups[R600_GROUP_MAX];
192 unsigned pm4_ndwords;
193 unsigned pm4_cdwords;
194 unsigned pm4_dirty_cdwords;
195 unsigned ctx_pm4_ndwords;
196 unsigned nreloc;
197 unsigned creloc;
198 struct r600_reloc *reloc;
199 struct radeon_ws_bo **bo;
200 u32 *pm4;
201 };
202
203 struct r600_draw {
204 u32 vgt_num_indices;
205 u32 vgt_num_instances;
206 u32 vgt_index_type;
207 u32 vgt_draw_initiator;
208 u32 indices_bo_offset;
209 struct radeon_ws_bo *indices;
210 };
211
212 int r600_context_init(struct r600_context *ctx, struct radeon *radeon);
213 void r600_context_fini(struct r600_context *ctx);
214 void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state);
215 void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
216 void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
217 void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
218 void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
219 void r600_context_flush(struct r600_context *ctx);
220 void r600_context_dump_bof(struct r600_context *ctx, const char *file);
221 void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw);
222
223 #endif