diff options
| author | Gangzheng Tong <tonggangzheng@gmail.com> | 2025-07-25 10:56:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-25 17:56:50 +0000 |
| commit | c0726e1d571f7f319a244ee6a6ba1ed2c361e079 (patch) | |
| tree | ad6c5c3872b67a3b147aca285098862925b6f63e | |
| parent | c5091f0ae3a8b816af893e84ef289f745acf39dc (diff) | |
Fix for Generic Function Redefinition Error (#7891)
* emit literal values in getTypeNameHint for bool, str etc.
* add test for specializing generics with bool literals
* fix build error
* add specializing with Enum type test
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 24 | ||||
| -rw-r--r-- | tests/language-feature/generics/generic-interface-linkage-2.slang | 48 |
2 files changed, 72 insertions, 0 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index a1d043dff..9b852b803 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -719,6 +719,30 @@ void getTypeNameHint(StringBuilder& sb, IRInst* type) case kIROp_IntLit: sb << as<IRIntLit>(type)->getValue(); break; + case kIROp_BoolLit: + sb << (as<IRBoolLit>(type)->getValue() ? "true" : "false"); + break; + case kIROp_FloatLit: + sb << as<IRFloatLit>(type)->getValue(); + break; + case kIROp_StringLit: + { + auto stringLit = as<IRStringLit>(type); + sb << "\""; + sb << stringLit->getStringSlice(); + sb << "\""; + } + break; + case kIROp_VoidLit: + sb << "void"; + break; + case kIROp_PtrLit: + { + auto ptrLit = as<IRPtrLit>(type); + sb << "ptr_"; + sb << (UInt64)ptrLit->getValue(); + } + break; default: if (auto decor = type->findDecoration<IRNameHintDecoration>()) sb << decor->getName(); diff --git a/tests/language-feature/generics/generic-interface-linkage-2.slang b/tests/language-feature/generics/generic-interface-linkage-2.slang new file mode 100644 index 000000000..e10cb0348 --- /dev/null +++ b/tests/language-feature/generics/generic-interface-linkage-2.slang @@ -0,0 +1,48 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -compile-arg -obfuscate -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -compile-arg -obfuscate -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +float testBool<let doStuff : bool>() +{ + if (doStuff) + { + return 1.0; + } + else + { + return 2.0; + } +} + +enum Color { + RED, + GREEN +} + +float testEnum<let e : Color>() +{ + if (e == Color::RED) + { + return 3.0; + } + else + { + return 4.0; + } +} + +[shader("compute")] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + // CHECK: 1.0 + outputBuffer[0] = testBool<true>(); + // CHECK: 2.0 + outputBuffer[1] = testBool<false>(); + + // CHECK: 3.0 + outputBuffer[2] = testEnum<Color::RED>(); + // CHECK: 4.0 + outputBuffer[3] = testEnum<Color::GREEN>(); +} |
