diff options
| author | Yong He <yonghe@outlook.com> | 2023-12-15 18:10:17 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-15 18:10:17 -0800 |
| commit | eb89ccb177881f10a4ac3f88fcbe033703d9ecd5 (patch) | |
| tree | 54948a1d8d385331b9df6cae5f063dac029a6a52 /docs/user-guide | |
| parent | b507d881ca47135bfa46237767e7183f61e7d8e3 (diff) | |
Add doc for special scoping syntax. (#3416)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'docs/user-guide')
| -rw-r--r-- | docs/user-guide/03-convenience-features.md | 56 | ||||
| -rw-r--r-- | docs/user-guide/toc.html | 1 |
2 files changed, 57 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. + } +} +``` diff --git a/docs/user-guide/toc.html b/docs/user-guide/toc.html index 1533d3655..dceca681f 100644 --- a/docs/user-guide/toc.html +++ b/docs/user-guide/toc.html @@ -43,6 +43,7 @@ <li data-link="03-convenience-features#extensions"><span>Extensions</span></li> <li data-link="03-convenience-features#multi-level-break"><span>Multi-level break</span></li> <li data-link="03-convenience-features#force-inlining"><span>Force inlining</span></li> +<li data-link="03-convenience-features#special-scoping-syntax"><span>Special Scoping Syntax</span></li> </ul> </li> <li data-link="04-modules-and-access-control"><span>Modules and Access Control</span> |
