Sampler.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. bool seamlessCubemap = descriptor.UnpackSeamlessCubemap();
  24. AddressMode addressU = descriptor.UnpackAddressU();
  25. AddressMode addressV = descriptor.UnpackAddressV();
  26. AddressMode addressP = descriptor.UnpackAddressP();
  27. CompareMode compareMode = descriptor.UnpackCompareMode();
  28. CompareOp compareOp = descriptor.UnpackCompareOp();
  29. ColorF color = new ColorF(
  30. descriptor.BorderColorR,
  31. descriptor.BorderColorG,
  32. descriptor.BorderColorB,
  33. descriptor.BorderColorA);
  34. float minLod = descriptor.UnpackMinLod();
  35. float maxLod = descriptor.UnpackMaxLod();
  36. float mipLodBias = descriptor.UnpackMipLodBias();
  37. float maxRequestedAnisotropy = GraphicsConfig.MaxAnisotropy >= 0 && GraphicsConfig.MaxAnisotropy <= 16 ? GraphicsConfig.MaxAnisotropy : descriptor.UnpackMaxAnisotropy();
  38. float maxSupportedAnisotropy = context.Capabilities.MaximumSupportedAnisotropy;
  39. if (maxRequestedAnisotropy > maxSupportedAnisotropy)
  40. maxRequestedAnisotropy = maxSupportedAnisotropy;
  41. HostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
  42. minFilter,
  43. magFilter,
  44. seamlessCubemap,
  45. addressU,
  46. addressV,
  47. addressP,
  48. compareMode,
  49. compareOp,
  50. color,
  51. minLod,
  52. maxLod,
  53. mipLodBias,
  54. maxRequestedAnisotropy));
  55. }
  56. /// <summary>
  57. /// Disposes the host sampler object.
  58. /// </summary>
  59. public void Dispose()
  60. {
  61. HostSampler.Dispose();
  62. }
  63. }
  64. }