Emulator Issues #6742
closedShader Generator API
0%
Description
I've been seriously thinking about and toying with some code to create a API to a shader generator instead our current implementation of just writing straight text that can't get type-checked at all by the compiler. This has been hit multiple times by us where a typo has been in some obscure section of the shader that doesn't get hit very commonly.
My current implementations have been heavily based upon the IRBuilder used by the JITILs, either directly using the IRBuilder that is modified, or a new one that is based off of it. I feel now at this point that there could very well be a better way to go about it than the approach that I have gone with. I'll have at the bottom my current API and what it outputs.
I'm asking here is for someone to come up with a better API or to review the one I've currently got done. I know neobrain has an idea that could very well beat out my current one, so I'd like to hear opinions on this.
Current Test API:
IRBuilder build;
InstLoc uv = build.EmitUniformConst(CVec4, "uv");
build.EmitMainStart();
InstLoc ocol0 = build.EmitVec4Const(1.5, 1.0, 1.0, 1.0);
InstLoc ocol1 = build.EmitVec4Const(1.5, 1.0, 1.0, 1.0);
InstLoc ocolResult = build.EmitAdd(ocol0, ocol1);
InstLoc result = build.EmitAdd(ocolResult, uv);
build.EmitStoreOCol0(result);
build.EmitMainEnd();
printf("code:\n%s\n", WriteCode(&build).c_str());
Outputs:
code:
uniform vec4 uv;
void main() {
gl_FragColor = uv + vec4(3.000000, 2.000000, 2.000000, 2.000000);
}