From bf0f3d304bd5c92f26d9df2b5591d1f848a255f1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 10 Jul 2022 02:54:16 +0900 Subject: [PATCH] internal/graphicsdriver/directx: add optimization flag to D3DCompile Updates #2034 Updates #2188 --- internal/graphicsdriver/directx/api_windows.go | 6 ++++++ internal/graphicsdriver/directx/pipeline_windows.go | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/graphicsdriver/directx/api_windows.go b/internal/graphicsdriver/directx/api_windows.go index 779a579ae..26d54872a 100644 --- a/internal/graphicsdriver/directx/api_windows.go +++ b/internal/graphicsdriver/directx/api_windows.go @@ -60,6 +60,12 @@ const ( _D3D12XBOX_DEFAULT_SIZE_BYTES = 0xffffffff ) +type _D3DCOMPILE uint32 + +const ( + _D3DCOMPILE_OPTIMIZATION_LEVEL3 _D3DCOMPILE = (1 << 15) +) + type _D3D_FEATURE_LEVEL int32 const ( diff --git a/internal/graphicsdriver/directx/pipeline_windows.go b/internal/graphicsdriver/directx/pipeline_windows.go index 2e68e0d31..ee649344b 100644 --- a/internal/graphicsdriver/directx/pipeline_windows.go +++ b/internal/graphicsdriver/directx/pipeline_windows.go @@ -555,8 +555,10 @@ 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", 0, 0) + 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) } @@ -566,7 +568,7 @@ func newShader(source []byte, defs []_D3D_SHADER_MACRO) (vsh, psh *_ID3DBlob, fe } }() - p, err := _D3DCompile(source, "shader", defs, nil, "PSMain", "ps_5_0", 0, 0) + 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) }