Skip to content

Commit ca85e6e

Browse files
authored
Merge pull request #28 from ps2dev/cmake
Migrate to CMake; integrate openvcl+masp for all 13 VU1 renderers
2 parents 6929c50 + 1769a9d commit ca85e6e

36 files changed

Lines changed: 1281 additions & 1164 deletions

.github/workflows/compilation.yml

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,70 @@ jobs:
1313
container: ps2dev/ps2sdk:latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
17-
- name: Install dependencies
16+
17+
- name: Setup dependencies
1818
run: |
19-
apk add build-base git
19+
apk update
20+
apk add cmake build-base git make bash
21+
# Create /bin/bash symlink if it doesn't exist (Alpine installs to /usr/bin/bash)
22+
[ -f /bin/bash ] || ln -s /usr/bin/bash /bin/bash
2023
2124
- name: Install ps2stuff
2225
run: |
2326
git clone https://github.com/ps2dev/ps2stuff.git
24-
cd ps2stuff
25-
make -j $(getconf _NPROCESSORS_ONLN) clean
26-
make -j $(getconf _NPROCESSORS_ONLN) all
27-
make -j $(getconf _NPROCESSORS_ONLN) install
27+
cd ps2stuff
28+
git checkout cmake
29+
mkdir build
30+
cd build
31+
cmake ..
32+
make -j $(getconf _NPROCESSORS_ONLN)
33+
make install
2834
29-
- name: Compile project
35+
- name: Compile masp
3036
run: |
31-
make -j $(getconf _NPROCESSORS_ONLN) clean
32-
make -j $(getconf _NPROCESSORS_ONLN) all
33-
make -j $(getconf _NPROCESSORS_ONLN) install
37+
git clone https://github.com/fjtrujy/masp.git
38+
cd masp
39+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PS2DEV"
40+
cmake --build build -j $(getconf _NPROCESSORS_ONLN)
41+
cmake --install build
42+
43+
- name: Install openvcl
44+
run: |
45+
git clone https://github.com/fjtrujy/openvcl.git
46+
cd openvcl
47+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PS2DEV" -DBUILD_TESTING=OFF
48+
cmake --build build -j $(getconf _NPROCESSORS_ONLN)
49+
cmake --install build
50+
3451
35-
- name: Compile GLUT
52+
- name: Configure with CMake
3653
run: |
37-
cd glut
38-
make -j $(getconf _NPROCESSORS_ONLN) clean
39-
make -j $(getconf _NPROCESSORS_ONLN) all
40-
make -j $(getconf _NPROCESSORS_ONLN) install
41-
42-
- name: Compile examples
54+
mkdir build
55+
cd build
56+
cmake -DBUILD_GLUT=ON -DBUILD_EXAMPLES=ON ..
57+
58+
- name: Build project with CMake
4359
run: |
44-
cd examples
45-
cd box && make clean all && cd ..
46-
cd logo && make clean all && cd ..
47-
cd performance && make clean all && cd ..
48-
cd tricked_out && make clean all && cd ..
49-
cd nehe/lesson02 && make clean all && cd ../..
50-
cd nehe/lesson03 && make clean all && cd ../..
51-
cd nehe/lesson04 && make clean all && cd ../..
52-
cd nehe/lesson05 && make clean all && cd ../..
60+
cd build
61+
make -j $(getconf _NPROCESSORS_ONLN)
62+
63+
- name: Install libraries
64+
run: |
65+
cd build
66+
make -j $(getconf _NPROCESSORS_ONLN) install
67+
5368
69+
- name: Get short SHA
70+
id: slug
71+
run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT
5472

