VulkanRenderer.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. using Ryujinx.Common.Configuration;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.Graphics.GAL;
  4. using Ryujinx.Graphics.Shader;
  5. using Ryujinx.Graphics.Shader.Translation;
  6. using Ryujinx.Graphics.Vulkan.Queries;
  7. using Silk.NET.Vulkan;
  8. using Silk.NET.Vulkan.Extensions.EXT;
  9. using Silk.NET.Vulkan.Extensions.KHR;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Runtime.InteropServices;
  14. namespace Ryujinx.Graphics.Vulkan
  15. {
  16. public sealed class VulkanRenderer : IRenderer
  17. {
  18. private Instance _instance;
  19. private SurfaceKHR _surface;
  20. private PhysicalDevice _physicalDevice;
  21. private Device _device;
  22. private WindowBase _window;
  23. internal FormatCapabilities FormatCapabilities { get; private set; }
  24. internal HardwareCapabilities Capabilities;
  25. internal Vk Api { get; private set; }
  26. internal KhrSurface SurfaceApi { get; private set; }
  27. internal KhrSwapchain SwapchainApi { get; private set; }
  28. internal ExtConditionalRendering ConditionalRenderingApi { get; private set; }
  29. internal ExtExtendedDynamicState ExtendedDynamicStateApi { get; private set; }
  30. internal KhrPushDescriptor PushDescriptorApi { get; private set; }
  31. internal ExtTransformFeedback TransformFeedbackApi { get; private set; }
  32. internal KhrDrawIndirectCount DrawIndirectCountApi { get; private set; }
  33. internal ExtDebugUtils DebugUtilsApi { get; private set; }
  34. internal uint QueueFamilyIndex { get; private set; }
  35. internal Queue Queue { get; private set; }
  36. internal Queue BackgroundQueue { get; private set; }
  37. internal object BackgroundQueueLock { get; private set; }
  38. internal object QueueLock { get; private set; }
  39. internal MemoryAllocator MemoryAllocator { get; private set; }
  40. internal CommandBufferPool CommandBufferPool { get; private set; }
  41. internal DescriptorSetManager DescriptorSetManager { get; private set; }
  42. internal PipelineLayoutCache PipelineLayoutCache { get; private set; }
  43. internal BackgroundResources BackgroundResources { get; private set; }
  44. internal BufferManager BufferManager { get; private set; }
  45. internal HashSet<ShaderCollection> Shaders { get; }
  46. internal HashSet<ITexture> Textures { get; }
  47. internal HashSet<SamplerHolder> Samplers { get; }
  48. private Counters _counters;
  49. private SyncManager _syncManager;
  50. private PipelineFull _pipeline;
  51. private DebugUtilsMessengerEXT _debugUtilsMessenger;
  52. internal HelperShader HelperShader { get; private set; }
  53. internal PipelineFull PipelineInternal => _pipeline;
  54. public IPipeline Pipeline => _pipeline;
  55. public IWindow Window => _window;
  56. private readonly Func<Instance, Vk, SurfaceKHR> _getSurface;
  57. private readonly Func<string[]> _getRequiredExtensions;
  58. private readonly string _preferredGpuId;
  59. internal Vendor Vendor { get; private set; }
  60. internal bool IsAmdWindows { get; private set; }
  61. internal bool IsIntelWindows { get; private set; }
  62. internal bool IsAmdGcn { get; private set; }
  63. public string GpuVendor { get; private set; }
  64. public string GpuRenderer { get; private set; }
  65. public string GpuVersion { get; private set; }
  66. public bool PreferThreading => true;
  67. public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;
  68. public VulkanRenderer(Func<Instance, Vk, SurfaceKHR> surfaceFunc, Func<string[]> requiredExtensionsFunc, string preferredGpuId)
  69. {
  70. _getSurface = surfaceFunc;
  71. _getRequiredExtensions = requiredExtensionsFunc;
  72. _preferredGpuId = preferredGpuId;
  73. Shaders = new HashSet<ShaderCollection>();
  74. Textures = new HashSet<ITexture>();
  75. Samplers = new HashSet<SamplerHolder>();
  76. }
  77. private unsafe void LoadFeatures(string[] supportedExtensions, uint maxQueueCount, uint queueFamilyIndex)
  78. {
  79. FormatCapabilities = new FormatCapabilities(Api, _physicalDevice);
  80. var supportedFeatures = Api.GetPhysicalDeviceFeature(_physicalDevice);
  81. if (Api.TryGetDeviceExtension(_instance, _device, out ExtConditionalRendering conditionalRenderingApi))
  82. {
  83. ConditionalRenderingApi = conditionalRenderingApi;
  84. }
  85. if (Api.TryGetDeviceExtension(_instance, _device, out ExtExtendedDynamicState extendedDynamicStateApi))
  86. {
  87. ExtendedDynamicStateApi = extendedDynamicStateApi;
  88. }
  89. if (Api.TryGetDeviceExtension(_instance, _device, out KhrPushDescriptor pushDescriptorApi))
  90. {
  91. PushDescriptorApi = pushDescriptorApi;
  92. }
  93. if (Api.TryGetDeviceExtension(_instance, _device, out ExtTransformFeedback transformFeedbackApi))
  94. {
  95. TransformFeedbackApi = transformFeedbackApi;
  96. }
  97. if (Api.TryGetDeviceExtension(_instance, _device, out KhrDrawIndirectCount drawIndirectCountApi))
  98. {
  99. DrawIndirectCountApi = drawIndirectCountApi;
  100. }
  101. if (maxQueueCount >= 2)
  102. {
  103. Api.GetDeviceQueue(_device, queueFamilyIndex, 1, out var backgroundQueue);
  104. BackgroundQueue = backgroundQueue;
  105. BackgroundQueueLock = new object();
  106. }
  107. PhysicalDeviceProperties2 properties2 = new PhysicalDeviceProperties2()
  108. {
  109. SType = StructureType.PhysicalDeviceProperties2
  110. };
  111. PhysicalDeviceSubgroupSizeControlPropertiesEXT propertiesSubgroupSizeControl = new PhysicalDeviceSubgroupSizeControlPropertiesEXT()
  112. {
  113. SType = StructureType.PhysicalDeviceSubgroupSizeControlPropertiesExt
  114. };
  115. if (Capabilities.SupportsSubgroupSizeControl)
  116. {
  117. properties2.PNext = &propertiesSubgroupSizeControl;
  118. }
  119. bool supportsTransformFeedback = supportedExtensions.Contains(ExtTransformFeedback.ExtensionName);
  120. PhysicalDeviceTransformFeedbackPropertiesEXT propertiesTransformFeedback = new PhysicalDeviceTransformFeedbackPropertiesEXT()
  121. {
  122. SType = StructureType.PhysicalDeviceTransformFeedbackPropertiesExt
  123. };
  124. if (supportsTransformFeedback)
  125. {
  126. propertiesTransformFeedback.PNext = properties2.PNext;
  127. properties2.PNext = &propertiesTransformFeedback;
  128. }
  129. Api.GetPhysicalDeviceProperties2(_physicalDevice, &properties2);
  130. PhysicalDeviceFeatures2 features2 = new PhysicalDeviceFeatures2()
  131. {
  132. SType = StructureType.PhysicalDeviceFeatures2
  133. };
  134. PhysicalDeviceRobustness2FeaturesEXT featuresRobustness2 = new PhysicalDeviceRobustness2FeaturesEXT()
  135. {
  136. SType = StructureType.PhysicalDeviceRobustness2FeaturesExt
  137. };
  138. PhysicalDeviceShaderFloat16Int8FeaturesKHR featuresShaderInt8 = new PhysicalDeviceShaderFloat16Int8FeaturesKHR()
  139. {
  140. SType = StructureType.PhysicalDeviceShaderFloat16Int8Features
  141. };
  142. if (supportedExtensions.Contains("VK_EXT_robustness2"))
  143. {
  144. features2.PNext = &featuresRobustness2;
  145. }
  146. if (supportedExtensions.Contains("VK_KHR_shader_float16_int8"))
  147. {
  148. featuresShaderInt8.PNext = features2.PNext;
  149. features2.PNext = &featuresShaderInt8;
  150. }
  151. Api.GetPhysicalDeviceFeatures2(_physicalDevice, &features2);
  152. Capabilities = new HardwareCapabilities(
  153. supportedExtensions.Contains("VK_EXT_index_type_uint8"),
  154. supportedExtensions.Contains("VK_EXT_custom_border_color"),
  155. supportedExtensions.Contains(KhrDrawIndirectCount.ExtensionName),
  156. supportedExtensions.Contains("VK_EXT_fragment_shader_interlock"),
  157. supportedExtensions.Contains("VK_NV_geometry_shader_passthrough"),
  158. supportedExtensions.Contains("VK_EXT_subgroup_size_control"),
  159. featuresShaderInt8.ShaderInt8,
  160. supportedExtensions.Contains(ExtConditionalRendering.ExtensionName),
  161. supportedExtensions.Contains(ExtExtendedDynamicState.ExtensionName),
  162. features2.Features.MultiViewport,
  163. featuresRobustness2.NullDescriptor,
  164. supportedExtensions.Contains(KhrPushDescriptor.ExtensionName),
  165. supportsTransformFeedback,
  166. propertiesTransformFeedback.TransformFeedbackQueries,
  167. supportedFeatures.GeometryShader,
  168. propertiesSubgroupSizeControl.MinSubgroupSize,
  169. propertiesSubgroupSizeControl.MaxSubgroupSize,
  170. propertiesSubgroupSizeControl.RequiredSubgroupSizeStages);
  171. ref var properties = ref properties2.Properties;
  172. MemoryAllocator = new MemoryAllocator(Api, _device, properties.Limits.MaxMemoryAllocationCount);
  173. CommandBufferPool = VulkanInitialization.CreateCommandBufferPool(Api, _device, Queue, QueueLock, queueFamilyIndex);
  174. DescriptorSetManager = new DescriptorSetManager(_device);
  175. PipelineLayoutCache = new PipelineLayoutCache();
  176. BackgroundResources = new BackgroundResources(this, _device);
  177. BufferManager = new BufferManager(this, _physicalDevice, _device);
  178. _syncManager = new SyncManager(this, _device);
  179. _pipeline = new PipelineFull(this, _device);
  180. _pipeline.Initialize();
  181. HelperShader = new HelperShader(this, _device);
  182. _counters = new Counters(this, _device, _pipeline);
  183. }
  184. private unsafe void SetupContext(GraphicsDebugLevel logLevel)
  185. {
  186. var api = Vk.GetApi();
  187. Api = api;
  188. _instance = VulkanInitialization.CreateInstance(api, logLevel, _getRequiredExtensions(), out ExtDebugUtils debugUtils, out _debugUtilsMessenger);
  189. DebugUtilsApi = debugUtils;
  190. if (api.TryGetInstanceExtension(_instance, out KhrSurface surfaceApi))
  191. {
  192. SurfaceApi = surfaceApi;
  193. }
  194. _surface = _getSurface(_instance, api);
  195. _physicalDevice = VulkanInitialization.FindSuitablePhysicalDevice(api, _instance, _surface, _preferredGpuId);
  196. var queueFamilyIndex = VulkanInitialization.FindSuitableQueueFamily(api, _physicalDevice, _surface, out uint maxQueueCount);
  197. var supportedExtensions = VulkanInitialization.GetSupportedExtensions(api, _physicalDevice);
  198. _device = VulkanInitialization.CreateDevice(api, _physicalDevice, queueFamilyIndex, supportedExtensions, maxQueueCount);
  199. if (api.TryGetDeviceExtension(_instance, _device, out KhrSwapchain swapchainApi))
  200. {
  201. SwapchainApi = swapchainApi;
  202. }
  203. api.GetDeviceQueue(_device, queueFamilyIndex, 0, out var queue);
  204. Queue = queue;
  205. QueueLock = new object();
  206. LoadFeatures(supportedExtensions, maxQueueCount, queueFamilyIndex);
  207. _window = new Window(this, _surface, _physicalDevice, _device);
  208. }
  209. public BufferHandle CreateBuffer(int size)
  210. {
  211. return BufferManager.CreateWithHandle(this, size, false);
  212. }
  213. public IProgram CreateProgram(ShaderSource[] sources, ShaderInfo info)
  214. {
  215. bool isCompute = sources.Length == 1 && sources[0].Stage == ShaderStage.Compute;
  216. if (info.State.HasValue || isCompute)
  217. {
  218. return new ShaderCollection(this, _device, sources, info.State ?? default, info.FromCache);
  219. }
  220. else
  221. {
  222. return new ShaderCollection(this, _device, sources);
  223. }
  224. }
  225. internal ShaderCollection CreateProgramWithMinimalLayout(ShaderSource[] sources, SpecDescription[] specDescription = null)
  226. {
  227. return new ShaderCollection(this, _device, sources, specDescription: specDescription, isMinimal: true);
  228. }
  229. public ISampler CreateSampler(GAL.SamplerCreateInfo info)
  230. {
  231. return new SamplerHolder(this, _device, info);
  232. }
  233. public ITexture CreateTexture(TextureCreateInfo info, float scale)
  234. {
  235. if (info.Target == Target.TextureBuffer)
  236. {
  237. return new TextureBuffer(this, info, scale);
  238. }
  239. return CreateTextureView(info, scale);
  240. }
  241. internal TextureView CreateTextureView(TextureCreateInfo info, float scale)
  242. {
  243. // This should be disposed when all views are destroyed.
  244. var storage = CreateTextureStorage(info, scale);
  245. return storage.CreateView(info, 0, 0);
  246. }
  247. internal TextureStorage CreateTextureStorage(TextureCreateInfo info, float scale)
  248. {
  249. return new TextureStorage(this, _physicalDevice, _device, info, scale);
  250. }
  251. public void DeleteBuffer(BufferHandle buffer)
  252. {
  253. BufferManager.Delete(buffer);
  254. }
  255. internal void FlushAllCommands()
  256. {
  257. _pipeline?.FlushCommandsImpl();
  258. }
  259. public ReadOnlySpan<byte> GetBufferData(BufferHandle buffer, int offset, int size)
  260. {
  261. return BufferManager.GetData(buffer, offset, size);
  262. }
  263. public unsafe Capabilities GetCapabilities()
  264. {
  265. FormatFeatureFlags compressedFormatFeatureFlags =
  266. FormatFeatureFlags.FormatFeatureSampledImageBit |
  267. FormatFeatureFlags.FormatFeatureSampledImageFilterLinearBit |
  268. FormatFeatureFlags.FormatFeatureBlitSrcBit |
  269. FormatFeatureFlags.FormatFeatureTransferSrcBit |
  270. FormatFeatureFlags.FormatFeatureTransferDstBit;
  271. bool supportsBc123CompressionFormat = FormatCapabilities.OptimalFormatsSupport(compressedFormatFeatureFlags,
  272. GAL.Format.Bc1RgbaSrgb,
  273. GAL.Format.Bc1RgbaUnorm,
  274. GAL.Format.Bc2Srgb,
  275. GAL.Format.Bc2Unorm,
  276. GAL.Format.Bc3Srgb,
  277. GAL.Format.Bc3Unorm);
  278. bool supportsBc45CompressionFormat = FormatCapabilities.OptimalFormatsSupport(compressedFormatFeatureFlags,
  279. GAL.Format.Bc4Snorm,
  280. GAL.Format.Bc4Unorm,
  281. GAL.Format.Bc5Snorm,
  282. GAL.Format.Bc5Unorm);
  283. bool supportsBc67CompressionFormat = FormatCapabilities.OptimalFormatsSupport(compressedFormatFeatureFlags,
  284. GAL.Format.Bc6HSfloat,
  285. GAL.Format.Bc6HUfloat,
  286. GAL.Format.Bc7Srgb,
  287. GAL.Format.Bc7Unorm);
  288. PhysicalDeviceVulkan12Features featuresVk12 = new PhysicalDeviceVulkan12Features()
  289. {
  290. SType = StructureType.PhysicalDeviceVulkan12Features
  291. };
  292. PhysicalDeviceFeatures2 features2 = new PhysicalDeviceFeatures2()
  293. {
  294. SType = StructureType.PhysicalDeviceFeatures2,
  295. PNext = &featuresVk12
  296. };
  297. Api.GetPhysicalDeviceFeatures2(_physicalDevice, &features2);
  298. Api.GetPhysicalDeviceProperties(_physicalDevice, out var properties);
  299. var limits = properties.Limits;
  300. return new Capabilities(
  301. api: TargetApi.Vulkan,
  302. GpuVendor,
  303. hasFrontFacingBug: IsIntelWindows,
  304. hasVectorIndexingBug: Vendor == Vendor.Qualcomm,
  305. supportsAstcCompression: features2.Features.TextureCompressionAstcLdr,
  306. supportsBc123Compression: supportsBc123CompressionFormat,
  307. supportsBc45Compression: supportsBc45CompressionFormat,
  308. supportsBc67Compression: supportsBc67CompressionFormat,
  309. supports3DTextureCompression: true,
  310. supportsBgraFormat: true,
  311. supportsR4G4Format: false,
  312. supportsFragmentShaderInterlock: Capabilities.SupportsFragmentShaderInterlock,
  313. supportsFragmentShaderOrderingIntel: false,
  314. supportsGeometryShaderPassthrough: Capabilities.SupportsGeometryShaderPassthrough,
  315. supportsImageLoadFormatted: features2.Features.ShaderStorageImageReadWithoutFormat,
  316. supportsMismatchingViewFormat: true,
  317. supportsCubemapView: !IsAmdGcn,
  318. supportsNonConstantTextureOffset: false,
  319. supportsShaderBallot: false,
  320. supportsTextureShadowLod: false,
  321. supportsViewportIndex: featuresVk12.ShaderOutputViewportIndex,
  322. supportsViewportSwizzle: false,
  323. supportsIndirectParameters: Capabilities.SupportsIndirectParameters,
  324. maximumUniformBuffersPerStage: Constants.MaxUniformBuffersPerStage,
  325. maximumStorageBuffersPerStage: Constants.MaxStorageBuffersPerStage,
  326. maximumTexturesPerStage: Constants.MaxTexturesPerStage,
  327. maximumImagesPerStage: Constants.MaxImagesPerStage,
  328. maximumComputeSharedMemorySize: (int)limits.MaxComputeSharedMemorySize,
  329. maximumSupportedAnisotropy: (int)limits.MaxSamplerAnisotropy,
  330. storageBufferOffsetAlignment: (int)limits.MinStorageBufferOffsetAlignment);
  331. }
  332. public HardwareInfo GetHardwareInfo()
  333. {
  334. return new HardwareInfo(GpuVendor, GpuRenderer);
  335. }
  336. public static DeviceInfo[] GetPhysicalDevices()
  337. {
  338. try
  339. {
  340. return VulkanInitialization.GetSuitablePhysicalDevices(Vk.GetApi());
  341. }
  342. catch (Exception)
  343. {
  344. // If we got an exception here, Vulkan is most likely not supported.
  345. return Array.Empty<DeviceInfo>();
  346. }
  347. }
  348. private static string ParseStandardVulkanVersion(uint version)
  349. {
  350. return $"{version >> 22}.{(version >> 12) & 0x3FF}.{version & 0xFFF}";
  351. }
  352. private static string ParseDriverVersion(ref PhysicalDeviceProperties properties)
  353. {
  354. uint driverVersionRaw = properties.DriverVersion;
  355. // NVIDIA differ from the standard here and uses a different format.
  356. if (properties.VendorID == 0x10DE)
  357. {
  358. return $"{(driverVersionRaw >> 22) & 0x3FF}.{(driverVersionRaw >> 14) & 0xFF}.{(driverVersionRaw >> 6) & 0xFF}.{driverVersionRaw & 0x3F}";
  359. }
  360. else
  361. {
  362. return ParseStandardVulkanVersion(driverVersionRaw);
  363. }
  364. }
  365. private unsafe void PrintGpuInformation()
  366. {
  367. Api.GetPhysicalDeviceProperties(_physicalDevice, out var properties);
  368. string vendorName = VendorUtils.GetNameFromId(properties.VendorID);
  369. Vendor = VendorUtils.FromId(properties.VendorID);
  370. IsAmdWindows = Vendor == Vendor.Amd && RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
  371. IsIntelWindows = Vendor == Vendor.Intel && RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
  372. GpuVendor = vendorName;
  373. GpuRenderer = Marshal.PtrToStringAnsi((IntPtr)properties.DeviceName);
  374. GpuVersion = $"Vulkan v{ParseStandardVulkanVersion(properties.ApiVersion)}, Driver v{ParseDriverVersion(ref properties)}";
  375. IsAmdGcn = Vendor == Vendor.Amd && VendorUtils.AmdGcnRegex.IsMatch(GpuRenderer);
  376. Logger.Notice.Print(LogClass.Gpu, $"{GpuVendor} {GpuRenderer} ({GpuVersion})");
  377. }
  378. public GAL.PrimitiveTopology TopologyRemap(GAL.PrimitiveTopology topology)
  379. {
  380. return topology switch
  381. {
  382. GAL.PrimitiveTopology.Quads => GAL.PrimitiveTopology.Triangles,
  383. GAL.PrimitiveTopology.QuadStrip => GAL.PrimitiveTopology.TriangleStrip,
  384. _ => topology
  385. };
  386. }
  387. public bool TopologyUnsupported(GAL.PrimitiveTopology topology)
  388. {
  389. return topology switch
  390. {
  391. GAL.PrimitiveTopology.Quads => true,
  392. _ => false
  393. };
  394. }
  395. public void Initialize(GraphicsDebugLevel logLevel)
  396. {
  397. SetupContext(logLevel);
  398. PrintGpuInformation();
  399. }
  400. public bool NeedsVertexBufferAlignment(int attrScalarAlignment, out int alignment)
  401. {
  402. if (Vendor != Vendor.Nvidia)
  403. {
  404. // Vulkan requires that vertex attributes are globally aligned by their component size,
  405. // so buffer strides that don't divide by the largest scalar element are invalid.
  406. // Guest applications do this, NVIDIA GPUs are OK with it, others are not.
  407. alignment = attrScalarAlignment;
  408. return true;
  409. }
  410. alignment = 1;
  411. return false;
  412. }
  413. public void PreFrame()
  414. {
  415. _syncManager.Cleanup();
  416. }
  417. public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved)
  418. {
  419. return _counters.QueueReport(type, resultHandler, hostReserved);
  420. }
  421. public void ResetCounter(CounterType type)
  422. {
  423. _counters.QueueReset(type);
  424. }
  425. public void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
  426. {
  427. BufferManager.SetData(buffer, offset, data, _pipeline.CurrentCommandBuffer, _pipeline.EndRenderPass);
  428. }
  429. public void UpdateCounters()
  430. {
  431. _counters.Update();
  432. }
  433. public void BackgroundContextAction(Action action, bool alwaysBackground = false)
  434. {
  435. action();
  436. }
  437. public void CreateSync(ulong id)
  438. {
  439. _syncManager.Create(id);
  440. }
  441. public IProgram LoadProgramBinary(byte[] programBinary, bool isFragment, ShaderInfo info)
  442. {
  443. throw new NotImplementedException();
  444. }
  445. public void WaitSync(ulong id)
  446. {
  447. _syncManager.Wait(id);
  448. }
  449. public void Screenshot()
  450. {
  451. _window.ScreenCaptureRequested = true;
  452. }
  453. public void OnScreenCaptured(ScreenCaptureImageInfo bitmap)
  454. {
  455. ScreenCaptured?.Invoke(this, bitmap);
  456. }
  457. public unsafe void Dispose()
  458. {
  459. CommandBufferPool.Dispose();
  460. BackgroundResources.Dispose();
  461. _counters.Dispose();
  462. _window.Dispose();
  463. HelperShader.Dispose();
  464. _pipeline.Dispose();
  465. BufferManager.Dispose();
  466. DescriptorSetManager.Dispose();
  467. PipelineLayoutCache.Dispose();
  468. MemoryAllocator.Dispose();
  469. if (_debugUtilsMessenger.Handle != 0)
  470. {
  471. DebugUtilsApi.DestroyDebugUtilsMessenger(_instance, _debugUtilsMessenger, null);
  472. }
  473. foreach (var shader in Shaders)
  474. {
  475. shader.Dispose();
  476. }
  477. foreach (var texture in Textures)
  478. {
  479. texture.Release();
  480. }
  481. foreach (var sampler in Samplers)
  482. {
  483. sampler.Dispose();
  484. }
  485. SurfaceApi.DestroySurface(_instance, _surface, null);
  486. Api.DestroyDevice(_device, null);
  487. // Last step destroy the instance
  488. Api.DestroyInstance(_instance, null);
  489. }
  490. }
  491. }