using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; using System.IO; namespace Veldrid.SPIRV { /// /// Contains information about the vertex attributes and resource types, and their binding slots, for a compiled /// set of shaders. This information can be used to construct and /// objects. /// public class SpirvReflection { private static readonly Lazy s_serializer = new Lazy(CreateSerializer); /// /// An array containing a description of each vertex element that is used by the compiled shader set. /// This array will be empty for compute shaders. /// public VertexElementDescription[] VertexElements { get; } /// /// An array containing a description of each set of resources used by the compiled shader set. /// public ResourceLayoutDescription[] ResourceLayouts { get; } /// /// Constructs a new instance. /// /// /// An array containing a description of each vertex element that is used by /// the compiled shader set. /// An array containing a description of each set of resources used by the /// compiled shader set. public SpirvReflection( VertexElementDescription[] vertexElements, ResourceLayoutDescription[] resourceLayouts) { VertexElements = vertexElements; ResourceLayouts = resourceLayouts; } /// /// Loads a object from a serialized JSON file at the given path. /// /// The path to the JSON file. /// A new object, deserialized from the file. public static SpirvReflection LoadFromJson(string jsonPath) { using (FileStream jsonStream = File.OpenRead(jsonPath)) { return LoadFromJson(jsonStream); } } /// /// Loads a object from a serialized JSON stream. /// /// The stream of serialized JSON text. /// A new object, deserialized from the stream. public static SpirvReflection LoadFromJson(Stream jsonStream) { using (StreamReader sr = new StreamReader(jsonStream)) using (JsonTextReader jtr = new JsonTextReader(sr)) { return s_serializer.Value.Deserialize(jtr); } } private static JsonSerializer CreateSerializer() { JsonSerializer serializer = new JsonSerializer(); serializer.Formatting = Formatting.Indented; StringEnumConverter enumConverter = new StringEnumConverter(); serializer.Converters.Add(enumConverter); return serializer; } } }