summaryrefslogtreecommitdiff
path: root/docs/user-guide/03-convenience-features.md
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-12-15 18:10:17 -0800
committerGitHub <noreply@github.com>2023-12-15 18:10:17 -0800
commiteb89ccb177881f10a4ac3f88fcbe033703d9ecd5 (patch)
tree54948a1d8d385331b9df6cae5f063dac029a6a52 /docs/user-guide/03-convenience-features.md
parentb507d881ca47135bfa46237767e7183f61e7d8e3 (diff)
Add doc for special scoping syntax. (#3416)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'docs/user-guide/03-convenience-features.md')
-rw-r--r--docs/user-guide/03-convenience-features.md56
1 files changed, 56 insertions, 0 deletions
diff --git a/docs/user-guide/03-convenience-features.md b/docs/user-guide/03-convenience-features.md
index eefd9fc63..2aea1fdff 100644
--- a/docs/user-guide/03-convenience-features.md
+++ b/docs/user-guide/03-convenience-features.md
@@ -460,3 +460,59 @@ by using the `[ForceInline]` decoration:
[ForceInline]
int f(int x) { return x + 1; }
```
+
+
+Special Scoping Syntax
+-------------------
+Slang supports three special scoping syntax to allow users to mix in custom decorators and content in the shader code. These constructs allow a rendering engine to define custom meta-data in the shader, or map engine-specific block syntax to a meaningful block that is understood by the compiler via proper `#define`s.
+
+### `__ignored_block`
+An ignored block will be parsed and ignored by the compiler:
+```
+__ignored_block
+{
+ arbitrary content in the source file,
+ will be ignored by the compiler as if it is a comment.
+ Can have nested {} here.
+}
+```
+
+### `__transparent_block`
+Symbols defined in a transparent block will be treated as if they are defined
+in the parent scope:
+```csharp
+struct MyType
+{
+ __transparent_block
+ {
+ int myFunc() { return 0; }
+ }
+}
+```
+Is equivalent to:
+```csharp
+struct MyType
+{
+ int myFunc() { return 0; }
+}
+```
+
+### `__file_decl`
+Symbols defined in a `__file_decl` will be treated as if they are defined in
+the global scope. However, symbols defined in different `__file_decl`s is not visible
+to each other. For example:
+```csharp
+__file_decl
+{
+ void f1()
+ {
+ }
+}
+__file_decl
+{
+ void f2()
+ {
+ f1(); // error: f1 is not visible from here.
+ }
+}
+```