mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
shader: Bug fix: Returning value's integer literals were wrong
This commit is contained in:
parent
f5829b2cf3
commit
0b1d29b6e7
@ -722,7 +722,7 @@ func (cs *compileState) parseBlock(outer *block, fname string, stmts []ast.Stmt,
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for _, stmt := range stmts {
|
for _, stmt := range stmts {
|
||||||
ss, ok := cs.parseStmt(block, fname, stmt, inParams)
|
ss, ok := cs.parseStmt(block, fname, stmt, inParams, outParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,16 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/shaderir"
|
"github.com/hajimehoshi/ebiten/internal/shaderir"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inParams []variable) ([]shaderir.Stmt, bool) {
|
func (cs *compileState) forceToInt(stmt ast.Stmt, expr *shaderir.Expr) bool {
|
||||||
|
if !canTruncateToInteger(expr.Const) {
|
||||||
|
cs.addError(stmt.Pos(), fmt.Sprintf("constant %s truncated to integer", expr.Const.String()))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
expr.ConstType = shaderir.ConstTypeInt
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inParams, outParams []variable) ([]shaderir.Stmt, bool) {
|
||||||
var stmts []shaderir.Stmt
|
var stmts []shaderir.Stmt
|
||||||
|
|
||||||
switch stmt := stmt.(type) {
|
switch stmt := stmt.(type) {
|
||||||
@ -78,13 +87,9 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
}
|
}
|
||||||
stmts = append(stmts, ss...)
|
stmts = append(stmts, ss...)
|
||||||
|
|
||||||
if rhs[0].Type == shaderir.NumberExpr {
|
if rhs[0].Type == shaderir.NumberExpr && ts[0].Main == shaderir.Int {
|
||||||
if ts[0].Main == shaderir.Int {
|
if !cs.forceToInt(stmt, &rhs[0]) {
|
||||||
if !canTruncateToInteger(rhs[0].Const) {
|
return nil, false
|
||||||
cs.addError(stmt.Pos(), fmt.Sprintf("constant %s truncated to integer", rhs[0].Const.String()))
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
rhs[0].ConstType = shaderir.ConstTypeInt
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +212,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
}
|
}
|
||||||
end := exprs[0].Exprs[1].Const
|
end := exprs[0].Exprs[1].Const
|
||||||
|
|
||||||
postSs, ok := cs.parseStmt(pseudoBlock, fname, stmt.Post, inParams)
|
postSs, ok := cs.parseStmt(pseudoBlock, fname, stmt.Post, inParams, outParams)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -386,6 +391,14 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
cs.addError(r.Pos(), "multiple-context with return is not implemented yet")
|
cs.addError(r.Pos(), "multiple-context with return is not implemented yet")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expr := exprs[0]
|
||||||
|
if expr.Type == shaderir.NumberExpr && outParams[i].typ.Main == shaderir.Int {
|
||||||
|
if !cs.forceToInt(stmt, &expr) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stmts = append(stmts, shaderir.Stmt{
|
stmts = append(stmts, shaderir.Stmt{
|
||||||
Type: shaderir.Assign,
|
Type: shaderir.Assign,
|
||||||
Exprs: []shaderir.Expr{
|
Exprs: []shaderir.Expr{
|
||||||
@ -393,7 +406,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
|
|||||||
Type: shaderir.LocalVariable,
|
Type: shaderir.LocalVariable,
|
||||||
Index: len(inParams) + i,
|
Index: len(inParams) + i,
|
||||||
},
|
},
|
||||||
exprs[0],
|
expr,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
2
internal/shader/testdata/number.expected.vs
vendored
2
internal/shader/testdata/number.expected.vs
vendored
@ -43,6 +43,6 @@ void F2(out float l0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void F3(out int l0) {
|
void F3(out int l0) {
|
||||||
l0 = 1.0;
|
l0 = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user