using Ryujinx.Graphics.GAL; using System; namespace Ryujinx.Graphics.Gpu.Shader { /// /// Represents a program composed of one or more shader stages (for graphics shaders), /// or a single shader (for compute shaders). /// class CachedShaderProgram : IDisposable { /// /// Host shader program object. /// public IProgram HostProgram { get; } /// /// Optional vertex shader converted to compute. /// public ShaderAsCompute VertexAsCompute { get; } /// /// Optional geometry shader converted to compute. /// public ShaderAsCompute GeometryAsCompute { get; } /// /// GPU state used to create this version of the shader. /// public ShaderSpecializationState SpecializationState { get; } /// /// Compiled shader for each shader stage. /// public CachedShaderStage[] Shaders { get; } /// /// Cached shader bindings, ready for placing into the bindings manager. /// public CachedShaderBindings Bindings { get; } /// /// Creates a new instance of the shader bundle. /// /// Host program with all the shader stages /// GPU state used to create this version of the shader /// Shaders public CachedShaderProgram(IProgram hostProgram, ShaderSpecializationState specializationState, params CachedShaderStage[] shaders) { HostProgram = hostProgram; SpecializationState = specializationState; Shaders = shaders; SpecializationState.Prepare(shaders); Bindings = new CachedShaderBindings(shaders.Length == 1, shaders); } public CachedShaderProgram( IProgram hostProgram, ShaderAsCompute vertexAsCompute, ShaderAsCompute geometryAsCompute, ShaderSpecializationState specializationState, CachedShaderStage[] shaders) : this(hostProgram, specializationState, shaders) { VertexAsCompute = vertexAsCompute; GeometryAsCompute = geometryAsCompute; } /// /// Dispose of the host shader resources. /// public void Dispose() { HostProgram.Dispose(); VertexAsCompute?.HostProgram.Dispose(); GeometryAsCompute?.HostProgram.Dispose(); } } }