86w ago - Following up on
previous news and the
PS3 Linux kernel module, this weekend PlayStation 3 developer
gzorin (aka
Alexander Betts) has made available RSXGL - the RSX Graphics Library for PS3.
Download:
RSXGL GIT
To quote: RSXGL - The RSX Graphics Library
This library implements parts of the OpenGL 3.1 core profile specification for the PlayStation 3's RSX GPU. It's suitable for use in programs that have exclusive access to the RSX, such as GameOS software (and is likely unsuitable for implementing a multitasking desktop, as the library
doesn't arbitrate access to the RSX).
Please see the STATUS file for up-to-date information about the current capabilities of this library.
Briefly, the following OpenGL 3.1 features haven't been implemented yet (the RSX is capable of supporting most of them):
- Full GLSL support. Currently, GLSL and Cg shaders can be compiled offline and used with a OpenGL ES 2 style API.
- Instanced draw commands.
- Framebuffer objects and multiple render targets.
- glQuery*() objects.
- Point sprites.
- A variety of capabilities related to texture maps (rectangular and cube textures, the behavior of glPixelStore, copying from the framebuffer, mipmap generation, and texture formats, including compressed formats, that require conversion and/or swizzling).
- Client-side vertex array data. OpenGL 3.1's core profile specifically omits this, but it is specified by OpenGL ES 2 (as well as the OpenGL 3 compatibility profile), and is likely still widely used, particularly by smaller demonstration programs.
- Application object namespaces (another feature omitted by OpenGL 3.1, but used by earlier specs).
- Most glGet*() functions haven't been implemented. Some specified behavior of glEnable()/glDisable() likely needs to be implemented as well.
Further details follow:
This is admittedly a large area of missing capability. Currently you can compile GLSL (and Cg) programs offline using NVIDIA's cgc compiler, and use them in an OpenGL program via an API that resembles the OpenGL ES 2 API - glShaderBinary() is used to load shader objects, and exactly two such shader objects (a vertex program and a fragment program) can be linked together by glLinkProgram().
This project certainly hopes to extend its implementation of GLSL further.
Intel contributed a standalone GLSL compiler to Mesa which can emit two intermediate representations that maybe could be translated to the NVIDIA microcode used by the RSX (maybe this compiler does this already; I haven't looked in a few months). Perhaps this compiler could be made to run from within a PS3 program.
Another longer avenue would be to explore writing an NVIDIA microcode backend for the LLVM compiler (my own brief investigation of this suggests that this might be hard, as LLVM possibly requires that its targets model some sort of heap, which the NVIDIA cards don't do).
There are opportunities to creatively implement other, recent OpenGL features. Uniform buffer objects could be supported, since both the vertex and fragment stages of the RSX can fetch from floating point textures. Transform feedback might be implemented by having the GLSL compiler factor out the program paths that compute vertices and generate a separate "fragment" program that renders to a buffer. Newer pipeline stages, like tesselation and geometry programs, could possibly be executed on the PS3's SPU's.
The RSX can directly read from a handful of texture formats, but the OpenGL spec calls for many more besides. RSXGL currently implements only those formats whereby image data can simply be copied to the RSX's memory; other formats will require pixel-by-pixel type conversion and swizzling. The Mesa library appears to be able to perform many of these conversions.
- STREAMING, SYNCHRONIZATION, CACHING
Right now, RSXGL takes a conservative approach to handling data that streams to the GPU - if an application wants to write to an area of memory that the GPU is using, then the application will wait for the GPU to finish.
This library will implement other strategies. OpenGL specifies a few ways for an application to request synchronization behavior, but
affords implementations a wide latitude for interpreting such requests. Data stores might be partially or fully double-buffered, temporarily or for the entire lifetime of the memory area. Additionally, the PS3 itself makes two equally-sized memory areas available to the RSX, with different transfer speeds in each direction.
RSXGL takes a similarly greedy approach the flushing the GPU's vertex and texture caches - it does this every time a new glDraw*() command is sent by the application. The library will instead use the information it has available to it to determine if these caches really
ought to be flushed or not before drawing.
RSXGL performs the equivalent of a glFlush() when the framebuffer is flipped, and when the application needs to wait for the GPU to finish with a buffer before modifying its contents (in addition to the occasions when flushing is explicitly called for by a GL function
call).
I've noticed that whan a large-ish number of glDraw*() commands (on the order of several thousand) are submitted per frame without any additional flushing that performance degrades considerably. This particularly is the case if program uniform variables (such as an object's transformation matrix) are modified prior to each draw call. Therefore it's currently a good idea for the application to call glFlush() frequently.
Obviously this needs to be handled more transparently by the library itself, but I'm undecided as to a flushing policy - should it happen every draw call, or per a certain number of draw calls, or should it happen based upon the number of vertices being drawn, or the current size of the command buffer? (You can be assured that this will be an application-tunable setting.
I'm unclear as to how expensive an operation glFlush() is - it involves a small write by the PPU to the RSX's control register, allegedly a fast operation (reading from RSX memory by the PPU is not fast), but beyond that I don't know.
I haven't either tried to observe what happens when the command buffer's capacity is exceeded before the framebuffer is flipped (the libEGL implementation creates a command buffer with the capcity for 524288 commands, which is set in rsxgl_config.h and can be overriden at runtime by calling rsxeglInit() before initializing EGL).
The OpenGL ES 2 profile, as well as OpenGL profiles prior to version 3.1, allow an application to specify vertex data from the system's main memory, without specifically asking the library to create a buffer of some predetermined size. This usually requires the library
to implement some strategies to migrate client-side memory to the GPU, and there are likely many ways to try to perform this efficiently.
OpenGL 3.1 requires applications to create buffer objects for any vertex data (though not for index buffers; these can still be migrated
from client memory). This makes life easier for the library implementor, and is one reason why RSXGL implements GL 3.1 and not GL ES 2 (it also helps keep the data structures that the library allocates small).
Nonetheless, many existing programs depend upon the older spec, so it'd be good to support this in RSXGL (even if it's not super-efficient at first). Since supporting this older capability can potentially bloat RSXGL's data structures, this will likely be an
option specified when the library is configured.
Since client memory can be mapped into the RSX's address space, there will also be capability, implemented in the style of an OpenGL extension, for the application to promise that the client pointers submitted via glVertexArrayPointer are so mapped, eliminating a memcpy.
OpenGL 3.1 requires that applications call glGen*() functions to create the names for objects that get created. ES 2 and previous GL
versions made this optional, allowing the application to come up with any unsigned integers it wanted to name objects with. This change was another reason to implement OpenGL 3.1, because it allows for a faster pool-style allocation of object data structures instead of potentially requiring a costly data structure like an associative map.
The older behavior will be supported as a configure option, too, for compatibility with existing programs.
I'm interested in porting the [OpenGL Samples Pack] (http://www.g-truc.net/project-0026.html). They are small demonstration programs that are helpfully organized by the OpenGL profiles that they support.
INSTALL:
RSXGL uses the GNU autotools for its build system and is distributed with a configure script. It requires the following projects:
- [ps3toolchain](http://github.com/ps3dev/ps3toolchain)
- [PSL1GHT](http://github.com/ps3dev/PSL1GHT
NVIDIA's cgc shader compiler, from the Cg toolkit, is also required to use vertex and fragment GPU programs.
The RSXGL library depends upon a toolchain that can generate binaries for the PS3's PPU, and also upon parts of the PSL1GHT SDK. The sample programs also require a few ported libraries, such as libpng, which are provided by the ps3toolchain project. ps3toolchain recommends setting two environment variables to locate these dependencies:
export PS3DEV=/usr/local/ps3dev
export PSL1GHT=$PS3DEV
RSXGL's configure script will use these environment variables if they're set; if they aren't set, by default the script uses the above settings. The PORTLIBS environment variable may also be set to further control were the ported libraries can be found.
Anyway if these variables are set reasonably, then the following commands should build RSXGL and its samples:
./configure --prefix=/location/of/rsxgl
make
make install
(Sample programs are packaged into NPDRM packages, but those packages remain in their build locations; they don't get moved anywhere relative to RSXGL's install path).
By default, configure will create non-debug builds with low optimization settings (-O1). Other options are:
# Debug build, including assertions:
./configure --enable-debug
# Optimized build (-O3):
./configure --enable-ppu-optimize
The locations of the library's dependencies can be specified on the configure command-line, too:
./configure \
--with-ps3dev=/usr/local/ps3dev \
--with-psl1ght=/usr/local/ps3dev/libpsl1ght \
--with-portlibs=/usr/local/ps3dev/portlibs
The configure expects to find versions of the gcc, g++, ar, ranlib, and ld programs that target the PS3's PPU. It tries to find these in $PS3DEV/ppu/bin, but the following environment variables can be set to provide full paths to these programs to the configure script:
PPU_CC Location of C compiler
PPU_CXX Location of C++ compiler
PPU_AR Location of the ar archive utility
PPU_RANLIB Location of the ranlib utility
PPU_LD Location of the ld linker
The following environment variables can also be set to further influence how headers and libraries are located:
PS3DEV_PPU_CPPFLAGS
PS3DEV_PPU_LDFLAGS
PSL1GHT_PPU_CPPFLAGS
PSL1GHT_PPU_LDFLAGS
PORTLIBS_PPU_CPPFLAGS
PORTLIBS_PPU_LDFLAGS
Currently two sample programs are built:
- src/samples/rsxgltest - A very simple test program whose contents and behavior will vary. This program is mainly used to try out various features of the library as they are developed.
- src/samples/rsxglgears - A port of an old chestnut, the "glgears" program that uses OpenGL to render some spinning gears. This port is based upon a version included in the Mesa library, which was itself a port to OpenGL ES 2 after being handed down throughout the ages.
The sample can print debugging information over TCP, in the manner of PSL1GHT's network/debugtest sample. src/samples/rsxgltest/main.c has symbols called TEST_IP and TESTPORT which specify the IP address and port number to try to connect to, and you can use "nc -l portnum" to receive messages.
TO DO:
- Instanced rendering
- Framebuffer objects
- x glMapBuffer* should block if an operation on the buffer is still pending.
- Better-performing glMapBuffer.
- Less conservative approach to buffer mapping & GPU cache invalidation.
- (Finish) object "orphaning" (Programs orphanable, Disposal of orphaned objects)
- x Handle timestamp overflow
- Integer vertex specification.
Textures:
- format conversion (take this from mesa).
- test mipmapping
- cube maps
- rectangular textures (x implement glTexStorage*())
- implement glCopyTexImage*() and glCopyTexSubImage*()
- proxy textures
- implement the effects of glPixelStore
- Support for GLES2-style client vertex data.
- Support for GLES2-style application object namespaces.
- Implement glGet*() functions.
- More GLSL support.
- Make it possible to work with non-EGL configured display.
- Move object storage from globals to context.
- Support multiple contexts with shared objects.
- __restrict keyword where appropriate.
- x Add libstdc++.a to libGL.a, so that client code doesn't need to use g++ to link.
- oglsamples
- Flushing and orphan cleanup policy
- Vertex program textures
Download: https://github.com/gzorin/RSXGL/zipball/master / https://github.com/gzorin/RSXGL
From his blog: RSXGL Working and Usable
Hi everyone!
When the PS3 homebrew scene started, a lot of people were complaining that it wasn’t possible to write 3D games for the PS3 because of its lack of OpenGL library.
Almost a year ago, Alex Betts thought he would tackle this problem and he started working on RSXGL... an implementation of the OpenGL 3.1 specification written from scratch targeting the PS3′s RSX.
Anyone in their right mind would say that it’s impossible, that it’s too much work, but Alex spent the last year working on it, alone, until it became usable. You can read some news about it here.
For some reason though, no one used it to build their own apps. Maybe the status of the project was scaring them, it was said to be incomplete, there was no GLSL support, etc...
I am writing today to tell you that RSXGL is perfectly usable! It supports online GLSL compilation, as well as any feature you might want. As proof, I have written a new hardware accelerated engine for the EFL using RSXGL and it worked great!
Alex and I spent a lot of time testing and fixing all the issues that were in RSXGL that were made visible by the EFL’s GL engine and I am happy to say that it’s working now. Expedite is able to run most of its tests at 50 to 60 fps on 1080p resolution (instead of the average of 5 to 10 fps it had on 720p before).
You can see performance tests right here (Running some tests from expedite) :
Software rendering: dl.dropbox.com/u/22642664/expedite_psl1ght.log
eng_output_resize called : 1280x720
4.15 , Widgets File Icons
10.79 , Widgets File Icons 2
10.76 , Widgets File Icons 2 Grouped
11.66 , Widgets File Icons 2 Same
11.83 , Widgets File Icons 2 Same Grouped
16.90 , Widgets File Icons 3
11.23 , Widgets File Icons 4
10.11 , Widgets List
10.23 , Widgets List Grouped
10.18 , Widgets List 2
10.22 , Widgets List 2 Grouped
9.50 , Widgets List 3
9.59 , Widgets List 3 Grouped
9.66 , Widgets List 4
9.73 , Widgets List 4 Grouped
6.84 , Image Blend Unscaled
6.34 , Image Blend Solid Middle Unscaled
3.30 , Image Blend Fade Unscaled
3.30 , Image Blend Fade Power 2 Unscaled
32.39 , Image Blend Solid Unscaled
4.58 , Image Blend Solid Fade Unscaled
4.58 , Image Blend Solid Fade Power 2 Unscaled
2.11 , Image Blend Nearest Scaled
31.52 , Image Blend Nearest Solid Scaled
0.55 , Image Blend Smooth Scaled
9.62 , Image Blend Smooth Solid Scaled
14.08 , Image Blend Nearest Same Scaled
52.70 , Image Blend Nearest Solid Same Scaled
14.04 , Image Blend Smooth Same Scaled
59.43 , Image Blend Smooth Solid Same Scaled
0.66 , Image Blend Border
9.32 , Image Blend Solid Middle Border
11.40 , Image Blend Solid Border
0.54 , Image Blend Border Recolor
1.52 , Image Map Rotate
1.67 , Image Map Solid Rotate
5.53 , Image Map Nearest Rotate
8.17 , Image Map Nearest Solid Rotate
1.35 , Image Map Color Rotate
1.47 , Image Map Color Solid Rotate
3.02 , Image Map Color Nearest Rotate
3.67 , Image Map Color Nearest Solid Rotate
1.33 , Image Map Color Alpha Rotate
1.31 , Image Map Color Alpha Solid Rotate
2.91 , Image Map Color Alpha Nearest Rotate
2.84 , Image Map Color Alpha Nearest Solid Rotate
15.30 , Image Map 3D 1
7.79 , Image Map 3D 2
7.28 , Image Map 3D 3
3.61 , Image Map 3D 4
13.83 , Image Map 3D 5
31.59 , Image Map 3D 6
3.67 , Image Map 3D Flow
4.06 , Image Quality Scale
60.33 , Image Data ARGB
11.85 , Image Data ARGB Alpha
30.35 , Image Data YCbCr 601 Pointer List
14.44 , Image Data YCbCr 601 Pointer List Wide Stride
eng_output_resize called : 1280x720
EGL surface size is : 1280x720
5.43 , Widgets File Icons
28.61 , Widgets File Icons 2
35.00 , Widgets File Icons 2 Grouped
39.51 , Widgets File Icons 2 Same
48.14 , Widgets File Icons 2 Same Grouped
10.81 , Widgets File Icons 3
56.57 , Widgets File Icons 4
56.78 , Widgets List
58.22 , Widgets List Grouped
58.23 , Widgets List 2
58.25 , Widgets List 2 Grouped
56.10 , Widgets List 3
56.18 , Widgets List 3 Grouped
56.17 , Widgets List 4
56.18 , Widgets List 4 Grouped
51.26 , Image Blend Unscaled
11.30 , Image Blend Solid Middle Unscaled
60.63 , Image Blend Fade Unscaled
60.41 , Image Blend Fade Power 2 Unscaled
46.28 , Image Blend Solid Unscaled
60.82 , Image Blend Solid Fade Unscaled
60.42 , Image Blend Solid Fade Power 2 Unscaled
59.95 , Image Blend Nearest Scaled
57.85 , Image Blend Nearest Solid Scaled
60.29 , Image Blend Smooth Scaled
57.83 , Image Blend Smooth Solid Scaled
60.43 , Image Blend Nearest Same Scaled
59.88 , Image Blend Nearest Solid Same Scaled
60.49 , Image Blend Smooth Same Scaled
59.89 , Image Blend Smooth Solid Same Scaled
59.97 , Image Blend Border
38.29 , Image Blend Solid Middle Border
38.64 , Image Blend Solid Border
59.54 , Image Blend Border Recolor
60.45 , Image Map Rotate
60.43 , Image Map Solid Rotate
60.41 , Image Map Nearest Rotate
60.42 , Image Map Nearest Solid Rotate
60.40 , Image Map Color Rotate
60.43 , Image Map Color Solid Rotate
60.42 , Image Map Color Nearest Rotate
60.44 , Image Map Color Nearest Solid Rotate
60.40 , Image Map Color Alpha Rotate
60.42 , Image Map Color Alpha Solid Rotate
60.40 , Image Map Color Alpha Nearest Rotate
60.42 , Image Map Color Alpha Nearest Solid Rotate
49.76 , Image Map 3D 1
60.41 , Image Map 3D 2
60.26 , Image Map 3D 3
60.43 , Image Map 3D 4
49.40 , Image Map 3D 5
60.41 , Image Map 3D 6
27.65 , Image Map 3D Flow
57.00 , Image Quality Scale
50.69 , Image Data ARGB
16.60 , Image Data ARGB Alpha
58.65 , Image Data YCbCr 601 Pointer List
58.99 , Image Data YCbCr 601 Pointer List Wide Stride
59.13 , Image Data YCbCr 601 Pointer List Map Solid Rotate
59.01 , Image Data YCbCr 601 Pointer List Map Nearest Solid Rotate
50.49 , Image Crossfade
59.31 , Text Basic
6.87 , Text Styles
5.31 , Text Styles Different Strings
22.79 , Text Change
51.44 , Textblock Basic
61.10 , Textblock text_append
44.35 , Rect Blend
44.55 , Rect Blend Power 2
29.77 , Rect Solid
61.03 , Rect Blend Few
60.40 , Rect Blend Power 2 Few
60.41 , Rect Solid Few
51.14 , Image Blend Occlude 1 Few
60.90 , Image Blend Occlude 2 Few
61.87 , Image Blend Occlude 3 Few
65.58 , Image Blend Occlude 1
60.42 , Image Blend Occlude 2
60.39 , Image Blend Occlude 3
27.06 , Image Blend Occlude 1 Many
33.53 , Image Blend Occlude 2 Many
56.23 , Image Blend Occlude 3 Many
0.93 , Image Blend Occlude 1 Very Many
1.42 , Image Blend Occlude 2 Very Many
3.09 , Image Blend Occlude 3 Very Many
26.48 , Polygon Blend
60.46 , Image Blend Unscaled Proxy
25.86 , Proxy Text Fixed
RSXGL : github.com/gzorin/RSXGL
EFL : github.com/kakaroto/e17
Enjoy!
More PlayStation 3 News...
I can see this leading to lots of good things.