1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
#include <sys/types.h>
#include "xf86drm.h"
#include "radeon_drm.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>
#include "radeondemo.h"
#include "radeon_bo_gem.h"
#include "radeon_cs_gem.h"
struct radeon _radeon_ctx;
struct radeon *radeon = &_radeon_ctx;
int run_test1(struct radeon *radeon)
{
struct r600_accel_object test1 = {0};
int size, i;
test1.pitch = 1408;
test1.width = 1366;
test1.height = 768;
test1.bpp = 32;
test1.domain = RADEON_GEM_DOMAIN_VRAM;
test1.tiling_flags = 0;
size = test1.pitch*test1.height*(test1.bpp / 8);
test1.bo = radeon_bo_open(radeon->bufmgr, 0, size, 4096, RADEON_GEM_DOMAIN_VRAM, 0);
if (!test1.bo)
return -1;
radeon_bo_map(test1.bo, 1);
{
uint32_t *data = test1.bo->ptr;
data[0] = 0xdeadbeef;
}
radeon_bo_unmap(test1.bo);
do_solid_fill_prepare(radeon, &test1, 0xffff0000);
evergreen_solid(radeon, 0, 0, test1.width, test1.height);
evergreen_finish_op(radeon, 8);
radeon_cs_flush_indirect(radeon);
radeon_bo_map(test1.bo, 0);
{
uint32_t *data = test1.bo->ptr;
for (i = 0; i < 32; i++) {
fprintf(stderr,"%08x ", data[i]);
}
fprintf(stderr,"\n");
// fprintf(stderr,"bo1 %08x %08x\n", data[0], data[1]);
}
radeon_bo_unmap(test1.bo);
}
int run_test2(struct radeon *radeon)
{
struct r600_accel_object test1 = {0};
int size, i;
test1.pitch = 1408;
test1.width = 1366;
test1.height = 768;
test1.bpp = 32;
test1.domain = RADEON_GEM_DOMAIN_GTT;
test1.tiling_flags = 0;
size = test1.pitch*test1.height*(test1.bpp / 8);
test1.bo = radeon_bo_open(radeon->bufmgr, 0, size, 4096, RADEON_GEM_DOMAIN_GTT, 0);
if (!test1.bo)
return -1;
radeon_bo_map(test1.bo, 1);
{
uint32_t *data = test1.bo->ptr;
data[0] = 0xdeadbeef;
}
radeon_bo_unmap(test1.bo);
do_solid_fill_prepare(radeon, &test1, 0xffff0000);
evergreen_solid(radeon, 0, 0, test1.width, test1.height);
evergreen_finish_op(radeon, 8);
radeon_cs_flush_indirect(radeon);
radeon_bo_map(test1.bo, 0);
{
uint32_t *data = test1.bo->ptr;
for (i = 0; i < 32; i++) {
fprintf(stderr,"%08x ", data[i]);
}
fprintf(stderr,"\n");
// fprintf(stderr,"bo1 %08x %08x\n", data[0], data[1]);
}
radeon_bo_unmap(test1.bo);
}
bool is_accel_working(struct radeon *radeon)
{
struct drm_radeon_info ginfo;
int r,tmp;
memset(&ginfo, 0, sizeof(ginfo));
ginfo.request = RADEON_INFO_ACCEL_WORKING2;
r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &ginfo, sizeof(ginfo));
if (r) {
/* If kernel is too old before 2.6.32 than assume accel is working */
if (r == -EINVAL) {
ErrorF("Kernel too old missing accel "
"information, assuming accel is working\n");
return true;
}
return false;
}
if (tmp)
return true;
return false;
}
int radeon_init(struct radeon *radeon, int fd)
{
radeon->fd = fd;
is_accel_working(radeon);
{
struct drm_radeon_gem_info mminfo;
if (!drmCommandWriteRead(fd, DRM_RADEON_GEM_INFO, &mminfo, sizeof(mminfo)))
{
radeon->vram_size = mminfo.vram_visible;
radeon->gart_size = mminfo.gart_size;
printf(
"mem size init: gart size :%llx vram size: s:%llx visible:%llx\n",
(unsigned long long)mminfo.gart_size,
(unsigned long long)mminfo.vram_size,
(unsigned long long)mminfo.vram_visible);
}
}
radeon->ChipFamily = CHIP_FAMILY_PALM;
radeon->bufmgr = radeon_bo_manager_gem_ctor(fd);
if (!radeon->bufmgr)
return -1;
radeon->csm = radeon_cs_manager_gem_ctor(fd);
if (!radeon->csm)
return -1;
radeon->cs = radeon_cs_create(radeon->csm, 16384);
if (!radeon->cs)
return -1;
radeon_cs_set_limit(radeon->cs, RADEON_GEM_DOMAIN_VRAM, radeon->vram_size);
radeon_cs_set_limit(radeon->cs, RADEON_GEM_DOMAIN_GTT, radeon->gart_size);
radeon_cs_space_set_flush(radeon->cs, (void(*)(void *))radeon_cs_flush_indirect, radeon);
radeon_vbo_init_lists(radeon);
if (radeon->ChipFamily == CHIP_FAMILY_PALM) {
EVERGREENAllocShaders(radeon);
EVERGREENLoadShaders(radeon);
}
radeon->accel_state.XInited3D = false;
radeon->accel_state.src_obj[0].bo = NULL;
radeon->accel_state.src_obj[1].bo = NULL;
radeon->accel_state.dst_obj.bo = NULL;
radeon->accel_state.vbo.vb_start_op = -1;
radeon->accel_state.cbuf.vb_start_op = -1;
radeon->accel_state.finish_op = evergreen_finish_op;
radeon->accel_state.vbo.verts_per_op = 3;
radeon->accel_state.cbuf.verts_per_op = 1;
return 0;
}
void radeon_fini(struct radeon *radeon)
{
radeon_cs_destroy(radeon->cs);
radeon_bo_manager_gem_dtor(radeon->bufmgr);
radeon_cs_manager_gem_dtor(radeon->csm);
}
int main(int argc, char **argv)
{
int drmFD;
int ret;
char *pciids = "pci:0000:00:01.0";
drmSetVersion sv;
drmFD = drmOpen(NULL, pciids);
if (drmFD < 0) {
drmError(drmFD, __func__);
fprintf(stderr, "Check that BusId is correct. You can find the correct BusId in /var/log/Xorg.0.log\n");
fprintf(stderr, "You can also try setting the environment variable LIBGL_DEBUG to \"verbose\" to see what libdrm is trying to do.\n");
exit(-1);
}
sv.drm_di_major = 1;
sv.drm_di_minor = 1;
sv.drm_dd_major = -1;
sv.drm_dd_minor = -1;
ret = drmSetInterfaceVersion(drmFD, &sv);
if (ret != 0){
drmClose(drmFD);
return -1;
}
ret = radeon_init(radeon, drmFD);
if (ret < 0) {
fprintf(stderr,"uanbel to init radeon\n");
exit(-1);
}
run_test1(radeon);
run_test2(radeon);
radeon_fini(radeon);
drmClose(drmFD);
}
void ErrorF(const char *f, ...)
{
va_list args;
va_start(args, f);
vfprintf(stderr, f, args);
va_end(args);
}
void radeon_cs_flush_indirect(struct radeon *radeon)
{
struct radeon_accel_state *accel_state = &radeon->accel_state;
int ret;
int i;
if (!radeon->cs->cdw)
return;
/* release the current VBO so we don't block on mapping it later */
if (accel_state->vbo.vb_offset && accel_state->vbo.vb_bo) {
radeon_vbo_put(radeon, &accel_state->vbo);
accel_state->vbo.vb_start_op = -1;
}
/* release the current VBO so we don't block on mapping it later */
if (accel_state->cbuf.vb_bo) {
radeon_vbo_put(radeon, &accel_state->cbuf);
accel_state->cbuf.vb_start_op = -1;
}
for (i = 0; i < radeon->cs->cdw; i++)
fprintf(stderr,"%d: %08x\n", i, radeon->cs->packets[i]);
radeon_cs_emit(radeon->cs);
radeon_cs_erase(radeon->cs);
radeon_vbo_flush_bos(radeon);
ret = radeon_cs_space_check_with_bo(radeon->cs,
accel_state->vbo.vb_bo,
RADEON_GEM_DOMAIN_GTT, 0);
if (ret)
ErrorF("space check failed in flush\n");
accel_state->XInited3D = false;
}
void radeon_ddx_cs_start(struct radeon *radeon,
int n, const char *file,
const char *func, int line)
{
if (radeon->cs->cdw + n > radeon->cs->ndw) {
radeon_cs_flush_indirect(radeon);
}
radeon_cs_begin(radeon->cs, n, file, func, line);
}
void radeon_vb_no_space(struct radeon *radeon,
struct radeon_vbo_object *vbo,
int vert_size)
{
struct radeon_accel_state *accel_state = &radeon->accel_state;
if (vbo->vb_bo) {
if (vbo->vb_start_op != vbo->vb_offset) {
accel_state->finish_op(radeon, vert_size);
accel_state->ib_reset_op = radeon->cs->cdw;
}
/* release the current VBO */
radeon_vbo_put(radeon, vbo);
}
/* get a new one */
radeon_vbo_get(radeon, vbo);
return;
}
void radeon_ib_discard(struct radeon *radeon)
{
struct radeon_accel_state *accel_state = &radeon->accel_state;
int ret;
if (accel_state->ib_reset_op) {
/* if we have data just reset the CS and ignore the operation */
radeon->cs->cdw = accel_state->ib_reset_op;
accel_state->ib_reset_op = 0;
goto out;
}
accel_state->vbo.vb_offset = 0;
accel_state->vbo.vb_start_op = -1;
accel_state->cbuf.vb_offset = 0;
accel_state->cbuf.vb_start_op = -1;
if (CS_FULL(radeon->cs)) {
radeon_cs_flush_indirect(radeon);
return;
}
radeon_cs_erase(radeon->cs);
ret = radeon_cs_space_check_with_bo(radeon->cs,
accel_state->vbo.vb_bo,
RADEON_GEM_DOMAIN_GTT, 0);
if (ret)
ErrorF("space check failed in flush\n");
if (accel_state->cbuf.vb_bo) {
ret = radeon_cs_space_check_with_bo(radeon->cs,
accel_state->cbuf.vb_bo,
RADEON_GEM_DOMAIN_GTT, 0);
if (ret)
ErrorF("space check failed in flush\n");
}
out:
accel_state->XInited3D = false;
}
int radeon_cp_start(struct radeon *radeon)
{
struct radeon_accel_state *accel_state = &radeon->accel_state;
if (CS_FULL(radeon->cs)) {
radeon_cs_flush_indirect(radeon);
}
accel_state->ib_reset_op = radeon->cs->cdw;
accel_state->vbo.vb_start_op = accel_state->vbo.vb_offset;
accel_state->cbuf.vb_start_op = accel_state->cbuf.vb_offset;
return 0;
}
|