summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-06-27 11:28:14 -0400
committerGitHub <noreply@github.com>2023-06-27 11:28:14 -0400
commit1b01ff909afa1eb6700c0dc947e679b9c3890880 (patch)
treeac532105009303c65c5a6ad4f3dad8041c99e362 /tools
parent4c9e4de4b68f2612a39e8783e9da89605ecf54e0 (diff)
Pointer layout support (#2930)
* WIP looking at reflection with pointers. * Added GetPointerLayout. * Initial test via reflection with layout of ptr type. * WIP handles ptrs to types that have layout that hasn't been completed. * Move tests to ptr. * WIP try to take into account lowering correctly between AggTypeDecl and Type, but doesn't quite work. * WIP a different path to handling recursive lowering problem with Ptr. * Fix issues with reflection output. * Small tidy. * Fix for infinite recursion issue. * Lower IRPointerTypeLayout * Working with generics. Has a hack to work around Layout around Ptr in IR. The reflection around the generic - the name isn't much use, it should probably have the generic parameters, but that would require getName to do something more sophisticated. * Fix issue around calling finishOuterGenerics to early. * Remove feature/ptr test. * Fix type legalization being an infinite loop with Ptr self referencing. * Disable the pointer self reference test because produces an infintie loop on emit. * Fixed comment based on review. * Fix for issue with emit and pointers causing infinite recursion.
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx/cpu/cpu-device.cpp5
-rw-r--r--tools/gfx/cuda/cuda-device.cpp3
-rw-r--r--tools/slang-reflection-test/slang-reflection-test-main.cpp45
3 files changed, 53 insertions, 0 deletions
diff --git a/tools/gfx/cpu/cpu-device.cpp b/tools/gfx/cpu/cpu-device.cpp
index 0db2b0fa7..4b8595e82 100644
--- a/tools/gfx/cpu/cpu-device.cpp
+++ b/tools/gfx/cpu/cpu-device.cpp
@@ -45,6 +45,11 @@ namespace cpu
m_info.timestampFrequency = 1000000000;
}
+ // Can support pointers (or something akin to that)
+ {
+ m_features.add("has-ptr");
+ }
+
return SLANG_OK;
}
diff --git a/tools/gfx/cuda/cuda-device.cpp b/tools/gfx/cuda/cuda-device.cpp
index bbf50cc58..7f931afa1 100644
--- a/tools/gfx/cuda/cuda-device.cpp
+++ b/tools/gfx/cuda/cuda-device.cpp
@@ -185,6 +185,9 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
// CUDA has support for realtime clock
m_features.add("realtime-clock");
+
+ // Allows use of a ptr like type
+ m_features.add("has-ptr");
}
cudaDeviceProp deviceProps;
diff --git a/tools/slang-reflection-test/slang-reflection-test-main.cpp b/tools/slang-reflection-test/slang-reflection-test-main.cpp
index 94062cf2b..cd726eb59 100644
--- a/tools/slang-reflection-test/slang-reflection-test-main.cpp
+++ b/tools/slang-reflection-test/slang-reflection-test-main.cpp
@@ -292,6 +292,7 @@ static void emitReflectionVarBindingInfoJSON(
CASE(MIXED, mixed);
CASE(REGISTER_SPACE, registerSpace);
CASE(GENERIC, generic);
+
#undef CASE
default:
@@ -769,6 +770,16 @@ static void emitReflectionTypeInfoJSON(
emitReflectionTypeJSON(writer, arrayType->getElementType());
}
break;
+ case slang::TypeReflection::Kind::Pointer:
+ {
+ auto pointerType = type;
+ writer.maybeComma();
+ writer << "\"kind\": \"pointer\"";
+ writer.maybeComma();
+ writer << "\"targetType\": ";
+ emitReflectionTypeJSON(writer, pointerType->getElementType());
+ }
+ break;
case slang::TypeReflection::Kind::Struct:
{
@@ -888,6 +899,40 @@ static void emitReflectionTypeLayoutInfoJSON(
emitReflectionTypeInfoJSON(writer, typeLayout->getType());
break;
+ case slang::TypeReflection::Kind::Pointer:
+ {
+ auto valueTypeLayout = typeLayout->getElementTypeLayout();
+ SLANG_ASSERT(valueTypeLayout);
+
+ writer.maybeComma();
+ writer << "\"kind\": \"pointer\"";
+
+ writer.maybeComma();
+ writer << "\"valueType\": ";
+
+ auto typeName = valueTypeLayout->getType()->getName();
+
+ if (typeName && typeName[0])
+ {
+ // TODO(JS):
+ // We can't emit the type layout, because the type could contain
+ // a pointer and we end up in a recursive loop. For now we output the typename.
+ writer.writeEscapedString(UnownedStringSlice(typeName));
+ }
+ else
+ {
+ // TODO(JS): We will need to generate name that we will associate with this type
+ // as it doesn't seem to have one
+ writer.writeEscapedString(toSlice("unknown name!"));
+ SLANG_ASSERT(!"Doesn't have an associated name");
+ }
+
+ /*
+ emitReflectionTypeLayoutJSON(
+ writer,
+ valueTypeLayout); */
+ }
+ break;
case slang::TypeReflection::Kind::Array:
{
auto arrayTypeLayout = typeLayout;