Graphics Shader Program Development in C# Using Source Generators
摘要
Low-level GPU (Graphics Processing Unit) development requires the use of a Graphics API to control the GPU device and involves shader development for implementing the kernel applications executing on the GPU. Every Graphics API supports and prefers a different shader language, therefore in case of multi-API development the same shader programs must be implemented multiple times to support all required shader languages. Searching for ways to make shader development multi-API is a current and active research area. There are multiple approaches to cross-compile shaders from one language to another or to develop shaders in a specialized language capable of compiling to multiple shader languages. In our research, we're designing and developing a Graphics API abstraction layer in C#, that is capable of handling the differences of several Graphics APIs. Abstraction of the shader languages are also a required ability of this layer. In our approach, we're using the C# language as a base and we're developing an EDSL (Embedded Domain Specific Language) on the top of C# allowing the implementation of graphics shader programs in the form of C# classes. These shader classes can be compiled into GLSL, SPIR-V, and HLSL shader languages with our prototype compiler tool. Also, our approach allows the usage of high-level features of the C# language in shader development and code sharing between different shaders or even between GPU shaders and regular C# CPU code.