mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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 {
|
func (s *Shader) init(device mtl.Device) error {
|
||||||
const (
|
src := msl.Compile(s.ir)
|
||||||
v = "Vertex"
|
|
||||||
f = "Fragment"
|
|
||||||
)
|
|
||||||
|
|
||||||
src := msl.Compile(s.ir, v, f)
|
|
||||||
lib, err := device.MakeLibrary(src, mtl.CompileOptions{})
|
lib, err := device.MakeLibrary(src, mtl.CompileOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("metal: device.MakeLibrary failed: %w, source: %s", err, src)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("metal: lib.MakeFunction for vertex failed: %w, source: %s", err, src)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("metal: lib.MakeFunction for fragment failed: %w, source: %s", err, src)
|
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 {
|
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 {
|
if got, want := metalNormalize(m), metalNormalize(string(tc.Metal)); got != want {
|
||||||
compare(t, "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.
|
// Just check that Compile doesn't cause panic.
|
||||||
// TODO: Should the results be tested?
|
// 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)
|
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 != "" {
|
if tc.Metal != "" {
|
||||||
got := m
|
got := m
|
||||||
want := tc.Metal + "\n"
|
want := tc.Metal + "\n"
|
||||||
|
@ -65,7 +65,12 @@ constexpr sampler texture_sampler{filter::nearest};`
|
|||||||
return str
|
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{
|
c := &compileContext{
|
||||||
structNames: map[string]string{},
|
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 {
|
if p.VertexFunc.Block != nil && len(p.VertexFunc.Block.Stmts) > 0 {
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
lines = append(lines,
|
lines = append(lines,
|
||||||
fmt.Sprintf("vertex Varyings %s(", vertex),
|
fmt.Sprintf("vertex Varyings %s(", VertexName),
|
||||||
"\tuint vid [[vertex_id]],",
|
"\tuint vid [[vertex_id]],",
|
||||||
"\tconst device Attributes* attributes [[buffer(0)]]")
|
"\tconst device Attributes* attributes [[buffer(0)]]")
|
||||||
for i, u := range p.Uniforms {
|
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 {
|
if p.FragmentFunc.Block != nil && len(p.FragmentFunc.Block.Stmts) > 0 {
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
lines = append(lines,
|
lines = append(lines,
|
||||||
fmt.Sprintf("fragment float4 %s(", fragment),
|
fmt.Sprintf("fragment float4 %s(", FragmentName),
|
||||||
"\tVaryings varyings [[stage_in]]")
|
"\tVaryings varyings [[stage_in]]")
|
||||||
for i, u := range p.Uniforms {
|
for i, u := range p.Uniforms {
|
||||||
lines[len(lines)-1] += ","
|
lines[len(lines)-1] += ","
|
||||||
|
Loading…
Reference in New Issue
Block a user