diff --git a/internal/graphicsdriver/metal/shader_darwin.go b/internal/graphicsdriver/metal/shader_darwin.go index 5525534cf..428fab19f 100644 --- a/internal/graphicsdriver/metal/shader_darwin.go +++ b/internal/graphicsdriver/metal/shader_darwin.go @@ -63,21 +63,16 @@ func (s *Shader) Dispose() { } func (s *Shader) init(device mtl.Device) error { - const ( - v = "Vertex" - f = "Fragment" - ) - - src := msl.Compile(s.ir, v, f) + src := msl.Compile(s.ir) lib, err := device.MakeLibrary(src, mtl.CompileOptions{}) if err != nil { return fmt.Errorf("metal: device.MakeLibrary failed: %w, source: %s", err, src) } - vs, err := lib.MakeFunction(v) + vs, err := lib.MakeFunction(msl.VertexName) if err != nil { return fmt.Errorf("metal: lib.MakeFunction for vertex failed: %w, source: %s", err, src) } - fs, err := lib.MakeFunction(f) + fs, err := lib.MakeFunction(msl.FragmentName) if err != nil { return fmt.Errorf("metal: lib.MakeFunction for fragment failed: %w, source: %s", err, src) } diff --git a/internal/shader/shader_test.go b/internal/shader/shader_test.go index 45e5b0a43..fd4abaee1 100644 --- a/internal/shader/shader_test.go +++ b/internal/shader/shader_test.go @@ -195,7 +195,7 @@ func TestCompile(t *testing.T) { } if tc.Metal != nil { - m := msl.Compile(s, "Vertex", "Fragment") + m := msl.Compile(s) if got, want := metalNormalize(m), metalNormalize(string(tc.Metal)); got != want { compare(t, "Metal", got, want) } @@ -203,7 +203,7 @@ func TestCompile(t *testing.T) { // Just check that Compile doesn't cause panic. // TODO: Should the results be tested? - msl.Compile(s, "Vertex", "Fragmentp") + msl.Compile(s) }) } } diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index 8bb68bce0..f9cf78596 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -1088,7 +1088,7 @@ void main(void) { t.Errorf("%s fragment: got: %s, want: %s", tc.Name, got, want) } } - m := msl.Compile(&tc.Program, "Vertex", "Fragment") + m := msl.Compile(&tc.Program) if tc.Metal != "" { got := m want := tc.Metal + "\n" diff --git a/internal/shaderir/msl/msl.go b/internal/shaderir/msl/msl.go index 5951c9186..24a78a987 100644 --- a/internal/shaderir/msl/msl.go +++ b/internal/shaderir/msl/msl.go @@ -65,7 +65,12 @@ constexpr sampler texture_sampler{filter::nearest};` return str } -func Compile(p *shaderir.Program, vertex, fragment string) (shader string) { +const ( + VertexName = "Vertex" + FragmentName = "Fragment" +) + +func Compile(p *shaderir.Program) (shader string) { c := &compileContext{ structNames: map[string]string{}, } @@ -109,7 +114,7 @@ func Compile(p *shaderir.Program, vertex, fragment string) (shader string) { if p.VertexFunc.Block != nil && len(p.VertexFunc.Block.Stmts) > 0 { lines = append(lines, "") lines = append(lines, - fmt.Sprintf("vertex Varyings %s(", vertex), + fmt.Sprintf("vertex Varyings %s(", VertexName), "\tuint vid [[vertex_id]],", "\tconst device Attributes* attributes [[buffer(0)]]") for i, u := range p.Uniforms { @@ -132,7 +137,7 @@ func Compile(p *shaderir.Program, vertex, fragment string) (shader string) { if p.FragmentFunc.Block != nil && len(p.FragmentFunc.Block.Stmts) > 0 { lines = append(lines, "") lines = append(lines, - fmt.Sprintf("fragment float4 %s(", fragment), + fmt.Sprintf("fragment float4 %s(", FragmentName), "\tVaryings varyings [[stage_in]]") for i, u := range p.Uniforms { lines[len(lines)-1] += ","