From 9d2178cf713613d61191ec0ee516207f185c63e1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 23 Apr 2023 22:57:30 +0900 Subject: [PATCH] internal/shaderir: rename the built-in func to get a texel to __texelAt --- internal/graphics/shader.go | 4 ++-- internal/shader/expr.go | 2 +- internal/shaderir/glsl/type.go | 2 +- internal/shaderir/hlsl/hlsl.go | 2 +- internal/shaderir/hlsl/type.go | 4 ++-- internal/shaderir/msl/msl.go | 2 +- internal/shaderir/msl/type.go | 4 ++-- internal/shaderir/program.go | 6 +++--- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/graphics/shader.go b/internal/graphics/shader.go index 704728103..95e1d2915 100644 --- a/internal/graphics/shader.go +++ b/internal/graphics/shader.go @@ -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) } diff --git a/internal/shader/expr.go b/internal/shader/expr.go index 96fd8ce2d..821a325a6 100644 --- a/internal/shader/expr.go +++ b/internal/shader/expr.go @@ -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 diff --git a/internal/shaderir/glsl/type.go b/internal/shaderir/glsl/type.go index 2b3b9e3d2..9363a45c6 100644 --- a/internal/shaderir/glsl/type.go +++ b/internal/shaderir/glsl/type.go @@ -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" } diff --git a/internal/shaderir/hlsl/hlsl.go b/internal/shaderir/hlsl/hlsl.go index ad251b5b0..32bec5e50 100644 --- a/internal/shaderir/hlsl/hlsl.go +++ b/internal/shaderir/hlsl/hlsl.go @@ -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:], ", ")) diff --git a/internal/shaderir/hlsl/type.go b/internal/shaderir/hlsl/type.go index e48db85fc..0e40883ad 100644 --- a/internal/shaderir/hlsl/type.go +++ b/internal/shaderir/hlsl/type.go @@ -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) } diff --git a/internal/shaderir/msl/msl.go b/internal/shaderir/msl/msl.go index c0dd14049..c618049c2 100644 --- a/internal/shaderir/msl/msl.go +++ b/internal/shaderir/msl/msl.go @@ -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:], ", ")) diff --git a/internal/shaderir/msl/type.go b/internal/shaderir/msl/type.go index e839b127a..561435e05 100644 --- a/internal/shaderir/msl/type.go +++ b/internal/shaderir/msl/type.go @@ -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) } diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index efde255dd..e3bd08b97 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -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