LibXenon
Bare-metal Xbox 360 homebrew library
Loading...
Searching...
No Matches
xe.c
Go to the documentation of this file.
1#include "xe.h"
2#include "xe_internal.h"
3#include <stdio.h>
4#include <string.h>
5#include <stdarg.h>
6#include <malloc.h>
7#include <assert.h>
8#include <stdlib.h>
9#include <time.h>
10#include <cache.h>
11#include <xenon_smc/xenon_smc.h>
12#include <stdint.h>
13#include <time/time.h>
14#include <debug.h>
15
16#define WRITEBACK_ZONE_SIZE 0x20000
17
18#define RPTR_WRITEBACK 0x10000
19#define SCRATCH_WRITEBACK 0x10100
20
21#define RINGBUFFER_PRIMARY_SIZE (0x8000/4)
22#define RINGBUFFER_SECONDARY_SIZE (0x400000/4)
23#define RINGBUFFER_SECONDARY_GUARD (0x200000/4)
24
25#define RADEON_CP_PACKET0 0x00000000
26#define RADEON_ONE_REG_WR (1 << 15)
27
28#define CP_PACKET0( reg, n ) \
29 (RADEON_CP_PACKET0 | ((n) << 16) | ((reg) >> 2))
30#define CP_PACKET0_TABLE( reg, n ) \
31 (RADEON_CP_PACKET0 | RADEON_ONE_REG_WR | ((n) << 16) | ((reg) >> 2))
32
33#define VBPOOL_NUM_TRIANGLES 2000
34
35static inline void Xe_pWriteReg(struct XenosDevice *xe, u32 reg, u32 val)
36{
37 rput32(CP_PACKET0(reg, 0));
38 rput32(val);
39}
40
41static inline u32 SurfaceInfo(int surface_pitch, int msaa_samples, int hi_zpitch)
42{
43 return surface_pitch | (msaa_samples << 16) | (hi_zpitch << 18);
44}
45
46static inline u32 xy32(int x, int y)
47{
48 return x | (y << 16);
49}
50
51
52void Xe_pSyncToDevice(struct XenosDevice *xe, volatile void *data, int len)
53{
54 memdcbst((void *)data, len);
55}
56
57void Xe_pSyncFromDevice(struct XenosDevice *xe, volatile void *data, int len)
58{
59 memdcbf((void *)data, len);
60}
61
62void *Xe_pAlloc(struct XenosDevice *xe, u32 *phys, int size, int align)
63{
64 void *r;
65 if (!align)
66 align = size;
67
68 r=memalign(align,size);
69 if (!r)
70 Xe_Fatal(xe, "out of memory\n");
71
72 if (phys)
73 *phys = (u32) r &~ 0x80000000;
74
75 return r;
76}
77
78void Xe_pFree(struct XenosDevice *xe, void * ptr)
79{
80 free(ptr);
81}
82
84{
85 size += 0x1FFF;
86 size &= ~0x1FFF;
87
88 rput32p(0x00000a31);
89 rput32p(0x01000000);
90 rput32p(0x00010a2f);
92 rput32p(0xc0043c00);
93 rput32p(0x00000003); rput32p(0x00000a31); rput32p(0x00000000); rput32p(0x80000000); rput32p(0x00000008);
94}
95
96
98{
99 int i;
100 for (i=0; i<0x20; ++i)
101 rput32p(0x80000000);
103 __asm__ ("sync");
104 w32(0x0714, xe->rb_primary_wptr);
105// printf("committed to %08x\n", xe->rb_primary_wptr);
106}
107
108void Xe_pRBKickSegment(struct XenosDevice *xe, int base, int len)
109{
110// printf("kick_segment: %x..%x, len=%x\n", base, base + len * 4, len * 4);
111 Xe_pSyncToDevice(xe, xe->rb_secondary + base * 4, len * 4);
112 Xe_pInvalidateGpuCache_Primary(xe, xe->rb_secondary_base + base * 4, len * 4 + 0x1000);
113 rput32p(0xc0013f00);
114 rput32p(xe->rb_secondary_base + base * 4); rput32p(len);
115}
116
117void Xe_pRBKick(struct XenosDevice *xe)
118{
119// printf("kick: wptr = %x, last_wptr = %x\n", xe->rb_secondary_wptr, xe->last_wptr);
120
122
123 xe->rb_secondary_wptr += (-xe->rb_secondary_wptr)&0x1F; /* 128byte align */
124
126 Xe_Fatal(xe, "increase guardband");
127
129 xe->rb_secondary_wptr = 0;
130
132
134}
135
136#define SEGMENT_SIZE 1024
137
139{
140// printf("may kick: wptr = %x, last_wptr = %x\n", rb_secondary_wptr, last_wptr);
141 int distance = xe->rb_secondary_wptr - xe->last_wptr;
142 if (distance < 0)
143 distance += RINGBUFFER_SECONDARY_SIZE;
144
145 if (distance >= SEGMENT_SIZE)
146 Xe_pRBKick(xe);
147}
148
150{
151 u32 rb_primary_phys;
152 xe->rb_primary = Xe_pAlloc(xe, &rb_primary_phys, RINGBUFFER_PRIMARY_SIZE * 4, 0);
154 return rb_primary_phys;
155}
156
157void Xe_pSetSurfaceClip(struct XenosDevice *xe, int offset_x, int offset_y, int sc_left, int sc_top, int sc_right, int sc_bottom)
158{
159 rput32(0x00022080);
160 rput32(xy32(offset_x, offset_y));
161 rput32(xy32(sc_left, sc_top));
162 rput32(xy32(sc_right, sc_bottom));
163}
164
165void Xe_pSetBin(struct XenosDevice *xe, u32 mask_low, u32 select_low, u32 mask_hi, u32 select_hi)
166{
167 rput32(0xc0006000);
168 rput32(mask_low);
169 rput32(0xc0006200);
170 rput32(select_low);
171 rput32(0xc0006100);
172 rput32(mask_hi);
173 rput32(0xc0006300);
174 rput32(select_hi);
175}
176
177void Xe_pWaitUntilIdle(struct XenosDevice *xe, u32 what)
178{
179 rput32(0x000005c8);
180 rput32(what);
181}
182
183void Xe_pDrawNonIndexed(struct XenosDevice *xe, int num_points, int primtype)
184{
185 rput32(0xc0012201);
186 rput32(0x00000000);
187 rput32(0x00000080 | (num_points << 16) | primtype);
188}
189
190void Xe_pDrawIndexedPrimitive(struct XenosDevice *xe, int primtype, int num_points, u32 indexbuffer, u32 indexbuffer_size, int indextype)
191{
192 assert(num_points <= XE_MAX_INDICES_PER_DRAW);
193 int type = 0;
194
195 rput32(0xc0032201);
196 rput32(0x00000000);
197 rput32(0x00000000 | (type << 6) | primtype | (num_points << 16) | (indextype << 11));
198 rput32(indexbuffer);
199 rput32((indexbuffer_size | 0x40000000) << indextype);
200}
201
202void Xe_pSetIndexOffset(struct XenosDevice *xe, int offset)
203{
204 rput32(0x00002102);
205 rput32(offset);
206}
207
209{
210 w32(0x0704, r32(0x0704) | 0x80000000);
211 w32(0x017c, 0);
212 w32(0x0714, 0);
213 w32(0x0704, r32(0x0704) &~0x80000000);
214}
215
216void Xe_pSetupRingbuffer(struct XenosDevice *xe, u32 buffer_base, u32 size_in_l2qw)
217{
219 w32(0x0704, size_in_l2qw | 0x8020000);
220 w32(0x0700, buffer_base);
221 w32(0x0718, 0x10);
222}
223
224void Xe_pLoadUcodes(struct XenosDevice *xe, const u32 *ucode0, const u32 *ucode1)
225{
226 int i;
227
228 w32(0x117c, 0);
229 udelay(100);
230
231 for (i = 0; i < 0x120; ++i)
232 w32(0x1180, ucode0[i]);
233
234 w32(0x117c, 0);
235 udelay(100);
236 for (i = 0; i < 0x120; ++i)
237 r32(0x1180);
238
239 w32(0x07e0, 0);
240 for (i = 0; i < 0x900; ++i)
241 w32(0x07e8, ucode1[i]);
242
243 w32(0x07e4, 0);
244 for (i = 0; i < 0x900; ++i)
245 if (r32(0x07e8) != ucode1[i])
246 {
247 printf("%04x: %08x %08x\n", i, r32(0x07e8), ucode1[i]);
248 break;
249 }
250
251 if (i != 0x900)
252 Xe_Fatal(xe, "ucode1 microcode verify error\n");
253}
254
256{
257 int timeout = 1<<24;
258 while (r32(0x1740) & 0x80000000)
259 {
260 if (!timeout--)
261 Xe_Fatal(xe, "timeout in init, likely the GPU was already hung before we started\n");
262 }
263}
264
266{
267 while (!(r32(0x1740) & 0x00040000));
268}
269
270void Xe_pInit1(struct XenosDevice *xe)
271{
272 w32(0x01a8, 0);
273 w32(0x0e6c, 0xC0F0000);
274 w32(0x3400, 0x40401);
275 udelay(1000);
276 w32(0x3400, 0x40400);
277 w32(0x3300, 0x3A22);
278 w32(0x340c, 0x1003F1F);
279 w32(0x00f4, 0x1E);
280}
281
282void Xe_pReset(struct XenosDevice *xe)
283{
284 Xe_pWaitReady2(xe);
285 Xe_pWaitReady(xe);
286#if 1
287 printf("waiting for reset.\n");
288 do {
289 w32(0x00f0, 0x8064); r32(0x00f0);
290 w32(0x00f0, 0);
291 w32(0x00f0, 0x11800); r32(0x00f0);
292 w32(0x00f0, 0);
293 udelay(1000);
294 } while (r32(0x1740) & 0x80000000);
295#endif
296
297 if (r32(0x00e0) != 0x10)
298 Xe_Fatal(xe, "value after reset not ok (%08x)\n", r32(0xe0));
299
300 Xe_pInit1(xe);
301}
302
303void Xe_pResetCP(struct XenosDevice *xe, u32 buffer_base, u32 size_in_l2qw)
304{
305 w32(0x07d8, 0x1000FFFF);
306 udelay(2000);
307 w32(0x00f0, 1);
308 (void)r32(0x00f0);
309 udelay(1000);
310 w32(0x00f0, 0);
311 udelay(1000);
312 Xe_pSetupRingbuffer(xe, buffer_base, size_in_l2qw);
313 Xe_pWaitReady(xe);
314
315 if (!(r32(0x07d8) & 0x10000000))
316 Xe_Fatal(xe, "something wrong (1)\n");
317
318 w32(0x07d8, 0xFFFF);
319 udelay(1000);
320
321 w32(0x3214, 7);
322 w32(0x3294, 1);
323 w32(0x3408, 0x800);
324
325 Xe_pWaitReady(xe);
326
327 if (r32(0x0714))
328 Xe_Fatal(xe, "[WARN] something wrong (2)\n");
329
330 if (r32(0x0710))
331 Xe_Fatal(xe, "[WARN] something wrong (3)\n");
332
333 w32(0x07ec, 0x1A);
334}
335
336void Xe_pSetup(struct XenosDevice *xe, u32 buffer_base, u32 buffer_size, const u32 *ucode0, const u32 *ucode1)
337{
338 Xe_pWaitReady(xe);
339
340 w32(0x07d8, 0x1000FFFF);
341
342 Xe_pSetupRingbuffer(xe, buffer_base, buffer_size);
343 Xe_pLoadUcodes(xe, ucode0, ucode1);
344 Xe_pWaitReady(xe);
345
346 w32(0x07d8, 0xFFFF);
347 w32(0x07d0, 0xFFFF);
348 w32(0x07f0, 0);
349 w32(0x0774, 0);
350 w32(0x0770, 0);
351 w32(0x3214, 7);
352 w32(0x3294, 1);
353 w32(0x3408, 0x800);
354 Xe_pResetCP(xe, buffer_base, buffer_size);
355 Xe_pWaitReady(xe);
356}
357
358extern u32 xenos_ucode0[];
359extern u32 xenos_ucode1[];
360
361void Xe_pMasterInit(struct XenosDevice *xe, u32 buffer_base)
362{
363 if ((r32(0x0e6c) & 0xF00) != 0xF00)
364 printf("something wrong (3)\n");
365
366 Xe_pSetup(xe, buffer_base, 0xC, xenos_ucode0, xenos_ucode1);
367
368 w32(0x07d4, 0);
369 w32(0x07d4, 1);
370
371 w32(0x2054, 0x1E);
372 w32(0x2154, 0x1E);
373
374 w32(0x3c10, 0xD);
375
376 w32(0x3c40, 0x17);
377 w32(0x3c48, 0);
378 while (r32(0x3c4c) & 0x80000000);
379
380 w32(0x3c40, 0x1017);
381 w32(0x3c48, 0);
382 while (r32(0x3c4c) & 0x80000000);
383
384 w32(0x87e4, 0x17);
385}
386
387void Xe_pEnableWriteback(struct XenosDevice *xe, u32 addr, int blocksize)
388{
389 u32 v = r32(0x0704);
390
391 v &= ~0x8003F00;
392 w32(0x0704, v);
393
394 w32(0x070c, addr | 2);
395 w32(0x0704, v | (blocksize << 8));
396}
397
398void Xe_pGInit0(struct XenosDevice *xe)
399{
400 rput32(0xc0003b00);
401 rput32(0x00000300);
402
403 rput32(0xc0192b00);
404 rput32(0x00000000); rput32(0x00000018);
405 rput32(0x00001003); rput32(0x00001200); rput32(0xc4000000); rput32(0x00001004);
406 rput32(0x00001200); rput32(0xc2000000); rput32(0x00001005); rput32(0x10061200);
407 rput32(0x22000000); rput32(0xc8000000); rput32(0x00000000); rput32(0x02000000);
408 rput32(0xc800c000); rput32(0x00000000); rput32(0xc2000000); rput32(0xc888c03e);
409 rput32(0x00000000); rput32(0xc2010100); rput32(0xc8000000); rput32(0x00000000);
410 rput32(0x02000000); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
411 rput32(0xc00a2b00);
412 rput32(0x00000001); rput32(0x00000009);
413
414 rput32(0x00000000); rput32(0x1001c400); rput32(0x22000000); rput32(0xc80f8000);
415 rput32(0x00000000); rput32(0xc2000000); rput32(0x00000000); rput32(0x00000000);
416 rput32(0x00000000);
417
418 rput32(0x00012180);
419 rput32(0x1000000e); rput32(0x00000000);
420 rput32(0x00022100);
421 rput32(0x0000ffff); rput32(0x00000000); rput32(0x00000000);
422 rput32(0x00022204);
423 rput32(0x00010000); rput32(0x00010000); rput32(0x00000300);
424 rput32(0x00002312);
425 rput32(0x0000ffff);
426 rput32(0x0000200d);
427 rput32(0x00000000);
428 rput32(0x00002200);
429 rput32(0x00000000);
430 rput32(0x00002203);
431 rput32(0x00000000);
432 rput32(0x00002208);
433 rput32(0x00000004);
434 rput32(0x00002104);
435 rput32(0x00000000);
436 rput32(0x00002280);
437 rput32(0x00080008);
438 rput32(0x00002302);
439 rput32(0x00000004);
440 Xe_pSetSurfaceClip(xe, 0, 0, 0, 0, 16, 16);
441}
442
443void Xe_pGInit1(struct XenosDevice *xe, int arg)
444{
445 rput32(0x000005c8);
446 rput32(0x00020000);
447 rput32(0x00078d00);
448 rput32(arg | 1); rput32(arg | 1); rput32(arg | 1); rput32(arg | 1);
449 rput32(arg | 1); rput32(arg | 1); rput32(arg | 1); rput32(arg | 1);
450 rput32(0x00000d00);
451 rput32(arg);
452}
453
454void Xe_pGInit2(struct XenosDevice *xe)
455{
456 int i;
457 for (i=0; i<24; ++i)
458 {
459 rput32(0xc0003600);
460 rput32(0x00010081);
461 }
462}
463
464void Xe_pGInit3(struct XenosDevice *xe)
465{
466 rput32(0x000005c8);
467 rput32(0x00020000);
468 rput32(0x00000d04);
469 rput32(0x00000000);
470}
471
472void Xe_pGInit4(struct XenosDevice *xe) /* "init_0" */
473{
474 rput32(0x00000d02); /* ? */
475 rput32(0x00010800);
476 rput32(0x00030a02);
477 rput32(0xc0100000); rput32(0x07f00000); rput32(0xc0000000); rput32(0x00100000);
478
479 Xe_pGInit3(xe);
480}
481
482void Xe_pGInit5(struct XenosDevice *xe) /* "init_1" */
483{
484 rput32(0x00000d01);
485 rput32(0x04000000);
486 rput32(0xc0022100);
487 rput32(0x00000081); rput32(0xffffffff); rput32(0x80010000);
488 rput32(0xc0022100);
489 rput32(0x00000082); rput32(0xffffffff); rput32(0x00000000);
490 rput32(0x00000e42);
491 rput32(0x00001f60);
492 rput32(0x00000c85);
493 rput32(0x00000003);
494 rput32(0x0000057c);
495 rput32(0x0badf00d);
496 rput32(0x0000057b);
497 rput32(0x00000000);
498}
499
500void Xe_pGInit6(struct XenosDevice *xe)
501{
502 Xe_pSetSurfaceClip(xe, 0, 0, 0, 0, 1024, 720);
503 rput32(0x0002857e);
504 rput32(0x00010017); rput32(0x00000000); rput32(0x03ff02cf);
505 rput32(0x0002857e);
506 rput32(0x00010017); rput32(0x00000004); rput32(0x03ff02cf);
507}
508
509void Xe_pGInit7(struct XenosDevice *xe)
510{
511 rput32(0x000005c8);
512 rput32(0x00020000);
513 rput32(0x00000f01);
514 rput32(0x0000200e);
515}
516
517void Xe_pGInit8(struct XenosDevice *xe)
518{
519 Xe_pSetSurfaceClip(xe, 0, 0, 0, 0, 1024, 720);
520}
521
522void Xe_pGInit9(struct XenosDevice *xe)
523{
524 int i;
525 rput32(0x0000057e);
526 rput32(0x00010019);
527
528 Xe_pGInit0(xe);
529
530 for (i = 0x10; i <= 0x70; ++i)
531 Xe_pGInit1(xe, 0x00000000 | (i << 12) | ((0x80 - i) << 4));
532
533 Xe_pGInit2(xe);
534 rput32(0x0000057e);
535 rput32(0x0001001a);
536
537 Xe_pGInit8(xe);
538}
539
540void Xe_pGInit10(struct XenosDevice *xe)
541{
542 Xe_pSetSurfaceClip(xe, 0, 0, 0, 0, 1024, 720);
543
544 rput32(0x0000057e);
545 rput32(0x00010019);
546 rput32(0xc0003b00);
547 rput32(0x00000300);
548
549 Xe_pGInit7(xe);
550
551 Xe_pGInit9(xe);
552}
553
554void Xe_pGInit(struct XenosDevice *xe)
555{
556 rput32(0xc0114800);
557 rput32(0x000003ff); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
558 rput32(0x00000080); rput32(0x00000100); rput32(0x00000180); rput32(0x00000200);
559 rput32(0x00000280); rput32(0x00000300); rput32(0x00000380); rput32(0x00010800);
560 rput32(0x00000007); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
561 rput32(0x00000000); rput32(0x00000000);
562
563 Xe_pGInit4(xe);
564
565 Xe_pGInit5(xe);
566 Xe_pGInit6(xe);
567 Xe_pGInit10(xe);
568}
569
570void Xe_DirtyAluConstant(struct XenosDevice *xe, int base, int len)
571{
572 len += base & 15;
573 base >>= 4;
574 while (len > 0)
575 {
576 xe->alu_dirty |= 1 << base;
577 ++base;
578 len -= 16;
579 }
580 xe->dirty |= DIRTY_ALU;
581}
582
583void Xe_DirtyFetch(struct XenosDevice *xe, int base, int len)
584{
585 len += base % 3;
586 base /= 3;
587 while (len > 0)
588 {
589 xe->fetch_dirty |= 1 << base;
590 ++base;
591 len -= 3;
592 }
593 xe->dirty |= DIRTY_FETCH;
594}
595
596struct XenosShader *Xe_LoadShader(struct XenosDevice *xe, const char *filename)
597{
598 FILE *f = fopen(filename, "rb");
599 if (!f)
600 Xe_Fatal(xe, "FATAL: shader %s not found!\n", filename);
601
602 fseek(f, 0, SEEK_END);
603 int size = ftell(f);
604 fseek(f, 0, SEEK_SET);
605
606 void *m = malloc(size);
607 fread(m, size, 1, f);
608 fclose(f);
609
610 return Xe_LoadShaderFromMemory(xe, m);
611}
612
614{
615 struct XenosShaderHeader *hdr = m;
616
617 if ((hdr->magic >> 16) != 0x102a)
618 Xe_Fatal(xe, "shader version: %08x, expected: something with 102a.\n", hdr->magic);
619
620 struct XenosShader *s = malloc(sizeof(struct XenosShader));
621 memset(s, 0, sizeof(*s));
622 s->shader = m;
623
624 struct XenosShaderData *data = m + hdr->off_shader;
625 s->program_control = data->program_control;
626 s->context_misc = data->context_misc;
627
628 return s;
629}
630
632{
633 struct XenosShaderHeader *hdr = s->shader;
634
635 if (hdr->off_constants)
636 {
637 /* upload shader constants */
638// printf("off_constants: %d\n", hdr->off_constants);
639 void *constants = s->shader + hdr->off_constants;
640
641 constants += 16;
642
643// int size = *(u32*)constants;
644 constants += 4;
645
646// printf("uploading shader constants..\n");
647
648 // float constants
649 for(;;)
650 {
651 u16 start = *(u16*)constants; constants += 2;
652 u16 count = *(u16*)constants; constants += 2;
653
654 if(!count) break;
655
656 u32 offset = *(u32*)constants; constants += 4;
657
658 float *c = s->shader + hdr->offset + offset;
659 memcpy(xe->alu_constants + start * 4, c, count * 4);
660 Xe_DirtyAluConstant(xe, start, count);
661
662/* int i;
663 printf("float cst count: %d\n",count);
664 for(i=0;i<count;++i) printf("%f ",c[i]);
665 printf("\n");*/
666 }
667
668 // int constants
669 for(;;)
670 {
671 u16 start = *(u16*)constants; constants += 2;
672 u16 count = *(u16*)constants; constants += 2;
673
674 if(!count) break;
675
676 memcpy(&xe->integer_constants[(start-0x2300)/4],constants,count*4);
677 xe->dirty |= DIRTY_INTEGER;
678
679/* int i;
680 printf("int cst count: %d\n",count);
681 for(i=0;i<count*2;++i) printf("%04x ",((u16*)constants)[i]);
682 printf("\n");*/
683
684 constants += count * 4 + 4;
685 }
686 }
687}
688
689int Xe_VBFCalcSize(struct XenosDevice *xe, const struct XenosVBFElement *fmt)
690{
691 switch (fmt->fmt)
692 {
693 case 6: // char4
694 return 4;
695 case 37: // float2
696 return 8;
697 case 38: // float4
698 return 16;
699 case 57: // float3
700 return 12;
701 default:
702 Xe_Fatal(xe, "Unknown VBF %d!\n", fmt->fmt);
703 }
704}
705
707{
708 switch (fmt->fmt)
709 {
710 case 6: // char4
711 return 4;
712 case 37: // float2
713 return 2;
714 case 38: // float4
715 return 4;
716 case 57: // float3
717 return 3;
718 default:
719 Xe_Fatal(xe, "Unknown VBF %d!\n", fmt->fmt);
720 }
721}
722
723int Xe_VBFCalcStride(struct XenosDevice *xe, const struct XenosVBFFormat *fmt)
724{
725 int i;
726 int total_size = 0;
727 for (i=0; i<fmt->num; ++i)
728 total_size += Xe_VBFCalcSize(xe, &fmt->e[i]);
729 return total_size;
730}
731
732void Xe_pInvalidateGpuCache(struct XenosDevice *xe, int base, int size)
733{
734 rput32(0x00000a31);
735 rput32(0x01000000);
736 rput32(0x00010a2f);
738 rput32(0xc0043c00);
739 rput32(0x00000003); rput32(0x00000a31); rput32(0x00000000); rput32(0x80000000); rput32(0x00000008);
740}
741
743{
744 rput32(0x00000a31);
745 rput32(0x03000100);
746 rput32(0x00010a2f);
748 rput32(0xc0043c00);
749 rput32(0x00000003); rput32(0x00000a31); rput32(0x00000000); rput32(0x80000000); rput32(0x00000008);
750}
751
752void Xe_pUnlock(struct XenosDevice *xe, struct XenosLock *lock)
753{
754 if (!lock->start)
755 Xe_Fatal(xe, "unlock without lock");
756 if (lock->flags & XE_LOCK_WRITE)
757 {
758 Xe_pSyncToDevice(xe, lock->start, lock->size);
759 Xe_pInvalidateGpuCache(xe, lock->phys, lock->size);
760 }
761 lock->start = 0;
762}
763
764void Xe_pLock(struct XenosDevice *xe, struct XenosLock *lock, void *addr, u32 phys, int size, int flags)
765{
766 size=(size+4095)&~4095;
767
768 if (!flags)
769 Xe_Fatal(xe, "flags=0");
770 if (lock->start)
771 Xe_Fatal(xe, "locked twice");
772 if (lock->flags & XE_LOCK_READ)
773 {
774 /* *you* must make sure that the GPU already flushed this content. (usually, it is, though) */
775 Xe_pSyncFromDevice(xe, addr, size);
776 }
777 lock->start = addr;
778 lock->phys = phys;
779 lock->size = size;
780 lock->flags = flags;
781}
782
783
784 /* shaders are not specific to a vertex input format.
785 the vertex format specified in a vertex shader is just
786 dummy. Thus we need to patch the vfetch instructions to match
787 our defined structure. */
788void Xe_ShaderApplyVFetchPatches(struct XenosDevice *xe, struct XenosShader *sh, unsigned int index, const struct XenosVBFFormat *fmt)
789{
790 assert(index < XE_SHADER_MAX_INSTANCES);
791 assert(sh->shader_phys[index]);
792
793 struct XenosLock lock;
794 memset(&lock, 0, sizeof(lock));
796
797 int stride = Xe_VBFCalcStride(xe, fmt);
798
799 if (stride & 3)
800 Xe_Fatal(xe, "your vertex buffer format is not DWORD aligned.\n");
801
802 stride /= 4;
803
804 struct XenosShaderHeader *hdr = sh->shader;
805 struct XenosShaderData *data = sh->shader + hdr->off_shader;
806
807 void *shader_code = sh->shader_instance[index];
808 u32 *c = &data->unk1[2];
809 int skip = *c++;
810 int num_vfetch = *c;
811 ++c;
812
813 c += skip * 2;
814 int i;
815
816 int fetched_to = 0;
817
818 for (i=0; i<num_vfetch; ++i)
819 {
820 u32 vfetch_patch = *c++;
821 int type = (vfetch_patch >> 12) & 0xF;
822 int stream = (vfetch_patch >> 16) & 0xF;
823 int insn = vfetch_patch & 0xFFF;
824
825// printf("raw: %08x\n", vfetch_patch);
826// printf("type=%d, stream=%d, insn=%d\n", type, stream, insn);
827 u32 *vfetch = shader_code + insn * 12;
828// printf(" old vfetch: %08x %08x %08x\n", vfetch[0], vfetch[1], vfetch[2]);
829// printf(" old swizzle: %08x\n", vfetch[1] & 0xFFF);
830
831 int Offset = (vfetch[2] & 0x7fffff00) >> 8;
832 int DataFormat = (vfetch[1] & 0x003f0000) >> 16;
833 int Stride= (vfetch[2] & 0x000000ff);
834 int Signed= (vfetch[1] & 0x00001000) >> 12;
835 int NumFormat = (vfetch[1] & 0x00002000) >> 13;
836 int PrefetchCount= (vfetch[0] & 0x38000000) >> 27;
837// printf(" old Offset=%08x, DataFormat=%d, Stride=%d, Signed=%d, NumFormat=%d, PrefetchCount=%d\n",
838// Offset,DataFormat, Stride, Signed, NumFormat, PrefetchCount);
839
840 /* let's find the element which applies for this. */
841 int j;
842 int offset = 0;
843 for (j=0; j < fmt->num; ++j)
844 {
845 if ((fmt->e[j].usage == type) && (fmt->e[j].index == stream))
846 break;
847 offset += Xe_VBFCalcSize(xe, &fmt->e[j]);
848 }
849
850 offset /= 4;
851
852 if (j == fmt->num)
853 Xe_Fatal(xe, "shader requires input type %d_%d, which wasn't found in vertex format.\n", type, stream);
854
855 Offset = offset;
856 DataFormat = fmt->e[j].fmt;
857
858 Signed = 0;
859 Stride = stride;
860 NumFormat = 0; // fraction
861
862 if (DataFormat != 6)
863 NumFormat = 1;
864
865 int to_fetch = 0;
866
867 /* if we need fetching... */
868 if (fetched_to <= offset + ((Xe_VBFCalcSize(xe, &fmt->e[j])+3)/4))
869 to_fetch = stride - fetched_to;
870
871 if (to_fetch > 8)
872 to_fetch = 8;
873 to_fetch = 1; /* FIXME: prefetching doesn't always work. */
874
875 int is_mini = 0;
876
877 if (to_fetch == 0)
878 {
879 PrefetchCount = 0;
880 is_mini = 1;
881 } else
882 PrefetchCount = to_fetch - 1;
883
884 fetched_to += to_fetch;
885
886 /* patch vfetch instruction */
887 vfetch[0] &= ~(0x00000000|0x00000000|0x00000000|0x00000000|0x00000000|0x38000000|0x00000000);
888 vfetch[1] &= ~(0x00000000|0x003f0000|0x00000000|0x00001000|0x00002000|0x00000000|0x40000000);
889 vfetch[2] &= ~(0x7fffff00|0x00000000|0x000000ff|0x00000000|0x00000000|0x00000000|0x00000000);
890
891 vfetch[2] |= Offset << 8;
892 vfetch[1] |= DataFormat << 16;
893 vfetch[2] |= Stride;
894 vfetch[1] |= Signed << 12;
895 vfetch[1] |= NumFormat << 13;
896 vfetch[0] |= PrefetchCount << 27;
897 vfetch[1] |= is_mini << 30;
898
899// printf("specified swizzle: %08x\n", fmt->e[j].swizzle);
900
901 int comp;
902 int nrcomp = Xe_pVBFNrComponents(xe, &fmt->e[j]);
903 for (comp = 0; comp < 4; comp++)
904 {
905 int shift = comp * 3;
906 int sw = (vfetch[1] >> shift) & 7; /* see original swizzle, xyzw01_? */
907// printf("comp%d sw=%c ", comp, "xyzw01?_"[sw]);
908 if ((sw < 4) && (sw >= nrcomp)) /* refer to an unavailable position? */
909 {
910 if (sw == 3) // a/w
911 sw = 5; // 1
912 else
913 sw = 4; // 0
914 }
915// printf(" -> %c\n", "xyzw01?_"[sw]);
916 vfetch[1] &= ~(7<<shift);
917 vfetch[1] |= sw << shift;
918 }
919
920
921 Offset = (vfetch[2] & 0x7fffff00) >> 8;
922 DataFormat = (vfetch[1] & 0x003f0000) >> 16;
923 Stride= (vfetch[2] & 0x000000ff);
924 Signed= (vfetch[1] & 0x00001000) >> 12;
925 NumFormat = (vfetch[1] & 0x00002000) >> 13;
926 PrefetchCount= (vfetch[0] & 0x38000000) >> 27;
927// printf(" new Offset=%08x, DataFormat=%d, Stride=%d, Signed=%d, NumFormat=%d, PrefetchCount=%d\n",
928// Offset,DataFormat, Stride, Signed, NumFormat, PrefetchCount);
929// printf(" new vfetch: %08x %08x %08x\n", vfetch[0], vfetch[1], vfetch[2]);
930 }
931
932 Xe_pUnlock(xe, &lock);
933}
934
935void Xe_InstantiateShader(struct XenosDevice *xe, struct XenosShader *sh, unsigned int index)
936{
937 assert(index < XE_SHADER_MAX_INSTANCES);
938 struct XenosShaderHeader *hdr = sh->shader;
939 struct XenosShaderData *data = sh->shader + hdr->off_shader;
940 void *shader_code = sh->shader + data->sh_off + hdr->offset;
941
942 sh->shader_phys_size = data->sh_size;
943 void *p = Xe_pAlloc(xe, &sh->shader_phys[index], data->sh_size, 0x100);
944 memcpy(p, shader_code, data->sh_size);
945 Xe_pSyncToDevice(xe, p, data->sh_size);
946 sh->shader_instance[index] = p;
947}
948
949int Xe_GetShaderLength(struct XenosDevice *xe, void *sh)
950{
951 struct XenosShaderHeader *hdr = sh;
952 struct XenosShaderData *data = sh + hdr->off_shader;
953 return data->sh_off + hdr->offset + data->sh_size;
954}
955
956void Xe_Init(struct XenosDevice *xe)
957{
958 memset(xe, 0, sizeof(*xe));
959
960 xe->regs = (void*)0xec800000;
961
962 xe->default_fb.ptr = r32(0x6110);
963 xe->default_fb.wpitch = r32(0x6120) * 4;
964 xe->default_fb.width = r32(0x6134);
965 xe->default_fb.height = r32(0x6138);
966 xe->default_fb.bypp = 4;
967 xe->default_fb.base = (void*)(long)xe->default_fb.ptr;
969 xe->default_fb.tiled = 1;
970
971 xe->tex_fb=xe->default_fb;
972
973 printf("[xe] Framebuffer %d x %d @ %08x\n", xe->tex_fb.width, xe->tex_fb.height, xe->tex_fb.ptr);
974
975 u32 rb_phys=0;
977
978 u32 rb_primary_phys = Xe_pRBAlloc(xe);
979
980 Xe_pMasterInit(xe, rb_primary_phys);
981 Xe_pEnableWriteback(xe, rb_phys + RPTR_WRITEBACK, 6);
982
984
985 Xe_pWriteReg(xe, 0x0774, rb_phys + SCRATCH_WRITEBACK);
986 Xe_pWriteReg(xe, 0x0770, 0x20033);
987
988 Xe_pWriteReg(xe, 0x15e0, 0x1234567);
989
990 Xe_pGInit(xe);
991
992 Xe_pInvalidateGpuCache(xe, 0, 0x20000000); // whole DRAM
993
994 xe->clear_color=0; // color clear: black
995 xe->clear_stencil_z=0xffffff00; // zbuffer / stencil clear: z to -1, stencil to 0
996}
997
998void Xe_SetRenderTarget(struct XenosDevice *xe, struct XenosSurface *rt)
999{
1000 xe->rt = rt;
1001 xe->vp_xres = rt->width;
1002 xe->vp_yres = rt->height;
1003
1004 xe->msaa_samples = 0;
1005 xe->edram_colorformat = 0;
1006
1007 int tile_size_x = (xe->msaa_samples < 2) ? 80 : 40, tile_size_y = (xe->msaa_samples > 0) ? 8 : 16;
1008 if ((xe->edram_colorformat == 15) || (xe->edram_colorformat == 7) || (xe->edram_colorformat == 5))
1009 tile_size_x /= 2;
1010 int tiles_per_line = (xe->vp_xres + tile_size_x - 1) / tile_size_x;
1011 tiles_per_line += 1;
1012 tiles_per_line &= ~1;
1013
1014 int tiles_height = (xe->vp_yres + tile_size_y - 1) / tile_size_y;
1015
1016 // what about 64bit targets?
1017
1018 xe->edram_pitch = tiles_per_line * tile_size_x;
1019 xe->edram_hizpitch = tiles_per_line * tile_size_x;
1020
1021#if 0
1022 xe->edram_color0base = 0;
1023 xe->edram_depthbase = tiles_per_line * tiles_height;
1024#else
1025 xe->edram_color0base = tiles_per_line * tiles_height;
1026 xe->edram_depthbase = 0;
1027#endif
1028}
1029
1031{
1032 rput32(0x00022000);
1033 rput32(SurfaceInfo(xe->edram_pitch, xe->msaa_samples, xe->edram_hizpitch)); // SurfaceInfo
1034 rput32((xe->edram_colorformat << 16) | xe->edram_color0base);
1035 rput32(xe->edram_depthbase | (0<<16) ); // depth info, float Z
1036}
1037
1039{
1040 Xe_pWriteReg(xe, 0x8c74, xe->clear_stencil_z);
1041
1042 unsigned int clearv[2];
1043
1044 switch (xe->edram_colorformat)
1045 {
1046 case 0:
1047 case 1:
1048 clearv[0] = clearv[1] = xe->clear_color;
1049 break;
1050 case 4:
1051 case 5:
1052 clearv[0] = (xe->clear_color & 0xFF000000);
1053 clearv[0] |= (xe->clear_color & 0x00FF0000)>>8;
1054 clearv[0] >>= 1;
1055 clearv[0] |= (clearv[0] >> 8) & 0x00FF00FF;
1056 clearv[1] = (xe->clear_color & 0x0000FF00)<<16;
1057 clearv[1] |= (xe->clear_color & 0x000000FF)<<8;
1058 clearv[1] >>= 1;
1059 clearv[1] |= (clearv[1] >> 8) & 0x00FF00FF;
1060 break;
1061 default:
1062 clearv[0] = clearv[1] = 0;
1063 }
1064
1065 Xe_pWriteReg(xe, 0x8c78, clearv[0]);
1066 Xe_pWriteReg(xe, 0x8c7c, clearv[1]);
1067}
1068
1069void Xe_ResolveInto(struct XenosDevice *xe, struct XenosSurface *surface, int source, int clear)
1070{
1071 Xe_pSetSurfaceClip(xe, 0, 0, 0, 0, surface->width, surface->height);
1072
1073 Xe_VBBegin(xe, 2);
1074 float vbdata[] =
1075 {
1076 -.5, -.5, /* never ever dare to mess with these values. NO, you can not resolve arbitrary areas or even shapes. */
1077 surface->width - .5,
1078 0,
1079 surface->width - .5,
1080 surface->height - .5
1081 };
1082
1083 Xe_VBPut(xe, vbdata, sizeof(vbdata) / 4);
1084 struct XenosVertexBuffer *vb = Xe_VBEnd(xe);
1085 Xe_VBPoolAdd(xe, vb);
1086
1088
1089 rput32(0x00002104);
1090 rput32(0x0000000f); // colormask
1091 rput32(0x0005210f);
1092 rput32(0x44000000); rput32(0x44000000);
1093 rput32(0xc3b40000); rput32(0x43b40000);
1094 rput32(0x3f800000); rput32(0x00000000);
1095
1096 int msaavals[] = {0,4,6};
1097 int pitch;
1098 switch (surface->format & XE_FMT_MASK)
1099 {
1100 case XE_FMT_8888: pitch = surface->wpitch / 4; break;
1101 case XE_FMT_16161616: pitch = surface->wpitch / 8; break;
1102 default: Xe_Fatal(xe, "unsupported resolve target format");
1103 }
1104 rput32(0x00032318);
1105 rput32(0x00100000 | (msaavals[xe->msaa_samples]<<4) | (clear << 8) | source ); // 300 = color,depth clear enabled!
1106 rput32(surface->ptr);
1107 rput32(xy32(pitch, surface->height));
1108 rput32(0x01000000 | ((surface->format&XE_FMT_MASK)<<7) | ((surface->format&~XE_FMT_MASK)>>6));
1109
1111
1112 // edram copy
1113
1114 rput32(0x00002208); rput32(0x00000006);
1115 rput32(0x00002208); rput32((clear&XE_CLEAR_COLOR || surface->base)?6:5);
1116 rput32(0x00002200); rput32(0x8777);
1117 rput32(0x000005c8); rput32(0x00020000);
1118
1119 // invalidate state
1120
1121 rput32(0xc0003b00); rput32(0x00000100);
1122
1123 // load a shader
1124
1125 rput32(0xc0102b00); rput32(0x00000000);
1126 rput32(0x0000000f);
1127
1128 rput32(0x10011002); rput32(0x00001200); rput32(0xc4000000);
1129 rput32(0x00000000); rput32(0x1003c200); rput32(0x22000000);
1130 rput32(0x00080000); rput32(0x00253b48); rput32(0x00000002);
1131 rput32(0xc80f803e); rput32(0x00000000); rput32(0xc2000000);
1132 rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
1133
1134 rput32(0x00012180); rput32(0x00010002); rput32(0x00000000);
1135
1136 // prepare draw edram FB to real dram FB
1137
1138 rput32(0x00002203); rput32(0x00000000);
1139 rput32(0x00022100); rput32(0x0000ffff); rput32(0x00000000); rput32(0x00000000);
1140 rput32(0x00022204); rput32(0x00010000); rput32(0x00010000); rput32(0x00000300);
1141 rput32(0x00002312); rput32(0x0000ffff);
1142 rput32(0x0000200d); rput32(0x00000000);
1143
1144 rput32(0x00054800); rput32((vb->phys_base) | 3); rput32(0x1000001a); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
1145
1146 rput32(0x00025000); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
1147
1148 // draw command
1149
1150 rput32(0xc0003600); rput32(0x00030088);
1151 rput32(0xc0004600); rput32(0x00000006);
1152 rput32(0x00002007); rput32(0x00000000);
1153
1154 // flush dram FB
1155
1156 Xe_pInvalidateGpuCacheAll(xe, surface->ptr, surface->wpitch * surface->height);
1157
1158 // cleanup
1159
1160 rput32(0x0000057e); rput32(0x00010001);
1161 rput32(0x00002318); rput32(0x00000000);
1162 rput32(0x0000231b); rput32(0x00000000);
1163
1164 xe->dirty = ~0;
1165}
1166
1167void Xe_Clear(struct XenosDevice *xe, int flags)
1168{
1169 struct XenosSurface surface = *xe->rt;
1170 surface.base = NULL;
1171
1172 Xe_ResolveInto(xe, &surface, 0, flags);
1173}
1174
1175void Xe_Resolve(struct XenosDevice *xe)
1176{
1178}
1179
1180
1181void VERTEX_FETCH(u32 *dst, u32 base, int len)
1182{
1183 dst[0] = base | 3;
1184 dst[1] = 0x10000002 | (len << 2);
1185}
1186
1187void TEXTURE_FETCH(u32 *dst, u32 base, int width, int height, int pitch, int tiled, int format, u32 base_mip, int anisop, int filter, int uaddr, int vaddr)
1188{
1189 switch (format & XE_FMT_MASK)
1190 {
1191 case XE_FMT_8: pitch /= 32; break;
1192 case XE_FMT_5551: pitch /= 64; break;
1193 case XE_FMT_565: pitch /= 64; break;
1194 case XE_FMT_16161616: pitch /= 256; break;
1195 case XE_FMT_8888: pitch /= 128; break;
1196 default: abort();
1197 }
1198
1199 dst[0] = 0x00000002 | (pitch << 22) | (tiled << 31) | (uaddr << 10) | (vaddr << 13);
1200 dst[1] = 0x00000000 | base | format; /* BaseAddress */
1201 dst[2] = (height << 13) | width;
1202 dst[3] = 0x00a00c14 | (anisop << 25) | (filter <<19);
1203 if (base_mip)
1204 dst[4] = 0x00000e03;
1205 else
1206 dst[4] = 0;
1207 dst[5] = 0x00000a00 | base_mip; /* MipAddress */
1208}
1209
1210void Xe_pLoadShader(struct XenosDevice *xe, int base, int type, int size)
1211{
1212 rput32(0xc0012700);
1213 rput32(base | type);
1214 rput32(size);
1215}
1216
1217void Xe_pAlign(struct XenosDevice *xe)
1218{
1219 while ((xe->rb_secondary_wptr&3) != 3)
1220 rput32(0x80000000);
1221}
1222
1224{
1225 Xe_pWriteReg(xe, 0x1720, 0x20000);
1226}
1227
1228void Xe_pStep(struct XenosDevice *xe, int x)
1229{
1230 Xe_pWriteReg(xe, 0x15e0, x);
1231}
1232
1233void Xe_pStuff(struct XenosDevice *xe)
1234{
1235 rput32(0x00072380);
1236 rput32(0x00000000); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
1237 rput32(0x00000000); rput32(0x00000000); rput32(0x00000000); rput32(0x00000000);
1238}
1239
1240
1241void Xe_Fatal(struct XenosDevice *xe, const char *fmt, ...)
1242{
1243 va_list arg;
1244 printf("[xe] Fatal error: ");
1245 va_start(arg, fmt);
1246 vprintf(fmt, arg);
1247 va_end(arg);
1248 printf("\n");
1249 abort();
1250}
1251
1253{
1254 return &xe->tex_fb;
1255}
1256
1258{
1259 if(!fb->tiled)
1260 Xe_Fatal(xe, "new framebuffer surface should be tiled.\n");
1261
1262 if(fb->bypp!=4)
1263 Xe_Fatal(xe, "new framebuffer surface format should be 32bit (BGRA8888).\n");
1264
1265 w32(0x6110,fb->ptr);
1266 w32(0x6120,fb->wpitch/4);
1267 w32(0x6134,fb->width);
1268 w32(0x6138,fb->height);
1269
1270 xe->tex_fb.ptr = r32(0x6110);
1271 xe->tex_fb.wpitch = r32(0x6120) * 4;
1272 xe->tex_fb.width = r32(0x6134);
1273 xe->tex_fb.height = r32(0x6138);
1274 xe->tex_fb.bypp = 4;
1275 xe->tex_fb.base = (void*)(long)xe->tex_fb.ptr;
1276}
1277
1278void Xe_Execute(struct XenosDevice *xe)
1279{
1281 Xe_pRBKick(xe);
1282}
1283
1285{
1286 Xe_pWriteReg(xe, 0x15e0, xe->frameidx);
1287
1288 Xe_Execute(xe);
1289
1290// printf("waiting for frameidx %08x\n", xe->frameidx);
1291 int timeout = 1<<24;
1292 do {
1294 if (!timeout--)
1295 Xe_Fatal(xe, "damn, the GPU seems to hang. There is no (known) way to recover, you have to reboot.\n");
1296// udelay(1000);
1297 } while (*(volatile u32*)(xe->rb + SCRATCH_WRITEBACK) != xe->frameidx) ;
1298 xe->frameidx++;
1299// printf("done\n");
1300}
1301
1302void Xe_Sync(struct XenosDevice *xe)
1303{
1304 Xe_pDebugSync(xe);
1305 Xe_VBReclaim(xe);
1306}
1307
1309
1311{
1312 while (xe->alu_dirty)
1313 {
1314 int start, end;
1315 for (start = 0; start < 32; ++start)
1316 if (xe->alu_dirty & (1<<start))
1317 break;
1318 for (end = start; end < 32; ++end)
1319 if (!(xe->alu_dirty & (1<<end)))
1320 break;
1321 else
1322 xe->alu_dirty &= ~(1<<end);
1323
1324 int base = start * 16;
1325 int num = (end - start) * 16 * 4;
1326
1327 stat_alu_uploaded += num;
1328 Xe_pAlign(xe);
1329 rput32(0x00004000 | (base * 4) | ((num-1) << 16));
1330 rput(xe->alu_constants + base * 4, num);
1331 }
1332}
1333
1335{
1336 while (xe->fetch_dirty)
1337 {
1338 int start, end;
1339 for (start = 0; start < 32; ++start)
1340 if (xe->fetch_dirty & (1<<start))
1341 break;
1342 for (end = start; end < 32; ++end)
1343 if (!(xe->fetch_dirty & (1<<end)))
1344 break;
1345 else
1346 xe->fetch_dirty &= ~(1<<end);
1347
1348 int base = start * 3;
1349 int num = (end - start) * 3 * 2;
1350
1351 stat_alu_uploaded += num;
1352 Xe_pAlign(xe);
1353 rput32(0x00004800 | (base * 2) | ((num-1) << 16));
1354 rput(xe->fetch_constants + base * 2, num);
1355 }
1356}
1357
1359{
1360 Xe_pAlign(xe);
1361 rput32(0x00172388);
1362 rput(xe->clipplane, 6*4);
1363}
1364
1366{
1367 Xe_pAlign(xe);
1368 rput32(0x00274900);
1369 rput(xe->integer_constants, 10*4);
1370}
1371
1373{
1374 rput32(0x00082200);
1375 rput(xe->controlpacket, 9);
1376}
1377
1379{
1380 u32 program_control = 0, context_misc = 0;
1381 if (xe->ps)
1382 {
1385 program_control |= xe->ps->program_control;
1386 context_misc |= xe->ps->context_misc;
1387 }
1388
1389 if (xe->vs)
1390 {
1393 program_control |= xe->vs->program_control;
1394 context_misc |= xe->vs->context_misc;
1395 }
1396
1397 rput32(0x00022180);
1398 rput32(program_control);
1399 rput32(context_misc);
1400 rput32(0xFFFFFFFF); /* interpolation mode */
1401}
1402
1404{
1405 xe->controlpacket[0] = 0x00700736|0x80; // DEPTH
1406 xe->controlpacket[1] = 0x00010001; // BLEND
1407 xe->controlpacket[2] = 0x87000007; // COLOR
1408 xe->controlpacket[3] = 0x00000000; // HI
1409 xe->controlpacket[4] = 0x00080000; // CLIP
1410 xe->controlpacket[5] = 0x00010006; // MODE
1411 if (xe->msaa_samples)
1412 xe->controlpacket[5] |= 1<<15;
1413 xe->controlpacket[6] = 0x0000043f; // VTE
1414 xe->controlpacket[7] = 0;
1415 xe->controlpacket[8] = 0x00000004; // EDRAM
1416
1417 xe->stencildata[0] = 0xFFFF00;
1418 xe->stencildata[1] = 0xFFFF00;
1419
1421}
1422
1423void Xe_SetZFunc(struct XenosDevice *xe, int z_func)
1424{
1425 xe->controlpacket[0] = (xe->controlpacket[0]&~0x70) | (z_func<<4);
1426 xe->dirty |= DIRTY_CONTROL;
1427}
1428
1429void Xe_SetZWrite(struct XenosDevice *xe, int zw)
1430{
1431 xe->controlpacket[0] = (xe->controlpacket[0]&~4) | (zw<<2);
1432 xe->dirty |= DIRTY_CONTROL;
1433}
1434
1435void Xe_SetZEnable(struct XenosDevice *xe, int ze)
1436{
1437 xe->controlpacket[0] = (xe->controlpacket[0]&~2) | (ze<<1);
1438 xe->dirty |= DIRTY_CONTROL;
1439}
1440
1441void Xe_SetFillMode(struct XenosDevice *xe, int front, int back)
1442{
1443 xe->controlpacket[5] &= ~(0x3f<<5);
1444 xe->controlpacket[5] |= front << 5;
1445 xe->controlpacket[5] |= back << 8;
1446 xe->controlpacket[5] |= 1<<3;
1447
1448 xe->dirty |= DIRTY_CONTROL;
1449}
1450
1451void Xe_SetBlendControl(struct XenosDevice *xe, int col_src, int col_op, int col_dst, int alpha_src, int alpha_op, int alpha_dst)
1452{
1453 xe->controlpacket[1] = col_src | (col_op << 5) | (col_dst << 8) | (alpha_src << 16) | (alpha_op << 21) | (alpha_dst << 24);
1454 xe->dirty |= DIRTY_CONTROL;
1455}
1456
1457void Xe_SetSrcBlend(struct XenosDevice *xe, unsigned int blend)
1458{
1459 assert(blend < 32);
1460 xe->controlpacket[1] &= ~0x1F;
1461 xe->controlpacket[1] |= blend;
1462 xe->dirty |= DIRTY_CONTROL;
1463}
1464
1465void Xe_SetDestBlend(struct XenosDevice *xe, unsigned int blend)
1466{
1467 assert(blend < 32);
1468 xe->controlpacket[1] &= ~(0x1F<<8);
1469 xe->controlpacket[1] |= blend<<8;
1470 xe->dirty |= DIRTY_CONTROL;
1471}
1472
1473void Xe_SetBlendOp(struct XenosDevice *xe, unsigned int blendop)
1474{
1475 assert(blendop < 8);
1476 xe->controlpacket[1] &= ~(0x7<<5);
1477 xe->controlpacket[1] |= blendop<<5;
1478 xe->dirty |= DIRTY_CONTROL;
1479}
1480
1481void Xe_SetSrcBlendAlpha(struct XenosDevice *xe, unsigned int blend)
1482{
1483 assert(blend < 32);
1484 xe->controlpacket[1] &= ~(0x1F<<16);
1485 xe->controlpacket[1] |= blend << 16;
1486 xe->dirty |= DIRTY_CONTROL;
1487}
1488
1489void Xe_SetDestBlendAlpha(struct XenosDevice *xe, unsigned int blend)
1490{
1491 assert(blend < 32);
1492 xe->controlpacket[1] &= ~(0x1F<<24);
1493 xe->controlpacket[1] |= blend<< 24;
1494 xe->dirty |= DIRTY_CONTROL;
1495}
1496
1497void Xe_SetBlendOpAlpha(struct XenosDevice *xe, unsigned int blendop)
1498{
1499 assert(blendop < 8);
1500 xe->controlpacket[1] &= ~(0x7<<21);
1501 xe->controlpacket[1] |= blendop<<21;
1502 xe->dirty |= DIRTY_CONTROL;
1503}
1504
1505void Xe_SetCullMode(struct XenosDevice *xe, unsigned int cullmode)
1506{
1507 assert(cullmode < 8);
1508 xe->controlpacket[5] &= ~7;
1509 xe->controlpacket[5] |= cullmode;
1510 xe->dirty |= DIRTY_CONTROL;
1511}
1512
1513void Xe_SetAlphaTestEnable(struct XenosDevice *xe, int enable)
1514{
1515 xe->controlpacket[2] &= ~8;
1516 xe->controlpacket[2] |= (!!enable) << 3;
1517 xe->dirty |= DIRTY_CONTROL;
1518}
1519
1520void Xe_SetAlphaFunc(struct XenosDevice *xe, unsigned int func)
1521{
1522 assert(func <= 7);
1523 xe->controlpacket[2] &= ~7;
1524 xe->controlpacket[2] |= func;
1525 xe->dirty |= DIRTY_CONTROL;
1526}
1527
1528void Xe_SetAlphaRef(struct XenosDevice *xe, float alpharef)
1529{
1530 xe->alpharef = alpharef;
1531 xe->dirty |= DIRTY_MISC;
1532}
1533
1534void Xe_SetStencilFunc(struct XenosDevice *xe, int bfff, unsigned int func)
1535{
1536 assert(func <= 7);
1537 if (bfff & 1)
1538 {
1539 xe->controlpacket[0] &= ~(7<<8);
1540 xe->controlpacket[0] |= func << 8;
1541 }
1542 if (bfff & 2)
1543 {
1544 xe->controlpacket[0] &= ~(7<<20);
1545 xe->controlpacket[0] |= func << 20;
1546 }
1547 xe->dirty |= DIRTY_CONTROL;
1548}
1549
1550void Xe_SetStencilEnable(struct XenosDevice *xe, unsigned int enable)
1551{
1552 assert(enable <= 1);
1553 xe->controlpacket[0] &= ~1;
1554 xe->controlpacket[0] |= enable;
1555 xe->dirty |= DIRTY_CONTROL;
1556}
1557
1558void Xe_SetStencilOp(struct XenosDevice *xe, int bfff, int fail, int zfail, int pass)
1559{
1560 assert(fail <= 7);
1561 assert(zfail <= 7);
1562 assert(pass <= 7);
1563
1564 if (bfff & 1)
1565 {
1566 if (fail >= 0)
1567 {
1568 xe->controlpacket[0] &= ~(7<<11);
1569 xe->controlpacket[0] |= fail << 11;
1570 }
1571 if (pass >= 0)
1572 {
1573 xe->controlpacket[0] &= ~(7<<14);
1574 xe->controlpacket[0] |= pass << 14;
1575 }
1576 if (zfail >= 0)
1577 {
1578 xe->controlpacket[0] &= ~(7<<17);
1579 xe->controlpacket[0] |= zfail << 17;
1580 }
1581 }
1582 if (bfff & 2)
1583 {
1584 if (fail >= 0)
1585 {
1586 xe->controlpacket[0] &= ~(7<<23);
1587 xe->controlpacket[0] |= fail << 23;
1588 }
1589 if (pass >= 0)
1590 {
1591 xe->controlpacket[0] &= ~(7<<26);
1592 xe->controlpacket[0] |= pass << 26;
1593 }
1594 if (zfail >= 0)
1595 {
1596 xe->controlpacket[0] &= ~(7<<29);
1597 xe->controlpacket[0] |= zfail << 29;
1598 }
1599 }
1600 xe->dirty |= DIRTY_CONTROL;
1601}
1602
1603void Xe_SetStencilRef(struct XenosDevice *xe, int bfff, int ref)
1604{
1605 if (bfff & 1)
1606 xe->stencildata[1] = (xe->stencildata[1] & ~0xFF) | ref;
1607
1608 if (bfff & 2)
1609 xe->stencildata[0] = (xe->stencildata[0] & ~0xFF) | ref;
1610 xe->dirty |= DIRTY_MISC;
1611}
1612
1613void Xe_SetStencilMask(struct XenosDevice *xe, int bfff, int mask)
1614{
1615 if (bfff & 1)
1616 xe->stencildata[1] = (xe->stencildata[1] & ~0xFF00) | (mask<<8);
1617
1618 if (bfff & 2)
1619 xe->stencildata[0] = (xe->stencildata[0] & ~0xFF00) | (mask<<8);
1620 xe->dirty |= DIRTY_MISC;
1621}
1622
1623void Xe_SetStencilWriteMask(struct XenosDevice *xe, int bfff, int writemask)
1624{
1625 if (bfff & 1)
1626 xe->stencildata[1] = (xe->stencildata[1] & ~0xFF0000) | (writemask<<16);
1627
1628 if (bfff & 2)
1629 xe->stencildata[0] = (xe->stencildata[0] & ~0xFF0000) | (writemask<<16);
1630 xe->dirty |= DIRTY_MISC;
1631}
1632
1633void Xe_SetScissor(struct XenosDevice *xe, int enable, int left, int top, int right, int bottom)
1634{
1635 xe->scissor_enable=enable;
1636 if (left>=0) xe->scissor_ltrb[0]=left;
1637 if (top>=0) xe->scissor_ltrb[1]=top;
1638 if (right>=0) xe->scissor_ltrb[2]=right;
1639 if (bottom>=0) xe->scissor_ltrb[3]=bottom;
1640 xe->dirty |= DIRTY_MISC;
1641}
1642
1643void Xe_SetClipPlaneEnables(struct XenosDevice *xe, int enables)
1644{
1645 xe->controlpacket[4] &= ~0x3f;
1646 xe->controlpacket[4] |= enables&0x3f;
1647 xe->dirty |= DIRTY_CONTROL;
1648}
1649
1650void Xe_SetClipPlane(struct XenosDevice *xe, int idx, float * plane)
1651{
1652 assert(idx>=0 && idx<6);
1653 memcpy(&xe->clipplane[idx*4],plane,4*4);
1654 xe->dirty |= DIRTY_CLIP;
1655}
1656
1658{
1659 xe->dirty = ~0;
1660 xe->alu_dirty = ~0;
1661 xe->fetch_dirty = ~0;
1662 Xe_pInitControl(xe);
1663}
1664
1665void Xe_SetShader(struct XenosDevice *xe, int type, struct XenosShader *sh, int index)
1666{
1667 struct XenosShader **s;
1668 int *i = 0;
1669 if (type == SHADER_TYPE_PIXEL)
1670 {
1671 s = &xe->ps;
1672 } else
1673 {
1674 s = &xe->vs;
1675 i = &xe->vs_index;
1676 assert(sh->shader_instance[index]);
1677 }
1678
1679 if ((*s != sh) || (i && *i != index))
1680 {
1681 *s = sh;
1682 if (i)
1683 *i = index;
1684 xe->dirty |= DIRTY_SHADER;
1685 }
1686}
1687
1689{
1690 if (xe->dirty & DIRTY_CONTROL)
1692
1693 if (xe->dirty & DIRTY_SHADER)
1694 Xe_pUploadShader(xe);
1695
1696 if (xe->dirty & DIRTY_ALU)
1698
1699 if (xe->dirty & DIRTY_FETCH)
1700 {
1702 rput32(0x00025000);
1703 rput32(0x00000000); rput32(0x00025000); rput32(0x00000000);
1704 }
1705
1706 if (xe->dirty & DIRTY_CLIP)
1708
1709 if (xe->dirty & DIRTY_INTEGER)
1711
1712 if (xe->dirty & DIRTY_MISC)
1713 {
1714 if (xe->scissor_enable)
1715 Xe_pSetSurfaceClip(xe, 0, 0, xe->scissor_ltrb[0], xe->scissor_ltrb[1], xe->scissor_ltrb[2], xe->scissor_ltrb[3]);
1716 else
1717 Xe_pSetSurfaceClip(xe, 0, 0, 0, 0, xe->vp_xres, xe->vp_yres);
1718
1720 rput32(0x0000200d);
1721 rput32(0x00000000);
1722 rput32(0x00012100);
1723 rput32(0x00ffffff);
1724 rput32(0x00000000);
1725 rput32(0x00002104);
1726 rput32(0x0000000f);
1727 rput32(0x0008210c);
1728 rput32(xe->stencildata[0]);
1729 rput32(xe->stencildata[1]);
1730 rputf(xe->alpharef); /* this does not work. */
1731 rputf(xe->vp_xres / 2.0);
1732 rputf(xe->vp_xres / 2.0);
1733 rputf(-xe->vp_yres / 2.0);
1734 rputf(xe->vp_yres / 2.0);
1735 rputf(1.0);
1736 rputf(0.0);
1737
1738 int vals[] = {0, 2 | (4 << 13), 4 | (6 << 13)};
1739 rput32(0x00002301);
1740 rput32(vals[xe->msaa_samples]);
1741 rput32(0x00002312);
1742 rput32(0x0000ffff);
1743 }
1744
1745 xe->dirty = 0;
1746}
1747
1748void Xe_SetTexture(struct XenosDevice *xe, int index, struct XenosSurface *tex)
1749{
1750 if (tex!=NULL)
1751 TEXTURE_FETCH(xe->fetch_constants + index * 6, tex->ptr, tex->width - 1, tex->height - 1, tex->wpitch, tex->tiled, tex->format, tex->ptr_mip, 2, tex->use_filtering, tex->u_addressing, tex->v_addressing);
1752 else
1753 memset(xe->fetch_constants + index * 6,0,24);
1754
1755 Xe_DirtyFetch(xe, index + index * 3, 3);
1756}
1757
1758void Xe_SetClearColor(struct XenosDevice *xe, u32 clearcolor)
1759{
1760 xe->clear_color = clearcolor;
1761}
1762
1764{
1765 struct XenosVertexBuffer *vb = malloc(sizeof(struct XenosVertexBuffer));
1766 memset(vb, 0, sizeof(struct XenosVertexBuffer));
1767 printf("--- alloc new vb, at %p, size %d\n", vb, size);
1768 vb->base = Xe_pAlloc(xe, &vb->phys_base, size, 0x1000);
1769 vb->size = 0;
1770 vb->space = size;
1771 vb->next = 0;
1772 vb->vertices = 0;
1773// printf("alloc done, at %p %x\n", vb->base, vb->phys_base);
1774 return vb;
1775}
1776
1778{
1779 Xe_pFree(xe,vb->base);
1780 free(vb);
1781}
1782
1784{
1785 struct XenosVertexBuffer **vbp = &xe->vb_pool;
1786
1787 while (*vbp)
1788 {
1789 struct XenosVertexBuffer *vb = *vbp;
1790// printf("use %d %d\n",vb->space,size);
1791 if (vb->space >= size)
1792 {
1793 *vbp = vb->next;
1794 vb->next = 0;
1795 vb->size = 0;
1796 vb->vertices = 0;
1797 return vb;
1798 }
1799 vbp = &vb->next;
1800 }
1801
1802 return Xe_CreateVertexBuffer(xe, size);
1803}
1804
1805void Xe_VBPoolAdd(struct XenosDevice *xe, struct XenosVertexBuffer *vb)
1806{
1808 while (*vbp)
1809 vbp = &(*vbp)->next;
1810
1811 *vbp = vb;
1812}
1813
1815{
1816 struct XenosVertexBuffer **vbp = xe->vb_pool ? &xe->vb_pool->next : &xe->vb_pool;
1817 while (*vbp)
1818 vbp = &(*vbp)->next;
1819
1820 *vbp = xe->vb_pool_after_frame;
1821 xe->vb_pool_after_frame = 0;
1822}
1823
1824void Xe_VBBegin(struct XenosDevice *xe, int pitch)
1825{
1826 if (xe->vb_head || xe->vb_current)
1827 Xe_Fatal(xe, "FATAL: VertexBegin without VertexEnd! (head %08x, current %08x)\n", xe->vb_head, xe->vb_current);
1828 xe->vb_current_pitch = pitch;
1829}
1830
1831void Xe_VBPut(struct XenosDevice *xe, void *data, int len)
1832{
1833 if (len % xe->vb_current_pitch)
1834 Xe_Fatal(xe, "FATAL: VertexPut with non-even len\n");
1835
1836 while (len)
1837 {
1838 int remaining = xe->vb_current ? (xe->vb_current->space - xe->vb_current->size) / 4 : 0;
1839
1840 remaining -= remaining % xe->vb_current_pitch;
1841
1842// printf("rem %d len %d\n",remaining,len);
1843
1844 if (remaining > len)
1845 remaining = len;
1846
1847 if (!remaining)
1848 {
1849 struct XenosVertexBuffer **n = xe->vb_head ? &xe->vb_current->next : &xe->vb_head;
1851 *n = xe->vb_current;
1852 continue;
1853 }
1854
1855 memcpy(xe->vb_current->base + xe->vb_current->size, data, remaining * 4);
1856 xe->vb_current->size += remaining * 4;
1857 xe->vb_current->vertices += remaining / xe->vb_current_pitch;
1858 data += remaining * 4;
1859 len -= remaining;
1860 }
1861}
1862
1864{
1865 struct XenosVertexBuffer *res;
1866 res = xe->vb_head;
1867
1868 while (xe->vb_head)
1869 {
1870 Xe_pSyncToDevice(xe, xe->vb_head->base, xe->vb_head->space);
1871 Xe_pInvalidateGpuCache(xe, xe->vb_head->phys_base, xe->vb_head->space + 0x1000);
1872 xe->vb_head = xe->vb_head->next;
1873 }
1874
1875 xe->vb_head = xe->vb_current = 0;
1876
1877 return res;
1878}
1879
1880void Xe_Draw(struct XenosDevice *xe, struct XenosVertexBuffer *vb, struct XenosIndexBuffer *ib)
1881{
1882 Xe_pStuff(xe);
1883
1884 if (vb->lock.start)
1885 Xe_Fatal(xe, "cannot draw locked VB");
1886 if (ib && ib->lock.start)
1887 Xe_Fatal(xe, "cannot draw locked IB");
1888
1889 while (vb)
1890 {
1891 Xe_SetStreamSource(xe, 0, vb, 0, 0);
1892 Xe_pSetState(xe);
1893
1894 rput32(0x00002007);
1895 rput32(0x00000000);
1896
1897 Xe_pSetIndexOffset(xe, 0);
1898 if (!ib)
1899 {
1901 } else
1903
1904 xe->tris_drawn += vb->vertices / 3;
1905 vb = vb->next;
1906 }
1907}
1908
1909int Xe_pCalcVtxCount(struct XenosDevice *xe, int primtype, int primcnt)
1910{
1911 switch (primtype)
1912 {
1913 case XE_PRIMTYPE_POINTLIST: return primcnt;
1914 case XE_PRIMTYPE_LINELIST: return primcnt * 2;
1915 case XE_PRIMTYPE_LINESTRIP: return 1 + primcnt;
1916 case XE_PRIMTYPE_TRIANGLELIST: return primcnt * 3;
1917 case XE_PRIMTYPE_TRIANGLESTRIP: /* fall trough */
1918 case XE_PRIMTYPE_TRIANGLEFAN: return 2 + primcnt;
1919 case XE_PRIMTYPE_RECTLIST: return primcnt * 3;
1920 case XE_PRIMTYPE_QUADLIST: return primcnt * 4;
1921 default:
1922 Xe_Fatal(xe, "unknown primitive type");
1923 }
1924}
1925
1926void Xe_DrawIndexedPrimitive(struct XenosDevice *xe, int type, int base_index, int min_index, int num_vertices, int start_index, int primitive_count)
1927{
1928 int cnt;
1929
1930 assert(xe->ps); assert(xe->vs);
1931
1932 Xe_pStuff(xe); /* fixme */
1933 Xe_pSetState(xe);
1934 rput32(0x00002007);
1935 rput32(0x00000000);
1936
1937 Xe_pSetIndexOffset(xe, base_index);
1938 cnt = Xe_pCalcVtxCount(xe, type, primitive_count);
1939 int bpi = 2 << xe->current_ib->fmt;
1940 Xe_pDrawIndexedPrimitive(xe, type, cnt, xe->current_ib->phys_base + bpi * start_index, cnt, xe->current_ib->fmt);
1941}
1942
1943void Xe_DrawPrimitive(struct XenosDevice *xe, int type, int start, int primitive_count)
1944{
1945 int cnt;
1946
1947 assert(xe->ps); assert(xe->vs);
1948
1949 Xe_pStuff(xe); /* fixme */
1950 Xe_pSetState(xe);
1951 rput32(0x00002007);
1952 rput32(0x00000000);
1953
1954 Xe_pSetIndexOffset(xe, start); /* ?? */
1955 cnt = Xe_pCalcVtxCount(xe, type, primitive_count);
1957}
1958
1959void Xe_SetStreamSource(struct XenosDevice *xe, int index, struct XenosVertexBuffer *vb, int offset, int stride)
1960{
1961 if (vb->lock.start)
1962 Xe_Fatal(xe, "cannot use locked VB");
1963
1964 xe->current_vb = vb;
1965 VERTEX_FETCH(xe->fetch_constants + (95 + index) * 2, vb->phys_base + offset, vb->space - offset);
1966 Xe_DirtyFetch(xe, 95 + index, 1);
1967}
1968
1969void Xe_SetIndices(struct XenosDevice *xe, struct XenosIndexBuffer *ib)
1970{
1971 xe->current_ib = ib;
1972}
1973
1974struct XenosIndexBuffer *Xe_CreateIndexBuffer(struct XenosDevice *xe, int length, int format)
1975{
1976 struct XenosIndexBuffer *ib = malloc(sizeof(struct XenosIndexBuffer));
1977 memset(ib, 0, sizeof(struct XenosIndexBuffer));
1978 ib->base = Xe_pAlloc(xe, &ib->phys_base, length, 32);
1979 ib->size = length;
1980 ib->indices = 0;
1981 ib->fmt = format;
1982 return ib;
1983}
1984
1986{
1987 Xe_pFree(xe,ib->base);
1988 free(ib);
1989}
1990
1991void *Xe_VB_Lock(struct XenosDevice *xe, struct XenosVertexBuffer *vb, int offset, int size, int flags)
1992{
1993 Xe_pLock(xe, &vb->lock, vb->base + offset, vb->phys_base + offset, size, flags);
1994 return vb->base + offset;
1995}
1996
1997void Xe_VB_Unlock(struct XenosDevice *xe, struct XenosVertexBuffer *vb)
1998{
1999 Xe_pUnlock(xe, &vb->lock);
2000}
2001
2002void *Xe_IB_Lock(struct XenosDevice *xe, struct XenosIndexBuffer *ib, int offset, int size, int flags)
2003{
2004 Xe_pLock(xe, &ib->lock, ib->base + offset, ib->phys_base + offset, size, flags);
2005 return ib->base + offset;
2006}
2007
2008void Xe_IB_Unlock(struct XenosDevice *xe, struct XenosIndexBuffer *ib)
2009{
2010 Xe_pUnlock(xe, &ib->lock);
2011}
2012
2013void Xe_SetVertexShaderConstantF(struct XenosDevice *xe, int start, const float *data, int count)
2014{
2015// printf("SetVertexShaderConstantF\n");
2016 memcpy(xe->alu_constants + start * 4, data, count * 16);
2017 Xe_DirtyAluConstant(xe, start, count);
2018// while (count--)
2019// {
2020// printf("%.3f %.3f %.3f %.3f\n", data[0], data[1], data[2], data[3]);
2021// data += 4;
2022// }
2023}
2024
2025void Xe_SetPixelShaderConstantF(struct XenosDevice *xe, int start, const float *data, int count)
2026{
2027 start += 256;
2028// printf("SetPixelShaderConstantF (%d+)\n", start);
2029 memcpy(xe->alu_constants + start * 4, data, count * 16);
2030 Xe_DirtyAluConstant(xe, start, count);
2031// while (count--)
2032// {
2033// printf("%.3f %.3f %.3f %.3f\n", data[0], data[1], data[2], data[3]);
2034// data += 4;
2035// }
2036}
2037
2038void Xe_SetVertexShaderConstantB(struct XenosDevice *xe, int index, int value)
2039{
2040 int bit=1<<(index&0x1f);
2041 int block=index>>5;
2042
2043 if (value)
2044 xe->integer_constants[block] |= bit;
2045 else
2046 xe->integer_constants[block] &= ~bit;
2047
2048 xe->dirty |= DIRTY_INTEGER;
2049}
2050
2051void Xe_SetPixelShaderConstantB(struct XenosDevice *xe, int index, int value)
2052{
2053 index += 128;
2054
2055 u32 bit=1<<(index&0x1f);
2056 u32 block=index>>5;
2057
2058 if (value)
2059 xe->integer_constants[block] |= bit;
2060 else
2061 xe->integer_constants[block] &= ~bit;
2062
2063 xe->dirty |= DIRTY_INTEGER;
2064}
2065
2066struct XenosSurface *Xe_CreateTexture(struct XenosDevice *xe, unsigned int width, unsigned int height, unsigned int levels, int format, int tiled)
2067{
2068 struct XenosSurface *surface = malloc(sizeof(struct XenosSurface));
2069 memset(surface, 0, sizeof(struct XenosSurface));
2070 int bypp = 0;
2071
2072 switch (format & XE_FMT_MASK)
2073 {
2074 case XE_FMT_8: bypp = 1; break;
2075 case XE_FMT_5551: bypp = 2; break;
2076 case XE_FMT_565: bypp = 2; break;
2077 case XE_FMT_8888: bypp = 4; break;
2078 case XE_FMT_16161616: bypp = 8; break;
2079 }
2080 assert(bypp);
2081
2082 int wpitch = (width * bypp + 127) &~127;
2083 int hpitch = (height + 31) &~31;
2084
2085 surface->width = width;
2086 surface->height = height;
2087 surface->wpitch = wpitch;
2088 surface->hpitch = hpitch;
2089 surface->tiled = tiled;
2090 surface->format = format;
2091 surface->ptr_mip = 0;
2092 surface->bypp = bypp;
2093 surface->base = Xe_pAlloc(xe, &surface->ptr, hpitch * wpitch, 4096);
2094
2095 surface->use_filtering = 1;
2096 surface->u_addressing = XE_TEXADDR_WRAP;
2097 surface->v_addressing = XE_TEXADDR_WRAP;
2098
2099 return surface;
2100}
2101
2102void Xe_DestroyTexture(struct XenosDevice *xe, struct XenosSurface *surface)
2103{
2104 Xe_pFree(xe,surface->base);
2105 free(surface);
2106}
2107
2108void *Xe_Surface_LockRect(struct XenosDevice *xe, struct XenosSurface *surface, int x, int y, int w, int h, int flags)
2109{
2110#if 0
2111 if (surface == xe->rt) /* current render target? sync. */
2112 {
2113 Xe_Resolve(xe);
2114 Xe_Sync(xe);
2115 }
2116#endif
2117 if (!w)
2118 w = surface->width;
2119 if (!h)
2120 h = surface->height;
2121
2122 int offset = y * surface->wpitch + x * surface->bypp;
2123 int size = h * surface->wpitch;
2124
2125 if (surface->height != surface->hpitch) {
2126 //TODO: find a better way to handle this
2127 offset = 0;
2128 size = surface->hpitch * surface->wpitch;
2129 }
2130
2131 Xe_pLock(xe, &surface->lock, surface->base + offset, surface->ptr + offset, size, flags);
2132 return surface->base + offset;
2133}
2134
2135void Xe_Surface_Unlock(struct XenosDevice *xe, struct XenosSurface *surface)
2136{
2137 Xe_pUnlock(xe, &surface->lock);
2138}
2139
2140
2142{
2143// printf("%08x\n", r32(0x6534));
2144 return r32(0x6534) & 0x1000;
2145}
uint16_t length
Definition: ata.h:4
void lock(unsigned int *lock)
uint32_t width
Definition: console.c:3
#define base
uint32_t height
Definition: console.c:4
#define NULL
Definition: def.h:47
void memdcbf(void *addr, int len)
void memdcbst(void *addr, int len)
int cnt
Definition: enet.c:409
__asm__(".global _mcount \n" "_mcount: \n" "stwu %sp, -0x70(%sp) \n" "mflr %r0 \n" "stw %r0, 0x60(%sp) \n" "std %r3, 0x10(%sp) \n" "std %r4, 0x18(%sp) \n" "std %r5, 0x20(%sp) \n" "std %r6, 0x28(%sp) \n" "std %r7, 0x30(%sp) \n" "std %r8, 0x38(%sp) \n" "std %r9, 0x40(%sp) \n" "std %r10, 0x48(%sp) \n" "mflr %r3 \n" "lwz %r4,0x74(%sp) \n" "bl internal_mcount \n" "ld %r3, 0x10(%sp) \n" "ld %r4, 0x18(%sp) \n" "ld %r5, 0x20(%sp) \n" "ld %r6, 0x28(%sp) \n" "ld %r7, 0x30(%sp) \n" "ld %r8, 0x38(%sp) \n" "ld %r9, 0x40(%sp) \n" "ld %r10, 0x48(%sp) \n" "lwz %r11, 0x60(%sp) \n" "addi %sp, %sp, 0x70 \n" "mtlr %r0 \n" "lwz %r0,4(%sp) \n" "mtctr %r11 \n" "mtlr %r0 \n" "bctr \n")
static uint32_t val
Definition: io.h:17
u32 ptr
Definition: iso9660.c:536
u32 size
Definition: iso9660.c:537
void abort(void)
Definition: newlib.c:136
int dirty
Definition: xe.h:263
int rb_primary_wptr
Definition: xe.h:268
struct XenosSurface default_fb
Definition: xe.h:274
int vb_current_pitch
Definition: xe.h:287
u32 stencildata[2]
Definition: xe.h:250
int last_wptr
Definition: xe.h:277
struct XenosSurface tex_fb
Definition: xe.h:273
int scissor_enable
Definition: xe.h:298
int vp_xres
Definition: xe.h:279
int edram_hizpitch
Definition: xe.h:296
int scissor_ltrb[4]
Definition: xe.h:299
struct XenosVertexBuffer * current_vb
Definition: xe.h:294
struct XenosVertexBuffer * vb_pool_after_frame
Definition: xe.h:290
volatile void * rb_secondary
Definition: xe.h:267
struct XenosVertexBuffer * vb_current
Definition: xe.h:286
int edram_colorformat
Definition: xe.h:296
int rb_secondary_wptr
Definition: xe.h:268
int frameidx
Definition: xe.h:280
int msaa_samples
Definition: xe.h:284
u32 fetch_dirty
Definition: xe.h:245
int tris_drawn
Definition: xe.h:292
u32 clear_stencil_z
Definition: xe.h:283
struct XenosShader * ps
Definition: xe.h:253
struct XenosSurface * rt
Definition: xe.h:276
u32 fetch_constants[96 *2]
Definition: xe.h:242
u32 clear_color
Definition: xe.h:282
int edram_color0base
Definition: xe.h:296
u32 alu_dirty
Definition: xe.h:244
float clipplane[6 *4]
Definition: xe.h:247
volatile void * rb
Definition: xe.h:267
struct XenosIndexBuffer * current_ib
Definition: xe.h:293
float alu_constants[256 *4 *2]
Definition: xe.h:241
struct XenosShader * vs
Definition: xe.h:253
struct XenosVertexBuffer * vb_head
Definition: xe.h:286
u32 rb_secondary_base
Definition: xe.h:266
volatile unsigned int * regs
Definition: xe.h:271
int vs_index
Definition: xe.h:254
u32 controlpacket[9]
Definition: xe.h:250
int edram_depthbase
Definition: xe.h:296
volatile void * rb_primary
Definition: xe.h:267
unsigned int alpharef
Definition: xe.h:251
int edram_pitch
Definition: xe.h:296
struct XenosVertexBuffer * vb_pool
Definition: xe.h:289
u32 integer_constants[10 *4]
Definition: xe.h:249
int vp_yres
Definition: xe.h:279
int size
Definition: xe.h:232
u32 phys_base
Definition: xe.h:230
void * base
Definition: xe.h:233
struct XenosLock lock
Definition: xe.h:236
int indices
Definition: xe.h:231
Definition: xe.h:90
void * start
Definition: xe.h:91
u32 offset
Definition: xe.h:114
u32 off_constants
Definition: xe.h:118
u32 off_shader
Definition: xe.h:118
u32 context_misc
Definition: xe.h:106
u32 shader_phys[XE_SHADER_MAX_INSTANCES]
Definition: xe.h:106
void * shader
Definition: xe.h:103
u32 program_control
Definition: xe.h:106
u32 shader_phys_size
Definition: xe.h:106
void * shader_instance[XE_SHADER_MAX_INSTANCES]
Definition: xe.h:107
int use_filtering
Definition: xe.h:205
struct XenosLock lock
Definition: xe.h:210
int u_addressing
Definition: xe.h:206
int v_addressing
Definition: xe.h:206
int wpitch
Definition: xe.h:201
int format
Definition: xe.h:201
int width
Definition: xe.h:201
void * base
Definition: xe.h:208
int height
Definition: xe.h:201
int bypp
Definition: xe.h:203
u32 ptr
Definition: xe.h:202
int hpitch
Definition: xe.h:201
int tiled
Definition: xe.h:201
u32 ptr_mip
Definition: xe.h:202
struct XenosLock lock
Definition: xe.h:220
struct XenosVertexBuffer * next
Definition: xe.h:222
u32 phys_base
Definition: xe.h:215
void * base
Definition: xe.h:218
int vertices
Definition: xe.h:216
void udelay(int u)
Definition: time.c:12
void Xe_pSetBin(struct XenosDevice *xe, u32 mask_low, u32 select_low, u32 mask_hi, u32 select_hi)
Definition: xe.c:165
void Xe_pResetRingbuffer(struct XenosDevice *xe)
Definition: xe.c:208
void Xe_SetRenderTarget(struct XenosDevice *xe, struct XenosSurface *rt)
Definition: xe.c:998
void Xe_pDebugSync(struct XenosDevice *xe)
Definition: xe.c:1284
void Xe_SetStencilFunc(struct XenosDevice *xe, int bfff, unsigned int func)
Definition: xe.c:1534
void * Xe_IB_Lock(struct XenosDevice *xe, struct XenosIndexBuffer *ib, int offset, int size, int flags)
Definition: xe.c:2002
void Xe_pUploadShader(struct XenosDevice *xe)
Definition: xe.c:1378
void Xe_pInit1(struct XenosDevice *xe)
Definition: xe.c:270
void * Xe_pAlloc(struct XenosDevice *xe, u32 *phys, int size, int align)
Definition: xe.c:62
void Xe_pSetState(struct XenosDevice *xe)
Definition: xe.c:1688
int stat_alu_uploaded
Definition: xe.c:1308
void Xe_InstantiateShader(struct XenosDevice *xe, struct XenosShader *sh, unsigned int index)
Definition: xe.c:935
void Xe_Draw(struct XenosDevice *xe, struct XenosVertexBuffer *vb, struct XenosIndexBuffer *ib)
Definition: xe.c:1880
void Xe_pUploadClipPlane(struct XenosDevice *xe)
Definition: xe.c:1358
#define RINGBUFFER_SECONDARY_SIZE
Definition: xe.c:22
void Xe_VBPut(struct XenosDevice *xe, void *data, int len)
Definition: xe.c:1831
void VERTEX_FETCH(u32 *dst, u32 base, int len)
Definition: xe.c:1181
void Xe_pGInit7(struct XenosDevice *xe)
Definition: xe.c:509
void Xe_SetZWrite(struct XenosDevice *xe, int zw)
Definition: xe.c:1429
void Xe_SetZEnable(struct XenosDevice *xe, int ze)
Definition: xe.c:1435
#define RINGBUFFER_PRIMARY_SIZE
Definition: xe.c:21
#define CP_PACKET0(reg, n)
Definition: xe.c:28
void Xe_pSetupRingbuffer(struct XenosDevice *xe, u32 buffer_base, u32 size_in_l2qw)
Definition: xe.c:216
void Xe_Surface_Unlock(struct XenosDevice *xe, struct XenosSurface *surface)
Definition: xe.c:2135
void Xe_DirtyAluConstant(struct XenosDevice *xe, int base, int len)
Definition: xe.c:570
int Xe_GetShaderLength(struct XenosDevice *xe, void *sh)
Definition: xe.c:949
int Xe_VBFCalcStride(struct XenosDevice *xe, const struct XenosVBFFormat *fmt)
Definition: xe.c:723
void Xe_InvalidateState(struct XenosDevice *xe)
Definition: xe.c:1657
void Xe_DirtyFetch(struct XenosDevice *xe, int base, int len)
Definition: xe.c:583
void Xe_DrawIndexedPrimitive(struct XenosDevice *xe, int type, int base_index, int min_index, int num_vertices, int start_index, int primitive_count)
Definition: xe.c:1926
void Xe_pUploadShaderConstants(struct XenosDevice *xe, struct XenosShader *s)
Definition: xe.c:631
void Xe_SetStencilEnable(struct XenosDevice *xe, unsigned int enable)
Definition: xe.c:1550
#define SCRATCH_WRITEBACK
Definition: xe.c:19
void Xe_SetVertexShaderConstantB(struct XenosDevice *xe, int index, int value)
Definition: xe.c:2038
struct XenosIndexBuffer * Xe_CreateIndexBuffer(struct XenosDevice *xe, int length, int format)
Definition: xe.c:1974
void * Xe_VB_Lock(struct XenosDevice *xe, struct XenosVertexBuffer *vb, int offset, int size, int flags)
Definition: xe.c:1991
void Xe_pInvalidateGpuCache_Primary(struct XenosDevice *xe, int base, int size)
Definition: xe.c:83
void Xe_pLoadShader(struct XenosDevice *xe, int base, int type, int size)
Definition: xe.c:1210
void Xe_pGInit9(struct XenosDevice *xe)
Definition: xe.c:522
void Xe_SetCullMode(struct XenosDevice *xe, unsigned int cullmode)
Definition: xe.c:1505
void Xe_pGInit4(struct XenosDevice *xe)
Definition: xe.c:472
u32 xenos_ucode1[]
Definition: ucode.c:25
void Xe_ResolveInto(struct XenosDevice *xe, struct XenosSurface *surface, int source, int clear)
Definition: xe.c:1069
void Xe_SetSrcBlend(struct XenosDevice *xe, unsigned int blend)
Definition: xe.c:1457
void Xe_pUnlock(struct XenosDevice *xe, struct XenosLock *lock)
Definition: xe.c:752
#define WRITEBACK_ZONE_SIZE
Definition: xe.c:16
void Xe_DestroyTexture(struct XenosDevice *xe, struct XenosSurface *surface)
Definition: xe.c:2102
void Xe_pRBKick(struct XenosDevice *xe)
Definition: xe.c:117
void Xe_pGInit10(struct XenosDevice *xe)
Definition: xe.c:540
void Xe_SetStencilOp(struct XenosDevice *xe, int bfff, int fail, int zfail, int pass)
Definition: xe.c:1558
void Xe_SetPixelShaderConstantB(struct XenosDevice *xe, int index, int value)
Definition: xe.c:2051
void Xe_pUploadIntegerConstants(struct XenosDevice *xe)
Definition: xe.c:1365
void Xe_Sync(struct XenosDevice *xe)
Definition: xe.c:1302
void Xe_SetBlendControl(struct XenosDevice *xe, int col_src, int col_op, int col_dst, int alpha_src, int alpha_op, int alpha_dst)
Definition: xe.c:1451
struct XenosShader * Xe_LoadShader(struct XenosDevice *xe, const char *filename)
Definition: xe.c:596
void Xe_pGInit5(struct XenosDevice *xe)
Definition: xe.c:482
struct XenosSurface * Xe_GetFramebufferSurface(struct XenosDevice *xe)
Definition: xe.c:1252
void Xe_DestroyVertexBuffer(struct XenosDevice *xe, struct XenosVertexBuffer *vb)
Definition: xe.c:1777
void Xe_DrawPrimitive(struct XenosDevice *xe, int type, int start, int primitive_count)
Definition: xe.c:1943
void Xe_VBReclaim(struct XenosDevice *xe)
Definition: xe.c:1814
void Xe_SetDestBlend(struct XenosDevice *xe, unsigned int blend)
Definition: xe.c:1465
#define VBPOOL_NUM_TRIANGLES
Definition: xe.c:33
void Xe_SetSrcBlendAlpha(struct XenosDevice *xe, unsigned int blend)
Definition: xe.c:1481
u32 xenos_ucode0[]
Definition: ucode.c:3
struct XenosVertexBuffer * Xe_VBPoolAlloc(struct XenosDevice *xe, int size)
Definition: xe.c:1783
void Xe_SetClearColor(struct XenosDevice *xe, u32 clearcolor)
Definition: xe.c:1758
void Xe_pGInit0(struct XenosDevice *xe)
Definition: xe.c:398
void Xe_pStep(struct XenosDevice *xe, int x)
Definition: xe.c:1228
void Xe_SetAlphaTestEnable(struct XenosDevice *xe, int enable)
Definition: xe.c:1513
void Xe_pUploadFetchConstants(struct XenosDevice *xe)
Definition: xe.c:1334
void Xe_pWaitUntilIdle(struct XenosDevice *xe, u32 what)
Definition: xe.c:177
void Xe_Init(struct XenosDevice *xe)
Definition: xe.c:956
void Xe_pLock(struct XenosDevice *xe, struct XenosLock *lock, void *addr, u32 phys, int size, int flags)
Definition: xe.c:764
void Xe_SetScissor(struct XenosDevice *xe, int enable, int left, int top, int right, int bottom)
Definition: xe.c:1633
void Xe_Execute(struct XenosDevice *xe)
Definition: xe.c:1278
void Xe_pSyncToDevice(struct XenosDevice *xe, volatile void *data, int len)
Definition: xe.c:52
void Xe_pUploadControl(struct XenosDevice *xe)
Definition: xe.c:1372
void Xe_pSyncFromDevice(struct XenosDevice *xe, volatile void *data, int len)
Definition: xe.c:57
int Xe_pVBFNrComponents(struct XenosDevice *xe, const struct XenosVBFElement *fmt)
Definition: xe.c:706
void Xe_SetClipPlane(struct XenosDevice *xe, int idx, float *plane)
Definition: xe.c:1650
void Xe_SetBlendOp(struct XenosDevice *xe, unsigned int blendop)
Definition: xe.c:1473
void Xe_SetStreamSource(struct XenosDevice *xe, int index, struct XenosVertexBuffer *vb, int offset, int stride)
Definition: xe.c:1959
void Xe_DestroyIndexBuffer(struct XenosDevice *xe, struct XenosIndexBuffer *ib)
Definition: xe.c:1985
struct XenosVertexBuffer * Xe_VBEnd(struct XenosDevice *xe)
Definition: xe.c:1863
void Xe_SetStencilMask(struct XenosDevice *xe, int bfff, int mask)
Definition: xe.c:1613
void Xe_IB_Unlock(struct XenosDevice *xe, struct XenosIndexBuffer *ib)
Definition: xe.c:2008
void Xe_ShaderApplyVFetchPatches(struct XenosDevice *xe, struct XenosShader *sh, unsigned int index, const struct XenosVBFFormat *fmt)
Definition: xe.c:788
void Xe_pGInit8(struct XenosDevice *xe)
Definition: xe.c:517
void Xe_pSetClearValues(struct XenosDevice *xe)
Definition: xe.c:1038
void Xe_pRBKickSegment(struct XenosDevice *xe, int base, int len)
Definition: xe.c:108
void Xe_pGInit2(struct XenosDevice *xe)
Definition: xe.c:454
void Xe_SetFrameBufferSurface(struct XenosDevice *xe, struct XenosSurface *fb)
Definition: xe.c:1257
void Xe_pAlign(struct XenosDevice *xe)
Definition: xe.c:1217
void * Xe_Surface_LockRect(struct XenosDevice *xe, struct XenosSurface *surface, int x, int y, int w, int h, int flags)
Definition: xe.c:2108
void Xe_SetFillMode(struct XenosDevice *xe, int front, int back)
Definition: xe.c:1441
void Xe_SetDestBlendAlpha(struct XenosDevice *xe, unsigned int blend)
Definition: xe.c:1489
void Xe_pSetup(struct XenosDevice *xe, u32 buffer_base, u32 buffer_size, const u32 *ucode0, const u32 *ucode1)
Definition: xe.c:336
void Xe_Resolve(struct XenosDevice *xe)
Definition: xe.c:1175
void Xe_SetVertexShaderConstantF(struct XenosDevice *xe, int start, const float *data, int count)
Definition: xe.c:2013
void Xe_pRBMayKick(struct XenosDevice *xe)
Definition: xe.c:138
void Xe_SetClipPlaneEnables(struct XenosDevice *xe, int enables)
Definition: xe.c:1643
void Xe_pEnableWriteback(struct XenosDevice *xe, u32 addr, int blocksize)
Definition: xe.c:387
void Xe_SetIndices(struct XenosDevice *xe, struct XenosIndexBuffer *ib)
Definition: xe.c:1969
void Xe_pUploadALUConstants(struct XenosDevice *xe)
Definition: xe.c:1310
int Xe_VBFCalcSize(struct XenosDevice *xe, const struct XenosVBFElement *fmt)
Definition: xe.c:689
void Xe_pReset(struct XenosDevice *xe)
Definition: xe.c:282
void TEXTURE_FETCH(u32 *dst, u32 base, int width, int height, int pitch, int tiled, int format, u32 base_mip, int anisop, int filter, int uaddr, int vaddr)
Definition: xe.c:1187
int Xe_IsVBlank(struct XenosDevice *xe)
Definition: xe.c:2141
void Xe_pBlockUntilIdle(struct XenosDevice *xe)
Definition: xe.c:1223
void Xe_VBBegin(struct XenosDevice *xe, int pitch)
Definition: xe.c:1824
void Xe_pGInit6(struct XenosDevice *xe)
Definition: xe.c:500
void Xe_pResetCP(struct XenosDevice *xe, u32 buffer_base, u32 size_in_l2qw)
Definition: xe.c:303
void Xe_SetStencilRef(struct XenosDevice *xe, int bfff, int ref)
Definition: xe.c:1603
void Xe_pDrawIndexedPrimitive(struct XenosDevice *xe, int primtype, int num_points, u32 indexbuffer, u32 indexbuffer_size, int indextype)
Definition: xe.c:190
void Xe_SetBlendOpAlpha(struct XenosDevice *xe, unsigned int blendop)
Definition: xe.c:1497
void Xe_Fatal(struct XenosDevice *xe, const char *fmt,...)
Definition: xe.c:1241
int Xe_pCalcVtxCount(struct XenosDevice *xe, int primtype, int primcnt)
Definition: xe.c:1909
void Xe_pGInit3(struct XenosDevice *xe)
Definition: xe.c:464
void Xe_SetPixelShaderConstantF(struct XenosDevice *xe, int start, const float *data, int count)
Definition: xe.c:2025
struct XenosShader * Xe_LoadShaderFromMemory(struct XenosDevice *xe, void *m)
Definition: xe.c:613
void Xe_pFree(struct XenosDevice *xe, void *ptr)
Definition: xe.c:78
void Xe_pSetEDRAMLayout(struct XenosDevice *xe)
Definition: xe.c:1030
struct XenosVertexBuffer * Xe_CreateVertexBuffer(struct XenosDevice *xe, int size)
Definition: xe.c:1763
void Xe_pMasterInit(struct XenosDevice *xe, u32 buffer_base)
Definition: xe.c:361
void Xe_SetAlphaFunc(struct XenosDevice *xe, unsigned int func)
Definition: xe.c:1520
void Xe_VBPoolAdd(struct XenosDevice *xe, struct XenosVertexBuffer *vb)
Definition: xe.c:1805
#define SEGMENT_SIZE
Definition: xe.c:136
void Xe_pSetSurfaceClip(struct XenosDevice *xe, int offset_x, int offset_y, int sc_left, int sc_top, int sc_right, int sc_bottom)
Definition: xe.c:157
void Xe_VB_Unlock(struct XenosDevice *xe, struct XenosVertexBuffer *vb)
Definition: xe.c:1997
void Xe_pStuff(struct XenosDevice *xe)
Definition: xe.c:1233
#define RPTR_WRITEBACK
Definition: xe.c:18
void Xe_SetZFunc(struct XenosDevice *xe, int z_func)
Definition: xe.c:1423
void Xe_pSetIndexOffset(struct XenosDevice *xe, int offset)
Definition: xe.c:202
void Xe_pInvalidateGpuCache(struct XenosDevice *xe, int base, int size)
Definition: xe.c:732
void Xe_pWaitReady2(struct XenosDevice *xe)
Definition: xe.c:265
void Xe_SetAlphaRef(struct XenosDevice *xe, float alpharef)
Definition: xe.c:1528
void Xe_SetStencilWriteMask(struct XenosDevice *xe, int bfff, int writemask)
Definition: xe.c:1623
void Xe_pRBCommitPrimary(struct XenosDevice *xe)
Definition: xe.c:97
void Xe_Clear(struct XenosDevice *xe, int flags)
Definition: xe.c:1167
void Xe_pWaitReady(struct XenosDevice *xe)
Definition: xe.c:255
void Xe_SetTexture(struct XenosDevice *xe, int index, struct XenosSurface *tex)
Definition: xe.c:1748
u32 Xe_pRBAlloc(struct XenosDevice *xe)
Definition: xe.c:149
#define RINGBUFFER_SECONDARY_GUARD
Definition: xe.c:23
void Xe_SetShader(struct XenosDevice *xe, int type, struct XenosShader *sh, int index)
Definition: xe.c:1665
void Xe_pGInit1(struct XenosDevice *xe, int arg)
Definition: xe.c:443
void Xe_pInitControl(struct XenosDevice *xe)
Definition: xe.c:1403
void Xe_pLoadUcodes(struct XenosDevice *xe, const u32 *ucode0, const u32 *ucode1)
Definition: xe.c:224
void Xe_pGInit(struct XenosDevice *xe)
Definition: xe.c:554
struct XenosSurface * Xe_CreateTexture(struct XenosDevice *xe, unsigned int width, unsigned int height, unsigned int levels, int format, int tiled)
Definition: xe.c:2066
void Xe_pInvalidateGpuCacheAll(struct XenosDevice *xe, int base, int size)
Definition: xe.c:742
void Xe_pDrawNonIndexed(struct XenosDevice *xe, int num_points, int primtype)
Definition: xe.c:183
#define DIRTY_FETCH
Definition: xe.h:257
#define XE_PRIMTYPE_LINELIST
Definition: xe.h:16
#define XE_FMT_MASK
Definition: xe.h:175
#define SHADER_TYPE_PIXEL
Definition: xe.h:12
#define DIRTY_ALU
Definition: xe.h:256
#define XE_FMT_8
Definition: xe.h:176
#define XE_FMT_16161616
Definition: xe.h:180
#define XE_TEXADDR_WRAP
Definition: xe.h:68
#define XE_PRIMTYPE_TRIANGLESTRIP
Definition: xe.h:20
#define XE_FMT_5551
Definition: xe.h:178
#define XE_PRIMTYPE_TRIANGLEFAN
Definition: xe.h:19
#define XE_PRIMTYPE_POINTLIST
Definition: xe.h:15
#define DIRTY_INTEGER
Definition: xe.h:259
#define XE_FMT_565
Definition: xe.h:179
#define XE_PRIMTYPE_TRIANGLELIST
Definition: xe.h:18
#define DIRTY_CLIP
Definition: xe.h:258
#define XE_PRIMTYPE_LINESTRIP
Definition: xe.h:17
#define XE_PRIMTYPE_QUADLIST
Definition: xe.h:22
#define XE_FMT_8888
Definition: xe.h:177
#define XE_PRIMTYPE_RECTLIST
Definition: xe.h:21
#define XE_CLEAR_DS
Definition: xe.h:312
#define XE_FMT_BGRA
Definition: xe.h:182
#define XE_MAX_INDICES_PER_DRAW
Definition: xe.h:10
#define SHADER_TYPE_VERTEX
Definition: xe.h:13
#define XE_LOCK_WRITE
Definition: xe.h:394
#define XE_SOURCE_COLOR
Definition: xe.h:308
#define DIRTY_MISC
Definition: xe.h:262
#define XE_CLEAR_COLOR
Definition: xe.h:311
#define DIRTY_CONTROL
Definition: xe.h:260
void const char * fmt
Definition: xe.h:303
#define XE_LOCK_READ
Definition: xe.h:393
#define XE_SHADER_MAX_INSTANCES
Definition: xe.h:97
#define DIRTY_SHADER
Definition: xe.h:261
#define rput32(d)
Definition: xe_internal.h:14
#define rput32p(d)
Definition: xe_internal.h:16
#define rputf(d)
Definition: xe_internal.h:18
#define w32(o, v)
Definition: xe_internal.h:21
#define r32(o)
Definition: xe_internal.h:20
#define rput(base, len)
Definition: xe_internal.h:15
u8 type
Definition: xenos_edid.h:1
u8 c
Definition: xenos_edid.h:7
union @15 data
u8 j
Definition: xenos_edid.h:10
__le16 m
Definition: xenos_edid.h:8
uint16_t u16
16bit unsigned integer
Definition: xetypes.h:13
uint32_t u32
32bit unsigned integer
Definition: xetypes.h:14