Update glsl

This commit is contained in:
Zyko 2024-04-08 23:43:19 +02:00
parent 577664c1cb
commit 280cc1a732
3 changed files with 9 additions and 6 deletions

View File

@ -823,9 +823,11 @@ func (cs *compileState) parseFunc(block *block, d *ast.FuncDecl) (function, bool
}
// The first out-param is treated as gl_FragColor in GLSL.
if outParams[0].typ.Main != shaderir.Vec4 {
cs.addError(d.Pos(), "fragment entry point must have at least one returning vec4 value for a color")
return function{}, false
for i := range outParams {
if outParams[i].typ.Main != shaderir.Vec4 {
cs.addError(d.Pos(), "fragment entry point must only have vec4 return values for colors")
return function{}, false
}
}
// Adjust the number of textures to write to
cs.ir.ColorsOutCount = len(outParams)

View File

@ -334,7 +334,8 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
case *ast.ReturnStmt:
if len(stmt.Results) != len(outParams) && len(stmt.Results) != 1 {
if !(len(stmt.Results) == 0 && len(outParams) > 0 && outParams[0].name != "") {
// Fragment function does not have to return a value due to discard
if fname != cs.fragmentEntry && !(len(stmt.Results) == 0 && len(outParams) > 0 && outParams[0].name != "") {
// TODO: Check variable shadowings.
// https://go.dev/ref/spec#Return_statements
cs.addError(stmt.Pos(), fmt.Sprintf("the number of returning variables must be %d but %d", len(outParams), len(stmt.Results)))

View File

@ -603,7 +603,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
}
case shaderir.Discard:
// 'discard' is invoked only in the fragment shader entry point.
lines = append(lines, idt+"discard;", idt+"return vec4(0.0);")
lines = append(lines, idt+"discard;") //, idt+"return vec4(0.0);")
default:
lines = append(lines, fmt.Sprintf("%s?(unexpected stmt: %d)", idt, s.Type))
}
@ -651,7 +651,7 @@ func adjustProgram(p *shaderir.Program) *shaderir.Program {
Main: shaderir.Vec4,
}
}
newP.FragmentFunc.Block.LocalVarIndexOffset += (p.ColorsOutCount-1)
newP.FragmentFunc.Block.LocalVarIndexOffset += (p.ColorsOutCount - 1)
newP.Funcs = append(newP.Funcs, shaderir.Func{
Index: funcIdx,