internal/graphicsdriver/directx: call D3DCompile in parallel

D3DCompile can be very slow on some old machines.

See also https://bugs.chromium.org/p/angleproject/issues/detail?id=422
This commit is contained in:
Hajime Hoshi 2022-12-24 01:17:14 +09:00
parent de8184ac10
commit 1b4f68d775
3 changed files with 33 additions and 16 deletions

1
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/jfreymuth/oggvorbis v1.0.4
golang.org/x/image v0.2.0
golang.org/x/mobile v0.0.0-20221110043201-43a038452099
golang.org/x/sync v0.1.0
golang.org/x/sys v0.3.0
golang.org/x/tools v0.4.0
)

1
go.sum
View File

@ -44,6 +44,7 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -19,6 +19,8 @@ import (
"math"
"unsafe"
"golang.org/x/sync/errgroup"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
)
@ -377,28 +379,41 @@ func (p *pipelineStates) ensureRootSignature(device *_ID3D12Device) (rootSignatu
func newShader(source []byte, defs []_D3D_SHADER_MACRO) (vsh, psh *_ID3DBlob, ferr error) {
var flag uint32 = uint32(_D3DCOMPILE_OPTIMIZATION_LEVEL3)
// Create a shader
v, err := _D3DCompile(source, "shader", defs, nil, "VSMain", "vs_5_0", flag, 0)
if err != nil {
return nil, nil, fmt.Errorf("directx: D3DCompile for VSMain failed, original source: %s, %w", string(source), err)
}
defer func() {
if ferr != nil {
v.Release()
if ferr == nil {
return
}
if vsh != nil {
vsh.Release()
}
if psh != nil {
psh.Release()
}
}()
p, err := _D3DCompile(source, "shader", defs, nil, "PSMain", "ps_5_0", flag, 0)
if err != nil {
return nil, nil, fmt.Errorf("directx: D3DCompile for PSMain failed, original source: %s, %w", string(source), err)
}
defer func() {
if ferr != nil {
p.Release()
var wg errgroup.Group
wg.Go(func() error {
v, err := _D3DCompile(source, "shader", defs, nil, "VSMain", "vs_5_0", flag, 0)
if err != nil {
return fmt.Errorf("directx: D3DCompile for VSMain failed, original source: %s, %w", string(source), err)
}
}()
vsh = v
return nil
})
wg.Go(func() error {
p, err := _D3DCompile(source, "shader", defs, nil, "PSMain", "ps_5_0", flag, 0)
if err != nil {
return fmt.Errorf("directx: D3DCompile for PSMain failed, original source: %s, %w", string(source), err)
}
psh = p
return nil
})
return v, p, nil
if err := wg.Wait(); err != nil {
return nil, nil, err
}
return
}
func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3DBlob, blend graphicsdriver.Blend, stencilMode stencilMode, screen bool) (state *_ID3D12PipelineState, ferr error) {