From 94ea13acc71e96ed4942b3a256ecb85a952742e4 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 10 Nov 2023 23:32:26 +0100 Subject: [PATCH 1/6] Blog post for Spirv --- images/Spir.png | Bin 0 -> 16828 bytes ...vestigating-spirv-for-the-shader-system.md | 86 ++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 images/Spir.png create mode 100644 posts/investigating-spirv-for-the-shader-system.md diff --git a/images/Spir.png b/images/Spir.png new file mode 100644 index 0000000000000000000000000000000000000000..f49cfd1e1814d07900c309497289a216493ecf33 GIT binary patch literal 16828 zcmeJE`9IYE_dkvgku8G=Wh_ylM0Un9BB^9cLRnLmY+>xiSh8=4%D!Y7MJQw)WJwES zEH(DAkFkwq7!2cc_jta(m&^N)`2I4wOt(4b+|KRX&U(GY85`=cvtD2Yfk5nc@7#I- z0-ag{f#}H0r-5%OC77-Qf6l{oE#Rh}j&Of_@8_VK&pe+#7rEpQucLZk3qtx87nZ^NGcIgnjBVhW45O|clwOA`BfcFwc+Hfp zie1<4YDBo`UK#TgM@c2`lN-$RBB7r?ku;cMF5Lb1I_Y$i@I&97HhMsSm+<4SEWlr_ zf>XdJy&&+x00llouyp_bFaJ*=2MbTKK?QoP$4A~X{?dynLs57&gSO+0nef)}=KVQZ zDlEIC=M%n}14-Nao(2Y`&k6wRe_}O>x5z}Xwos{d>I>Ovlz!;-WjatexE>)K3)7%CS*n_);d=_#KsJZ8Fxgm9{?@oXrH{TmtnZZER!jUlWdw zktEQ!;OSsb0w(%S(bD=(ftcZ81ib*Yv!P!$%wE;Fw-`l!+&-ZeAlDU>3lbi?v1%!> z?r$4Q(?X>?}fX)u0wxYk6W4 z^ZfJgbD4!t0|ge^XC{zwJBv`iq1h9;A|OAz z+;4Q8FesDzJ@>)GJXeD0_kf^1-zxBv@Q#Q>si**f1zz9CpkC?q*p0r2o?+^nV<^W4%pB!dtTu;GHY~U}KOI(pdY@Q5GN2 z1^?|HgO_M1Kz_t0y}oF{>jD)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v-for-the-shader-system.md b/posts/investigating-spirv-for-the-shader-system.md new file mode 100644 index 00000000..385925fb --- /dev/null +++ b/posts/investigating-spirv-for-the-shader-system.md @@ -0,0 +1,86 @@ +--- +title: "Investigating spir-v for the shader system" +author: youness +popular: false +image: /images/spir.png +tags: ['.NET', 'spir-v', 'shader', 'hlsl', 'glsl', 'sdsl', 'compilation'] +--- + +Let's investigate how the shader system works in Stride and how to make it better thanks to spir-v. +--- + +Table of Contents: + +[[TOC]] + +The Stride engine has a powerful shader system, helping users build very complex shaders thanks to its language features like composition and inheritance, and its C# integration through the very powerful material system. + +## What are shaders ? + +Simply put, they are typically snippets of codes that are run on the GPU, moslty written in C-like languages like GLSL and HLSL. + +When a game has to render on the screen, it starts by preparing the data on the GPU and then sends shaders with commands. The GPU then executes those commands and if everything goes well, the game ends with a lovely screen ! + +## How does it work in Stride ? + +To first understand how it works in Stride we have to know the many barriers we're facing. + +Stride is meant to run on a wide range of devices, from computers to mobiles. For that we have to make sure our shaders can run on many kind of GPUs through different drivers. + +There are 3 most used shader languages and they are, for some, tide to different kind of machines. + +* For Windows machines, HLSL and GLSL are the most used languages through Vulkan, OpenGL and Direct3D drivers. Where HLSL with Direct3D is only available on Windows. +* For Linux and Android machines, Vulkan and OpenGL are the most used options. +* For Mac and iOS machines, MSL is used with Metal. + +Since there is no one-size-fits-all solution, every game engine has to come up with a more complex solution that makes sure we have one shader language for every machines. A language that will either be transpiled or cross-compiled into another one. + +This is where SDSL was born. + +## SDSL and transpilation + +For the sake of this article we won't dive into the language, but you can learn a lot more about SDSL [through the manual](https://doc.stride3d.net/latest/en/manual/graphics/effects-and-shaders/index.html). +From here, the article will assume you have a high level view about how programming languages are compiled and knowledge about shader programming. + +SDSL (StriDe Shader Language), was born for the need to transpile HLSL code to GLSL. It is heavily inspired from HLSL but with more features to simplify the process of creating complex shader computations. + +The shader system has 3 sides to it, an effect system, a shader mixer and the transpilation. + +The effect system will use the many different SDSL features to create uber-shaders/permutations for creating complex pipeline rendering. + +Since HLSL and GLSL are very close to each other, all this mixing is done through the abstract syntax tree level(AST). There are very few modification on the code itself, most of the work is done for managing input/output of shaders. + +The SDSL AST will then be transformed into HLSL or GLSL depending the graphics driver used. + + +## Why investigating spir-v? + +Unfortunately for us, this complex transpilation involves issues regarding performance. Working with tree structures, especially with string data, makes computations very slow can introduce issues like defensive copies. + +We would need tools to help us transpile this SDSL into other languages without going through tree structures, but maybe through arrays. + +Three things happened lately, Vulkan was released with a new kind of bytecode shader language called spir-v and .NET core came out with a new feature for operating on arrays without loss of performance, namely `Span`. And most importantly, spirv-cross was created as a mean to perform cross-compilation of shaders in a performant way. + +It was clear for everyone, we had to investigate how we could compile SDSL to spir-v and use tools like spirv-cross. + +## Problems ahead + +SDSL is a very peculiar shader language, using current spir-v tools to generate spir-v byte code would be extremely difficult to design given how spir-v has a very tight specification. +Another problem is that most spir-v tools are written in system languages like Rust/C/C++, which is another barrier for a .NET based game engine. + +To be able to use spir-v to it's fullest we have to create a C#/.NET library from scratch, something that will help us assemble and manipulate spir-v bytecode the way SDSL works. + +## Mise en bouche for Part 2 of this article + +I've started to work on this issue not long ago through two projects : + +* [A new simplified parser for SDSL](https://github.com/ykafia/SDSLParser) +* [A spir-v assembler library for SDSL](https://github.com/ykafia/SoftTouch.Spirv) + +Those will be the core subjects of part 2! + +## Summary + +Embracing spir-v for Stride's shader system will hopefully empower us with a better control over the shader language but also improve performance for shader compilation! + +Thank you for reading! From 3c2f0de0bf261963d4fc59ed75d3a22505e4f3fd Mon Sep 17 00:00:00 2001 From: Youness KAFIA <32330908+ykafia@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:11:18 +0100 Subject: [PATCH 2/6] Better structure for spirv blog --- images/blog/spirv/shaders-explanation.png | Bin 0 -> 15141 bytes ...vestigating-spirv-for-the-shader-system.md | 86 +++++++++++------- 2 files changed, 53 insertions(+), 33 deletions(-) create mode 100644 images/blog/spirv/shaders-explanation.png diff --git a/images/blog/spirv/shaders-explanation.png b/images/blog/spirv/shaders-explanation.png new file mode 100644 index 0000000000000000000000000000000000000000..6148eeee84d8196843ced57e18b69987d44268df GIT binary patch literal 15141 zcmeHuXEfYh+b<$|7cI!>lITQFMvGn}38F^{qD2{B08h@h%OAmFnaXf zjnU@(<-YHCopqk`tn=mla@PBNv8?|t*LD5&)%TuAJsnkYlA9zrI5_0$Y7g~saPW+A zaBu~P2!Jn$qyY*X95x*FhYC-8%(pV3n|4prW`*Q_F+yx`!*8l##~ntsjXIe$8`w2+ zzQ}vaydUcD%A*s1EmvlZ$tgyNPQcp*$CCtmeywvDasTY6ziFr`tkt7oMXWB%C#6>L zsUn>qmF$V3ywfV)$Uy)G+@986CpTD!KA7^bm|aZ744^%BJhBh`27I^AJhD6nS3=%_ zh~#nbs9xjXv*83kBKj!&?rF5*KOb<3o)8Jh-~vOqe`Ya8;wU zHgscm1@ApA+Cb5t9)P{)0yhY;r05-nF{s?!Ws?tyys33A{`X5N4;A+gsCVh))W&2R zuE8n#(V$R^?n;+y3`2o@pORP5>Zf{wIXUW=B(L!lLCDPde4Ykmo>F0 zNLOJ2)ku;!>r!hD&7G%K%A!DVopJRQW zKxZ#5OJCl`W}Th29L~s2UtCsFbGoDJyAw3o;GNfg^3Lsz4-C0m!02ZBsf`QY%Pja- zo!6a46KQe7@gpt3H-?UoFQqWH?bzQj@d-1jazw=ettJ$Ad^VW5lOj7UtXZ~_dP0MWlIehT{7kDmKqC*J^TYXbdnV-jZP5FK98_W z6lbX@xeKQ&Im4vOF3X@3sw~{Iim(WXb@`_gCmj#MO}A1~4x7F0OnU}=O{=fSX88y-q7 z7qPAnKI{vd|BS(|{@zOqOAT?X3xIJ;TAP`c@>oF+e)2J^H=;{;r^lC;It8L?E;0gE z3*Qy&^6WZzo2PW3MGI?Ma^+l17%2UWd<5nn+i{-XyUU@8uaihce*KGSO^@#U;v_Q% zd@&so$aai)m?+0i369sz*sUiKu&|E`ml4bu0LfgUI-eB{Qc@c`Bjde9vnsZ;gsBm10}lvY4J=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RKYzthSJru0qG`. And most importantly, spirv-cross was created as a mean to perform cross-compilation of shaders in a performant way. +#### Drivers are not all the same -It was clear for everyone, we had to investigate how we could compile SDSL to spir-v and use tools like spirv-cross. +Drivers can be seen as a front-end API to use the GPU. They have different paradigm and logic which may result in your shader code needing to be different across different drivers. -## Problems ahead +Here's a table of which language is supported by which machine depending on the driver used. I chose the most used machines for gaming. -SDSL is a very peculiar shader language, using current spir-v tools to generate spir-v byte code would be extremely difficult to design given how spir-v has a very tight specification. -Another problem is that most spir-v tools are written in system languages like Rust/C/C++, which is another barrier for a .NET based game engine. +Note that some APIs are tied to the machine you're developing for, adding more complexity to the shader system, needing to handle GPUs that have very specific features. +
-To be able to use spir-v to it's fullest we have to create a C#/.NET library from scratch, something that will help us assemble and manipulate spir-v bytecode the way SDSL works. +| | Direct3D | Vulkan | OpenGL | Metal | PSGL | NVN | +|-----------------|----------|-----------|--------|-------|------|----------------| +| Windows | HLSL | HLSL/GLSL | GLSL | | | | +| Linux | | HLSL/GLSL | GLSL | | | | +| Mac/iOS | | | | MSL | | | +| Android | | HLSL/GLSL | GLSL | | | | +| Playstation 4/5 | | | | | PSSL | | +| Nintendo Switch | | HLSL/GLSL | | | | NVN language ? | +| XBOX Series X/S | HLSL | | | | | | +
+
-## Mise en bouche for Part 2 of this article +#### Performance Cost -I've started to work on this issue not long ago through two projects : +Managed languages like C# are well known to be slower with string objects since they treat them as immutable. On top of that, tree structures, especially the one used for shader compilation in Stride, tend to perform very slowly and are prone to be slow and work against the GC. + +## Why investigating spir-v? + +Three things happened in the past 10 years, Vulkan was released with a new kind of bytecode shader language called spir-v, .NET core came out with a new high performance feature for operating on slices of array (something that C# is way better at than processing string objects), namely `Span`, and most importantly, tools like [spirv-cross](https://github.com/KhronosGroup/SPIRV-Cross) and [naga](https://github.com/gfx-rs/wgpu/tree/trunk/naga) were created as a mean to translate shaders through spir-v. + +It was clear for everyone that we had to investigate how we could compile SDSL to spir-v and use all those very performant tools to transpile SDSL to other languages. + +## Problems ahead -* [A new simplified parser for SDSL](https://github.com/ykafia/SDSLParser) -* [A spir-v assembler library for SDSL](https://github.com/ykafia/SoftTouch.Spirv) +SDSL is a very peculiar language and shifting from processing tree structures to processing segments of byte code is a great endeavor, especially for an engine. -Those will be the core subjects of part 2! +The following parts of this series of blog posts will focus on how such system can be made thanks to many new C# and .NET features that came out since .NET Core. ## Summary From 8a8608e10c3132fabc197be76828292c0b95de22 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 13 Nov 2023 12:17:41 +0100 Subject: [PATCH 3/6] Structure + text --- .../shaders-explanation.png | Bin ...estigating-spirv-for-the-shader-system.md} | 61 ++++++++++-------- 2 files changed, 33 insertions(+), 28 deletions(-) rename images/blog/{spirv => 2023-11}/shaders-explanation.png (100%) rename posts/{investigating-spirv-for-the-shader-system.md => 2023-11-10-investigating-spirv-for-the-shader-system.md} (64%) diff --git a/images/blog/spirv/shaders-explanation.png b/images/blog/2023-11/shaders-explanation.png similarity index 100% rename from images/blog/spirv/shaders-explanation.png rename to images/blog/2023-11/shaders-explanation.png diff --git a/posts/investigating-spirv-for-the-shader-system.md b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md similarity index 64% rename from posts/investigating-spirv-for-the-shader-system.md rename to posts/2023-11-10-investigating-spirv-for-the-shader-system.md index 4f332006..4689e83b 100644 --- a/posts/investigating-spirv-for-the-shader-system.md +++ b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md @@ -1,12 +1,12 @@ --- -title: "Investigating spir-v for the shader system - Part 1" +title: "Investigating spirv for the shader system - Part 1" author: youness popular: false image: /images/spir.png -tags: ['.NET', 'spir-v', 'shader', 'hlsl', 'glsl', 'sdsl', 'compilation'] +tags: ['.NET', 'Shaders'] --- -Let's investigate how the shader system works in Stride and how to make it better thanks to spir-v. +Let's investigate how the shader system works in Stride and how to make it better thanks to spirv. --- @@ -23,7 +23,7 @@ Simply put, they are typically snippets of codes that are run on the GPU, moslty When a game has to render on the screen, it starts by preparing the data on the GPU and then sends shaders with commands. The GPU then executes those commands and if everything goes well, the game ends with a lovely picture drawn on the screen ! This single call of a GPU is called a `draw call`. -![shader overview](/images/blog/spirv/shaders-explanation.png) +![shader overview](/images/blog/2023-11/shaders-explanation.png) It can be simplified to this view. There is a first stage called `Vertex stage` which is meant to compute vertices and make sure they are transformed into data that can be rasterized by your GPU, and a final stage called `Pixel stage` or `Fragment stage` that takes the rasterized output of the rasterizer and computes color for each pixel on the screen based on which triangles they belong to. @@ -31,11 +31,11 @@ In both stages, you can provide textures/images and data through buffers, this c ## Rendering in game engines -Drawing a single mesh is simple, one buffer of vertices, maybe some textures, do a draw call and marvel at the screen. Repeat it many times and you get a video, very useful to make video games. +Drawing a single mesh is simple, one buffer of vertices, maybe some textures, do a draw call and ✨ marvel at the screen ✨. Repeat it many times and you get a video, very useful to make video games 👾. In game engines, objects being drawn the same ways are grouped into `materials`. A material can be seen as a recipe for drawing a mesh with ingredients like shader code, textures, vertices and other informations. -Having many different materials implies creating many shader source code, and depending if you use [forward or deferred shading](https://learnopengl.com/Advanced-Lighting/Deferred-Shading), you might need reuse code from one file to another leading to some duplicate code. +Having many different materials implies creating many shader source code, and depending if you use [forward or deferred shading](https://learnopengl.com/Advanced-Lighting/Deferred-Shading), you might need to reuse code from one file to another leading to lots of duplicate code 👩‍đŸ’ģ👨‍đŸ’ģ. To solve this problem, all game engines have developped shader systems that help create permutation of shader code depending the material you're using. It helps re-use code you've already written, which speeds up development gives you the power to organize your code in more manageable ways! @@ -47,53 +47,58 @@ Stride has its own shader language called SDSL which stands for **S**tri**D**e * SDSL uses a very smart system of composition and inheritance, similar to object oriented programming. You can learn more about it [through the manual](https://doc.stride3d.net/latest/en/manual/graphics/effects-and-shaders/index.html). -### The barriers +## The many problems shader systems are facing To create permutations you need to be aware of the many limitations you will face while writing code for GPU. -#### GPUs are all different + +### GPUs are all different As obvious as it sounds, it needs to be reminded. Whenever you write code for your GPU you have to be aware that it will not work for all other GPUs. 10 years ago, two languages were the most used for writing shader code : HLSL and GLSL. -In the case of OpenGL GPU vendors would provide you with their own compilers to work for their GPUs through different drivers. A valid code for one compiler would be a syntax error for another. It was a big mess! +In the case of OpenGL, GPU vendors would provide you with their own GLSL compilers to work for their GPUs through different drivers. A valid code for one compiler would be a syntax error for another. It was a big mess 💩, but a manageable one! -Stride was created during this period and it was designed to run on a wide variety of devices. +Stride was created during this period and it was designed to run on a wide variety of devices 🎮 🕹ī¸ đŸ’ģ đŸ–Ĩī¸. -The solution chosen for creating code permutations that could work on many different machine was transpilation. Text would be parsed in abstract syntax trees and the text would be translated from one language to another by manipulating those trees. [To have a better idea of how abstract syntax tree work, this playlist will definitely help !](https://www.youtube.com/watch?v=cxNlb2GTKIc&list=PLTd6ceoshpreZuklA7RBMubSmhE0OHWh_&pp=iAQB) +The solution chosen for creating code permutations that could work on many different machine was transpilation. Text would be parsed in abstract syntax trees and the text would be translated from one language to another by manipulating those trees. [To have a better idea of how abstract syntax tree work, this playlist of videos will definitely help !](https://www.youtube.com/watch?v=cxNlb2GTKIc&list=PLTd6ceoshpreZuklA7RBMubSmhE0OHWh_&pp=iAQB) -#### Drivers are not all the same +### Drivers are not all the same Drivers can be seen as a front-end API to use the GPU. They have different paradigm and logic which may result in your shader code needing to be different across different drivers. Here's a table of which language is supported by which machine depending on the driver used. I chose the most used machines for gaming. -Note that some APIs are tied to the machine you're developing for, adding more complexity to the shader system, needing to handle GPUs that have very specific features. +Note that some APIs are tied to the machine you're developing for, adding more complexity to the shader system, needing to handle GPUs that have very specific features. Vulkan and OpenGL can be used on Mac and iOS but OpenGL is deprecated and Vulkan run on MoltenVK, a Vulkan implementation on top of Metal.
-| | Direct3D | Vulkan | OpenGL | Metal | PSGL | NVN | -|-----------------|----------|-----------|--------|-------|------|----------------| -| Windows | HLSL | HLSL/GLSL | GLSL | | | | -| Linux | | HLSL/GLSL | GLSL | | | | -| Mac/iOS | | | | MSL | | | -| Android | | HLSL/GLSL | GLSL | | | | -| Playstation 4/5 | | | | | PSSL | | -| Nintendo Switch | | HLSL/GLSL | | | | NVN language ? | -| XBOX Series X/S | HLSL | | | | | | +| | Direct3D | Vulkan | OpenGL | Metal | PSGL | NVN | +|-----------------|--------------|-----------|--------|-------|------|-----| +| Windows/XBox | HLSL | HLSL/GLSL | GLSL | | | | +| Linux | | HLSL/GLSL | GLSL | | | | +| Mac/iOS | | HLSL/GLSL | GLSL | MSL | | | +| Android | | HLSL/GLSL | GLSL | | | | +| Playstation 4/5 | | | | | PSSL | | +| Nintendo Switch | | HLSL/GLSL | GLSL | | | ? | +

-#### Performance Cost +### Performance Cost Managed languages like C# are well known to be slower with string objects since they treat them as immutable. On top of that, tree structures, especially the one used for shader compilation in Stride, tend to perform very slowly and are prone to be slow and work against the GC. -## Why investigating spir-v? +## Why investigating spirv? + +Three things happened in the past 10 years : + +* Vulkan was released with a new kind of bytecode shader language called spirv -Three things happened in the past 10 years, Vulkan was released with a new kind of bytecode shader language called spir-v, .NET core came out with a new high performance feature for operating on slices of array (something that C# is way better at than processing string objects), namely `Span`, and most importantly, tools like [spirv-cross](https://github.com/KhronosGroup/SPIRV-Cross) and [naga](https://github.com/gfx-rs/wgpu/tree/trunk/naga) were created as a mean to translate shaders through spir-v. +* .NET core came out with a new high performance feature for operating on slices of array (something that C# is way better at than processing string objects), namely `Span` -It was clear for everyone that we had to investigate how we could compile SDSL to spir-v and use all those very performant tools to transpile SDSL to other languages. +* Most importantly, tools like [spirv-cross](https://github.com/KhronosGroup/SPIRV-Cross) and [naga](https://github.com/gfx-rs/wgpu/tree/trunk/naga) were created as a mean to translate shaders through spirv. -## Problems ahead +It was clear for everyone that we had to investigate how we could compile SDSL to spirv and use all those very performant tools to transpile SDSL to other languages. SDSL is a very peculiar language and shifting from processing tree structures to processing segments of byte code is a great endeavor, especially for an engine. @@ -101,6 +106,6 @@ The following parts of this series of blog posts will focus on how such system c ## Summary -Embracing spir-v for Stride's shader system will hopefully empower us with a better control over the shader language but also improve performance for shader compilation! +Embracing spirv for Stride's shader system will hopefully empower us with a better control over the shader language but also improve performance for shader compilation! đŸ’ĒđŸ’Ē Thank you for reading! From f6bd08cd0372b2253f6592ff422ebc87bd655bcc Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 13 Nov 2023 12:47:45 +0100 Subject: [PATCH 4/6] update of introduction text --- posts/2023-11-10-investigating-spirv-for-the-shader-system.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/posts/2023-11-10-investigating-spirv-for-the-shader-system.md b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md index 4689e83b..cb54296d 100644 --- a/posts/2023-11-10-investigating-spirv-for-the-shader-system.md +++ b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md @@ -6,7 +6,8 @@ image: /images/spir.png tags: ['.NET', 'Shaders'] --- -Let's investigate how the shader system works in Stride and how to make it better thanks to spirv. +In this first part of a new series of blog posts, we will learn more about Stride's shader system, its limitations and how to make it better thanks to very useful shader language called spirv! +This will be the first step in implementing a new and better shader system. --- From 3fe1872bdbb08953ac148583fdf8e6a5f10f15ec Mon Sep 17 00:00:00 2001 From: Vaclav Elias Date: Tue, 14 Nov 2023 00:38:50 +0100 Subject: [PATCH 5/6] Update 2023-11-10-investigating-spirv-for-the-shader-system.md --- ...vestigating-spirv-for-the-shader-system.md | 117 ++++++++++++------ 1 file changed, 82 insertions(+), 35 deletions(-) diff --git a/posts/2023-11-10-investigating-spirv-for-the-shader-system.md b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md index cb54296d..1c372b89 100644 --- a/posts/2023-11-10-investigating-spirv-for-the-shader-system.md +++ b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md @@ -1,13 +1,12 @@ --- -title: "Investigating spirv for the shader system - Part 1" +title: "Investigating SPIR-V for the shader system - Part 1" author: youness popular: false image: /images/spir.png tags: ['.NET', 'Shaders'] --- -In this first part of a new series of blog posts, we will learn more about Stride's shader system, its limitations and how to make it better thanks to very useful shader language called spirv! -This will be the first step in implementing a new and better shader system. +In this first part of a new series of blog posts, we will learn more about Stride's shader system, its limitations and how to make it better thanks to a very useful shader language called SPIR-V! This will be the first step in implementing a new and better shader system. --- @@ -17,12 +16,11 @@ Table of Contents: The Stride engine has a powerful shader system, helping users build very complex shaders thanks to its language features like composition and inheritance, and its C# integration through the very powerful material system. -## What are shaders ? +## What are shaders? -Simply put, they are typically snippets of codes that are run on the GPU, moslty written in C-like languages like GLSL and HLSL. +Simply put, they are typically snippets of code that are run on the GPU, mostly written in C-like languages like GLSL and HLSL. -When a game has to render on the screen, it starts by preparing the data on the GPU and then sends shaders with commands. The GPU then executes those commands and if everything goes well, the game ends with a lovely picture drawn on the screen ! -This single call of a GPU is called a `draw call`. +When a game has to render on the screen, it starts by preparing the data on the GPU and then sends shaders with commands. The GPU then executes those commands and if everything goes well, the game ends with a lovely picture drawn on the screen. This single call of a GPU is called a `draw call`. ![shader overview](/images/blog/2023-11/shaders-explanation.png) @@ -38,11 +36,11 @@ In game engines, objects being drawn the same ways are grouped into `materials`. Having many different materials implies creating many shader source code, and depending if you use [forward or deferred shading](https://learnopengl.com/Advanced-Lighting/Deferred-Shading), you might need to reuse code from one file to another leading to lots of duplicate code 👩‍đŸ’ģ👨‍đŸ’ģ. -To solve this problem, all game engines have developped shader systems that help create permutation of shader code depending the material you're using. It helps re-use code you've already written, which speeds up development gives you the power to organize your code in more manageable ways! +To solve this problem, all game engines have developed shader systems that help create permutations of shader code depending on the material you're using. It helps reuse code you've already written, which speeds up development and gives you the power to organize your code in more manageable ways. A good example of that are [shader graphs from Unity](https://unity.com/features/shader-graph) or [the material editor in Unreal](https://docs.unrealengine.com/5.0/en-US/unreal-engine-material-editor-ui/), whenever you add a block/function to the graph, it reuses shader code already written, to create a new permutation. -## How does it work in Stride ? +## How does it work in Stride? Stride has its own shader language called SDSL which stands for **S**tri**D**e **S**hader **L**anguage. @@ -52,17 +50,15 @@ SDSL uses a very smart system of composition and inheritance, similar to object To create permutations you need to be aware of the many limitations you will face while writing code for GPU. - ### GPUs are all different As obvious as it sounds, it needs to be reminded. Whenever you write code for your GPU you have to be aware that it will not work for all other GPUs. -10 years ago, two languages were the most used for writing shader code : HLSL and GLSL. -In the case of OpenGL, GPU vendors would provide you with their own GLSL compilers to work for their GPUs through different drivers. A valid code for one compiler would be a syntax error for another. It was a big mess 💩, but a manageable one! +10 years ago, two languages were the most used for writing shader code: HLSL and GLSL. In the case of OpenGL, GPU vendors would provide you with their own GLSL compilers to work for their GPUs through different drivers. A valid code for one compiler would be a syntax error for another. It was a big mess 💩, but a manageable one! Stride was created during this period and it was designed to run on a wide variety of devices 🎮 🕹ī¸ đŸ’ģ đŸ–Ĩī¸. -The solution chosen for creating code permutations that could work on many different machine was transpilation. Text would be parsed in abstract syntax trees and the text would be translated from one language to another by manipulating those trees. [To have a better idea of how abstract syntax tree work, this playlist of videos will definitely help !](https://www.youtube.com/watch?v=cxNlb2GTKIc&list=PLTd6ceoshpreZuklA7RBMubSmhE0OHWh_&pp=iAQB) +The solution chosen for creating code permutations that could work on many different machine was transpilation. Text would be parsed in abstract syntax trees and the text would be translated from one language to another by manipulating those trees. [To have a better idea of how abstract syntax tree work, this playlist of videos will definitely help](https://www.youtube.com/watch?v=cxNlb2GTKIc&list=PLTd6ceoshpreZuklA7RBMubSmhE0OHWh_&pp=iAQB). ### Drivers are not all the same @@ -71,42 +67,93 @@ Drivers can be seen as a front-end API to use the GPU. They have different parad Here's a table of which language is supported by which machine depending on the driver used. I chose the most used machines for gaming. Note that some APIs are tied to the machine you're developing for, adding more complexity to the shader system, needing to handle GPUs that have very specific features. Vulkan and OpenGL can be used on Mac and iOS but OpenGL is deprecated and Vulkan run on MoltenVK, a Vulkan implementation on top of Metal. -
- -| | Direct3D | Vulkan | OpenGL | Metal | PSGL | NVN | -|-----------------|--------------|-----------|--------|-------|------|-----| -| Windows/XBox | HLSL | HLSL/GLSL | GLSL | | | | -| Linux | | HLSL/GLSL | GLSL | | | | -| Mac/iOS | | HLSL/GLSL | GLSL | MSL | | | -| Android | | HLSL/GLSL | GLSL | | | | -| Playstation 4/5 | | | | | PSSL | | -| Nintendo Switch | | HLSL/GLSL | GLSL | | | ? | -
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Direct3DVulkanOpenGLMetalPSGLNVN
Windows/XBoxHLSLHLSL/GLSLGLSL
LinuxHLSL/GLSLGLSL
Mac/iOSHLSL/GLSLGLSLMSL
AndroidHLSL/GLSLGLSL
Playstation 4/5PSSL
Nintendo SwitchHLSL/GLSLGLSL?
### Performance Cost Managed languages like C# are well known to be slower with string objects since they treat them as immutable. On top of that, tree structures, especially the one used for shader compilation in Stride, tend to perform very slowly and are prone to be slow and work against the GC. -## Why investigating spirv? - -Three things happened in the past 10 years : - -* Vulkan was released with a new kind of bytecode shader language called spirv +## Why investigating SPIR-V? -* .NET core came out with a new high performance feature for operating on slices of array (something that C# is way better at than processing string objects), namely `Span` +Three things happened in the past 10 years: -* Most importantly, tools like [spirv-cross](https://github.com/KhronosGroup/SPIRV-Cross) and [naga](https://github.com/gfx-rs/wgpu/tree/trunk/naga) were created as a mean to translate shaders through spirv. +* Vulkan was released with a new kind of bytecode shader language called SPIR-V +* .NET Core introduced a new high-performance feature for operating on slices of array (something that C# is way better at than processing string objects), namely `Span` +* Most importantly, tools like [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) and [Naga](https://github.com/gfx-rs/wgpu/tree/trunk/naga) were created as a means to translate shaders through SPIR-V. -It was clear for everyone that we had to investigate how we could compile SDSL to spirv and use all those very performant tools to transpile SDSL to other languages. +It was clear for everyone that we had to investigate how we could compile SDSL to SPIR-V and use all those very performant tools to transpile SDSL to other languages. SDSL is a very peculiar language and shifting from processing tree structures to processing segments of byte code is a great endeavor, especially for an engine. -The following parts of this series of blog posts will focus on how such system can be made thanks to many new C# and .NET features that came out since .NET Core. +The following parts of this series of blog posts will focus on how such a system can be created, thanks to the many new C# and .NET features that came out since the release of .NET Core. ## Summary -Embracing spirv for Stride's shader system will hopefully empower us with a better control over the shader language but also improve performance for shader compilation! đŸ’ĒđŸ’Ē +Embracing SPIR-V for Stride's shader system will hopefully empower us with a better control over the shader language but also improve performance for shader compilation đŸ’ĒđŸ’Ē. Thank you for reading! From a7388526080dc152498b24f9a87eed0a565e8a68 Mon Sep 17 00:00:00 2001 From: Vaclav Elias Date: Tue, 14 Nov 2023 00:48:51 +0100 Subject: [PATCH 6/6] feat: Typos and content updates --- ...2023-11-10-investigating-spirv-for-the-shader-system.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/posts/2023-11-10-investigating-spirv-for-the-shader-system.md b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md index 1c372b89..815dc41e 100644 --- a/posts/2023-11-10-investigating-spirv-for-the-shader-system.md +++ b/posts/2023-11-10-investigating-spirv-for-the-shader-system.md @@ -6,7 +6,7 @@ image: /images/spir.png tags: ['.NET', 'Shaders'] --- -In this first part of a new series of blog posts, we will learn more about Stride's shader system, its limitations and how to make it better thanks to a very useful shader language called SPIR-V! This will be the first step in implementing a new and better shader system. +In this first part of a new series of blog posts, we will learn more about Stride's shader system, its limitations and how to make it better thanks to a very useful shader language called SPIR-V. This will be the first step in implementing a new and better shader system. --- @@ -69,6 +69,7 @@ Here's a table of which language is supported by which machine depending on the Note that some APIs are tied to the machine you're developing for, adding more complexity to the shader system, needing to handle GPUs that have very specific features. Vulkan and OpenGL can be used on Mac and iOS but OpenGL is deprecated and Vulkan run on MoltenVK, a Vulkan implementation on top of Metal. + @@ -77,7 +78,7 @@ Note that some APIs are tied to the machine you're developing for, adding more c - + @@ -144,7 +145,7 @@ Three things happened in the past 10 years: * Vulkan was released with a new kind of bytecode shader language called SPIR-V * .NET Core introduced a new high-performance feature for operating on slices of array (something that C# is way better at than processing string objects), namely `Span` -* Most importantly, tools like [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) and [Naga](https://github.com/gfx-rs/wgpu/tree/trunk/naga) were created as a means to translate shaders through SPIR-V. +* Most importantly, tools like [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) and [Naga](https://github.com/gfx-rs/wgpu/tree/trunk/naga) were created as a means to translate shaders through SPIR-V It was clear for everyone that we had to investigate how we could compile SDSL to SPIR-V and use all those very performant tools to transpile SDSL to other languages.
Direct3DMetal PSGL NVN
Windows/XBox HLSL