Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
545f9c1
WIP
snacchus Jan 29, 2025
59c8f69
WIP
snacchus Jan 31, 2025
097412e
Vertex attribute loaders
snacchus Feb 1, 2025
e5c5e11
fixes + attribute patches
snacchus Feb 9, 2025
d74a49a
fix vertex input
snacchus Mar 1, 2025
188b2fa
improve vector multiplication
snacchus Mar 1, 2025
d3335b6
fix dependency scanning of ctc2
snacchus Mar 1, 2025
7c47366
fix labels being removed
snacchus Mar 1, 2025
32e69f3
add -o cli param
snacchus Mar 1, 2025
facc094
support defines without value
snacchus Mar 1, 2025
9c211da
remove #defines from output
snacchus Mar 3, 2025
5155397
remove function label for shaders
snacchus Mar 3, 2025
f9e831e
Revert "remove #defines from output"
snacchus Mar 3, 2025
72a2f0d
revert package.json and yarn.lock
snacchus Mar 5, 2025
41d412a
Merge remote-tracking branch 'upstream/main' into magma
snacchus Nov 4, 2025
aa4db2a
Merge remote-tracking branch 'upstream/main' into magma
snacchus May 24, 2026
9a47477
fix null ref
snacchus May 24, 2026
1c9509a
fix merge
snacchus May 24, 2026
22a6cce
Merge remote-tracking branch 'upstream/main' into magma
snacchus Jun 4, 2026
f2fb12c
add tests for vector multiplications
snacchus Jun 5, 2026
53fb99e
add coverage report to .gitignore
snacchus Jun 5, 2026
d0238fc
add test for defines without value
snacchus Jun 5, 2026
ac55355
add tests for uniforms
snacchus Jun 5, 2026
de65502
fix annotations missing on declaration-assigment
snacchus Jun 6, 2026
1cb6752
add test for very large uniform binding number
snacchus Jun 6, 2026
c031b2e
add tests for attributes
snacchus Jun 6, 2026
24207eb
improve attribute tests
snacchus Jun 6, 2026
90cd2a0
add tests for shaders
snacchus Jun 6, 2026
393529e
add more general tests
snacchus Jun 6, 2026
7ee633d
Merge remote-tracking branch 'upstream/main' into magma
snacchus Jun 7, 2026
0acb0ce
fix tests after merge
snacchus Jun 7, 2026
3d106ce
revert pessimization
snacchus Jun 7, 2026
d9ea3d0
add magma info to Docs.md
snacchus Jun 7, 2026
2c653fb
add mgfx as magma example
snacchus Jun 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.parcel-cache
dist/
coverage/
node_modules
.vscode
.idea
66 changes: 66 additions & 0 deletions Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -855,5 +855,71 @@ Example:
asm_include("./some_ucode.inc");
```

## Magma
RSPL supports writing magma vertex shaders.
To enable magma mode, pass `--magma` on the command line.<br>
When this mode is enabled, different syntax becomes available and the file must be structured slightly differently.

### `shader`
This is a special function that must be defined exactly once in your file.<br>
In a magma vertex shader, there are no commands, but instead a single entry point.
This is the code that will be run whenever the shader is invoked.<br>
Example:
```c++
shader myshader()
{
// ...
}
```

### `uniform`
Uniforms are a type of state which can be used to provide constant values as input to the shader.<br>
Multiple uniforms can be defined, and each of them is assigned a binding number.<br>
Example:
```c++
uniform<0> MATRICES
{
vec16 MATRICES_MVP[4];
vec16 MATRICES_MV[4];
}
```

### `attribute`
This keyword is used to define the layout of input vertices.<br>
Multiple attributes can be defined, and each of them is assigned an input number.<br>
Attributes can be marked as optional.<br>
Example:
```c++
attribute<0> s16 POSITION[3];
attribute<1> u32 COLOR?; // use '?' to mark the attribute as optional
```

### `@AttrLoader(string)`
This annotation is used to mark an instruction as an attribute loader.<br>
Attribute loaders must be either scalar or vector load instructions, which is the case for any of the builtin `load()` functions.<br>
Magma will then automatically patch the offset of these instructions to the configured offset of the specified attribute.<br>
Therefore, the address register should point to the beginnning of a vertex, so that they load the value of the attribute.<br>
Pass the name of an attribute as the argument of the annotation.<br>
Example:
```c++
// No need to specify the offset, it will be automatically patched
@AttrLoader("POSITION") position.xyzw = load(vertex_ptr).xyzw;
```

### `@AttrPatch(string)`
This annotation is used to mark an instruction as an attribute patch.<br>
The string argument is the name of an attribute, plus an assembly instruction separated by a colon.<br>
When the patch is applied, the marked instruction is replaced by that assembly instruction.<br>
When an optional attribute is omitted, all patches of that attribute are applied.<br>
Example:
```c++
// When the COLOR attribute is omitted, this instruction gets replaced with vnop
@AttrPatch("COLOR:vnop") vrgba:sfract *= vrgba_in:sfract;
```

### Further restrictions
When magma mode is enabled, no commands may be defined.<br>
Also, any `state`, `data` or `bss` blocks may only contain `extern` labels.

## References
- <a href="https://emudev.org/2020/03/28/RSP.html" target="_blank">RSP Instruction Set</a>
16 changes: 13 additions & 3 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ let config = {
defines: {},
patchFunctions: [],
watch: false,
debugInfo: true
debugInfo: true,
magma: false
};

function getFunctionStartEnd(source, funcName) {
Expand Down Expand Up @@ -71,7 +72,16 @@ for(let i=3; i<process.argv.length; ++i) {
if(process.argv[i] === "-D") {
if(!process.argv[i+1])throw new Error("Missing define name/value in arguments!");
const [key, value] = process.argv[++i].split("=");
config.defines[key] = value;
config.defines[key] = value ?? "";
}

if (process.argv[i] === "-o") {
if(!process.argv[i+1])throw new Error("Missing output path in arguments!");
config.output = process.argv[++i]
}

if(process.argv[i] === "--magma") {
config.magma = true;
}
}

Expand All @@ -90,7 +100,7 @@ async function main() {
}
lastFileHash = fileHash;

const pathOut = process.argv[2].replace(".rspl", "") + ".S";
const pathOut = config.output ?? process.argv[2].replace(".rspl", "") + ".S";

const selfPath = process.argv.find(arg => arg.includes(".mjs"));
//const worker = new WorkerThreads(config.optimizeWorker, selfPath);
Expand Down
Loading
Loading