From 0371deef52c2ef9ffda3c5ec11f5b1082c0b96e8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 4 Mar 2024 14:15:22 -0800 Subject: Add user-guide section on pointers. (#3670) --- README.md | 2 ++ docs/user-guide/03-convenience-features.md | 15 +++++++++++++++ docs/user-guide/toc.html | 1 + 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 4df7214db..5489041dd 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ We also provide a few [examples](examples/) of how to integrate Slang into a ren These examples use a graphics layer that we include with Slang called "GFX" which is an abstraction library of various graphics APIs (D3D11, D2D12, OpenGL, Vulkan, CUDA, and the CPU) to support cross-platform applications using GPU graphics and compute capabilities. If you'd like to learn more about GFX, see the [GFX User Guide](https://shader-slang.com/slang/gfx-user-guide/index.html). +Additionally, we recommend checking out [Vulkan Mini Examples](https://github.com/nvpro-samples/vk_mini_samples/) for more examples of using Slang's language features available on Vulkan, such as pointers and the ray tracing intrinsics. + Contributing ------------ diff --git a/docs/user-guide/03-convenience-features.md b/docs/user-guide/03-convenience-features.md index 948400731..ca4635df4 100644 --- a/docs/user-guide/03-convenience-features.md +++ b/docs/user-guide/03-convenience-features.md @@ -361,6 +361,21 @@ float4 myPackedVector = reinterpret(myVal); `reinterpret` can pack any type into any other type as long as the target type is no smaller than the source type. +## Pointers + +Slang supports pointers when generating code for SPIRV, C++ and CUDA targets. The syntax for pointers is similar to C, with the exception that operator `.` can also be used to dereference a member. Slang currently does not support the `->` operator. +For example: +```csharp +int test(MyType* pObj) +{ + MyType* pNext = pObj + 1; + MyType* pNext = &pNext[1]; + return pNext.a + (*pNext).a + pNext[0].a; +} +``` + +Pointer types can also be specified using the generic syntax: `Ptr` is equivalent to `MyType*`. + ## `struct` inheritance (limited) Slang supports a limited form of inheritance. A derived `struct` type has all the members defined in the base type it is inherited from: diff --git a/docs/user-guide/toc.html b/docs/user-guide/toc.html index c9aa4cafb..3564ccf69 100644 --- a/docs/user-guide/toc.html +++ b/docs/user-guide/toc.html @@ -40,6 +40,7 @@
  • Subscript Operator
  • `Optional<T>` type
  • `reinterpret<T>` operation
  • +
  • Pointers
  • `struct` inheritance (limited)
  • Extensions
  • Multi-level break
  • -- cgit v1.2.3