From 8adcf250497b57cc7a67f226238c3a8f3ec59128 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 10 Apr 2021 12:54:58 +0200 Subject: [PATCH] gpu/internal/convertshaders: batch calls to winepath Wine tools can be slow to run, so it makes sense to batch their use. Fortunately, winepath supports resolving multiple paths in one execution. Signed-off-by: Elias Naur --- gpu/internal/convertshaders/hlsl.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gpu/internal/convertshaders/hlsl.go b/gpu/internal/convertshaders/hlsl.go index 0e6bcb45..9ccefdb5 100644 --- a/gpu/internal/convertshaders/hlsl.go +++ b/gpu/internal/convertshaders/hlsl.go @@ -117,12 +117,17 @@ func (dxc *DXC) Compile(path, variant string, input []byte, entryPoint string, p // winepath uses the winepath tool to convert a paths to Windows format. // The returned path can be used as arguments for Windows command line tools. func winepath(paths ...*string) error { + winepath := exec.Command("winepath", "--windows") for _, path := range paths { - out, err := exec.Command("winepath", "--windows", *path).Output() - if err != nil { - return fmt.Errorf("unable to run `winepath --windows %q`: %w", *path, err) - } - *path = strings.TrimSpace(string(out)) + winepath.Args = append(winepath.Args, *path) + } + out, err := winepath.Output() + if err != nil { + return fmt.Errorf("unable to run `winepath --windows`: %w", err) + } + winPaths := strings.Split(strings.TrimSpace(string(out)), "\n") + for i, path := range paths { + *path = winPaths[i] } return nil }