Sampler.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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(0, 0, 0, 0);
  29. float minLod = descriptor.UnpackMinLod();
  30. float maxLod = descriptor.UnpackMaxLod();
  31. float mipLodBias = descriptor.UnpackMipLodBias();
  32. float maxAnisotropy = descriptor.UnpackMaxAnisotropy();
  33. HostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
  34. minFilter,
  35. magFilter,
  36. addressU,
  37. addressV,
  38. addressP,
  39. compareMode,
  40. compareOp,
  41. color,
  42. minLod,
  43. maxLod,
  44. mipLodBias,
  45. maxAnisotropy));
  46. }
  47. /// <summary>
  48. /// Disposes the host sampler object.
  49. /// </summary>
  50. public void Dispose()
  51. {
  52. HostSampler.Dispose();
  53. }
  54. }
  55. }