Skip to content

[HLSL] Don't invoke dxv from clang-dxc for text output #135876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2025

Conversation

bogner
Copy link
Contributor

@bogner bogner commented Apr 15, 2025

Running clang-dxc with textual output was emitting various spurious warnings (if dxv wasn't on your path) or errors (if it was). Avoid these by not attempting to run this tool when it doesn't make sense to do so.

Fixes #135874.

Running `clang-dxc` with textual output was emitting various spurious
warnings (if `dxv` wasn't on your path) or errors (if it was). Avoid
these by not attempting to run this tool when it doesn't make sense to
do so.

Fixes llvm#135874.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' HLSL HLSL Language Support labels Apr 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 15, 2025

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang-driver

Author: Justin Bogner (bogner)

Changes

Running clang-dxc with textual output was emitting various spurious warnings (if dxv wasn't on your path) or errors (if it was). Avoid these by not attempting to run this tool when it doesn't make sense to do so.

Fixes #135874.


Full diff: https://github.com/llvm/llvm-project/pull/135876.diff

6 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+3)
  • (modified) clang/test/Driver/HLSL/metal-converter.hlsl (+6-4)
  • (modified) clang/test/Driver/dxc_D.hlsl (+1-1)
  • (modified) clang/test/Driver/dxc_dxv_path.hlsl (+3-3)
  • (modified) clang/test/Driver/dxc_options.hlsl (+1-2)
  • (modified) clang/test/Driver/hlsl-lang-targets.hlsl (+4-4)
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 22498bff1f251..59e9050af8a76 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -309,6 +309,9 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
 }
 
 bool HLSLToolChain::requiresValidation(DerivedArgList &Args) const {
+  if (!Args.hasArg(options::OPT_dxc_Fo))
+    return false;
+
   if (Args.getLastArg(options::OPT_dxc_disable_validation))
     return false;
 
diff --git a/clang/test/Driver/HLSL/metal-converter.hlsl b/clang/test/Driver/HLSL/metal-converter.hlsl
index 536f24be6e73b..3c4257b3fbb28 100644
--- a/clang/test/Driver/HLSL/metal-converter.hlsl
+++ b/clang/test/Driver/HLSL/metal-converter.hlsl
@@ -1,11 +1,13 @@
-// RUN: %clang_dxc -T cs_6_0 %s -metal -Fo %t.mtl -### 2>&1 | FileCheck %s
-// RUN: %clang_dxc -T cs_6_0 %s -metal -Vd -Fo %t.mtl -### 2>&1 | FileCheck %s
-// CHECK: "{{.*}}metal-shaderconverter{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}.mtl"
+// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv
+
+// RUN: env PATH="" %clang_dxc -T cs_6_0 %s -metal -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=NO_DXV %s
+// RUN: env PATH="" %clang_dxc -T cs_6_0 %s -metal -Vd -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=NO_DXV %s
+// RUN: env PATH="" %clang_dxc -T cs_6_0 %s --dxv-path=%T -metal -Vd -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=NO_DXV %s
+// NO_DXV: "{{.*}}metal-shaderconverter{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}.mtl"
 
 // RUN: %clang_dxc -T cs_6_0 %s -metal -### 2>&1 | FileCheck --check-prefix=NO_MTL %s
 // NO_MTL-NOT: metal-shaderconverter
 
-// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv
 // RUN: %clang_dxc -T cs_6_0 %s --dxv-path=%T -metal -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=DXV %s
 // DXV: "{{.*}}dxv{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}.dxo"
 // DXV: "{{.*}}metal-shaderconverter{{(.exe)?}}" "{{.*}}.dxo" "-o" "{{.*}}.mtl"
diff --git a/clang/test/Driver/dxc_D.hlsl b/clang/test/Driver/dxc_D.hlsl
index f32a22c503327..5737f0a819d47 100644
--- a/clang/test/Driver/dxc_D.hlsl
+++ b/clang/test/Driver/dxc_D.hlsl
@@ -1,5 +1,5 @@
 // RUN: %clang_dxc -DTEST=2 -Tlib_6_7 -### %s 2>&1 | FileCheck %s
-// RUN: %clang_dxc -DTEST=2  -Tlib_6_7 %s -fcgl -Fo - | FileCheck %s --check-prefix=ERROR
+// RUN: %clang_dxc -DTEST=2  -Tlib_6_7 %s | FileCheck %s --check-prefix=ERROR
 
 // Make sure -D send to cc1.
 // CHECK:"-D" "TEST=2"
diff --git a/clang/test/Driver/dxc_dxv_path.hlsl b/clang/test/Driver/dxc_dxv_path.hlsl
index 55a07f34a648e..65e386f2f35ab 100644
--- a/clang/test/Driver/dxc_dxv_path.hlsl
+++ b/clang/test/Driver/dxc_dxv_path.hlsl
@@ -1,10 +1,10 @@
-// RUN: %clang_dxc -I test -Tlib_6_3  -### %s 2>&1 | FileCheck %s
+// RUN: env PATH="" %clang_dxc -I test -Tlib_6_3 -Fo %T/a.dxo  -### %s 2>&1 | FileCheck %s
 
 // Make sure report warning.
 // CHECK:dxv not found
 
-// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv && %clang_dxc --dxv-path=%T %s -Tlib_6_3 -### 2>&1 | FileCheck %s --check-prefix=DXV_PATH
-// DXV_PATH:dxv{{(.exe)?}}" "-" "-o" "{{.*}}.dxo"
+// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv && %clang_dxc --dxv-path=%T %s -Tlib_6_3 -Fo %T/a.dxo -### 2>&1 | FileCheck %s --check-prefix=DXV_PATH
+// DXV_PATH:dxv{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}/a.dxo"
 
 // RUN: %clang_dxc -I test -Vd -Tlib_6_3  -### %s 2>&1 | FileCheck %s --check-prefix=VD
 // VD:"-cc1"{{.*}}"-triple" "dxilv1.3-unknown-shadermodel6.3-library"
diff --git a/clang/test/Driver/dxc_options.hlsl b/clang/test/Driver/dxc_options.hlsl
index 09fdba1c3dd5f..5026b75e52688 100644
--- a/clang/test/Driver/dxc_options.hlsl
+++ b/clang/test/Driver/dxc_options.hlsl
@@ -4,5 +4,4 @@
 // RUN: -fdiagnostics-color \
 // RUN: -fno-diagnostics-color \
 // RUN: -fdiagnostics-color=auto \
-// RUN: -Tlib_6_7 -Vd -fdriver-only -- %s 2>&1 |count 0
-
+// RUN: -Tlib_6_7 -fdriver-only -- %s 2>&1 |count 0
diff --git a/clang/test/Driver/hlsl-lang-targets.hlsl b/clang/test/Driver/hlsl-lang-targets.hlsl
index 7ce490a66df5f..b321b00548e9b 100644
--- a/clang/test/Driver/hlsl-lang-targets.hlsl
+++ b/clang/test/Driver/hlsl-lang-targets.hlsl
@@ -2,10 +2,10 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil--shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target dxil--shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target dxil-unknown-shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil--shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil--shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
 
 // Empty shader model
 //

@llvmbot
Copy link
Member

llvmbot commented Apr 15, 2025

@llvm/pr-subscribers-clang

Author: Justin Bogner (bogner)

Changes

Running clang-dxc with textual output was emitting various spurious warnings (if dxv wasn't on your path) or errors (if it was). Avoid these by not attempting to run this tool when it doesn't make sense to do so.

Fixes #135874.


Full diff: https://github.com/llvm/llvm-project/pull/135876.diff

6 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+3)
  • (modified) clang/test/Driver/HLSL/metal-converter.hlsl (+6-4)
  • (modified) clang/test/Driver/dxc_D.hlsl (+1-1)
  • (modified) clang/test/Driver/dxc_dxv_path.hlsl (+3-3)
  • (modified) clang/test/Driver/dxc_options.hlsl (+1-2)
  • (modified) clang/test/Driver/hlsl-lang-targets.hlsl (+4-4)
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index 22498bff1f251..59e9050af8a76 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -309,6 +309,9 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
 }
 
 bool HLSLToolChain::requiresValidation(DerivedArgList &Args) const {
+  if (!Args.hasArg(options::OPT_dxc_Fo))
+    return false;
+
   if (Args.getLastArg(options::OPT_dxc_disable_validation))
     return false;
 
diff --git a/clang/test/Driver/HLSL/metal-converter.hlsl b/clang/test/Driver/HLSL/metal-converter.hlsl
index 536f24be6e73b..3c4257b3fbb28 100644
--- a/clang/test/Driver/HLSL/metal-converter.hlsl
+++ b/clang/test/Driver/HLSL/metal-converter.hlsl
@@ -1,11 +1,13 @@
-// RUN: %clang_dxc -T cs_6_0 %s -metal -Fo %t.mtl -### 2>&1 | FileCheck %s
-// RUN: %clang_dxc -T cs_6_0 %s -metal -Vd -Fo %t.mtl -### 2>&1 | FileCheck %s
-// CHECK: "{{.*}}metal-shaderconverter{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}.mtl"
+// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv
+
+// RUN: env PATH="" %clang_dxc -T cs_6_0 %s -metal -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=NO_DXV %s
+// RUN: env PATH="" %clang_dxc -T cs_6_0 %s -metal -Vd -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=NO_DXV %s
+// RUN: env PATH="" %clang_dxc -T cs_6_0 %s --dxv-path=%T -metal -Vd -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=NO_DXV %s
+// NO_DXV: "{{.*}}metal-shaderconverter{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}.mtl"
 
 // RUN: %clang_dxc -T cs_6_0 %s -metal -### 2>&1 | FileCheck --check-prefix=NO_MTL %s
 // NO_MTL-NOT: metal-shaderconverter
 
-// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv
 // RUN: %clang_dxc -T cs_6_0 %s --dxv-path=%T -metal -Fo %t.mtl -### 2>&1 | FileCheck --check-prefix=DXV %s
 // DXV: "{{.*}}dxv{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}.dxo"
 // DXV: "{{.*}}metal-shaderconverter{{(.exe)?}}" "{{.*}}.dxo" "-o" "{{.*}}.mtl"
diff --git a/clang/test/Driver/dxc_D.hlsl b/clang/test/Driver/dxc_D.hlsl
index f32a22c503327..5737f0a819d47 100644
--- a/clang/test/Driver/dxc_D.hlsl
+++ b/clang/test/Driver/dxc_D.hlsl
@@ -1,5 +1,5 @@
 // RUN: %clang_dxc -DTEST=2 -Tlib_6_7 -### %s 2>&1 | FileCheck %s
-// RUN: %clang_dxc -DTEST=2  -Tlib_6_7 %s -fcgl -Fo - | FileCheck %s --check-prefix=ERROR
+// RUN: %clang_dxc -DTEST=2  -Tlib_6_7 %s | FileCheck %s --check-prefix=ERROR
 
 // Make sure -D send to cc1.
 // CHECK:"-D" "TEST=2"
diff --git a/clang/test/Driver/dxc_dxv_path.hlsl b/clang/test/Driver/dxc_dxv_path.hlsl
index 55a07f34a648e..65e386f2f35ab 100644
--- a/clang/test/Driver/dxc_dxv_path.hlsl
+++ b/clang/test/Driver/dxc_dxv_path.hlsl
@@ -1,10 +1,10 @@
-// RUN: %clang_dxc -I test -Tlib_6_3  -### %s 2>&1 | FileCheck %s
+// RUN: env PATH="" %clang_dxc -I test -Tlib_6_3 -Fo %T/a.dxo  -### %s 2>&1 | FileCheck %s
 
 // Make sure report warning.
 // CHECK:dxv not found
 
-// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv && %clang_dxc --dxv-path=%T %s -Tlib_6_3 -### 2>&1 | FileCheck %s --check-prefix=DXV_PATH
-// DXV_PATH:dxv{{(.exe)?}}" "-" "-o" "{{.*}}.dxo"
+// RUN: echo "dxv" > %T/dxv && chmod 754 %T/dxv && %clang_dxc --dxv-path=%T %s -Tlib_6_3 -Fo %T/a.dxo -### 2>&1 | FileCheck %s --check-prefix=DXV_PATH
+// DXV_PATH:dxv{{(.exe)?}}" "{{.*}}.obj" "-o" "{{.*}}/a.dxo"
 
 // RUN: %clang_dxc -I test -Vd -Tlib_6_3  -### %s 2>&1 | FileCheck %s --check-prefix=VD
 // VD:"-cc1"{{.*}}"-triple" "dxilv1.3-unknown-shadermodel6.3-library"
diff --git a/clang/test/Driver/dxc_options.hlsl b/clang/test/Driver/dxc_options.hlsl
index 09fdba1c3dd5f..5026b75e52688 100644
--- a/clang/test/Driver/dxc_options.hlsl
+++ b/clang/test/Driver/dxc_options.hlsl
@@ -4,5 +4,4 @@
 // RUN: -fdiagnostics-color \
 // RUN: -fno-diagnostics-color \
 // RUN: -fdiagnostics-color=auto \
-// RUN: -Tlib_6_7 -Vd -fdriver-only -- %s 2>&1 |count 0
-
+// RUN: -Tlib_6_7 -fdriver-only -- %s 2>&1 |count 0
diff --git a/clang/test/Driver/hlsl-lang-targets.hlsl b/clang/test/Driver/hlsl-lang-targets.hlsl
index 7ce490a66df5f..b321b00548e9b 100644
--- a/clang/test/Driver/hlsl-lang-targets.hlsl
+++ b/clang/test/Driver/hlsl-lang-targets.hlsl
@@ -2,10 +2,10 @@
 
 // Supported targets
 //
-// RUN: %clang -target dxil--shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target dxil--shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
-// RUN: %clang -target dxil-unknown-shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil--shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil--shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
 
 // Empty shader model
 //

Copy link
Contributor

@Icohedron Icohedron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Now I don't have to specify -Vd when I run clang-dxc without -Fo :)

@bogner bogner merged commit ad12323 into llvm:main Apr 16, 2025
9 of 12 checks passed
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
Running `clang-dxc` with textual output was emitting various spurious
warnings (if `dxv` wasn't on your path) or errors (if it was). Avoid
these by not attempting to run this tool when it doesn't make sense to
do so.

Fixes llvm#135874.
@damyanp damyanp moved this to Closed in HLSL Support Apr 25, 2025
@mstorsjo
Copy link
Member

These tests that run env PATH="" %clang_dxc ... are problematic for my setup for running tests on Windows.

In my builds, I'm building with a dynamically linked libc++.dll provided by my toolchain, which is available in $PATH, so the built bin/clang.exe requires finding this libc++.dll when executed. Normally this works fine, but when invoking tests that do env PATH="" %clang ... then %clang will run in an environment where it no longer finds its required libc++.dll in $PATH, and thus fails.

Previously, we've waived such issues by omitting that kind of tests on Windows (where setting PATH also affects where dependent libraries are found) by wrapping %if !system-windows %{ ... %} around those bits - see f5a93c5.

Would you find it ok to do the same here? As these tests relate to HLSL, they're a bit more relevant for running on Windows, but tests clearing PATH are problematic for builds with a dynamically linked dependency, unfortunately.

@mstorsjo
Copy link
Member

I guess another way about it, is to require me to copy in all dependent DLLs into the built bin directory next to clang.exe etc. But that's an extra step that hasn't been needed so far...

@mstorsjo
Copy link
Member

These tests that run env PATH="" %clang_dxc ... are problematic for my setup for running tests on Windows.

In my builds, I'm building with a dynamically linked libc++.dll provided by my toolchain, which is available in $PATH, so the built bin/clang.exe requires finding this libc++.dll when executed. Normally this works fine, but when invoking tests that do env PATH="" %clang ... then %clang will run in an environment where it no longer finds its required libc++.dll in $PATH, and thus fails.

Previously, we've waived such issues by omitting that kind of tests on Windows (where setting PATH also affects where dependent libraries are found) by wrapping %if !system-windows %{ ... %} around those bits - see f5a93c5.

Ping - any opinion on the above?

In theory, we'd have the same issue also for MSVC/clang-cl based builds with /MD (or CMAKE_MSVC_RUNTIME_LIBRARY= MultiThreadedDLL) - however there, the compiler support DLLs are found in systemwide default paths, so they're found even if running with a cleared PATH variable.

I've worked around this issue on my end for now by just manually copying in the host compiler DLL dependencies into the bin build directory before running tests. It works but it's not very pretty. (But if we deem this to be the way to go going forward, we should probably revert f5a93c5 as well.)

@damyanp damyanp removed this from HLSL Support Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL] clang-dxc emits dxv related warnings and errors when compiling to textual DXIL
5 participants