PipelineLayoutCache.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Ryujinx.Graphics.GAL;
  2. using Silk.NET.Vulkan;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Graphics.Vulkan
  5. {
  6. class PipelineLayoutCache
  7. {
  8. private readonly PipelineLayoutCacheEntry[] _plce;
  9. private readonly List<PipelineLayoutCacheEntry> _plceMinimal;
  10. public PipelineLayoutCache()
  11. {
  12. _plce = new PipelineLayoutCacheEntry[1 << Constants.MaxShaderStages];
  13. _plceMinimal = new List<PipelineLayoutCacheEntry>();
  14. }
  15. public PipelineLayoutCacheEntry Create(VulkanRenderer gd, Device device, ShaderSource[] shaders)
  16. {
  17. var plce = new PipelineLayoutCacheEntry(gd, device, shaders);
  18. _plceMinimal.Add(plce);
  19. return plce;
  20. }
  21. public PipelineLayoutCacheEntry GetOrCreate(VulkanRenderer gd, Device device, uint stages, bool usePd)
  22. {
  23. if (_plce[stages] == null)
  24. {
  25. _plce[stages] = new PipelineLayoutCacheEntry(gd, device, stages, usePd);
  26. }
  27. return _plce[stages];
  28. }
  29. protected virtual unsafe void Dispose(bool disposing)
  30. {
  31. if (disposing)
  32. {
  33. for (int i = 0; i < _plce.Length; i++)
  34. {
  35. _plce[i]?.Dispose();
  36. }
  37. foreach (var plce in _plceMinimal)
  38. {
  39. plce.Dispose();
  40. }
  41. _plceMinimal.Clear();
  42. }
  43. }
  44. public void Dispose()
  45. {
  46. Dispose(true);
  47. }
  48. }
  49. }