Skip to content

Commit

Permalink
[SPIR-V] Lower templated enums correctly. (#6768)
Browse files Browse the repository at this point in the history
Templated enums lowering was not supported. This commit fixes those
cases.

Fixes #6753

Signed-off-by: Nathan Gauër <[email protected]>
  • Loading branch information
Keenuts authored Jul 20, 2024
1 parent e0c83a8 commit 3508cdc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/clang/lib/SPIRV/LowerTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,14 @@ const SpirvType *LowerTypeVisitor::lowerType(QualType type,
return spvContext.getSIntType(32);
}

// Templated types.
if (const auto *spec = type->getAs<TemplateSpecializationType>()) {
return lowerType(spec->desugar(), rule, isRowMajor, srcLoc);
}
if (const auto *spec = type->getAs<SubstTemplateTypeParmType>()) {
return lowerType(spec->desugar(), rule, isRowMajor, srcLoc);
}

emitError("lower type %0 unimplemented", srcLoc) << type->getTypeClassName();
type->dump();
return 0;
Expand Down
29 changes: 29 additions & 0 deletions tools/clang/test/CodeGenSPIRV/type.enum.templated.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %dxc -T cs_6_6 -E main -spirv %s -fcgl | FileCheck %s

template<typename T>
void templated_func() {
T tmp;
}

template<typename T>
void templated_func_deduced(T tmp) {
}

enum MyEnum { };

template<typename T>
using TemplatedType = MyEnum;

[numthreads(1, 1, 1)]
void main() {
// CHECK: %a = OpVariable %_ptr_Function_int Function
TemplatedType<MyEnum> a;

// CHECK: OpFunctionCall %void %templated_func
templated_func<MyEnum>();

// CHECK: [[a:%[0-9]+]] = OpLoad %int %a
// CHECK: OpStore %param_var_tmp [[a]]
// CHECK: OpFunctionCall %void %templated_func_deduced %param_var_tmp
templated_func_deduced(a);
}

0 comments on commit 3508cdc

Please sign in to comment.