diff options
| author | Yong He <yonghe@outlook.com> | 2024-05-03 12:18:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-03 12:18:47 -0700 |
| commit | 47a917c964f4fda32d75f200efe863f6d68c737c (patch) | |
| tree | 0957d915e937113af1322e5c0179012074fa7976 | |
| parent | 13250ffa4d54c4e51b0a6473927e50a5da351ab3 (diff) | |
Fix `Ptr::__subscript` to accept any integer index. (#4100)
* Fix `Ptr::__subscript` to accept any integer index.
* Fix `Ptr::__subscript` to allow 64bit indices.
| -rw-r--r-- | source/slang/core.meta.slang | 3 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang-parser.cpp | 1 | ||||
| -rw-r--r-- | tests/spirv/ptr-subscript.slang | 12 |
4 files changed, 19 insertions, 1 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index e6a98bc40..3fc2fc570 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -694,7 +694,8 @@ struct Ptr __intrinsic_op($(kIROp_CastIntToPtr)) __init(int64_t val); - __subscript(int index) -> T + __generic<TInt : __BuiltinIntegerType> + __subscript(TInt index) -> T { __intrinsic_op($(kIROp_GetOffsetPtr)) ref; diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 2bf5f1e96..a8cf11cdc 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -10050,6 +10050,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> { return ensureDecl(context, typedefDecl); } + else if (auto subscriptDecl = as<SubscriptDecl>(genDecl->inner)) + { + return ensureDecl(context, subscriptDecl); + } SLANG_RELEASE_ASSERT(false); UNREACHABLE_RETURN(LoweredValInfo()); } diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index ad0398e2f..d90e541f8 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -4311,6 +4311,7 @@ namespace Slang case ASTNodeType::TypeAliasDecl: case ASTNodeType::TypeDefDecl: case ASTNodeType::ExtensionDecl: + case ASTNodeType::SubscriptDecl: return true; default: return false; diff --git a/tests/spirv/ptr-subscript.slang b/tests/spirv/ptr-subscript.slang new file mode 100644 index 000000000..0b30fe98e --- /dev/null +++ b/tests/spirv/ptr-subscript.slang @@ -0,0 +1,12 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -entry main -stage compute -emit-spirv-directly + +// CHECK: OpEntryPoint + +ConstantBuffer<Ptr<int>> cbPtr; +void main(int id : SV_DispatchThreadID) +{ + // Check that the index operand is translated directly into a 64bit integer + // in th resulting SPIR-V without any truncations. + // CHECK: OpPtrAccessChain %_ptr_PhysicalStorageBuffer_int %{{.*}} %long_123 + cbPtr[123ll] = 4; +} |
