diff options
| author | James Helferty (NVIDIA) <jhelferty@nvidia.com> | 2025-06-26 14:15:43 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-26 18:15:43 +0000 |
| commit | 78dc7c3fd1441ba756c969b81ed90600fa9f9f38 (patch) | |
| tree | 61e778010669795c36c61aa8433d8311813af3bb /source/slang | |
| parent | 1be819f4f0dbd001d1b222d7461a4fd87452dee2 (diff) | |
Hide atomics struct from reflection api (#7520)
* Atomic reflection unit test
Test that Atomic<int> is reflected as a scalar/int instead of a struct
named Atomic.
* Hide AtomicType from reflection
Leverage the fact that returned variables go through convert() to
centralize the unwrapping of the AtomicType struct.
Fixes #6257
* Clean up unit test a bit
- rename bar to buf (since one of them is not Atomic and thus not a
barrier)
- validate deeper into the fields of bufC
- remove debug code
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 8688f5e41..b0d88e954 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -40,6 +40,12 @@ static inline Type* convert(SlangReflectionType* type) static inline SlangReflectionType* convert(Type* type) { + // Prevent the AtomicType struct from being visible to the user + // through the reflection API. + if (auto atomicType = as<AtomicType>(type)) + { + return (SlangReflectionType*)atomicType->getElementType(); + } return (SlangReflectionType*)type; } @@ -586,7 +592,7 @@ SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionTy if (auto arrayType = as<ArrayExpressionType>(type)) { - return (SlangReflectionType*)arrayType->getElementType(); + return convert(arrayType->getElementType()); } else if (auto parameterGroupType = as<ParameterGroupType>(type)) { @@ -1026,7 +1032,7 @@ SLANG_API SlangReflectionType* spReflection_FindTypeByName( if (as<ErrorType>(result)) return nullptr; - return (SlangReflectionType*)result; + return convert(result); } catch (...) { @@ -1158,7 +1164,7 @@ SLANG_API SlangReflectionType* spReflectionTypeLayout_GetType( if (!typeLayout) return nullptr; - return (SlangReflectionType*)typeLayout->type; + return convert(typeLayout->type); } SLANG_API SlangTypeKind spReflectionTypeLayout_getKind(SlangReflectionTypeLayout* inTypeLayout) @@ -4227,7 +4233,7 @@ SLANG_API SlangReflectionType* spReflectionTypeParameter_GetConstraintByIndex( { auto constraints = globalGenericParamDecl->getMembersOfType<GenericTypeConstraintDecl>(); - return (SlangReflectionType*)constraints[index]->sup.Ptr(); + return convert(constraints[index]->sup.Ptr()); } // TODO: Add case for entry-point generic parameters. } |
