namespace Brutal.VulkanApi.Abstractions; /// /// A builder for /// public class ShaderStages(Device inDevice, Span inStages, VkAllocator? allocator) : IDisposable { private readonly NativeList _stages = new(inStages); /// /// The number of stages /// public int Count => _stages.Count; /// /// Destroy shaders (only call this if you know you are responsible for destroying them!) /// public void Dispose() { if (_stages.Count == 0) return; for (var index = 0; index < _stages.Count; index++) inDevice.DestroyShaderModule(_stages[index].Module, allocator); _stages.Count = 0; } /// /// Implicit cast to the PipelineVertexInputStateCreateInfo structure /// public static unsafe implicit operator VkPipelineShaderStageCreateInfo*(ShaderStages inValue) => inValue._stages.Ptr; /// /// Offset the stages by some number /// public static unsafe VkPipelineShaderStageCreateInfo* operator +(ShaderStages inStages, int inValue) { if (inStages.Count <= inValue) throw new ArgumentOutOfRangeException(nameof(inValue)); return (VkPipelineShaderStageCreateInfo*)inStages + inValue; } /// /// Create a span from a subset of the shader stages /// /// The start element /// /// public Span Slice(int start) { return _stages.Slice(start); } /// /// Create a span from a subset of the shader stages /// /// The start element /// How many elements to include /// /// public Span Slice(int start, int length) { return _stages.Slice(start, length); } }