CachedShaderProgram.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Ryujinx.Graphics.GAL;
  2. using System;
  3. namespace Ryujinx.Graphics.Gpu.Shader
  4. {
  5. /// <summary>
  6. /// Represents a program composed of one or more shader stages (for graphics shaders),
  7. /// or a single shader (for compute shaders).
  8. /// </summary>
  9. class CachedShaderProgram : IDisposable
  10. {
  11. /// <summary>
  12. /// Host shader program object.
  13. /// </summary>
  14. public IProgram HostProgram { get; }
  15. /// <summary>
  16. /// GPU state used to create this version of the shader.
  17. /// </summary>
  18. public ShaderSpecializationState SpecializationState { get; }
  19. /// <summary>
  20. /// Compiled shader for each shader stage.
  21. /// </summary>
  22. public CachedShaderStage[] Shaders { get; }
  23. /// <summary>
  24. /// Cached shader bindings, ready for placing into the bindings manager.
  25. /// </summary>
  26. public CachedShaderBindings Bindings { get; }
  27. /// <summary>
  28. /// Creates a new instance of the shader bundle.
  29. /// </summary>
  30. /// <param name="hostProgram">Host program with all the shader stages</param>
  31. /// <param name="specializationState">GPU state used to create this version of the shader</param>
  32. /// <param name="shaders">Shaders</param>
  33. public CachedShaderProgram(IProgram hostProgram, ShaderSpecializationState specializationState, params CachedShaderStage[] shaders)
  34. {
  35. HostProgram = hostProgram;
  36. SpecializationState = specializationState;
  37. Shaders = shaders;
  38. SpecializationState.Prepare(shaders);
  39. Bindings = new CachedShaderBindings(shaders.Length == 1, shaders);
  40. }
  41. /// <summary>
  42. /// Dispose of the host shader resources.
  43. /// </summary>
  44. public void Dispose()
  45. {
  46. HostProgram.Dispose();
  47. }
  48. }
  49. }