Net bindings for google shaderc.
This sample use vk.net to create the shader module.
On success, Result
object will hold a native pointer on the generated spirv code suitable for the ShaderModuleCreateInfo
pCode field. This pointer will stay valid until the Result
disposal.
using (Compiler comp = new Compiler ()) {
using (Result res = comp.Compile ("test.vert", ShaderKind.VertexShader)) {
if (res.Status == Status.Success) {
VkShaderModuleCreateInfo ci = VkShaderModuleCreateInfo.New ();
ci.codeSize = res.codeSize;
ci.pCode = res.code;
vkCreateShaderModule (VkDev, ref moduleCreateInfo, IntPtr.Zero, out VkShaderModule shaderModule));
shaderc library provide the ability to add #include
statements as in c/c++. This functionality is enabled or not in the Options
class constructor, the default is enabled.
Options opt = new Options(false);
A default Options
instance is created by the Compiler
constructor which enable the include resolution. You may provide a custom Options instance to the compiler constructor.
Compiler comp = new Compiler (opt);
comp.Options.InvertY = true;
As in c/c++, you may have local or global include (enclosed in "" or <>). Local includes enclosed in "" will be searched from the current parsed source file. Global includes enclosed in '<>' will be searched in directories listed in Options.IncludeDirectories
. The pathes may be relative to the executable directory, or absolute.
comp.Options.IncludeDirectories.AddRange ("shaders", @"c:\test");
If you want to override the default include resolution, to search for embedded ressources for example, derive the Options
class and override the TryFindInclude
method.
class OptionsWithCustomIncResolve : Options {
protected override bool TryFindInclude (string sourcePath, string includePath, IncludeType incType, out string incFile, out string incContent) {
...