ShaderSpecializationList.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. namespace Ryujinx.Graphics.Gpu.Shader
  4. {
  5. /// <summary>
  6. /// List of cached shader programs that differs only by specialization state.
  7. /// </summary>
  8. class ShaderSpecializationList : IEnumerable<CachedShaderProgram>
  9. {
  10. private readonly List<CachedShaderProgram> _entries = new List<CachedShaderProgram>();
  11. /// <summary>
  12. /// Adds a program to the list.
  13. /// </summary>
  14. /// <param name="program">Program to be added</param>
  15. public void Add(CachedShaderProgram program)
  16. {
  17. _entries.Add(program);
  18. }
  19. /// <summary>
  20. /// Tries to find an existing 3D program on the cache.
  21. /// </summary>
  22. /// <param name="channel">GPU channel</param>
  23. /// <param name="poolState">Texture pool state</param>
  24. /// <param name="program">Cached program, if found</param>
  25. /// <returns>True if a compatible program is found, false otherwise</returns>
  26. public bool TryFindForGraphics(GpuChannel channel, GpuChannelPoolState poolState, out CachedShaderProgram program)
  27. {
  28. foreach (var entry in _entries)
  29. {
  30. if (entry.SpecializationState.MatchesGraphics(channel, poolState))
  31. {
  32. program = entry;
  33. return true;
  34. }
  35. }
  36. program = default;
  37. return false;
  38. }
  39. /// <summary>
  40. /// Tries to find an existing compute program on the cache.
  41. /// </summary>
  42. /// <param name="channel">GPU channel</param>
  43. /// <param name="poolState">Texture pool state</param>
  44. /// <param name="program">Cached program, if found</param>
  45. /// <returns>True if a compatible program is found, false otherwise</returns>
  46. public bool TryFindForCompute(GpuChannel channel, GpuChannelPoolState poolState, out CachedShaderProgram program)
  47. {
  48. foreach (var entry in _entries)
  49. {
  50. if (entry.SpecializationState.MatchesCompute(channel, poolState))
  51. {
  52. program = entry;
  53. return true;
  54. }
  55. }
  56. program = default;
  57. return false;
  58. }
  59. public IEnumerator<CachedShaderProgram> GetEnumerator()
  60. {
  61. return _entries.GetEnumerator();
  62. }
  63. IEnumerator IEnumerable.GetEnumerator()
  64. {
  65. return GetEnumerator();
  66. }
  67. }
  68. }