/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="byteCode"></param> public ShaderDescription(string name, ShaderStage type, byte[] byteCode) { Name = name; ShaderType = type; ByteCode = byteCode; ShaderReflector = new ShaderReflector(); }
/// <summary> /// Create Shader. /// <para>All constant buffers for all shaders are created here./></para> /// </summary> /// <param name="device"></param> /// <param name="pool"></param> /// <param name="logger"></param> /// <returns></returns> public ShaderBase CreateShader(Device device, IConstantBufferPool pool, LogWrapper logger) { if (ByteCode == null) { return(null); } ShaderReflector = ShaderReflector ?? new ShaderReflector(); ShaderReflector.Parse(ByteCode, ShaderType); Level = ShaderReflector.FeatureLevel; if (Level > device.FeatureLevel) { logger?.Log(LogLevel.Warning, $"Shader {this.Name} requires FeatureLevel {Level}. Current device only supports FeatureLevel {device.FeatureLevel} and below."); return(null); //throw new Exception($"Shader {this.Name} requires FeatureLevel {Level}. Current device only supports FeatureLevel {device.FeatureLevel} and below."); } this.ConstantBufferMappings = ShaderReflector.ConstantBufferMappings.Values.ToArray(); this.TextureMappings = ShaderReflector.TextureMappings.Values.ToArray(); this.UAVMappings = ShaderReflector.UAVMappings.Values.ToArray(); this.SamplerMappings = ShaderReflector.SamplerMappings.Values.ToArray(); ShaderBase shader = null; switch (ShaderType) { case ShaderStage.Vertex: shader = new VertexShader(device, Name, ByteCode); break; case ShaderStage.Pixel: shader = new PixelShader(device, Name, ByteCode); break; case ShaderStage.Compute: shader = new ComputeShader(device, Name, ByteCode); break; case ShaderStage.Domain: shader = new DomainShader(device, Name, ByteCode); break; case ShaderStage.Hull: shader = new HullShader(device, Name, ByteCode); break; case ShaderStage.Geometry: if (IsGSStreamOut) { shader = new GeometryShader(device, Name, ByteCode, GSSOElement, GSSOStrides, GSSORasterized); } else { shader = new GeometryShader(device, Name, ByteCode); } break; default: break; } if (ConstantBufferMappings != null) { foreach (var mapping in ConstantBufferMappings) { shader.ConstantBufferMapping.AddMapping(mapping.Description.Name, mapping.Slot, pool.Register(mapping.Description)); } } if (TextureMappings != null) { foreach (var mapping in TextureMappings) { shader.ShaderResourceViewMapping.AddMapping(mapping.Description.Name, mapping.Slot, mapping); } } if (UAVMappings != null) { foreach (var mapping in UAVMappings) { shader.UnorderedAccessViewMapping.AddMapping(mapping.Description.Name, mapping.Slot, mapping); } } if (SamplerMappings != null) { foreach (var mapping in SamplerMappings) { shader.SamplerMapping.AddMapping(mapping.Name, mapping.Slot, mapping); } } return(shader); }
/// <summary> /// Create a empty description /// </summary> public ShaderDescription() { ShaderReflector = new ShaderReflector(); }