From eb89ccb177881f10a4ac3f88fcbe033703d9ecd5 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 15 Dec 2023 18:10:17 -0800 Subject: Add doc for special scoping syntax. (#3416) Co-authored-by: Yong He --- docs/user-guide/03-convenience-features.md | 56 ++++++++++++++++++++++++++++++ docs/user-guide/toc.html | 1 + 2 files changed, 57 insertions(+) (limited to 'docs/user-guide') 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 @@
  • Extensions
  • Multi-level break
  • Force inlining
  • +
  • Special Scoping Syntax
  • Modules and Access Control -- cgit v1.2.3