internal/shaderir: rename the built-in func to get a texel to __texelAt

This commit is contained in:
Hajime Hoshi 2023-04-23 22:57:30 +09:00
parent 49582519c1
commit 9d2178cf71
8 changed files with 13 additions and 13 deletions

View File

@ -91,14 +91,14 @@ func imageSrcRegionOnTexture() (vec2, vec2) {
shaderSuffix += fmt.Sprintf(`
func imageSrc%[1]dUnsafeAt(pos vec2) vec4 {
// pos is the position in positions of the source texture (= 0th image's texture).
return texture2D(__t%[1]d, %[2]s)
return __texelAt(__t%[1]d, %[2]s)
}
func imageSrc%[1]dAt(pos vec2) vec4 {
// pos is the position of the source texture (= 0th image's texture).
// If pos is in the region, the result is (1, 1). Otherwise, either element is 0.
in := step(__textureSourceRegionOrigin, pos) - step(__textureSourceRegionOrigin + __textureSourceRegionSize, pos)
return texture2D(__t%[1]d, %[2]s) * in.x * in.y
return __texelAt(__t%[1]d, %[2]s) * in.x * in.y
}
`, i, pos)
}

View File

@ -602,7 +602,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
return nil, nil, nil, false
}
t = shaderir.Type{Main: shaderir.Mat4}
case shaderir.Texture2DF:
case shaderir.TexelAt:
if len(args) != 2 {
cs.addError(e.Pos(), fmt.Sprintf("number of %s's arguments must be 2 but %d", callee.BuiltinFunc, len(args)))
return nil, nil, nil, false

View File

@ -121,7 +121,7 @@ func (c *compileContext) builtinFuncString(f shaderir.BuiltinFunc) string {
return "dFdx"
case shaderir.Dfdy:
return "dFdy"
case shaderir.Texture2DF:
case shaderir.TexelAt:
if c.unit == shaderir.Pixel {
return "texelFetch"
}

View File

@ -476,7 +476,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
if len(args) == 1 {
return fmt.Sprintf("float4x4FromScalar(%s)", args[0])
}
case shaderir.Texture2DF:
case shaderir.TexelAt:
switch c.unit {
case shaderir.Pixel:
return fmt.Sprintf("%s.Load(int3(%s, 0))", args[0], strings.Join(args[1:], ", "))

View File

@ -143,8 +143,8 @@ func (c *compileContext) builtinFuncString(f shaderir.BuiltinFunc) string {
return "ddx"
case shaderir.Dfdy:
return "ddy"
case shaderir.Texture2DF:
return "?(texture2D)"
case shaderir.TexelAt:
return "?(__texelAt)"
default:
return string(f)
}

View File

@ -401,7 +401,7 @@ func (c *compileContext) block(p *shaderir.Program, topBlock, block *shaderir.Bl
for _, exp := range e.Exprs[1:] {
args = append(args, expr(&exp))
}
if callee.Type == shaderir.BuiltinFuncExpr && callee.BuiltinFunc == shaderir.Texture2DF {
if callee.Type == shaderir.BuiltinFuncExpr && callee.BuiltinFunc == shaderir.TexelAt {
switch p.Unit {
case shaderir.Texel:
return fmt.Sprintf("%s.sample(texture_sampler, %s)", args[0], strings.Join(args[1:], ", "))

View File

@ -149,8 +149,8 @@ func builtinFuncString(f shaderir.BuiltinFunc) string {
return "float4x4"
case shaderir.Inversesqrt:
return "rsqrt"
case shaderir.Texture2DF:
return "?(texture2D)"
case shaderir.TexelAt:
return "?(__texelAt)"
}
return string(f)
}

View File

@ -276,11 +276,11 @@ const (
Reflect BuiltinFunc = "reflect"
Refract BuiltinFunc = "refract"
Transpose BuiltinFunc = "transpose"
Texture2DF BuiltinFunc = "texture2D"
Dfdx BuiltinFunc = "dfdx"
Dfdy BuiltinFunc = "dfdy"
Fwidth BuiltinFunc = "fwidth"
DiscardF BuiltinFunc = "discard"
TexelAt BuiltinFunc = "__texelAt"
)
func ParseBuiltinFunc(str string) (BuiltinFunc, bool) {
@ -334,11 +334,11 @@ func ParseBuiltinFunc(str string) (BuiltinFunc, bool) {
Reflect,
Refract,
Transpose,
Texture2DF,
Dfdx,
Dfdy,
Fwidth,
DiscardF:
DiscardF,
TexelAt:
return BuiltinFunc(str), true
}
return "", false