summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-12-06 00:55:35 -0800
committerGitHub <noreply@github.com>2024-12-06 00:55:35 -0800
commit8ce7c6f6958f9f5ed750ef1a823b9e9ed8c042d8 (patch)
treee4cb0ff1639ea0cf8209b466bd7d7537db783599 /docs
parent22b64a446c8c37cc0b3670eb117b64575fc54d2f (diff)
Support specialization constant on WGSL and Metal. (#5780)
Diffstat (limited to 'docs')
-rw-r--r--docs/user-guide/a2-02-metal-target-specific.md19
-rw-r--r--docs/user-guide/a2-03-wgsl-target-specific.md18
-rw-r--r--docs/user-guide/toc.html2
3 files changed, 37 insertions, 2 deletions
diff --git a/docs/user-guide/a2-02-metal-target-specific.md b/docs/user-guide/a2-02-metal-target-specific.md
index 827f11200..e2602eb77 100644
--- a/docs/user-guide/a2-02-metal-target-specific.md
+++ b/docs/user-guide/a2-02-metal-target-specific.md
@@ -274,4 +274,21 @@ The HLSL `:register()` semantic is respected when emitting Metal code.
Since metal does not differentiate a constant buffer, a shader resource (read-only) buffer and an unordered access buffer, Slang will map `register(tN)`, `register(uN)` and `register(bN)` to `[[buffer(N)]]` when such `register` semantic is declared on a buffer typed parameter.
-`spaceN` specifiers inside `register` semantics are ignored. \ No newline at end of file
+`spaceN` specifiers inside `register` semantics are ignored.
+
+## Specialization Constants
+
+Specialization constants declared with the `[SpecializationConstant]` or `[vk::constant_id]` attribute will be translated into a `function_constant` when generating Metal source.
+For example:
+
+```csharp
+[vk::constant_id(7)]
+const int a = 2;
+```
+
+Translates to:
+
+```metal
+constant int fc_a_0 [[function_constant(7)]];
+constant int a_0 = is_function_constant_defined(fc_a_0) ? fc_a_0 : 2;
+``` \ No newline at end of file
diff --git a/docs/user-guide/a2-03-wgsl-target-specific.md b/docs/user-guide/a2-03-wgsl-target-specific.md
index c802a682b..743928a5f 100644
--- a/docs/user-guide/a2-03-wgsl-target-specific.md
+++ b/docs/user-guide/a2-03-wgsl-target-specific.md
@@ -161,4 +161,20 @@ Since the WGSL matrix multiplication convention is the normal one, where inner p
The `[vk::binding(index,set)]` attribute is respected when emitting WGSL code, and will translate to `@binding(index) @group(set)` in WGSL.
-If the `[vk::binding()]` attribute is not specified by a `:register()` semantic is present, Slang will derive the binding from the `register` semantic the same way as the SPIRV and GLSL backends. \ No newline at end of file
+If the `[vk::binding()]` attribute is not specified by a `:register()` semantic is present, Slang will derive the binding from the `register` semantic the same way as the SPIRV and GLSL backends.
+
+## Specialization Constants
+
+Specialization constants declared with the `[SpecializationConstant]` or `[vk::constant_id]` attribute will be translated into a global `override` declaration when generating WGSL source.
+For example:
+
+```csharp
+[vk::constant_id(7)]
+const int a = 2;
+```
+
+Translates to:
+
+```wgsl
+@id(7) override a : i32 = 2;
+``` \ No newline at end of file
diff --git a/docs/user-guide/toc.html b/docs/user-guide/toc.html
index 39cfd6164..283706adc 100644
--- a/docs/user-guide/toc.html
+++ b/docs/user-guide/toc.html
@@ -234,6 +234,7 @@
<li data-link="metal-target-specific#conservative-rasterization"><span>Conservative Rasterization</span></li>
<li data-link="metal-target-specific#address-space-assignment"><span>Address Space Assignment</span></li>
<li data-link="metal-target-specific#explicit-parameter-binding"><span>Explicit Parameter Binding</span></li>
+<li data-link="metal-target-specific#specialization-constants"><span>Specialization Constants</span></li>
</ul>
</li>
<li data-link="wgsl-target-specific"><span>WGSL specific functionalities</span>
@@ -251,6 +252,7 @@
<li data-link="wgsl-target-specific#address-space-assignment"><span>Address Space Assignment</span></li>
<li data-link="wgsl-target-specific#matrix-type-translation"><span>Matrix type translation</span></li>
<li data-link="wgsl-target-specific#explicit-parameter-binding"><span>Explicit Parameter Binding</span></li>
+<li data-link="wgsl-target-specific#specialization-constants"><span>Specialization Constants</span></li>
</ul>
</li>
</ul>