Sampler.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 maxAnisotropy = descriptor.UnpackMaxAnisotropy();
  37. HostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
  38. minFilter,
  39. magFilter,
  40. addressU,
  41. addressV,
  42. addressP,
  43. compareMode,
  44. compareOp,
  45. color,
  46. minLod,
  47. maxLod,
  48. mipLodBias,
  49. maxAnisotropy));
  50. }
  51. /// <summary>
  52. /// Disposes the host sampler object.
  53. /// </summary>
  54. public void Dispose()
  55. {
  56. HostSampler.Dispose();
  57. }
  58. }
  59. }