Editor/Prism/Compiler/Backends/IShaderBackend.cs

Interface for shader backends in the Prism compiler. Declares identity, display name, file extension, capabilities and an Emit method that turns an IrModule into text and reports diagnostics.

using Editor.Prism.Compiler.Ir;
using Editor.Prism.Core;

namespace Editor.Prism.Compiler.Backends;

/// <summary>
/// Turns an <see cref="IrModule"/> into text.
/// <para>
/// Everything upstream of a backend runs exactly once per compile and is backend-agnostic, which is
/// why emitting both the s&amp;box <c>.shader</c> and a portable <c>.slang</c> module costs almost
/// nothing beyond the second text serialization.
/// </para>
/// </summary>
public interface IShaderBackend
{
	/// <summary>Stable id, e.g. <c>sbox-hlsl</c> or <c>slang</c>.</summary>
	string Id { get; }

	/// <summary>Name shown in the UI.</summary>
	string DisplayName { get; }

	/// <summary>File extension of the primary artifact, without a dot.</summary>
	string FileExtension { get; }

	/// <summary>What this backend can express. Consulted during validation, not at emit time.</summary>
	BackendCapabilities Capabilities { get; }

	/// <summary>
	/// Emit the module. Never throws for user error — problems go to <paramref name="diagnostics"/>
	/// and the result comes back empty.
	/// </summary>
	BackendEmitResult Emit( IrModule module, BackendEmitOptions options, DiagnosticSink diagnostics );
}