From e9a020f774b81a9eab79fff2f53eed9d15c6c128 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 11 Apr 2021 19:58:55 +0200 Subject: [PATCH] gpu/internal/convertshaders: build compute shaders in HLSL cs_5_0 profile The recent changes to the compute shaders have fixed all errors previously reported by fxc. Switch from dxc to fxc to target shader model 5.0, supported by Direct3D 11. Because we know dxc must be available, always build compute shaders even though the result is not yet used. Signed-off-by: Elias Naur --- gpu/internal/convertshaders/hlsl.go | 2 ++ gpu/internal/convertshaders/main.go | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gpu/internal/convertshaders/hlsl.go b/gpu/internal/convertshaders/hlsl.go index 107fa271..a0079257 100644 --- a/gpu/internal/convertshaders/hlsl.go +++ b/gpu/internal/convertshaders/hlsl.go @@ -46,6 +46,8 @@ func (fxc *FXC) Compile(path, variant string, input []byte, entryPoint string, p profile = "ps_" + profileVersion case ".vert": profile = "vs_" + profileVersion + case ".comp": + profile = "cs_" + profileVersion default: return "", fmt.Errorf("unrecognized shader type %s", path) } diff --git a/gpu/internal/convertshaders/main.go b/gpu/internal/convertshaders/main.go index e55645ea..40183554 100644 --- a/gpu/internal/convertshaders/main.go +++ b/gpu/internal/convertshaders/main.go @@ -81,7 +81,6 @@ type Converter struct { glslvalidator *GLSLValidator spirv *SPIRVCross fxc *FXC - dxc *DXC } func NewConverter(workDir WorkDir, packageName, shadersDir string, directCompute bool) *Converter { @@ -99,18 +98,13 @@ func NewConverter(workDir WorkDir, packageName, shadersDir string, directCompute conv.glslvalidator = NewGLSLValidator() conv.spirv = NewSPIRVCross() conv.fxc = NewFXC() - conv.dxc = NewDXC() verifyBinaryPath(&conv.glslvalidator.Bin) verifyBinaryPath(&conv.spirv.Bin) - if directCompute { - verifyBinaryPath(&conv.dxc.Bin) - } // We cannot check fxc since it may depend on wine. conv.glslvalidator.WorkDir = workDir.Dir("glslvalidator") conv.fxc.WorkDir = workDir.Dir("fxc") - conv.dxc.WorkDir = workDir.Dir("dxc") conv.spirv.WorkDir = workDir.Dir("spirv") return conv @@ -378,16 +372,17 @@ func (conv *Converter) ComputeShader(shaderPath string) ([]driver.ShaderSources, } sources.GLSL310ES = unixLineEnding(sources.GLSL310ES) - if conv.directCompute { - hlslSource, err := conv.spirv.Convert(shaderPath, "", spirv, "hlsl", "50") - if err != nil { - return nil, fmt.Errorf("failed to convert hlsl compute shader %q: %w", shaderPath, err) - } + hlslSource, err := conv.spirv.Convert(shaderPath, "", spirv, "hlsl", "50") + if err != nil { + return nil, fmt.Errorf("failed to convert hlsl compute shader %q: %w", shaderPath, err) + } - sources.HLSL, err = conv.dxc.Compile(shaderPath, "0", []byte(hlslSource), "main", "cs_5_0") - if err != nil { - return nil, fmt.Errorf("failed to compile hlsl compute shader %q: %w", shaderPath, err) - } + dxil, err := conv.fxc.Compile(shaderPath, "0", []byte(hlslSource), "main", "5_0") + if err != nil { + return nil, fmt.Errorf("failed to compile hlsl compute shader %q: %w", shaderPath, err) + } + if conv.directCompute { + sources.HLSL = dxil } return []driver.ShaderSources{sources}, nil