From 50bddbffca5e50e82741d2b203f74a94c009a17c Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Wed, 3 Aug 2022 21:40:46 +0000 Subject: [PATCH] tint: Fix dxc on Linux Fixes "dxc failed : unable to parse shader model.". On windows the called program is responsible for splitting arguments from one joined string. Command line arguments on 'nix systems need to be passed as separate strings. This CL makes it so that we pass in the arg separately, and support ignoring empty string args to make writing this code easier. Change-Id: Ia9618c2a743f8fdb49913572e2bbfc4bd1519d3a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98110 Reviewed-by: Ben Clayton Kokoro: Kokoro Reviewed-by: Dan Sinclair Commit-Queue: Antonio Maiorano --- src/tint/utils/io/command_posix.cc | 4 +++- src/tint/utils/io/command_windows.cc | 4 +++- src/tint/val/hlsl.cc | 19 +++++++------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/tint/utils/io/command_posix.cc b/src/tint/utils/io/command_posix.cc index ff0a138920..b3371e7613 100644 --- a/src/tint/utils/io/command_posix.cc +++ b/src/tint/utils/io/command_posix.cc @@ -251,7 +251,9 @@ Command::Output Command::Exec(std::initializer_list arguments) cons std::vector args; args.emplace_back(path_.c_str()); for (auto& arg : arguments) { - args.emplace_back(arg.c_str()); + if (!arg.empty()) { + args.emplace_back(arg.c_str()); + } } args.emplace_back(nullptr); auto res = execv(path_.c_str(), const_cast(args.data())); diff --git a/src/tint/utils/io/command_windows.cc b/src/tint/utils/io/command_windows.cc index 36c39c6f03..8c94e254f4 100644 --- a/src/tint/utils/io/command_windows.cc +++ b/src/tint/utils/io/command_windows.cc @@ -200,7 +200,9 @@ Command::Output Command::Exec(std::initializer_list arguments) cons std::stringstream args; args << path_; for (auto& arg : arguments) { - args << " " << arg; + if (!arg.empty()) { + args << " " << arg; + } } PROCESS_INFORMATION pi{}; diff --git a/src/tint/val/hlsl.cc b/src/tint/val/hlsl.cc index 6119570266..eabbe68488 100644 --- a/src/tint/val/hlsl.cc +++ b/src/tint/val/hlsl.cc @@ -69,21 +69,16 @@ Result HlslUsingDXC(const std::string& dxc_path, break; } - std::string profile = - "-T " + std::string(stage_prefix) + "_" + std::string(shader_model_version); - if (require_16bit_types) { - // Add "-enable-16bit-types" flag if required - profile = profile + " -enable-16bit-types"; - } - // Match Dawn's compile flags // See dawn\src\dawn_native\d3d12\RenderPipelineD3D12.cpp // and dawn_native\d3d12\ShaderModuleD3D12.cpp (GetDXCArguments) - auto res = dxc(profile.c_str(), - "-E " + ep.first, // Entry point - "/Zpr", // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR - "/Gis", // D3DCOMPILE_IEEE_STRICTNESS - file.Path()); + auto res = dxc( + "-T " + std::string(stage_prefix) + "_" + std::string(shader_model_version), // Profile + "-E " + ep.first, // Entry point + "/Zpr", // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR + "/Gis", // D3DCOMPILE_IEEE_STRICTNESS + require_16bit_types ? "-enable-16bit-types" : "", // Enable 16-bit if required + file.Path()); if (!res.out.empty()) { if (!result.output.empty()) { result.output += "\n";