mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/shaderir/msl: always use the same function names
This commit is contained in:
parent
a176694dfb
commit
a4abc4472b
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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] += ","
|
||||
|
Loading…
Reference in New Issue
Block a user