Renderer.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using OpenTK.Graphics.OpenGL;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.Graphics.GAL;
  4. using Ryujinx.Graphics.OpenGL.Image;
  5. using Ryujinx.Graphics.OpenGL.Queries;
  6. using Ryujinx.Graphics.Shader;
  7. using System;
  8. namespace Ryujinx.Graphics.OpenGL
  9. {
  10. public sealed class Renderer : IRenderer
  11. {
  12. private readonly Pipeline _pipeline;
  13. public IPipeline Pipeline => _pipeline;
  14. private readonly Counters _counters;
  15. private readonly Window _window;
  16. public IWindow Window => _window;
  17. internal TextureCopy TextureCopy { get; }
  18. public string GpuVendor { get; private set; }
  19. public string GpuRenderer { get; private set; }
  20. public string GpuVersion { get; private set; }
  21. public Renderer()
  22. {
  23. _pipeline = new Pipeline();
  24. _counters = new Counters();
  25. _window = new Window(this);
  26. TextureCopy = new TextureCopy(this);
  27. }
  28. public IShader CompileShader(ShaderProgram shader)
  29. {
  30. return new Shader(shader);
  31. }
  32. public BufferHandle CreateBuffer(int size)
  33. {
  34. return Buffer.Create(size);
  35. }
  36. public IProgram CreateProgram(IShader[] shaders)
  37. {
  38. return new Program(shaders);
  39. }
  40. public ISampler CreateSampler(SamplerCreateInfo info)
  41. {
  42. return new Sampler(info);
  43. }
  44. public ITexture CreateTexture(TextureCreateInfo info)
  45. {
  46. return info.Target == Target.TextureBuffer ? new TextureBuffer(info) : new TextureStorage(this, info).CreateDefaultView();
  47. }
  48. public void DeleteBuffer(BufferHandle buffer)
  49. {
  50. Buffer.Delete(buffer);
  51. }
  52. public byte[] GetBufferData(BufferHandle buffer, int offset, int size)
  53. {
  54. return Buffer.GetData(buffer, offset, size);
  55. }
  56. public Capabilities GetCapabilities()
  57. {
  58. return new Capabilities(
  59. HwCapabilities.SupportsAstcCompression,
  60. HwCapabilities.SupportsNonConstantTextureOffset,
  61. HwCapabilities.MaximumComputeSharedMemorySize,
  62. HwCapabilities.StorageBufferOffsetAlignment,
  63. HwCapabilities.MaxSupportedAnisotropy);
  64. }
  65. public void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
  66. {
  67. Buffer.SetData(buffer, offset, data);
  68. }
  69. public void UpdateCounters()
  70. {
  71. _counters.Update();
  72. }
  73. public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler)
  74. {
  75. return _counters.QueueReport(type, resultHandler);
  76. }
  77. public void Initialize()
  78. {
  79. PrintGpuInformation();
  80. _counters.Initialize();
  81. }
  82. private void PrintGpuInformation()
  83. {
  84. GpuVendor = GL.GetString(StringName.Vendor);
  85. GpuRenderer = GL.GetString(StringName.Renderer);
  86. GpuVersion = GL.GetString(StringName.Version);
  87. Logger.PrintInfo(LogClass.Gpu, $"{GpuVendor} {GpuRenderer} ({GpuVersion})");
  88. }
  89. public void ResetCounter(CounterType type)
  90. {
  91. _counters.QueueReset(type);
  92. }
  93. public void Dispose()
  94. {
  95. TextureCopy.Dispose();
  96. _pipeline.Dispose();
  97. _window.Dispose();
  98. _counters.Dispose();
  99. }
  100. }
  101. }