5573
- name: Upload artifacts
74+
if: ${{ success() }}
5675
uses: actions/upload-artifact@v4
5776
with:
58-
name: examples
77+
name: ps2gl-examples-${{ steps.slug.outputs.sha8 }}
5978
path: |
60-
examples/**/*.elf
61-
examples/**/*.gl
62-
examples/**/*.rtx
63-
examples/**/*.bin
79+
build/examples/*.elf
80+
build/examples/*.gl
81+
build/examples/*.rtx
82+
build/examples/*.bin

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ prebuilddone
1111
*.a
1212
*.elf
1313
*.orig
14+
15+
# CMake
16+
build/

CMAKE_BUILD.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Building ps2gl with CMake
2+
3+
This document describes how to build ps2gl using CMake instead of the traditional Makefile.
4+
5+
## Prerequisites
6+
7+
- PS2DEV environment installed and configured
8+
- `PS2DEV` environment variable set
9+
- CMake 3.13 or later
10+
- VU1 development tools (optional - see note below):
11+
- **Open-source tools (recommended):** `openvcl`, `masp`, `dvp-as`
12+
- **Proprietary tools (legacy):** `vcl`, `gasp`, `dvp-as`
13+
14+
**Note:**
15+
- VU1 tools are only required for building VU1 renderers from source
16+
- The build automatically detects and prefers open-source tools (`openvcl` + `masp`) over proprietary ones (`vcl` + `gasp`)
17+
- If VU1 tools are not available (e.g., on macOS), the build will automatically use pre-built `.vo` object files from the `vu1/` directory
18+
- Pre-built objects can be generated by running the build once with VU1 tools available
19+
- **OpenVCL compatibility**: all 13 renderers (including `indexed` and `scei`) now compile successfully with `openvcl` + `masp`. The proprietary `vcl` + `gasp` toolchain remains supported as a fallback, but is no longer required.
20+
21+
## Building
22+
23+
### Basic Build
24+
25+
```bash
26+
mkdir build
27+
cd build
28+
cmake ..
29+
make
30+
```
31+
32+
### Debug Build
33+
34+
To enable debug symbols and `_DEBUG` definition:
35+
36+
```bash
37+
cmake -DDEBUG=ON ..
38+
make
39+
```
40+
41+
### Building with Tests
42+
43+
To build the test executables (when available):
44+
45+
```bash
46+
cmake -DBUILD_TESTS=ON ..
47+
make
48+
```
49+
50+
## Installing
51+
52+
To install the library and headers to `$PS2SDK/ports`:
53+
54+
```bash
55+
make install
56+
```
57+
58+
This will:
59+
- Install `libps2gl.a` to `$PS2SDK/ports/lib/`
60+
- Install GL headers to `$PS2SDK/ports/include/GL/`
61+
- Install ps2gl headers to `$PS2SDK/ports/include/ps2gl/`
62+
63+
## Configuration Options
64+
65+
The following CMake options are available:
66+
67+
| Option | Default | Description |
68+
|--------|---------|-------------|
69+
| `DEBUG` | OFF | Enable debug build with `_DEBUG` definition |
70+
| `BUILD_TESTS` | OFF | Build test executables |
71+
| `BUILD_EXAMPLES` | OFF | Build the example ELFs under `examples/` |
72+
| `BUILD_GLUT` | ON | Build the GLUT-compat library |
73+
| `PS2GL_USE_SCE_VSM` | OFF | Bypass the .vcl pipeline; assemble Sony's reference VSMs (`vu1/sce_<X>_vcl.vsm`) directly with `dvp-as`. Diagnostic mode: lets us isolate "openvcl produces wrong VSMs" from "ps2gl host-side bug" by comparing the SCE-built ELF behavior against the openvcl-built one. |
74+
75+
## Build Flags
76+
77+
The CMake build automatically applies the following flags:
78+
79+
- `-DNO_VU0_VECTORS` - Disables VU0 vector code (currently broken)
80+
- `-DNO_ASM` - Disables assembly optimizations
81+
- `-Wno-strict-aliasing` - Suppresses strict aliasing warnings
82+
- `-Wno-conversion-null` - Suppresses conversion null warnings
83+
84+
## VU1 Renderer Pipeline
85+
86+
ps2gl includes VU1 assembly renderers that go through a complex preprocessing pipeline:
87+
88+
1. **Step 1**: Remove C preprocessor directives and fix include paths
89+
2. **Step 2**: `gasp`/`masp` assembler preprocessing
90+
3. **Step 3**: Array notation conversion
91+
4. **Step 4**: C preprocessor with memory layout headers
92+
5. **Step 5**: `vcl`/`openvcl` compiler generates `.vsm` files
93+
6. **Step 6**: `dvp-as` assembler generates `.vo` object files
94+
95+
The CMake build handles all these steps automatically for all 13 renderers:
96+
97+
- fast_nolights, fast
98+
- general, general_quad, general_tri
99+
- general_nospec, general_nospec_quad, general_nospec_tri
100+
- general_pv_diff, general_pv_diff_quad, general_pv_diff_tri
101+
- indexed
102+
- scei
103+
104+
All 13 build with either `openvcl + masp` (preferred) or `vcl + gasp` (legacy
105+
fallback). The output `.vsm` from the open pipeline can be compared against
106+
the in-tree Sony reference (`vu1/sce_*_vcl.vsm`) for validation.
107+
108+
## CMake Toolchain
109+
110+
The build uses the PS2DEV CMake toolchain file located at:
111+
```
112+
$PS2DEV/share/ps2dev.cmake
113+
```
114+
115+
This toolchain file is automatically detected when `PS2DEV` is set.
116+
117+
## Clean Build
118+
119+
To perform a clean build:
120+
121+
```bash
122+
rm -rf build
123+
mkdir build
124+
cd build
125+
cmake ..
126+
make
127+
```
128+
129+
## Comparison with Makefile Build
130+
131+
The CMake build produces the same output as the traditional Makefile:
132+
- Same compiler flags
133+
- Same source files
134+
- Same VU1 preprocessing pipeline
135+
- Same install locations
136+
- Compatible library format
137+
138+
## Migration Notes
139+
140+
The CMake build system was designed to be compatible with the existing Makefile build. Both build systems can coexist in the repository.
141+
142+
### Key Differences:
143+
144+
1. **Out-of-source builds**: CMake uses a separate `build/` directory
145+
2. **Dependency tracking**: CMake automatically handles dependencies
146+
3. **Parallel VU1 processing**: CMake can process multiple VU1 renderers in parallel
147+
4. **Cross-platform**: CMake can generate build files for different build systems
148+
149+
## Troubleshooting
150+
151+
### PS2DEV not found
152+
153+
If you get an error about PS2DEV not being set:
154+
155+
```bash
156+
export PS2DEV=/path/to/ps2dev
157+
export PS2SDK=$PS2DEV/ps2sdk
158+
```
159+
160+
### Toolchain file not found
161+
162+
Make sure the toolchain file exists at `$PS2DEV/share/ps2dev.cmake`.
163+
164+
### VU1 tools not found
165+
166+
Make sure the VU1 tools are in your PATH. For open-source tools:
167+
168+
```bash
169+
which openvcl masp dvp-as
170+
```
171+
172+
Or for proprietary tools:
173+
174+
```bash
175+
which vcl gasp dvp-as
176+
```
177+
178+
The `dvp-as` tool should be installed as part of PS2DEV. For `openvcl` and `masp`:
179+
- openvcl: https://github.com/ps2dev/openvcl
180+
- masp: https://github.com/AzagraMac/masp
181+
182+
### Build errors
183+
184+
Try a clean build:
185+
186+
```bash
187+
rm -rf build
188+
mkdir build
189+
cd build
190+
cmake ..
191+
make
192+
```
193+
194+
### VU1 preprocessing errors
195+
196+
If VU1 preprocessing fails, check that:
197+
1. All `.vcl` source files exist in `vu1/`
198+
2. Memory layout headers exist: `vu1/vu1_mem_linear.h` and `vu1/vu1_mem_indexed.h`
199+
3. VU1 tools are properly installed

0 commit comments

Comments
 (0)