Skip to content

Commit 3861c5e

Browse files
authored
[SPIR-V] disable validation on error (microsoft#6044)
When the codegen fails, it shows an error, but the SPIR-V validation still runs. Because the generation fails, the generated SPIR-V code could be invalid without it being a compiler bug. But the validation error message could confuse the user as it says this is a DXC bug. Signed-off-by: Nathan Gauër <[email protected]>
1 parent f0aed97 commit 3861c5e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,8 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
865865

866866
// Output the constructed module.
867867
std::vector<uint32_t> m = spvBuilder.takeModule();
868+
if (context.getDiagnostics().hasErrorOccurred())
869+
return;
868870

869871
// Check the existance of Texture and Sampler with
870872
// [[vk::combinedImageSampler]] for the same descriptor set and binding.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: not %dxc -T cs_6_6 -E main -enable-16bit-types %s -spirv 2>&1 | FileCheck %s
2+
3+
// This test is to make sure if the SPIR-V code generation returned an
4+
// error, the compilation fails, but the validation is not run.
5+
// If the validation runs on incomplete code, the user might get confused
6+
// as validation error after compilation are considered to be a actual bug.
7+
8+
RWBuffer<half> a;
9+
10+
RWBuffer<half> b;
11+
12+
struct S {
13+
float a;
14+
};
15+
16+
// CHECK: error: cannot instantiate RWBuffer with struct type 'S'
17+
RWBuffer<S> buff;
18+
19+
[numthreads(1, 1, 1)]
20+
void main() {
21+
// CHECK-NOT: fatal error: generated SPIR-V is invalid
22+
a[0] = b[0];
23+
}
24+

0 commit comments

Comments
 (0)