Added boot process information to help someone find out what really happens.
[bootos.git] / tools / netrpc / rsxtest.py
blob5f5a62f26a4cc39fe239729fbe52be6b494bb1ee
1 #!/usr/bin/python
3 # netrpc - use your PS3 as a slave for Python code
5 # Copyright (C) 2010-2011 Hector Martin "marcan" <hector@marcansoft.com>
7 # This code is licensed to you under the terms of the GNU GPL, version 2;
8 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10 import sys, time
11 import random, math
12 from netrpc import *
13 from rsxutil import *
15 ps3host = os.environ.get("PS3HOST", "ps3")
16 p = LV1Client(ps3host)
18 try:
19 p.lv1_gpu_close()
20 except LV1Error:
21 pass
23 p.lv1_gpu_open(0)
24 p.clr_mmio()
26 mem_handle, ddr_lpar = p.lv1_gpu_memory_allocate(254<<20, 0, 0, 0, 0);
27 p.add_mmio(ddr_lpar, 254<<20)
29 ctrl_size = 65536
30 ctx_handle, ctrl_lpar, drv_lpar, rep_lpar, rep_size = p.lv1_gpu_context_allocate(mem_handle, 0)
32 p.add_mmio(ctrl_lpar, ctrl_size)
34 print "Memory handle: 0x%x"%mem_handle
35 print "Context handle: 0x%x"%ctx_handle
37 xdr_lpar = None
38 try:
39 xdr_ioif = 0x0c000000
40 xdr_size = 1024*1024*16
41 xdr_lpar, muid = p.lv1_allocate_memory(xdr_size, 20, 0, 0)
43 fifo_size = 65536
44 fifo_ioif = xdr_ioif
45 fifo_lpar = xdr_lpar
47 xfb_size = xdr_size - fifo_size
48 xfb_ioif = xdr_ioif + fifo_size
49 xfb_lpar = xdr_lpar + fifo_size
51 p.lv1_gpu_context_iomap(ctx_handle, xdr_ioif, xdr_lpar, xdr_size, \
52 CBE_IOPTE_PP_W | CBE_IOPTE_PP_R | CBE_IOPTE_M)
54 #p.lv1_gpu_fb_setup(ctx_handle, fifo_lpar, fifo_size, fifo_ioif)
56 fifo = RSXFIFO(p, ctx_handle, ctrl_lpar, fifo_lpar, fifo_ioif, fifo_size)
57 fifo.show()
59 off = 0
60 fb = RSXFB(p, off, ddr_lpar, 800, 600)
61 off += fb.size
62 off = (off+0xff)&~0xff
63 fragprog_buf = RSXBuffer(p, off, ddr_lpar, 0x1000)
65 print "Clearing FB..."
66 p.memset32(ddr_lpar, ~0xdeadbeef, fb.size)
67 print "Testing FIFO..."
69 for i in range(0x1000):
70 fifo.nop()
72 fifo.fire()
73 fifo.wait()
74 fifo.show()
75 print "FIFO OK!"
77 print "Initializing 3D..."
79 render = RSX3D(fifo, fb, fragprog_buf)
80 render.tcl_init()
82 fifo.fire()
83 fifo.wait()
84 fifo.show()
86 print "Rendering some random triangles..."
88 render.begin_triangles()
90 vertices = [
91 (-0.5, -0.433),
92 (0.5, -0.433),
93 (0, 0.433),
96 for i in range(40):
97 cx = random.randrange(64, 512-64)
98 cy = random.randrange(64, 512-64)
99 cr = random.uniform(0, 2*math.pi)
100 size = 64
102 for x,y in vertices:
103 xp = x*math.cos(cr) - y*math.sin(cr)
104 yp = x*math.sin(cr) + y*math.cos(cr)
105 render.vertex3(xp*size + cx, yp*size + cy, 0)
107 render.end()
109 fifo.fire()
110 fifo.wait()
111 fifo.show()
112 print "Reading FB..."
114 #p.lv1_gpu_fb_blit(ctx_handle, 0, fifo_ioif, (fb.w<<16)|fb.h, fb.pitch)
116 fb.getimg().show()
118 finally:
119 p.lv1_gpu_close()
120 if xdr_lpar is not None:
121 p.lv1_release_memory(xdr_lpar)