-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GLSL tutorial #19
base: main
Are you sure you want to change the base?
GLSL tutorial #19
Conversation
Closes shader-slang/slang#5448 |
|
||
## How to use GLSL shaders as the input | ||
By default, Slang doesn't recognize GLSL syntax. You need to explicitly enable it with an option, `-allow-glsl` or `-lang glsl`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the options for slangc
, maybe include the API options as well?
Curious, is it necessary to add -allow-glsl
if your shader has "import glsl;"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could give a try and see what the actual behaviors are.
But my understanding is that import glsl
just imports the GLSL functions top of what is available as Slang core modules.
It is not enough to allow the shader to use GLSL specific language syntax such as layout(location = 0)
.
These GLSL keywords are available only when -allow-glsl
is used.
I am not clear on what -lang glsl
actually does. I thought it is meant to includes -allow-glsl
but when I tried last time, I still had to have -allow-glsl
.
I will test a bit and update the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think you need -allow-glsl if you have #version 450 declaration in the source file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-lang glsl does nothing right now so let’s not mention it.
|
||
## Layout rules | ||
By default, Slang uses `std430` as the layout rule. You can explicitly specify to use `std140` whenever needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. Uniform buffer defaults to std140, shader storage buffers and structured buffers default to std430.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example below is using HLSL syntax but this doc is for glsl users, so it seems inappropriate, unless we start with some explanation, such as “to explicitly specify the layout of individual buffers, you can use the Slang syntax when declaring the buffer.”
StructuredBuffer<T, Std140DataLayout> std140Layout; | ||
StructuredBuffer<T, Std430DataLayout> std430Layout; | ||
StructuredBuffer<T, ScalarDataLayout> scalarLayout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a case for specifying layout for a ConstantBuffer<>.
``` | ||
|
||
The layout rule can also be changed with options like `-force-glsl-scalar-layout` or `-fvk-use-scalar-layout`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also -fvk-use-dx-layout now. See dxc documentation for what it means.
|
||
## Matrix | ||
Even though GLSL claims to use "Column-major", it is mostly nomenclature when it comes to the shader-side implementation. For this reason, `matXxY` and `floatXxY` can be used interchangeably in Slang. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just say matNxM is a typedef to floatNxM.
GLSL requires an entry point to be named `main`. This requirement prevents a shader file from having more than one entry point, unlike other shading languages such as HLSL and Metal. | ||
|
||
But this requirement doesn't apply when using Slang with the option `-allow-glsl`. In other words, you can define multiple entry points in the same shader file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talk about -fvk-use-EntryPoint-name here.
## Overview | ||
Slang allows developers to use GLSL syntax as input shaders. It provides an easy transition from your existing GLSL-based system to the Slang system. This document provides information that users may want to know when migrating from a GLSL-based system to the Slang system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… when migrating a glsl shader code base to Slang.
|
||
## How to use GLSL shaders as the input | ||
By default, Slang doesn't recognize GLSL syntax. You need to explicitly enable it with an option, `-allow-glsl` or `-lang glsl`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think you need -allow-glsl if you have #version 450 declaration in the source file.
|
||
## How to use GLSL shaders as the input | ||
By default, Slang doesn't recognize GLSL syntax. You need to explicitly enable it with an option, `-allow-glsl` or `-lang glsl`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-lang glsl does nothing right now so let’s not mention it.
For people who are interested in more details of how GLSL functions are translated, please refer to [glsl.meta.slang](https://github.com/shader-slang/slang/blob/master/source/slang/glsl.meta.slang). | ||
|
||
## How to use GLSL shaders as input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a section on the support level of glsl input:
The support for GLSL input in the slang compiler is best-effort rather than spec-complete. The Slang compiler understands many but not all GLSL syntax. Slang is not a drop-in replacement for any existing GLSL compiler. Instead, the intention is to make transition from glsl to Slang easy by allowing mixing GLSL syntax and Slang syntax so the user does not need to modify every line of code before they can use Slang features. The user is still expected to migrate from unsupported GLSL syntax before they can be accepted by the Slang compiler.
Most of the unsupported areas of GLSL syntax are around global parameter or layout declarations. We expect most functions written in GLSL to just work in Slang.
|
||
For a more detailed explanation about the matrix layout, please check another document, [Handling Matrix Layout Differences on Different Platforms](https://shader-slang.com/slang/user-guide/a1-01-matrix-layout.html). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need a section to talk about the difference of operator ==, * between glsl and HLSL, and how -allow-glsl/#version/import glsl changes that default behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a section on how shader storage buffers are parsed and supported.
Show the glsl syntax and equivalent slang code for constant buffers, structured buffers and storage buffers, so people know how to migrate the code to slang if they want to do so.
This is a tutorial document for "migrating from glsl".