From 8e6af6259bd1dd47d81c36f0562ff362ca5d42c3 Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Fri, 11 Apr 2025 15:34:07 -0700 Subject: Fix user-guide typos (#6789) * Fix user-guide typos Use LLM to scan each of the markdown files to fix typos. Try not to change anything but the typos in this CL. * typo not caught by LLM * add output of ./build_toc.ps1 --- docs/user-guide/00-introduction.md | 4 ++-- docs/user-guide/01-get-started.md | 6 +++--- docs/user-guide/02-conventional-features.md | 17 +++++++++-------- docs/user-guide/03-convenience-features.md | 12 ++++++------ docs/user-guide/04-modules-and-access-control.md | 4 ++-- docs/user-guide/05-capabilities.md | 2 +- docs/user-guide/06-interfaces-generics.md | 6 +++--- docs/user-guide/07-autodiff.md | 10 ++++------ docs/user-guide/08-compiling.md | 8 ++++---- docs/user-guide/09-reflection.md | 1 - docs/user-guide/09-targets.md | 4 ++-- docs/user-guide/10-link-time-specialization.md | 8 ++++---- docs/user-guide/a1-01-matrix-layout.md | 10 +++++----- docs/user-guide/a1-03-obfuscation.md | 10 +++++----- docs/user-guide/a1-04-interop.md | 4 ++-- docs/user-guide/a1-05-uniformity.md | 6 +++--- docs/user-guide/a2-01-spirv-target-specific.md | 20 ++++++++++---------- docs/user-guide/a2-02-metal-target-specific.md | 10 +++++----- docs/user-guide/a2-03-wgsl-target-specific.md | 6 +++--- docs/user-guide/a2-target-specific-features.md | 4 ++-- .../a3-01-reference-capability-profiles.md | 6 +++--- docs/user-guide/a3-02-reference-capability-atoms.md | 4 ++-- docs/user-guide/toc.html | 8 ++++---- 23 files changed, 84 insertions(+), 86 deletions(-) (limited to 'docs/user-guide') diff --git a/docs/user-guide/00-introduction.md b/docs/user-guide/00-introduction.md index 023256b9c..d9316cad8 100644 --- a/docs/user-guide/00-introduction.md +++ b/docs/user-guide/00-introduction.md @@ -21,11 +21,11 @@ Some of the benefits of Slang include: * _Parameter blocks_ allow shader parameters to be grouped by update rate in order to take advantage of Direct3D 12 descriptor tables and Vulkan descriptor sets, without verbose and error-prone per-parameter markup -* _Interfaces_ and _generics_ provide first-class alternative to hacky preprocessor-based or string-pasting shader specialization. Preprocessor hacks can be replaced with a well-understood language feature already used in Rust, Swift, C#, Java, and more. +* _Interfaces_ and _generics_ provide first-class alternatives to hacky preprocessor-based or string-pasting shader specialization. Preprocessor hacks can be replaced with a well-understood language feature already used in Rust, Swift, C#, Java, and more. * _Automatic differentiation_ greatly simplifies the implementation of learning-based techniques in shaders. Slang supports automatically generating both forward derivative and backward derivative propagation functions from forward computation code. -* Slang supports a first class _module_ system, which enables true separate compilation and semantic checking of shader code. +* Slang supports a first-class _module_ system, which enables true separate compilation and semantic checking of shader code. * Slang supports compute, rasterization, and ray-tracing shaders diff --git a/docs/user-guide/01-get-started.md b/docs/user-guide/01-get-started.md index 7868b4221..fce4e6644 100644 --- a/docs/user-guide/01-get-started.md +++ b/docs/user-guide/01-get-started.md @@ -5,11 +5,11 @@ permalink: /user-guide/get-started # Getting Started with Slang -Slang enables you to do many powerful things with shader code, including compiling shader code to many different platforms, obtaining reflection information, organizing your shader library in a modern modular fashion, controlling specialization and more. The following sections help you getting started with the basics of Slang in a simple example. We will assume Windows as the operating system, but the steps performed here are similar for other platforms. +Slang enables you to do many powerful things with shader code, including compiling shader code to many different platforms, obtaining reflection information, organizing your shader library in a modern modular fashion, controlling specialization and more. The following sections help you get started with the basics of Slang in a simple example. We will assume Windows as the operating system, but the steps performed here are similar for other platforms. ## Installation -The easiest way to start using Slang is to download a [binary release](https://github.com/shader-slang/slang/releases/) from the github repository. Once you have downloaded and extracted the files from a release package, you can find the `slangc.exe` executable under `/bin/windows-x64/release/`. In this tutorial we will use the `slangc` standalone Slang compiler included in a release package. Note that `slang.dll` and `slang-glslang.dll` must be placed in the same directory as `slangc.exe` as they are required by the standalone executable. +The easiest way to start using Slang is to download a [binary release](https://github.com/shader-slang/slang/releases/) from the GitHub repository. Once you have downloaded and extracted the files from a release package, you can find the `slangc.exe` executable under `/bin/windows-x64/release/`. In this tutorial we will use the `slangc` standalone Slang compiler included in a release package. Note that `slang.dll` and `slang-glslang.dll` must be placed in the same directory as `slangc.exe` as they are required by the standalone executable. If you are interested in building from source, please refer to the [documentation on building Slang](../building.md). @@ -99,4 +99,4 @@ Note that in the generated GLSL code, all shader parameters are qualified with e ## The full example -The full Vulkan example that sets up and runs the `hello-world.slang` shader in located in the [/examples/hello-world](https://github.com/shader-slang/slang/tree/master/examples/hello-world) directory of the Slang repository. The example code initializes a Vulkan context and runs the compiled SPIRV code. The example code demonstrates how to use the Slang API to load and compile shaders. +The full Vulkan example that sets up and runs the `hello-world.slang` shader is located in the [/examples/hello-world](https://github.com/shader-slang/slang/tree/master/examples/hello-world) directory of the Slang repository. The example code initializes a Vulkan context and runs the compiled SPIRV code. The example code demonstrates how to use the Slang API to load and compile shaders. diff --git a/docs/user-guide/02-conventional-features.md b/docs/user-guide/02-conventional-features.md index 5c15986f8..695d61e81 100644 --- a/docs/user-guide/02-conventional-features.md +++ b/docs/user-guide/02-conventional-features.md @@ -45,7 +45,7 @@ the list [`int`, `int64_t`] which can represent the specified literal value. If an `uint64_t` and a warning is given. The type of hexadecimal non-suffixed integer literal is the first type from the list [`int`, `uint`, `int64_t`, `uint64_t`] that can represent the specified literal value. For more information on 64 bit integer literals see the documentation on [64 bit type support](../64bit-type-support.md). -The following floating-point type are provided: +The following floating-point types are provided: | Name | Description | |---------------|------------------------------| @@ -57,7 +57,7 @@ All targets support the 32-bit `float`, but support for the other types depends ### Boolean Type -The type `bool` is used to represent Boolean truth value: `true` and `false`. +The type `bool` is used to represent Boolean truth values: `true` and `false`. For compatibility reasons, the `sizeof(bool)` depends on the target. @@ -955,7 +955,7 @@ Slang has the following rules: Initializer Lists ---------- -Initializer List's are an expression of the form `{...}`. +Initializer Lists are an expression of the form `{...}`. ```csharp int myFunc() @@ -964,35 +964,36 @@ int myFunc() } ``` -### Initializer List's - Scalar +### Initializer Lists - Scalar ```csharp // Equivalent to `int a = 1` int a = {1}; ``` -### Initializer List's - Vectors +### Initializer Lists - Vectors ```csharp // Equivalent to `float3 a = float3(1,2,3)` float3 a = {1, 2, 3}; ``` -### Initializer List's - Arrays/Matrixes +### Initializer Lists - Arrays/Matrices -#### Array Of Scalar's +#### Array Of Scalars ```csharp // Equivalent to `int[2] a; a[0] = 1; a[1] = 2;` int a[2] = {1, 2} ``` -#### Array Of Aggregate's +#### Array Of Aggregates ```csharp // Equivalent to `float3 a[2]; a[0] = {1,2,3}; b[1] = {4,5,6};` float3 a[2] = { {1,2,3}, {4,5,6} }; ``` + #### Flattened Array Initializer ```csharp diff --git a/docs/user-guide/03-convenience-features.md b/docs/user-guide/03-convenience-features.md index 29e8fd2aa..afde98f24 100644 --- a/docs/user-guide/03-convenience-features.md +++ b/docs/user-guide/03-convenience-features.md @@ -13,7 +13,7 @@ Slang supports automatic variable type inference: var a = 1; // OK, `a` is an `int`. var b = float3(0, 1, 2); // OK, `b` is a `float3`. ``` -Automatic type inference require an initialization expression to present. Without an initial value, the compiler is not able to infer the type of the variable. The following code will result in a compiler error: +Automatic type inference requires an initialization expression to be present. Without an initial value, the compiler is not able to infer the type of the variable. The following code will result in a compiler error: ```csharp var a; // Error, cannot infer the type of `a`. ``` @@ -365,7 +365,7 @@ int test() { MyType rs; rs[0, 0] = 1; - rs[1, 0] = rs[0, 0] + 1 + rs[1, 0] = rs[0, 0] + 1; return rs[1, 0]; // returns 2. } ``` @@ -457,8 +457,8 @@ void test() { if (let x = getOptInt()) { - // if we are here, `getOptInt` returns a value `int`. - // and `x` represents the `int` value. + // if we are here, `getOptInt` returns a value `int`. + // and `x` represents the `int` value. } } ``` @@ -478,9 +478,9 @@ MyType myVal; float4 myPackedVector = packMyTypeToFloat4(myVal); ``` -The `packMyTypeToFloat4` function is usually implemented by bit casting each field in the source type and assign it into the corresponding field in the target type, +The `packMyTypeToFloat4` function is usually implemented by bit casting each field in the source type and assigning it into the corresponding field in the target type, by calling `intAsFloat`, `floatAsInt` and using bit operations to shift things in the right place. -Instead of writing `packMyTypeToFloat4` function yourself, you can use Slang's builtin `reinterpret` to do just that for you: +Instead of writing `packMyTypeToFloat4` function yourself, you can use Slang's built-in `reinterpret` to do just that for you: ``` float4 myPackedVector = reinterpret(myVal); ``` diff --git a/docs/user-guide/04-modules-and-access-control.md b/docs/user-guide/04-modules-and-access-control.md index 0b4d44e0d..915c62e16 100644 --- a/docs/user-guide/04-modules-and-access-control.md +++ b/docs/user-guide/04-modules-and-access-control.md @@ -6,12 +6,12 @@ permalink: /user-guide/modules Modules and Access Control =========================== -While the preprocessor `#include`s is still supported, Slang provides a _module_ system for software engineering benefits such as clean expression of sub component boundaries and dependencies, hiding implementation details, and providing a path towards true separate compilation. +While the preprocessor `#include` is still supported, Slang provides a _module_ system for software engineering benefits such as clean expression of subcomponent boundaries and dependencies, hiding implementation details, and providing a path towards true separate compilation. ## Defining a Module -A module in Slang comprises one or more files. A module must have one and only one primary file that is used as the source-of-truth to uniquely identify the module. The primary file must start with `module` declaration. For example, the following code defines a module named `scene`: +A module in Slang comprises one or more files. A module must have one and only one primary file that is used as the source-of-truth to uniquely identify the module. The primary file must start with a `module` declaration. For example, the following code defines a module named `scene`: ``` // scene.slang diff --git a/docs/user-guide/05-capabilities.md b/docs/user-guide/05-capabilities.md index 6426cb37c..b398ba3a5 100644 --- a/docs/user-guide/05-capabilities.md +++ b/docs/user-guide/05-capabilities.md @@ -12,7 +12,7 @@ Slang exposes operations from all target platforms to allow the user to take max A consequence of this approach is that the user is now responsible for maintaining compatibility of their code. For example, if the user writes code that uses a Vulkan extension currently not available on D3D/HLSL, they will get an error when attempting to compile that code to D3D. -To help the user to maintain compatibility of their shader code on platforms matter to their applications, Slang's type system can now infer and enforce capability requirements +To help the user to maintain compatibility of their shader code on platforms that matter to their applications, Slang's type system can now infer and enforce capability requirements to provide assurance that the shader code will be compatible with the specific set of platforms before compiling for that platform. For example, `Texture2D.SampleCmp` is available on D3D and Vulkan, but not available on CUDA. If the user is intended to write cross-platform code that targets CUDA, they will diff --git a/docs/user-guide/06-interfaces-generics.md b/docs/user-guide/06-interfaces-generics.md index a07ccc6b7..bc2ab88df 100644 --- a/docs/user-guide/06-interfaces-generics.md +++ b/docs/user-guide/06-interfaces-generics.md @@ -6,7 +6,7 @@ permalink: /user-guide/interfaces-generics Interfaces and Generics =========================== -This chapter covers two interrelated Slang language features: interfaces and generics. We will talk about what they are, how do they relate to similar features in other languages, how are they parsed and translated by the compiler, and show examples on how these features simplifies and modularizes shader code. +This chapter covers two interrelated Slang language features: interfaces and generics. We will talk about what they are, how they relate to similar features in other languages, how they are parsed and translated by the compiler, and show examples on how these features simplify and modularize shader code. Interfaces ---------- @@ -423,7 +423,7 @@ struct MultiArrayFloatContainer : IFloatContainer } float getElementAt(Iterator iter) { - if (ite.indexr.x == 0) return firstBuffer[iter.index.y]; + if (iter.index.x == 0) return firstBuffer[iter.index.y]; else return secondBuffer[iter.index.y]; } } @@ -979,7 +979,7 @@ void printNumbers(expand each T args) where T == int } void compute(expand each T args) where T == int { - // Maps every element in `args` to `elementValue + 1`, and forward the + // Maps every element in `args` to `elementValue + 1`, and forwards the // new values as arguments to `printNumber`. printNumber(expand (each args) + 1); diff --git a/docs/user-guide/07-autodiff.md b/docs/user-guide/07-autodiff.md index 443a6db5b..ef60da4a5 100644 --- a/docs/user-guide/07-autodiff.md +++ b/docs/user-guide/07-autodiff.md @@ -7,11 +7,11 @@ permalink: /user-guide/autodiff To support differentiable graphics systems such as Gaussian splatters, neural radiance fields, differentiable path tracers, and more, Slang provides first class support for differentiable programming. -An overiew: +An overview: - Slang supports the `fwd_diff` and `bwd_diff` operators that can generate the forward and backward-mode derivative propagation functions for any valid Slang function annotated with the `[Differentiable]` attribute. - The `DifferentialPair` built-in generic type is used to pass derivatives associated with each function input. - The `IDifferentiable`, and the experimental `IDifferentiablePtrType`, interfaces denote differentiable value and pointer types respectively, and allow finer control over how types behave under differentiation. -- Futher, Slang allows for user-defined derivative functions through the `[ForwardDerivative(custom_fn)]` and `[BackwardDerivative(custom_fn)]` +- Further, Slang allows for user-defined derivative functions through the `[ForwardDerivative(custom_fn)]` and `[BackwardDerivative(custom_fn)]` - All Slang features, such as control-flow, generics, interfaces, extensions, and more are compatible with automatic differentiation, though the bottom of this chapter documents some sharp edges & known issues. ## Auto-diff operations `fwd_diff` and `bwd_diff` @@ -59,7 +59,7 @@ There are two basic ways to compute this product: The products described above allow the _propagation_ of derivatives forward and backward through the function $f$ The forward-mode derivative (Jacobian-vector product) can convert a derivative of the inputs to a derivative of the outputs. -For example, lets say inputs $$\mathbf{x}$$ depend on some scalar $$\theta$$, and $$\frac{\partial \mathbf{x}}{\partial \theta}$$ is a vector of partial derivatives describing that dependency. +For example, let's say inputs $$\mathbf{x}$$ depend on some scalar $$\theta$$, and $$\frac{\partial \mathbf{x}}{\partial \theta}$$ is a vector of partial derivatives describing that dependency. Invoking forward-mode auto-diff with $$\mathbf{v} = \frac{\partial \mathbf{x}}{\partial \theta}$$ converts this into a derivative of the outputs w.r.t the same scalar $$\theta$$. This can be verified by expanding the Jacobian and applying the [chain rule](https://en.wikipedia.org/wiki/Chain_rule) of derivatives: @@ -68,7 +68,7 @@ $$\langle D\mathbf{f}(\mathbf{x}), \frac{\partial \mathbf{x}}{\partial \theta} \ #### Propagating derivatives with reverse-mode auto-diff The reverse-mode derivative (vector-Jacobian product) can convert a derivative w.r.t outputs into a derivative w.r.t inputs. -For example, lets say we have some scalar $$\mathcal{L}$$ that depends on the outputs $$\mathbf{f}$$, and $$\frac{\partial \mathcal{L}}{\partial \mathbf{f}}$$ is a vector of partial derivatives describing that dependency. +For example, let's say we have some scalar $$\mathcal{L}$$ that depends on the outputs $$\mathbf{f}$$, and $$\frac{\partial \mathcal{L}}{\partial \mathbf{f}}$$ is a vector of partial derivatives describing that dependency. Invoking forward-mode auto-diff with $$\mathbf{v} = \frac{\partial \mathcal{L}}{\partial \mathbf{f}}$$ converts this into a derivative of the same scalar $$\mathcal{L}$$ w.r.t the inputs $$\mathbf{x}$$. To provide more intuition for this, we can expand the Jacobian in a same way we did above: @@ -679,8 +679,6 @@ float f(float x) t.member = x * x; // Error: assigning value with derivative into a non-differentiable location. return t.member; } -... -let result = fwd_diff(f)(diffPair(3.0, 1.0)).d; // result == 0.0 ``` In this case, we are assigning the value `x*x`, which carries a derivative, into a non-differentiable location `MyType.member`, thus throwing away any derivative info. When `f` returns `t.member`, there will be no derivative associated with it, so the function will not propagate the derivative through. This code is most likely not intending to discard the derivative through the assignment. To help avoid this kind of unintentional behavior, Slang will treat any assignments of a value with derivative info into a non-differentiable location as a compile-time error. To eliminate this error, the user should either make `t.member` differentiable, or to force the assignment by clarifying the intention to discard any derivatives using the built-in `detach` method. The following code will compile, and the derivatives will be discarded: diff --git a/docs/user-guide/08-compiling.md b/docs/user-guide/08-compiling.md index 5d259f311..29a1591d5 100644 --- a/docs/user-guide/08-compiling.md +++ b/docs/user-guide/08-compiling.md @@ -901,14 +901,14 @@ const char* spGetBuildTagString(); This assumes Slang has been built with the C++ multithreaded runtime, as is the default. -All other functions and methods are not [reentrant](https://en.wikipedia.org/wiki/Reentrancy_(computing)) and can only execute on a single thread. More precisely function and methods can only be called on a *single* thread at *any one time*. This means for example a global session can be used across multiple threads, as long as some synchronisation enforces that only one thread can be in a Slang call at any one time. +All other functions and methods are not [reentrant](https://en.wikipedia.org/wiki/Reentrancy_(computing)) and can only execute on a single thread. More precisely, functions and methods can only be called on a *single* thread at *any one time*. This means for example a global session can be used across multiple threads, as long as some synchronization enforces that only one thread can be in a Slang call at any one time. -Much of the Slang API is available through [COM interfaces](https://en.wikipedia.org/wiki/Component_Object_Model). In strict COM interfaces should be atomically reference counted. Currently *MOST* Slang API COM interfaces are *NOT* atomic reference counted. One exception is the `ISlangSharedLibrary` interface when produced from [host-callable](cpu-target.md#host-callable). It is atomically reference counted, allowing it to persist and be used beyond the original compilation and be freed on a different thread. +Much of the Slang API is available through [COM interfaces](https://en.wikipedia.org/wiki/Component_Object_Model). In strict COM, interfaces should be atomically reference counted. Currently *MOST* Slang API COM interfaces are *NOT* atomic reference counted. One exception is the `ISlangSharedLibrary` interface when produced from [host-callable](cpu-target.md#host-callable). It is atomically reference counted, allowing it to persist and be used beyond the original compilation and be freed on a different thread. ## Compiler Options -Both the `SessionDesc`, `TargetDesc` structures contain fields that encodes a `CompilerOptionEntry` array for additional compiler options to apply on the session or the target. In additional, +Both the `SessionDesc`, `TargetDesc` structures contain fields that encodes a `CompilerOptionEntry` array for additional compiler options to apply on the session or the target. In addition, the `IComponentType::linkWithOptions()` method allow you to specify additional compiler options when linking a program. All these places accepts the same encoding of compiler options, which is documented in this section. @@ -921,7 +921,7 @@ struct CompilerOptionEntry }; ``` Where `CompilerOptionName` is an `enum` specifying the compiler option to set, and `value` encodes the value of the option. -`CompilerOptionValue` is a structure that allows you to end code up to two integer or string values for a compiler option: +`CompilerOptionValue` is a structure that allows you to endcode up to two integer or string values for a compiler option: ```c++ enum class CompilerOptionValueKind { diff --git a/docs/user-guide/09-reflection.md b/docs/user-guide/09-reflection.md index 973019b13..bf09d04e0 100644 --- a/docs/user-guide/09-reflection.md +++ b/docs/user-guide/09-reflection.md @@ -1169,7 +1169,6 @@ Semantics are only relevant for shader parameters that became part of the varyin A semantic is decomposed into both a name and an index (e.g., `TEXCOORD5` has a name of `"TEXCOORD"` and an index of `5`). This information can be reflected with `getSemanticName()` and `getSemanticIndex()`: -```c++ ```c++ void printVarLayout(slang::VariableLayoutReflection* varLayout) diff --git a/docs/user-guide/09-targets.md b/docs/user-guide/09-targets.md index 711d3fa72..1e2fe7cd5 100644 --- a/docs/user-guide/09-targets.md +++ b/docs/user-guide/09-targets.md @@ -100,7 +100,7 @@ More importantly, though, using a root constant can avoid application code havin ## Direct3D 11 -Direct3D 11 (D3D11) is a older graphics API, but remains popular because it is much simpler to learn and use than some more recent APIs. +Direct3D 11 (D3D11) is an older graphics API, but remains popular because it is much simpler to learn and use than some more recent APIs. In this section we will give an overview of the relevant features of D3D11 when used as a target platform for Slang. Subsequent sections about other APIs may describe them by comparison to D3D11. @@ -135,7 +135,7 @@ Each stage has its own slots of the following types: - **Unordered access views** (UAVs) include textures, buffers, and other opaque resource types used for write or read-write operations in GPU code. UAVs use `u` registers. -- **Samplers** are used to pass opaque texture-sampling stage, and use `s` registers. +- **Samplers** are used to pass opaque texture-sampling state, and use `s` registers. In addition, the D3D11 pipeline provides _vertex buffer_ slots and a single _index buffer_ slot to be used as the source vertex and index data that defines primitives. User-defined varying vertex shader inputs are bound to _vertex attribute_ slots (referred to as "input elements" in D3D11) which define how data from vertex buffers should be fetched to provide values for vertex attributes. diff --git a/docs/user-guide/10-link-time-specialization.md b/docs/user-guide/10-link-time-specialization.md index 4c8a110bf..eba29076f 100644 --- a/docs/user-guide/10-link-time-specialization.md +++ b/docs/user-guide/10-link-time-specialization.md @@ -5,10 +5,10 @@ permalink: /user-guide/link-time-specialization # Link-time Specialization and Module Precompilation -Traditionally, graphics developers have been relying on the preprocessor defines to specialize their shader code for high-performance GPU execution. +Traditionally, graphics developers have been relying on preprocessor defines to specialize their shader code for high-performance GPU execution. While functioning systems can be built around preprocessor macros, overusing them leads to many problems: -- Long compilation time. With preprocessors defines, specialization happens before parsing, which is a very early stage in the compilation flow. - This means that the compiler must redo almost all work from the scratch with every specialized variant, including parsing, type checking, IR generation +- Long compilation time. With preprocessor defines, specialization happens before parsing, which is a very early stage in the compilation flow. + This means that the compiler must redo almost all work from scratch with every specialized variant, including parsing, type checking, IR generation and optimization, even when two specialized variants only differ in one constant value. The lack of reuse of compiler front-end work between different shader specializations contributes a significant portion to long shader compile times. - Reduced code readability and maintainability. The compiler cannot enforce any structures on preprocessor macros and cannot offer static checks to @@ -238,7 +238,7 @@ bool ISession::isBinaryModuleUpToDate( slang::IBlob* binaryModuleBlob); ``` -If the compiler options or source files has been changed since the module was last compiled, the `isBinaryModuleUpToDate` will return false. +If the compiler options or source files have been changed since the module was last compiled, the `isBinaryModuleUpToDate` will return false. The compiler can be setup to automatically use the precompiled modules when they exist and up-to-date. When loading a module, either triggered via the `ISession::loadModule` call or via transitive `import`s in the modules being loaded, the compiler will look in the diff --git a/docs/user-guide/a1-01-matrix-layout.md b/docs/user-guide/a1-01-matrix-layout.md index cb301ce8f..b3d98c5b6 100644 --- a/docs/user-guide/a1-01-matrix-layout.md +++ b/docs/user-guide/a1-01-matrix-layout.md @@ -5,7 +5,7 @@ layout: user-guide Handling Matrix Layout Differences on Different Platforms ========================================================= -The differences between default matrix layout or storage conventions between GLSL (OpenGL/Vulkan) and HLSL has been an issue that frequently causes confusion among developers. When writing applications that work on different targets, one important goal that developers frequently seek is to make it possible to pass the same matrix generated by host code to the same shader code, regardless of what graphics API is being used (e.g. Vulkan, OpenGL or Direct3D). As a solution to shader cross-compilation, Slang provides necessary tools for developers navigate around the differences between GLSL and HLSL targets. +The differences between default matrix layout or storage conventions between GLSL (OpenGL/Vulkan) and HLSL has been an issue that frequently causes confusion among developers. When writing applications that work on different targets, one important goal that developers frequently seek is to make it possible to pass the same matrix generated by host code to the same shader code, regardless of what graphics API is being used (e.g. Vulkan, OpenGL or Direct3D). As a solution to shader cross-compilation, Slang provides necessary tools for developers to navigate around the differences between GLSL and HLSL targets. A high level summary: @@ -24,7 +24,7 @@ Two conventions of matrix transform math Depending on the platform a developer is used to, a matrix-vector transform can be expressed as either `v*m` (`mul(v, m)` in HLSL), or `m*v` (`mul(m,v)` in HLSL). This convention, together with the matrix layout (column-major or row-major), determines how a matrix should be filled out in host code. -In HLSL/Slang the order of vector and matrix parameters to `mul` determine how the *vector* is interpreted. This interpretation is required because a vector does not in as of it's self differentiate between being a row or a column. +In HLSL/Slang the order of vector and matrix parameters to `mul` determine how the *vector* is interpreted. This interpretation is required because a vector does not in and of itself differentiate between being a row or a column. * `mul(v, m)` - v is interpreted as a row vector. * `mul(m, v)` - v is interpreted as a column vector. @@ -42,7 +42,7 @@ This behavior is *independent* of how a matrix layout in memory. Host code needs Another way to think about this difference is in terms of where translation terms should be placed in memory when filling a typical 4x4 transform matrix. When transforming a row vector (ie `mul(v, m)`) with a `row-major` matrix layout, translation will be at `m + 12, 13, 14`. For a `column-major` matrix layout, translation will be at `m + 3, 7, 11`. -Note it is a *HLSL*/*Slang* convention that the parameter ordering of `mul(v, m)` means v is a *row* vector. A host maths library *could* have a transform function `SomeLib::transform(v, m)` such that `v` is a interpreted as *column* vector. For simplicitys sake the remainder of this discussion assumes that the `mul(v, m)` in equivalent in host code follows the interpretation that `v` is *row* vector. +For simplicity's sake the remainder of this discussion assumes that the `mul(v, m)` equivalent in host code follows the interpretation that `v` is a *row* vector. Discussion ---------- @@ -68,7 +68,7 @@ Second lets consider performance. The matrix layout in a host maths library is n The performance difference comes down to a SIMD implementation having to do a transpose if the layout doesn't match the preferred vector interpretation. -If we put this all together - best performance, consistency between vector interpretation and platform independence we get: +If we put this all together - best performance, consistency between vector interpretation, and platform independence we get: 1) Consistency : Same vector interpretation in shader and host code 2) Platform independence: Kernel uses `row-major` matrix layout @@ -131,7 +131,7 @@ If a SIMD based host maths library with graphics-like APIs are being used, there If your application uses matrix sizes that are not 4x4 across the host/kernel boundary and it wants to work across all targets, it is *likely* that *some* matrices will have to be converted at the boundary. This being the case, having to handle transposing matrices at the boundary is a less significant issue. -In conclusion if your application has to perform matrix conversion work at the host/kernel boundary the previous observation about "best performance" implies `row-major` layout and `row` vector interpretation becomes somewhat mute. +In conclusion, if your application has to perform matrix conversion work at the host/kernel boundary, the previous observation about "best performance" implying `row-major` layout and `row` vector interpretation becomes somewhat moot. Overriding default matrix layout -------------------------------- diff --git a/docs/user-guide/a1-03-obfuscation.md b/docs/user-guide/a1-03-obfuscation.md index d0f10791b..bafafee9a 100644 --- a/docs/user-guide/a1-03-obfuscation.md +++ b/docs/user-guide/a1-03-obfuscation.md @@ -5,15 +5,15 @@ layout: user-guide Obfuscation =========== -The Slang obfuscation feature allows developers to distribute shader code in a way where the implementation details are kept secret. For example let's say a developer has produced a novel way to render and wants to protect that intellectual property. If it is possible to compile all possible uses of the shader code into SPIR-V/DXIL the developer can ship their product with those binaries without debug information. This is similar to the protection achieved by shipping an executable - a determined person may with a good deal of effort work out how some algorithm in the executable works, but doing so requires a considerable amount of work, and certainly more work than reading the original source code. +The Slang obfuscation feature allows developers to distribute shader code in a way where the implementation details are kept secret. For example, let's say a developer has produced a novel way to render and wants to protect that intellectual property. If it is possible to compile all possible uses of the shader code into SPIR-V/DXIL, the developer can ship their product with those binaries without debug information. This is similar to the protection achieved by shipping an executable - a determined person may with a good deal of effort work out how some algorithm in the executable works, but doing so requires a considerable amount of work, and certainly more work than reading the original source code. -If a developer is not able to ship all shader binaries then there is a problem. The developer doesn't want to ship the source code as in doing so it is relatively straight forward to see how it works or even copy the implementation. A developer could provide some level of protection by encrypting the source, but when compilation occurs it will still be necessary to decrypt and so make it available to read. A developer could obfuscate their source before shipping it. In this scenario +If a developer is not able to ship all shader binaries then there is a problem. The developer doesn't want to ship the source code as in doing so it is relatively straightforward to see how it works or even copy the implementation. A developer could provide some level of protection by encrypting the source, but when compilation occurs it will still be necessary to decrypt and so make it available to read. A developer could obfuscate their source before shipping it. In this scenario: * Requires tooling to do the obfuscation of the source -* Any source on the client that isn't obfuscated, needs to be able to call to the obfuscated code +* Any source on the client that isn't obfuscated needs to be able to call to the obfuscated code * Depending on how the obfuscation takes place this could be hard - remapping symbols or obfuscating on the fly on the client * If "public" symbols keep their original names they leak information about the implementation -* Obfuscated source, provides some protection but not typically as much as a binary format (like an object file without debug information) +* Obfuscated source provides some protection but not typically as much as a binary format (like an object file without debug information) * How can you debug, or determine where a crash occurred without the original source? * If a failure occurs - how is it possible to report meaningful errors? @@ -179,7 +179,7 @@ Notice here that the `-r` module reference is to the `.zip` file rather than the It is also worth noticing that in this second compilation, using `module.zip`, we need the `-obfuscate` flag set. If this isn't set linking will not work correctly. -NOTE! As previously discussed though you should *not* ship the .zip file with the obfuscated source map such that it's available on client machines, as doing so does leak some information about the original source. Not the original source itself, but the names of files and the locations in files. You could ship a .zip to client machines, but make sure the `.map` obfuscated source maps are stripped. Alternatively, and perhaps less riskily you could ship `.slang-module` files taken from the `.zip` file and then it is clear there is no source map information available. +NOTE! As previously discussed, though you should *not* ship the .zip file with the obfuscated source map such that it's available on client machines, as doing so does leak some information about the original source. Not the original source itself, but the names of files and the locations in files. You could ship a .zip to client machines, but make sure the `.map` obfuscated source maps are stripped. Alternatively, and perhaps less riskily, you could ship `.slang-module` files taken from the `.zip` file and then it is clear there is no source map information available. ## Accessing Source Maps without Files diff --git a/docs/user-guide/a1-04-interop.md b/docs/user-guide/a1-04-interop.md index 21ed40279..279325b40 100644 --- a/docs/user-guide/a1-04-interop.md +++ b/docs/user-guide/a1-04-interop.md @@ -142,7 +142,7 @@ Currently, the following target names are supported in a `case` statement: `cpp` ## Inline SPIRV Assembly -When targeting SPIRV, Slang allows you to directly write an SPIRV assembly block and use it as a part of an expression. For example: +When targeting SPIRV, Slang allows you to directly write a SPIRV assembly block and use it as part of an expression. For example: ```cpp int test() { @@ -164,7 +164,7 @@ where `` defines a value named `identifier` of ``, or simply: ``` When `` does not define a return value. -When used as part of an expression, the Slang type of the `spirv_asm` construct is defined by the last instruction, which must be in the form of +When used as part of an expression, the Slang type of the `spirv_asm` construct is defined by the last instruction, which must be in the form of: ``` result: = ... ``` diff --git a/docs/user-guide/a1-05-uniformity.md b/docs/user-guide/a1-05-uniformity.md index be07f89c0..f98e04572 100644 --- a/docs/user-guide/a1-05-uniformity.md +++ b/docs/user-guide/a1-05-uniformity.md @@ -7,7 +7,7 @@ Uniformity Analysis On certain hardware, accessing resources with a non-uniform index may lead to significant performance degradation. Developers can often benefit from a compiler warning for unintentional non-uniform resource access. -Starting from v2024.1.0, Slang provides uniformity analysis that can warn users if a non-dynamically-uniform value is being used unintentionally. This feature is not enabled by default but can be turned on with the `-validate-uniformity` commandline option when using `slangc`, or the `CompilerOptionName::ValidateUniformity` compiler option when using the API. +Starting from v2024.1.0, Slang provides uniformity analysis that can warn users if a non-dynamically-uniform value is being used unintentionally. This feature is not enabled by default but can be turned on with the `-validate-uniformity` command-line option when using `slangc`, or the `CompilerOptionName::ValidateUniformity` compiler option when using the API. In addition to specifying the compiler option, the source code must be augmented with the `dynamic_uniform` modifier to mark function parameters, struct fields or local variables as expecting a dynamic uniform value. @@ -82,7 +82,7 @@ In some cases, the compiler might not be able to deduce a value to be non-unifor be treated as dynamic uniform, you can call `asDynamicUniform()` function to force the compiler to treat the value as dynamic uniform. For example: ```csharp -void main(int tid: SV_DispatchThreadID +void main(int tid: SV_DispatchThreadID) { expectUniform(asDynamicUniform(tid)); // OK. } @@ -90,7 +90,7 @@ void main(int tid: SV_DispatchThreadID ## Treat Function Return Values as Non-uniform -The uniformity analysis will automatically propagate uniformity to function return values. However if you have +The uniformity analysis will automatically propagate uniformity to function return values. However, if you have an intrinsic function that does not have a body, or you simply wish the return value of a function to be always treated as non-uniform, you can mark the function with the `[NonUniformReturn]` attribute: ```csharp diff --git a/docs/user-guide/a2-01-spirv-target-specific.md b/docs/user-guide/a2-01-spirv-target-specific.md index 5090caacf..d37f41a5e 100644 --- a/docs/user-guide/a2-01-spirv-target-specific.md +++ b/docs/user-guide/a2-01-spirv-target-specific.md @@ -3,7 +3,7 @@ layout: user-guide permalink: /user-guide/spirv-target-specific --- -SPIR-V specific functionalities +SPIR-V-Specific Functionalities =============================== This chapter provides information for SPIR-V specific functionalities and behaviors. @@ -11,7 +11,7 @@ This chapter provides information for SPIR-V specific functionalities and behavi Experimental support for the older versions of SPIR-V ----------------------------------------------------- -Slang's SPIRV backend is stable when emitting SPIRV 1.3 and later, however, support for SPIR-V 1.0, 1.1 and 1.2 is still experimental. +Slang's SPIR-V backend is stable when emitting SPIR-V 1.3 and later, however, support for SPIR-V 1.0, 1.1 and 1.2 is still experimental. When targeting the older SPIR-V profiles, Slang may produce SPIR-V that uses the instructions and keywords that were introduced in the later versions of SPIR-V. @@ -26,7 +26,7 @@ For SPIR-V targets, explicit bindings may be provided through a single `vk::bind Sampler2D explicitBindingSampler; ``` -For other targets (HLSL or others) where combined texture samplers are _not_ supported intrinsicly, they are emulated by Slang using separate objects for Texture and Sampler. +For other targets (HLSL or others) where combined texture samplers are _not_ supported intrinsically, they are emulated by Slang using separate objects for Texture and Sampler. For explicit binding on such targets, you can specify two different register numbers for each: one for the texture register and another for the sampler register. ``` Sampler2D explicitBindingSampler : register(t4): register(s3); @@ -38,7 +38,7 @@ System-Value semantics The system-value semantics are translated to the following SPIR-V code. -| SV semantic name | SPIR-V code | +| SV semantic name | SPIR-V Code | |-------------------------------|-----------------------------------| | `SV_Barycentrics` | `BuiltIn BaryCoordKHR` | | `SV_ClipDistance` | `BuiltIn ClipDistance` | @@ -50,7 +50,7 @@ The system-value semantics are translated to the following SPIR-V code. | `SV_DepthLessEqual` | `BuiltIn FragDepth` | | `SV_DispatchThreadID` | `BuiltIn GlobalInvocationId` | | `SV_DomainLocation` | `BuiltIn TessCoord` | -| `SV_DrawIndex` | `Builtin DrawIndex` | +| `SV_DrawIndex`* | `Builtin DrawIndex` | | `SV_GSInstanceID` | `BuiltIn InvocationId` | | `SV_GroupID` | `BuiltIn WorkgroupId` | | `SV_GroupIndex` | `BuiltIn LocalInvocationIndex` | @@ -61,7 +61,7 @@ The system-value semantics are translated to the following SPIR-V code. | `SV_IntersectionAttributes` | *Not supported* | | `SV_IsFrontFace` | `BuiltIn FrontFacing` | | `SV_OutputControlPointID` | `BuiltIn InvocationId` | -| `SV_PointSizenote` | `BuiltIn PointSize` | +| `SV_PointSize`* | `BuiltIn PointSize` | | `SV_Position` | `BuiltIn Position/FragCoord` | | `SV_PrimitiveID` | `BuiltIn PrimitiveId` | | `SV_RenderTargetArrayIndex` | `BuiltIn Layer` | @@ -87,9 +87,9 @@ You can use OpDemoteToHelperInvocation by explicitly specifying the capability, As an example, the following command-line arguments can control the behavior of `discard` when targeting SPIR-V. ``` -slangc.exe test.slang -target spirv -profile spirv_1_5 # emits OpKill -slangc.exe test.slang -target spirv -profile spirv_1_6 # emits OpDemoteToHelperInvocation -slangc.exe test.slang -target spirv -capability SPV_EXT_demote_to_helper_invocation -profile spirv_1_5 # emits OpDemoteToHelperInvocation +slangc.exe test.slang -target spir-v -profile spir-v_1_5 # emits OpKill +slangc.exe test.slang -target spir-v -profile spir-v_1_6 # emits OpDemoteToHelperInvocation +slangc.exe test.slang -target spir-v -capability SPV_EXT_demote_to_helper_invocation -profile spir-v_1_5 # emits OpDemoteToHelperInvocation ``` @@ -413,7 +413,7 @@ Pack members using FXCs member packing rules when targeting GLSL or SPIRV. Uses the entrypoint name from the source instead of 'main' in the spirv output. ### -fspv-reflect -Include reflection decorations in the resulting SPIRV for shader parameters. +Include reflection decorations in the resulting SPIR-V for shader parameters. ### -spirv-core-grammar A path to a specific spirv.core.grammar.json to use when generating SPIR-V output diff --git a/docs/user-guide/a2-02-metal-target-specific.md b/docs/user-guide/a2-02-metal-target-specific.md index 48c6b4587..bbcf28005 100644 --- a/docs/user-guide/a2-02-metal-target-specific.md +++ b/docs/user-guide/a2-02-metal-target-specific.md @@ -3,7 +3,7 @@ layout: user-guide permalink: /user-guide/metal-target-specific --- -# Metal-specific functionalities +# Metal-Specific Functionalities This chapter provides information for Metal-specific functionalities and behaviors in Slang. @@ -153,7 +153,7 @@ using namespace metal; ## Parameter blocks and Argument Buffers `ParameterBlock` values are translated into _Argument Buffers_ potentially -containing nested resources. For example this Slang code... +containing nested resources. For example, this Slang code... ```slang struct MyParameters @@ -242,8 +242,8 @@ FragmentOutput main() Metal enforces strict type requirements for certain operations. Slang automatically performs the following conversions: -- Vector size expansion (e.g., float2 to float4), for example when the user - specified `float2` but the semantic type in Metal is float4. +- Vector size expansion (e.g., `float2` to `float4`), for example when the user + specified `float2` but the semantic type in Metal is `float4`. - Image store value expansion to 4-components For example: @@ -274,7 +274,7 @@ Metal requires explicit address space qualifiers. Slang automatically assigns ap 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. +Since Metal does not differentiate between 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. diff --git a/docs/user-guide/a2-03-wgsl-target-specific.md b/docs/user-guide/a2-03-wgsl-target-specific.md index b88c28648..cf28d4b49 100644 --- a/docs/user-guide/a2-03-wgsl-target-specific.md +++ b/docs/user-guide/a2-03-wgsl-target-specific.md @@ -3,10 +3,10 @@ layout: user-guide permalink: /user-guide/wgsl-target-specific --- -WGSL specific functionalities +WGSL-Specific Functionalities ============================= -This chapter provides information for WGSL (WebGPU Shading Language) -specific functionalities and behaviors. +This chapter provides information for WGSL (WebGPU Shading Language)-specific functionalities and behaviors. System-Value semantics @@ -161,7 +161,7 @@ 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. +If the `[vk::binding()]` attribute is not specified but a `:register()` semantic is present, Slang will derive the binding from the `register` semantic the same way as the SPIR-V and GLSL backends. The `[vk::location(N)]` attributes on stage input/output parameters are respected. diff --git a/docs/user-guide/a2-target-specific-features.md b/docs/user-guide/a2-target-specific-features.md index 32be22f08..e8a85dfff 100644 --- a/docs/user-guide/a2-target-specific-features.md +++ b/docs/user-guide/a2-target-specific-features.md @@ -2,9 +2,9 @@ layout: user-guide --- -# Target-specific features +# Target-Specific Features -Slang can produce code for a variety of targets. When producing code for a target, Slang attempts to translate HLSL intrinsics to the closes functionality provided by the target. In addition, Slang also support target specific intrinsics and language extensions that allow users to make best use of the target. This chapter documents all the important target-specific behaviors. +Slang can produce code for a variety of targets. When producing code for a target, Slang attempts to translate HLSL intrinsics to the closest functionality provided by the target. In addition, Slang also supports target-specific intrinsics and language extensions that allow users to make best use of the target. This chapter documents all the important target-specific behaviors. In this chapter: diff --git a/docs/user-guide/a3-01-reference-capability-profiles.md b/docs/user-guide/a3-01-reference-capability-profiles.md index 43fe8eedb..e54f21290 100644 --- a/docs/user-guide/a3-01-reference-capability-profiles.md +++ b/docs/user-guide/a3-01-reference-capability-profiles.md @@ -5,9 +5,9 @@ layout: user-guide Capability Profiles ============================ -### Accepted values of `-profile`: +### Accepted Values of `-profile`: -> Note: To 'make' your own 'profile's, try mixing capabilities with `-capability`. +> Note: To create your own profiles, try mixing capabilities with `-capability`. `sm_{4_0,4_1,5_0,5_1,6_0,6_1,6_2,6_3,6_4,6_5,6_6,6_7}` * HLSL shader model @@ -43,7 +43,7 @@ Capability Profiles * GLSL versions `spirv_1_{1,2,3,4,5,6}` -* SPIRV versions +* SPIR-V versions `metallib_2_{3,4}` * Metal versions diff --git a/docs/user-guide/a3-02-reference-capability-atoms.md b/docs/user-guide/a3-02-reference-capability-atoms.md index 9a6eead6d..1cb7f5bd5 100644 --- a/docs/user-guide/a3-02-reference-capability-atoms.md +++ b/docs/user-guide/a3-02-reference-capability-atoms.md @@ -953,7 +953,7 @@ Compound Capabilities > Collection of shader stages `meshshading` -> Ccapabilities required to use mesh shading features +> Capabilities required to use mesh shading features `shadermemorycontrol_compute` > (gfx targets) Capabilities required to use memory barriers that only work for raytracing & compute shader stages @@ -1204,7 +1204,7 @@ Compound Capabilities Other ---------------------- -*Capabilities which may be deprecated* +*Capabilities that may be deprecated* `SPIRV_1_0` > Use `spirv_1_0` instead diff --git a/docs/user-guide/toc.html b/docs/user-guide/toc.html index 8a314d688..b662c278e 100644 --- a/docs/user-guide/toc.html +++ b/docs/user-guide/toc.html @@ -187,9 +187,9 @@ -
  • Target-specific features +
  • Target-Specific Features
      -
    • SPIR-V specific functionalities +
    • SPIR-V-Specific Functionalities
      • Experimental support for the older versions of SPIR-V
      • Combined texture sampler
      • @@ -211,7 +211,7 @@
      • SPIR-V specific Compiler options
    • -
    • Metal-specific functionalities +
    • Metal-Specific Functionalities
      • Entry Point Parameter Handling
      • System-Value semantics
      • @@ -228,7 +228,7 @@
      • Specialization Constants
    • -
    • WGSL specific functionalities +
    • WGSL-Specific Functionalities
      • System-Value semantics
      • Supported HLSL features when targeting WGSL
      • -- cgit v1.2.3