Sampler.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Ryujinx.Graphics.GAL;
  2. using System;
  3. namespace Ryujinx.Graphics.Gpu.Image
  4. {
  5. /// <summary>
  6. /// Cached sampler entry for sampler pools.
  7. /// </summary>
  8. class Sampler : IDisposable
  9. {
  10. /// <summary>
  11. /// Host sampler object.
  12. /// </summary>
  13. public ISampler HostSampler { get; }
  14. /// <summary>
  15. /// Creates a new instance of the cached sampler.
  16. /// </summary>
  17. /// <param name="context">The GPU context the sampler belongs to</param>
  18. /// <param name="descriptor">The Maxwell sampler descriptor</param>
  19. public Sampler(GpuContext context, SamplerDescriptor descriptor)
  20. {
  21. MinFilter minFilter = descriptor.UnpackMinFilter();
  22. MagFilter magFilter = descriptor.UnpackMagFilter();
  23. AddressMode addressU = descriptor.UnpackAddressU();
  24. AddressMode addressV = descriptor.UnpackAddressV();
  25. AddressMode addressP = descriptor.UnpackAddressP();
  26. CompareMode compareMode = descriptor.UnpackCompareMode();
  27. CompareOp compareOp = descriptor.UnpackCompareOp();
  28. ColorF color = new ColorF(
  29. descriptor.BorderColorR,
  30. descriptor.BorderColorG,
  31. descriptor.BorderColorB,
  32. descriptor.BorderColorA);
  33. float minLod = descriptor.UnpackMinLod();
  34. float maxLod = descriptor.UnpackMaxLod();
  35. float mipLodBias = descriptor.UnpackMipLodBias();
  36. float maxRequestedAnisotropy = GraphicsConfig.MaxAnisotropy >= 0 && GraphicsConfig.MaxAnisotropy <= 16 ? GraphicsConfig.MaxAnisotropy : descriptor.UnpackMaxAnisotropy();
  37. float maxSupportedAnisotropy = context.Capabilities.MaximumSupportedAnisotropy;
  38. if (maxRequestedAnisotropy > maxSupportedAnisotropy)
  39. maxRequestedAnisotropy = maxSupportedAnisotropy;
  40. HostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
  41. minFilter,
  42. magFilter,
  43. addressU,
  44. addressV,
  45. addressP,
  46. compareMode,
  47. compareOp,
  48. color,
  49. minLod,
  50. maxLod,
  51. mipLodBias,
  52. maxRequestedAnisotropy));
  53. }
  54. /// <summary>
  55. /// Disposes the host sampler object.
  56. /// </summary>
  57. public void Dispose()
  58. {
  59. HostSampler.Dispose();
  60. }
  61. }
  62. }