Renderer.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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, TransformFeedbackDescriptor[] transformFeedbackDescriptors)
  37. {
  38. return new Program(shaders, transformFeedbackDescriptors);
  39. }
  40. public ISampler CreateSampler(SamplerCreateInfo info)
  41. {
  42. return new Sampler(info);
  43. }
  44. public ITexture CreateTexture(TextureCreateInfo info, float scaleFactor)
  45. {
  46. return info.Target == Target.TextureBuffer ? new TextureBuffer(info) : new TextureStorage(this, info, scaleFactor).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.SupportsImageLoadFormatted,
  61. HwCapabilities.SupportsNonConstantTextureOffset,
  62. HwCapabilities.SupportsViewportSwizzle,
  63. HwCapabilities.MaximumComputeSharedMemorySize,
  64. HwCapabilities.MaximumSupportedAnisotropy,
  65. HwCapabilities.StorageBufferOffsetAlignment);
  66. }
  67. public void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
  68. {
  69. Buffer.SetData(buffer, offset, data);
  70. }
  71. public void UpdateCounters()
  72. {
  73. _counters.Update();
  74. }
  75. public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler)
  76. {
  77. return _counters.QueueReport(type, resultHandler);
  78. }
  79. public void Initialize()
  80. {
  81. PrintGpuInformation();
  82. _counters.Initialize();
  83. }
  84. private void PrintGpuInformation()
  85. {
  86. GpuVendor = GL.GetString(StringName.Vendor);
  87. GpuRenderer = GL.GetString(StringName.Renderer);
  88. GpuVersion = GL.GetString(StringName.Version);
  89. Logger.PrintInfo(LogClass.Gpu, $"{GpuVendor} {GpuRenderer} ({GpuVersion})");
  90. }
  91. public void ResetCounter(CounterType type)
  92. {
  93. _counters.QueueReset(type);
  94. }
  95. public void Dispose()
  96. {
  97. TextureCopy.Dispose();
  98. _pipeline.Dispose();
  99. _window.Dispose();
  100. _counters.Dispose();
  101. }
  102. }
  103. }