/// <summary> /// Create a new ShaderInfo object by providing directly a VkShaderModule. Note /// that this module will not be own by this ShaderInfo, and so will not be /// destroyed on Dispose. /// </summary> public ShaderInfo(VkShaderStageFlags stageFlags, VkShaderModule module, SpecializationInfo specializationInfo = null, string entryPoint = "main") { EntryPoint = new FixedUtf8String(entryPoint); info.stage = stageFlags; info.pName = EntryPoint; info.module = module; info.pSpecializationInfo = (specializationInfo == null) ? IntPtr.Zero : specializationInfo.InfosPtr; }
public static ShaderInfo CreateShaderInfo(this shaderc.Compiler comp, Device dev, string shaderPath, shaderc.ShaderKind shaderKind, SpecializationInfo specializationInfo = null, string entryPoint = "main") { using (shaderc.Result res = comp.Compile(shaderPath, shaderKind)) { if (res.Status != shaderc.Status.Success) { throw new Exception($"Shaderc compilation failure: {res.ErrorMessage}"); } VkShaderStageFlags stageFlags = Utils.ShaderKindToStageFlag(shaderKind); return(new ShaderInfo(dev, stageFlags, res.CodePointer, (UIntPtr)res.CodeLength, specializationInfo, entryPoint)); } }
/// <summary> /// Create a new ShaderInfo object by providing the path to a compiled SpirV shader. /// </summary> /// <param name="dev">vke Device</param> /// <param name="_stageFlags">Stage flags.</param> /// <param name="_spirvPath">path to a compiled SpirV Shader on disk or as embedded ressource if path starts with '#'</param> /// <param name="specializationInfo">Specialization info</param> /// <param name="entryPoint">shader entry point, 'main' by default.</param> public ShaderInfo(Device dev, VkShaderStageFlags _stageFlags, string _spirvPath, SpecializationInfo specializationInfo = null, string entryPoint = "main") : this(_stageFlags, dev.CreateShaderModule(_spirvPath), specializationInfo, entryPoint) { this.dev = dev; //keep dev for destroying module created in this CTOR }
/// <summary> /// Create a new 'ShaderInfo' object by providing a handle to an native memory holding the compiled SpirV code /// and its size in byte. /// </summary> /// <param name="dev">Dev.</param> /// <param name="stageFlags">Stage flags.</param> /// <param name="code">a native pointer on the SpirV Code, typically a 'shaderc.Result.CodePointer</param> /// <param name="codeSize">Code size in byte</param> /// <param name="specializationInfo">Specialization info.</param> /// <param name="entryPoint">shader entry point</param> public ShaderInfo(Device dev, VkShaderStageFlags stageFlags, IntPtr code, UIntPtr codeSize, SpecializationInfo specializationInfo = null, string entryPoint = "main") : this(stageFlags, dev.CreateShaderModule(code, codeSize), specializationInfo, entryPoint) { this.dev = dev; //keep dev for destroying module created in this CTOR }
/// <summary> /// Dispose ShaderInfo at index 'shaderIndex' in the Shaders list, and replace it with a new one. /// </summary> public void ReplaceShader(int shaderIndex, Device dev, VkShaderStageFlags stageFlags, string spirvShaderPath, SpecializationInfo specializationInfo = null, string entryPoint = "main") { Shaders[shaderIndex].Dispose(); Shaders[shaderIndex] = new ShaderInfo(dev, stageFlags, spirvShaderPath, specializationInfo, entryPoint); }
/// <summary> /// Dispose ShaderInfo at index 'shaderIndex' in the Shaders list, and replace it with a new one. /// </summary> public void ReplaceShader(int shaderIndex, VkShaderStageFlags stageFlags, VkShaderModule module, SpecializationInfo specializationInfo = null, string entryPoint = "main") { Shaders[shaderIndex].Dispose(); Shaders[shaderIndex] = new ShaderInfo(stageFlags, module, specializationInfo, entryPoint); }
/// <summary> /// Add a new shader to this pipeline configuration. /// </summary> public void AddShader(Device dev, VkShaderStageFlags stageFlags, string spirvShaderPath, SpecializationInfo specializationInfo = null, string entryPoint = "main") { Shaders.Add(new ShaderInfo(dev, stageFlags, spirvShaderPath, specializationInfo, entryPoint)); }
/// <summary> /// Add a new shader to this pipeline configuration. /// </summary> public void AddShader(VkShaderStageFlags stageFlags, VkShaderModule module, SpecializationInfo specializationInfo = null, string entryPoint = "main") { Shaders.Add(new ShaderInfo(stageFlags, module, specializationInfo, entryPoint)); }