shaderir: Bug fix: Function prototypes were required for GLSL

Fixes #1267
This commit is contained in:
Hajime Hoshi 2020-07-27 23:51:05 +09:00
parent 5cf6c53418
commit a43efb66b2
30 changed files with 165 additions and 28 deletions

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
float l2 = float(0);
l2 = 0.0;

View File

@ -1,3 +1,6 @@
void F0(in vec2 l0, out vec4 l1);
void F1(out float l0, out float l1);
void F0(in vec2 l0, out vec4 l1) {
float l2 = float(0);
float l3 = float(0);

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
vec4 l2 = vec4(0);
{

View File

@ -1,3 +1,5 @@
void F0(out vec2 l0);
void F0(out vec2 l0) {
bool l1 = false;
l1 = true;

View File

@ -1,3 +1,5 @@
void F0(out bool l0);
void F0(out bool l0) {
l0 = true;
return;

View File

@ -1,3 +1,6 @@
void F0(in vec2 l0, out vec2 l1);
void F1(in vec2 l0, out vec2 l1);
void F0(in vec2 l0, out vec2 l1) {
vec2 l2 = vec2(0);
F1(l0, l2);

View File

@ -1,3 +1,6 @@
void F0(in vec2 l0, out vec2 l1);
void F1(in float l0, out float l1, out float l2);
void F0(in vec2 l0, out vec2 l1) {
float l2 = float(0);
float l3 = float(0);

View File

@ -1,3 +1,6 @@
void F0(in vec2 l0);
void F1(in float l0, in float l1, out float l2, out float l3);
void F0(in vec2 l0) {
float l1 = float(0);
float l2 = float(0);

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
vec4 l2 = vec4(0);
l2 = vec4(l0, 0.0, 1.0);

View File

@ -1,3 +1,6 @@
void F0(out vec2 l0);
void F1(out vec2 l0);
void F0(out vec2 l0) {
vec2 l1 = vec2(0);
vec2 l2 = vec2(0);

View File

@ -1,3 +1,6 @@
void F0(in vec2 l0, out vec4 l1);
void F1(out float l0, out float l1);
void F0(in vec2 l0, out vec4 l1) {
float l2 = float(0);
float l3 = float(0);

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
vec4 l2 = vec4(0);
l2 = (vec4(0.0)) * (vec4(0.0));

View File

@ -1,3 +1,5 @@
void F0(out vec2 l0);
void F0(out vec2 l0) {
vec2 l1 = vec2(0);
vec2 l3 = vec2(0);

View File

@ -1,3 +1,5 @@
void F0(out vec2 l0);
void F0(out vec2 l0) {
vec2 l1 = vec2(0);
vec2 l3 = vec2(0);

View File

@ -1,2 +1,4 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
}

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
l1 = vec4(l0, 0.0, 1.0);
return;

View File

@ -1,3 +1,5 @@
void F0(in vec4 l0, out float l1, out float l2, out float l3, out float l4);
void F0(in vec4 l0, out float l1, out float l2, out float l3, out float l4) {
l1 = (l0).x;
l2 = (l0).y;

View File

@ -1,3 +1,5 @@
void F0(out vec2 l0);
void F0(out vec2 l0) {
bool l1 = false;
l1 = true;

View File

@ -1,3 +1,5 @@
void F0(out vec2 l0);
void F0(out vec2 l0) {
bool l1 = false;
l1 = true;

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec2 l1);
void F0(in vec2 l0, out vec2 l1) {
vec2 l2 = vec2(0);
l2 = vec2(0.0);

View File

@ -1,3 +1,5 @@
void F0(out vec2 l0);
void F0(out vec2 l0) {
int l1 = 0;
int l2 = 0;

View File

@ -1,3 +1,5 @@
void F0(in vec4 l0, out vec4 l1);
void F0(in vec4 l0, out vec4 l1) {
vec4 l2 = vec4(0);
l2 = (mat4(1.0)) * (l0);

View File

@ -1,3 +1,8 @@
void F0(out vec2 l0);
void F1(out vec2 l0);
void F2(out float l0);
void F3(out int l0);
void F0(out vec2 l0) {
float l1 = float(0);
int l2 = 0;

View File

@ -1,3 +1,6 @@
void F0(out vec4 l0);
void F1(out vec4 l0);
void F0(out vec4 l0) {
int l1 = 0;
float l2 = float(0);

View File

@ -1,3 +1,6 @@
void F0(out vec4 l0);
void F1(out vec4 l0);
void F0(out vec4 l0) {
int l1 = 0;
int l2 = 0;

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
vec4 l2 = vec4(0);
l2 = vec4(l0, 0.0, 1.0);

View File

@ -1,3 +1,5 @@
void F0(in vec2 l0, out vec4 l1);
void F0(in vec2 l0, out vec4 l1) {
vec4 l2 = vec4(0);
vec4 l3 = vec4(0);

View File

@ -1,3 +1,7 @@
void F0(in vec2 l0, out vec4 l1);
void F1(in vec2 l0, out vec4 l1);
void F2(out vec2 l0, out vec2 l1);
void F0(in vec2 l0, out vec4 l1) {
vec2 l2 = vec2(0);
vec2 l3 = vec2(0);

View File

@ -91,11 +91,19 @@ func (p *Program) Glsl() (vertexShader, fragmentShader string) {
for i, t := range p.Varyings {
vslines = append(vslines, fmt.Sprintf("varying %s;", p.glslVarDecl(&t, fmt.Sprintf("V%d", i))))
}
if len(p.Funcs) > 0 {
if len(vslines) > 0 {
vslines = append(vslines, "")
}
}
for _, f := range p.Funcs {
vslines = append(vslines, p.glslFunc(&f, true)...)
}
for _, f := range p.Funcs {
if len(vslines) > 0 {
vslines = append(vslines, "")
}
vslines = append(vslines, p.glslFunc(&f)...)
vslines = append(vslines, p.glslFunc(&f, false)...)
}
if len(p.VertexFunc.Block.Stmts) > 0 {
@ -124,7 +132,13 @@ func (p *Program) Glsl() (vertexShader, fragmentShader string) {
if len(fslines) > 0 {
fslines = append(fslines, "")
}
fslines = append(fslines, p.glslFunc(&f)...)
fslines = append(fslines, p.glslFunc(&f, true)...)
}
for _, f := range p.Funcs {
if len(fslines) > 0 {
fslines = append(fslines, "")
}
fslines = append(fslines, p.glslFunc(&f, false)...)
}
if len(p.FragmentFunc.Block.Stmts) > 0 {
@ -211,7 +225,7 @@ func (p *Program) glslVarInit(t *Type) string {
}
}
func (p *Program) glslFunc(f *Func) []string {
func (p *Program) glslFunc(f *Func, prototype bool) []string {
var args []string
var idx int
for _, t := range f.InParams {
@ -227,8 +241,14 @@ func (p *Program) glslFunc(f *Func) []string {
argsstr = strings.Join(args, ", ")
}
sig := fmt.Sprintf("%s F%d(%s)", p.glslType(&f.Return), f.Index, argsstr)
var lines []string
lines = append(lines, fmt.Sprintf("%s F%d(%s) {", p.glslType(&f.Return), f.Index, argsstr))
if prototype {
lines = append(lines, fmt.Sprintf("%s;", sig))
return lines
}
lines = append(lines, fmt.Sprintf("%s {", sig))
lines = append(lines, p.glslBlock(&f.Block, &f.Block, 0, idx)...)
lines = append(lines, "}")

View File

@ -220,9 +220,13 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(void) {
GlslVS: `void F0(void);
void F0(void) {
}`,
GlslFS: `void F0(void) {
GlslFS: `void F0(void);
void F0(void) {
}`,
},
{
@ -242,9 +246,13 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) {
GlslVS: `void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3);
void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) {
}`,
GlslFS: `void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) {
GlslFS: `void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3);
void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) {
}`,
},
{
@ -266,10 +274,14 @@ varying vec3 V0;`,
},
},
},
GlslVS: `float F0(in float l0) {
GlslVS: `float F0(in float l0);
float F0(in float l0) {
return l0;
}`,
GlslFS: `float F0(in float l0) {
GlslFS: `float F0(in float l0);
float F0(in float l0) {
return l0;
}`,
},
@ -292,11 +304,15 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, out float l1) {
GlslVS: `void F0(in float l0, out float l1);
void F0(in float l0, out float l1) {
mat4 l2 = mat4(0);
mat4 l3 = mat4(0);
}`,
GlslFS: `void F0(in float l0, out float l1) {
GlslFS: `void F0(in float l0, out float l1);
void F0(in float l0, out float l1) {
mat4 l2 = mat4(0);
mat4 l3 = mat4(0);
}`,
@ -330,7 +346,9 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, out float l1) {
GlslVS: `void F0(in float l0, out float l1);
void F0(in float l0, out float l1) {
mat4 l2 = mat4(0);
mat4 l3 = mat4(0);
{
@ -338,7 +356,9 @@ varying vec3 V0;`,
mat4 l5 = mat4(0);
}
}`,
GlslFS: `void F0(in float l0, out float l1) {
GlslFS: `void F0(in float l0, out float l1);
void F0(in float l0, out float l1) {
mat4 l2 = mat4(0);
mat4 l3 = mat4(0);
{
@ -374,10 +394,14 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, in float l1, out float l2) {
GlslVS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
l2 = (l0) + (l1);
}`,
GlslFS: `void F0(in float l0, in float l1, out float l2) {
GlslFS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
l2 = (l0) + (l1);
}`,
},
@ -409,10 +433,14 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in bool l0, in float l1, in float l2, out float l3) {
GlslVS: `void F0(in bool l0, in float l1, in float l2, out float l3);
void F0(in bool l0, in float l1, in float l2, out float l3) {
l3 = (l0) ? (l1) : (l2);
}`,
GlslFS: `void F0(in bool l0, in float l1, in float l2, out float l3) {
GlslFS: `void F0(in bool l0, in float l1, in float l2, out float l3);
void F0(in bool l0, in float l1, in float l2, out float l3) {
l3 = (l0) ? (l1) : (l2);
}`,
},
@ -448,11 +476,15 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, in float l1, out vec2 l2) {
GlslVS: `void F0(in float l0, in float l1, out vec2 l2);
void F0(in float l0, in float l1, out vec2 l2) {
F1();
l2 = F2(l0, l1);
}`,
GlslFS: `void F0(in float l0, in float l1, out vec2 l2) {
GlslFS: `void F0(in float l0, in float l1, out vec2 l2);
void F0(in float l0, in float l1, out vec2 l2) {
F1();
l2 = F2(l0, l1);
}`,
@ -484,10 +516,14 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, in float l1, out float l2) {
GlslVS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
l2 = min(l0, l1);
}`,
GlslFS: `void F0(in float l0, in float l1, out float l2) {
GlslFS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
l2 = min(l0, l1);
}`,
},
@ -516,10 +552,14 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in vec4 l0, out vec2 l1) {
GlslVS: `void F0(in vec4 l0, out vec2 l1);
void F0(in vec4 l0, out vec2 l1) {
l1 = (l0).xz;
}`,
GlslFS: `void F0(in vec4 l0, out vec2 l1) {
GlslFS: `void F0(in vec4 l0, out vec2 l1);
void F0(in vec4 l0, out vec2 l1) {
l1 = (l0).xz;
}`,
},
@ -563,14 +603,18 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, in float l1, out float l2) {
GlslVS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
if ((l0) == (0.0)) {
l2 = l0;
} else {
l2 = l1;
}
}`,
GlslFS: `void F0(in float l0, in float l1, out float l2) {
GlslFS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
if ((l0) == (0.0)) {
l2 = l0;
} else {
@ -611,12 +655,16 @@ varying vec3 V0;`,
},
},
},
GlslVS: `void F0(in float l0, in float l1, out float l2) {
GlslVS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
for (int l3 = 0; l3 < 100; l3++) {
l2 = l0;
}
}`,
GlslFS: `void F0(in float l0, in float l1, out float l2) {
GlslFS: `void F0(in float l0, in float l1, out float l2);
void F0(in float l0, in float l1, out float l2) {
for (int l3 = 0; l3 < 100; l3++) {
l2 = l0;
}