namespace Brutal.VulkanApi.Abstractions; public static class Presets { public struct VertexInput { /// /// An empty vertex input /// public static readonly NativeList None = [new()]; } public struct BlendState { /// /// Color blend using alpha /// public static readonly PtrOwner BlendColorAlpha = new( new VkPipelineColorBlendStateCreateInfo { AttachmentCount = 1, Attachments = BlendAttachment.BlendColorAlpha, } ); /// /// Source color replaces destination color directly with no blending /// public static readonly PtrOwner BlendNone = new( new VkPipelineColorBlendStateCreateInfo { AttachmentCount = 1, Attachments = BlendAttachment.BlendNone } ); /// /// Additive blend /// public static readonly PtrOwner BlendAdditive = new( new VkPipelineColorBlendStateCreateInfo { AttachmentCount = 1, Attachments = BlendAttachment.BlendColorAdditive, } ); /// /// Source color is softer the brighter the destination color is, resulting components don't exceed 1 /// public static readonly PtrOwner BlendSoftAdditive = new( new VkPipelineColorBlendStateCreateInfo { AttachmentCount = 1, Attachments = BlendAttachment.BlendColorSoftAdditive, } ); /// /// Multiplicative blend /// public static readonly PtrOwner BlendMultiplicative = new( new VkPipelineColorBlendStateCreateInfo { AttachmentCount = 1, Attachments = BlendAttachment.BlendColorMultiplicative, } ); } public struct BlendAttachment { /// /// Source color replaces destination color directly with no blending /// public static readonly PtrOwner BlendNone = new( new VkPipelineColorBlendAttachmentState { BlendEnable = false, ColorWriteMask = VkColorComponentFlags.RBit | VkColorComponentFlags.GBit | VkColorComponentFlags.BBit | VkColorComponentFlags.ABit, } ); /// /// Color blend using alpha /// public static readonly PtrOwner BlendColorAlpha = new( new VkPipelineColorBlendAttachmentState { BlendEnable = true, SrcColorBlendFactor = VkBlendFactor.SrcAlpha, DstColorBlendFactor = VkBlendFactor.OneMinusSrcAlpha, ColorBlendOp = VkBlendOp.Add, SrcAlphaBlendFactor = VkBlendFactor.One, DstAlphaBlendFactor = VkBlendFactor.Zero, AlphaBlendOp = VkBlendOp.Add, ColorWriteMask = VkColorComponentFlags.RBit | VkColorComponentFlags.GBit | VkColorComponentFlags.BBit | VkColorComponentFlags.ABit, } ); /// /// Additive blend /// public static readonly PtrOwner BlendColorAdditive = new( new VkPipelineColorBlendAttachmentState { BlendEnable = true, SrcColorBlendFactor = VkBlendFactor.One, DstColorBlendFactor = VkBlendFactor.DstAlpha, ColorBlendOp = VkBlendOp.Add, SrcAlphaBlendFactor = VkBlendFactor.One, DstAlphaBlendFactor = VkBlendFactor.Zero, AlphaBlendOp = VkBlendOp.Add, ColorWriteMask = VkColorComponentFlags.RBit | VkColorComponentFlags.GBit | VkColorComponentFlags.BBit | VkColorComponentFlags.ABit, } ); /// /// Source color is softer the brighter the destination color is, resulting components don't exceed 1 /// public static readonly PtrOwner BlendColorSoftAdditive = new( new VkPipelineColorBlendAttachmentState { BlendEnable = true, SrcColorBlendFactor = VkBlendFactor.OneMinusDstColor, DstColorBlendFactor = VkBlendFactor.DstAlpha, ColorBlendOp = VkBlendOp.Add, SrcAlphaBlendFactor = VkBlendFactor.One, DstAlphaBlendFactor = VkBlendFactor.Zero, AlphaBlendOp = VkBlendOp.Add, ColorWriteMask = VkColorComponentFlags.RBit | VkColorComponentFlags.GBit | VkColorComponentFlags.BBit | VkColorComponentFlags.ABit, } ); /// /// Multiplicative blend /// public static readonly PtrOwner BlendColorMultiplicative = new( new VkPipelineColorBlendAttachmentState { BlendEnable = true, SrcColorBlendFactor = VkBlendFactor.DstColor, DstColorBlendFactor = VkBlendFactor.Zero, ColorBlendOp = VkBlendOp.Add, SrcAlphaBlendFactor = VkBlendFactor.One, DstAlphaBlendFactor = VkBlendFactor.Zero, AlphaBlendOp = VkBlendOp.Add, ColorWriteMask = VkColorComponentFlags.RBit | VkColorComponentFlags.GBit | VkColorComponentFlags.BBit | VkColorComponentFlags.ABit, } ); } /// /// Depth stencil presets /// public struct DepthStencil { /// /// Depth stencil with depth test and write enabled /// public static readonly PtrOwner DepthTestWrite = new( new VkPipelineDepthStencilStateCreateInfo { DepthTestEnable = true, DepthWriteEnable = true, DepthCompareOp = VkCompareOp.LessOrEqual, DepthBoundsTestEnable = false, StencilTestEnable = false, } ); /// /// Depth stencil with depth test enabled but not write. Good for a transparent particle /// public static readonly PtrOwner DepthTestNoWrite = new( new VkPipelineDepthStencilStateCreateInfo { DepthTestEnable = true, DepthWriteEnable = false, DepthCompareOp = VkCompareOp.LessOrEqual, DepthBoundsTestEnable = false, StencilTestEnable = false, } ); /// /// Depth stencil with depth test enabled and write enabled. Stencil test enabled and using front and back StencilOpState values. /// public static readonly PtrOwner DepthTestWriteStencil = new( new VkPipelineDepthStencilStateCreateInfo { DepthTestEnable = true, DepthWriteEnable = true, DepthCompareOp = VkCompareOp.LessOrEqual, DepthBoundsTestEnable = false, StencilTestEnable = true, Front = new VkStencilOpState(), Back = new VkStencilOpState(), } ); /// /// Depth stencil with depth test and write disabled. Stencil test enabled and using front and back StencilOpState values. /// public static readonly PtrOwner DepthNoTestNoWriteStencil = new( new VkPipelineDepthStencilStateCreateInfo { DepthTestEnable = false, DepthWriteEnable = false, DepthCompareOp = VkCompareOp.LessOrEqual, DepthBoundsTestEnable = false, StencilTestEnable = true, Front = new VkStencilOpState(), Back = new VkStencilOpState(), } ); /// /// Depth stencil with depth test enabled but not write. Good for a transparent particle /// public static readonly PtrOwner NoDepthTest = new( new VkPipelineDepthStencilStateCreateInfo() ); } public struct InputAssembly { /// /// /// public static readonly PtrOwner PointList = new( new VkPipelineInputAssemblyStateCreateInfo { Topology = VkPrimitiveTopology.PointList } ); /// /// /// public static readonly PtrOwner TriangleList = new( new VkPipelineInputAssemblyStateCreateInfo { Topology = VkPrimitiveTopology.TriangleList } ); /// /// /// public static readonly PtrOwner TriangleStrip = new( new VkPipelineInputAssemblyStateCreateInfo { Topology = VkPrimitiveTopology.TriangleStrip } ); /// /// /// public static readonly PtrOwner LineList = new( new VkPipelineInputAssemblyStateCreateInfo { Topology = VkPrimitiveTopology.LineList } ); /// /// /// public static readonly PtrOwner LineStrip = new( new VkPipelineInputAssemblyStateCreateInfo { Topology = VkPrimitiveTopology.LineStrip } ); /// /// /// public static readonly PtrOwner PatchList = new( new VkPipelineInputAssemblyStateCreateInfo { Topology = VkPrimitiveTopology.PatchList } ); } public struct Multisample { /// /// /// public static readonly PtrOwner None = new( new VkPipelineMultisampleStateCreateInfo { RasterizationSamples = VkSampleCountFlags._1Bit } ); } public struct Rasterization { /// /// /// public static class Fill { /// /// /// public static readonly PtrOwner CullBack = new( new VkPipelineRasterizationStateCreateInfo { CullMode = VkCullModeFlags.BackBit, LineWidth = 1 } ); /// /// /// public static readonly PtrOwner CullFront = new( new VkPipelineRasterizationStateCreateInfo { CullMode = VkCullModeFlags.FrontBit, LineWidth = 1 } ); /// /// /// public static readonly PtrOwner CullNone = new( new VkPipelineRasterizationStateCreateInfo { CullMode = VkCullModeFlags.None, LineWidth = 1 } ); } /// /// /// public static class Line { /// /// /// public static readonly PtrOwner CullBack = new( new VkPipelineRasterizationStateCreateInfo { CullMode = VkCullModeFlags.BackBit, PolygonMode = VkPolygonMode.Line, LineWidth = 1.0f, } ); /// /// /// public static readonly PtrOwner CullFront = new( new VkPipelineRasterizationStateCreateInfo { CullMode = VkCullModeFlags.FrontBit, PolygonMode = VkPolygonMode.Line, LineWidth = 1.0f, } ); /// /// /// public static readonly PtrOwner CullNone = new( new VkPipelineRasterizationStateCreateInfo { CullMode = VkCullModeFlags.None, PolygonMode = VkPolygonMode.Line, LineWidth = 1.0f, } ); } } public struct Components { /// /// /// public static readonly PtrOwner Default = new( new VkComponentMapping { R = VkComponentSwizzle.R, G = VkComponentSwizzle.G, B = VkComponentSwizzle.B, A = VkComponentSwizzle.A, } ); } public struct Entrypoint { Ptr Name; internal unsafe Entrypoint(ReadOnlySpan name) { Name = name.AsPointer(); } public static Entrypoint Main => new("main"u8); public static unsafe implicit operator byte*(Entrypoint entrypoint) => entrypoint.Name; } public struct ShaderStage { /// /// Create a shader stage with a pre-built module /// /// /// /// public static VkPipelineShaderStageCreateInfo Make(VkShaderStageFlags stage, VkShaderModule shaderModule) => new() { Name = Entrypoint.Main, Stage = stage, Module = shaderModule, }; /// /// Make a vertex shader stage /// public static VkPipelineShaderStageCreateInfo Vertex(VkShaderModule shaderModule) => Make(VkShaderStageFlags.VertexBit, shaderModule); /// /// Make a fragment shader stage /// public static VkPipelineShaderStageCreateInfo Fragment(VkShaderModule shaderModule) => Make(VkShaderStageFlags.FragmentBit, shaderModule); /// /// Make a geometry shader stage /// public static VkPipelineShaderStageCreateInfo Geometry(VkShaderModule shaderModule) => Make(VkShaderStageFlags.GeometryBit, shaderModule); /// /// Make a evaluation shader stage /// public static VkPipelineShaderStageCreateInfo Evaluation(VkShaderModule shaderModule) => Make(VkShaderStageFlags.TessellationEvaluationBit, shaderModule); /// /// Make a control shader stage /// public static VkPipelineShaderStageCreateInfo Control(VkShaderModule shaderModule) => Make(VkShaderStageFlags.TessellationControlBit, shaderModule); /// /// Make a compute shader stage /// public static VkPipelineShaderStageCreateInfo Compute(VkShaderModule shaderModule) => Make(VkShaderStageFlags.ComputeBit, shaderModule); } public struct Sampler { /// /// Basic sampler config for a standard trilinear sampler that is clamped, with no anisotrophy /// public static VkSamplerCreateInfo SamplerLinearClamped => new() { MagFilter = VkFilter.Linear, MinFilter = VkFilter.Linear, MipmapMode = VkSamplerMipmapMode.Linear, AddressModeU = VkSamplerAddressMode.ClampToEdge, AddressModeV = VkSamplerAddressMode.ClampToEdge, AddressModeW = VkSamplerAddressMode.ClampToEdge, MipLodBias = 0, AnisotropyEnable = false, MaxAnisotropy = 0, CompareEnable = false, CompareOp = VkCompareOp.Never, MinLod = 0, MaxLod = VK.LOD_CLAMP_NONE, BorderColor = VkBorderColor.FloatOpaqueBlack, UnnormalizedCoordinates = false, }; /// /// Basic sampler config for a standard trilinear sampler that repeats, with no anisotrophy /// public static VkSamplerCreateInfo SamplerLinearRepeat => new() { MagFilter = VkFilter.Linear, MinFilter = VkFilter.Linear, MipmapMode = VkSamplerMipmapMode.Linear, AddressModeU = VkSamplerAddressMode.Repeat, AddressModeV = VkSamplerAddressMode.Repeat, AddressModeW = VkSamplerAddressMode.Repeat, MipLodBias = 0, AnisotropyEnable = false, MaxAnisotropy = 0, CompareEnable = false, CompareOp = VkCompareOp.Never, MinLod = 0, MaxLod = VK.LOD_CLAMP_NONE, BorderColor = VkBorderColor.FloatOpaqueBlack, UnnormalizedCoordinates = false, }; /// /// Trilinear clamped sampler with 16x anisotropic filtering. Requires the /// samplerAnisotropy device feature; clamp MaxAnisotropy to the device's /// maxSamplerAnisotropy limit if it is lower. /// public static VkSamplerCreateInfo SamplerAnisotropicClamped { get { var info = SamplerLinearClamped; info.AnisotropyEnable = true; info.MaxAnisotropy = 16; return info; } } /// /// Trilinear repeating sampler with 16x anisotropic filtering. Requires the /// samplerAnisotropy device feature; clamp MaxAnisotropy to the device's /// maxSamplerAnisotropy limit if it is lower. /// public static VkSamplerCreateInfo SamplerAnisotropicRepeat { get { var info = SamplerLinearRepeat; info.AnisotropyEnable = true; info.MaxAnisotropy = 16; return info; } } /// /// Basic sampler config for a standard point sampler that is clamped, with no anisotrophy /// public static VkSamplerCreateInfo SamplerPointClamped => new() { MagFilter = VkFilter.Nearest, MinFilter = VkFilter.Nearest, MipmapMode = VkSamplerMipmapMode.Nearest, AddressModeU = VkSamplerAddressMode.ClampToEdge, AddressModeV = VkSamplerAddressMode.ClampToEdge, AddressModeW = VkSamplerAddressMode.ClampToEdge, MipLodBias = 0, AnisotropyEnable = false, MaxAnisotropy = 0, CompareEnable = false, CompareOp = VkCompareOp.Never, MinLod = 0, MaxLod = VK.LOD_CLAMP_NONE, BorderColor = VkBorderColor.FloatOpaqueBlack, UnnormalizedCoordinates = false, }; } }