Пример #1
0
 /// <summary>
 /// Creates the specified device.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="description">The description.</param>
 /// <returns></returns>
 protected override ShaderBase Create(Device device, ref ShaderDescription description)
 {
     return(description.ByteCode == null?NullShader.GetNullShader(description.ShaderType) : description.CreateShader(device, ConstantBufferPool));
 }
Пример #2
0
        /// <summary>
        /// Create Shader.
        /// <para>All constant buffers for all shaders are created here./></para>
        /// </summary>
        /// <param name="device"></param>
        /// <param name="pool"></param>
        /// <returns></returns>
        public ShaderBase CreateShader(Device device, IConstantBufferPool pool)
        {
            if (ByteCode == null)
            {
                return(null);
            }
            if (shaderReflector != null)
            {
                shaderReflector.Parse(ByteCode, ShaderType);
                Level = shaderReflector.FeatureLevel;
                if (Level > device.FeatureLevel)
                {
                    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:
                shader = new GeometryShader(device, Name, ByteCode);
                break;

            default:
                shader = NullShader.GetNullShader(ShaderType);
                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);
        }
Пример #3
0
 /// <summary>
 /// Gets the shader.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 public ShaderBase GetShader(ShaderStage type)
 {
     return(NullShader.GetNullShader(type));
 }