internal/restorable: compile shaders in parallel

This commit is contained in:
Hajime Hoshi 2022-12-24 02:00:42 +09:00
parent 1b4f68d775
commit 71492554a7

View File

@ -17,6 +17,8 @@ package restorable
import ( import (
"fmt" "fmt"
"golang.org/x/sync/errgroup"
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader" "github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
"github.com/hajimehoshi/ebiten/v2/internal/graphics" "github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand" "github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
@ -54,18 +56,24 @@ var (
) )
func init() { func init() {
{ var wg errgroup.Group
wg.Go(func() error {
ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false))) ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false)))
if err != nil { if err != nil {
panic(fmt.Sprintf("restorable: compiling the nearest shader failed: %v", err)) return fmt.Errorf("restorable: compiling the nearest shader failed: %w", err)
} }
NearestFilterShader = NewShader(ir) NearestFilterShader = NewShader(ir)
} return nil
{ })
wg.Go(func() error {
ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterLinear, builtinshader.AddressUnsafe, false))) ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterLinear, builtinshader.AddressUnsafe, false)))
if err != nil { if err != nil {
panic(fmt.Sprintf("restorable: compiling the linear shader failed: %v", err)) return fmt.Errorf("restorable: compiling the linear shader failed: %w", err)
} }
LinearFilterShader = NewShader(ir) LinearFilterShader = NewShader(ir)
return nil
})
if err := wg.Wait(); err != nil {
panic(err)
} }
} }