diff --git a/build/XUnit.props b/build/XUnit.props index 53ab2324a3..8f991ae442 100644 --- a/build/XUnit.props +++ b/build/XUnit.props @@ -6,7 +6,7 @@ - + diff --git a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs index 6f89e88cf3..143db003cd 100644 --- a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs @@ -160,7 +160,7 @@ namespace ControlCatalog.Pages } else { - SetFolder(await GetStorageProvider().TryGetFolderFromPathAsync(result)); + SetFolder(await GetStorageProvider().TryGetFolderFromPathAsync(result!)); results.ItemsSource = new[] { result }; resultsVisible.IsVisible = true; } diff --git a/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs b/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs index aef82768c8..b242d020b0 100644 --- a/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Markup.Xaml; @@ -14,26 +15,54 @@ namespace ControlCatalog.Pages private const string CustomFormat = "application/xxx-avalonia-controlcatalog-custom"; public DragAndDropPage() { - this.InitializeComponent(); + InitializeComponent(); _dropState = this.Get("DropState"); int textCount = 0; - SetupDnd("Text", d => d.Set(DataFormats.Text, - $"Text was dragged {++textCount} times"), DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link); - SetupDnd("Custom", d => d.Set(CustomFormat, "Test123"), DragDropEffects.Move); - SetupDnd("Files", async d => d.Set(DataFormats.Files, new[] { await (VisualRoot as TopLevel)!.StorageProvider.TryGetFileFromPathAsync(Assembly.GetEntryAssembly()?.GetModules().FirstOrDefault()?.FullyQualifiedName) }), DragDropEffects.Copy); + SetupDnd( + "Text", + d => d.Set(DataFormats.Text, $"Text was dragged {++textCount} times"), + DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link); + + SetupDnd( + "Custom", + d => d.Set(CustomFormat, "Test123"), + DragDropEffects.Move); + + SetupDnd( + "Files", + async d => + { + if (Assembly.GetEntryAssembly()?.GetModules().FirstOrDefault()?.FullyQualifiedName is { } name && + TopLevel.GetTopLevel(this) is { } topLevel && + await topLevel.StorageProvider.TryGetFileFromPathAsync(name) is { } storageFile) + { + d.Set(DataFormats.Files, new[] { storageFile }); + } + }, + DragDropEffects.Copy); } - void SetupDnd(string suffix, Action factory, DragDropEffects effects) + private void SetupDnd(string suffix, Action factory, DragDropEffects effects) => + SetupDnd( + suffix, + o => + { + factory(o); + return Task.CompletedTask; + }, + effects); + + private void SetupDnd(string suffix, Func factory, DragDropEffects effects) { var dragMe = this.Get("DragMe" + suffix); var dragState = this.Get("DragState" + suffix); - async void DoDrag(object? sender, Avalonia.Input.PointerPressedEventArgs e) + async void DoDrag(object? sender, PointerPressedEventArgs e) { var dragData = new DataObject(); - factory(dragData); + await factory(dragData); var result = await DragDrop.DoDragDrop(e, dragData, effects); switch (result) diff --git a/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs b/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs index 9c30992624..a1dd17af58 100644 --- a/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/ListBoxPageViewModel.cs @@ -48,7 +48,7 @@ namespace ControlCatalog.ViewModels foreach (var item in items) { - Items.Remove(item); + Items.Remove(item!); } }); diff --git a/samples/Generators.Sandbox/Controls/CustomTextBox.cs b/samples/Generators.Sandbox/Controls/CustomTextBox.cs index 68ee925986..1325c4cf64 100644 --- a/samples/Generators.Sandbox/Controls/CustomTextBox.cs +++ b/samples/Generators.Sandbox/Controls/CustomTextBox.cs @@ -1,10 +1,9 @@ using System; using Avalonia.Controls; -using Avalonia.Styling; namespace Generators.Sandbox.Controls; -public class CustomTextBox : TextBox, IStyleable +public class CustomTextBox : TextBox { - Type IStyleable.StyleKey => typeof(TextBox); -} \ No newline at end of file + protected override Type StyleKeyOverride => typeof(TextBox); +} diff --git a/samples/GpuInterop/D3DDemo/D3D11DemoControl.cs b/samples/GpuInterop/D3DDemo/D3D11DemoControl.cs index 8b1347e1d8..887ddaf654 100644 --- a/samples/GpuInterop/D3DDemo/D3D11DemoControl.cs +++ b/samples/GpuInterop/D3DDemo/D3D11DemoControl.cs @@ -20,21 +20,21 @@ namespace GpuInterop.D3DDemo; public class D3D11DemoControl : DrawingSurfaceDemoBase { - private D3DDevice _device; - private D3D11Swapchain _swapchain; - private SharpDX.Direct3D11.DeviceContext _context; + private D3DDevice? _device; + private D3D11Swapchain? _swapchain; + private DeviceContext? _context; private Matrix _view; private PixelSize _lastSize; - private Texture2D _depthBuffer; - private DepthStencilView _depthView; + private Texture2D? _depthBuffer; + private DepthStencilView? _depthView; private Matrix _proj; - private Buffer _constantBuffer; - private Stopwatch _st = Stopwatch.StartNew(); + private Buffer? _constantBuffer; + private readonly Stopwatch _st = Stopwatch.StartNew(); protected override (bool success, string info) InitializeGraphicsResources(Compositor compositor, CompositionDrawingSurface surface, ICompositionGpuInterop interop) { - if (interop?.SupportedImageHandleTypes.Contains(KnownPlatformGraphicsExternalImageHandleTypes + if (interop.SupportedImageHandleTypes.Contains(KnownPlatformGraphicsExternalImageHandleTypes .D3D11TextureGlobalSharedHandle) != true) return (false, "DXGI shared handle import is not supported by the current graphics backend"); @@ -60,8 +60,12 @@ public class D3D11DemoControl : DrawingSurfaceDemoBase protected override void FreeGraphicsResources() { - _swapchain.DisposeAsync(); - _swapchain = null!; + if (_swapchain is not null) + { + _swapchain.DisposeAsync().GetAwaiter().GetResult(); + _swapchain = null; + } + Utilities.Dispose(ref _depthView); Utilities.Dispose(ref _depthBuffer); Utilities.Dispose(ref _constantBuffer); @@ -80,10 +84,10 @@ public class D3D11DemoControl : DrawingSurfaceDemoBase _lastSize = pixelSize; Resize(pixelSize); } - using (_swapchain.BeginDraw(pixelSize, out var renderView)) + using (_swapchain!.BeginDraw(pixelSize, out var renderView)) { - _device.ImmediateContext.OutputMerger.SetTargets(_depthView, renderView); + _device!.ImmediateContext.OutputMerger.SetTargets(_depthView, renderView); var viewProj = Matrix.Multiply(_view, _proj); var context = _device.ImmediateContext; @@ -101,10 +105,10 @@ public class D3D11DemoControl : DrawingSurfaceDemoBase var ypr = Matrix4x4.CreateFromYawPitchRoll(Yaw, Pitch, Roll); // Update WorldViewProj Matrix - var worldViewProj = Matrix.RotationX((float)Yaw) * Matrix.RotationY((float)Pitch) - * Matrix.RotationZ((float)Roll) - * Matrix.Scaling(new Vector3(scaleX, scaleY, 1)) - * viewProj; + var worldViewProj = Matrix.RotationX(Yaw) * Matrix.RotationY(Pitch) + * Matrix.RotationZ(Roll) + * Matrix.Scaling(new Vector3(scaleX, scaleY, 1)) + * viewProj; worldViewProj.Transpose(); context.UpdateSubresource(ref worldViewProj, _constantBuffer); @@ -112,21 +116,25 @@ public class D3D11DemoControl : DrawingSurfaceDemoBase context.Draw(36, 0); - _context.Flush(); + _context!.Flush(); } } private void Resize(PixelSize size) { Utilities.Dispose(ref _depthBuffer); + + if (_device is null) + return; + _depthBuffer = new Texture2D(_device, new Texture2DDescription() { Format = Format.D32_Float_S8X24_UInt, ArraySize = 1, MipLevels = 1, - Width = (int)size.Width, - Height = (int)size.Height, + Width = size.Width, + Height = size.Height, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil, @@ -138,9 +146,9 @@ public class D3D11DemoControl : DrawingSurfaceDemoBase _depthView = new DepthStencilView(_device, _depthBuffer); // Setup targets and viewport for rendering - _device.ImmediateContext.Rasterizer.SetViewport(new Viewport(0, 0, (int)size.Width, (int)size.Height, 0.0f, 1.0f)); + _device.ImmediateContext.Rasterizer.SetViewport(new Viewport(0, 0, size.Width, size.Height, 0.0f, 1.0f)); // Setup new projection matrix with correct aspect ratio - _proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)(size.Width / size.Height), 0.1f, 100.0f); + _proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, size.Width / (float) size.Height, 0.1f, 100.0f); } } diff --git a/samples/GpuInterop/DrawingSurfaceDemoBase.cs b/samples/GpuInterop/DrawingSurfaceDemoBase.cs index 367436e5a5..be5d920b89 100644 --- a/samples/GpuInterop/DrawingSurfaceDemoBase.cs +++ b/samples/GpuInterop/DrawingSurfaceDemoBase.cs @@ -1,5 +1,4 @@ using System; -using System.Numerics; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; @@ -13,12 +12,12 @@ public abstract class DrawingSurfaceDemoBase : Control, IGpuDemo { private CompositionSurfaceVisual? _visual; private Compositor? _compositor; - private Action _update; - private string _info; + private readonly Action _update; + private string _info = string.Empty; private bool _updateQueued; private bool _initialized; - protected CompositionDrawingSurface Surface { get; private set; } + protected CompositionDrawingSurface? Surface { get; private set; } public DrawingSurfaceDemoBase() { @@ -113,7 +112,7 @@ public abstract class DrawingSurfaceDemoBase : Control, IGpuDemo protected abstract void RenderFrame(PixelSize pixelSize); protected virtual bool SupportsDisco => false; - public void Update(GpuDemo parent, float yaw, float pitch, float roll, float disco) + public void Update(GpuDemo? parent, float yaw, float pitch, float roll, float disco) { ParentControl = parent; if (ParentControl != null) diff --git a/samples/GpuInterop/GpuDemo.axaml.cs b/samples/GpuInterop/GpuDemo.axaml.cs index f7acac09e1..5a4b252fe8 100644 --- a/samples/GpuInterop/GpuDemo.axaml.cs +++ b/samples/GpuInterop/GpuDemo.axaml.cs @@ -80,13 +80,13 @@ public class GpuDemo : UserControl set => SetAndRaise(DiscoVisibleProperty, ref _discoVisible, value); } - private IGpuDemo _demo; + private IGpuDemo? _demo; - public static readonly DirectProperty DemoProperty = - AvaloniaProperty.RegisterDirect("Demo", o => o.Demo, + public static readonly DirectProperty DemoProperty = + AvaloniaProperty.RegisterDirect("Demo", o => o.Demo, (o, v) => o._demo = v); - public IGpuDemo Demo + public IGpuDemo? Demo { get => _demo; set => SetAndRaise(DemoProperty, ref _demo, value); @@ -102,7 +102,7 @@ public class GpuDemo : UserControl ) { if (change.Property == DemoProperty) - ((IGpuDemo)change.OldValue)?.Update(null, 0, 0, 0, 0); + ((IGpuDemo?)change.OldValue)?.Update(null, 0, 0, 0, 0); _demo?.Update(this, Yaw, Pitch, Roll, Disco); } @@ -112,5 +112,5 @@ public class GpuDemo : UserControl public interface IGpuDemo { - void Update(GpuDemo parent, float yaw, float pitch, float roll, float disco); + void Update(GpuDemo? parent, float yaw, float pitch, float roll, float disco); } diff --git a/samples/GpuInterop/VulkanDemo/VulkanCommandBufferPool.cs b/samples/GpuInterop/VulkanDemo/VulkanCommandBufferPool.cs index 2f018171dc..f89de4719f 100644 --- a/samples/GpuInterop/VulkanDemo/VulkanCommandBufferPool.cs +++ b/samples/GpuInterop/VulkanDemo/VulkanCommandBufferPool.cs @@ -13,7 +13,7 @@ namespace Avalonia.Vulkan private readonly CommandPool _commandPool; private readonly List _usedCommandBuffers = new(); - private object _lock = new object(); + private readonly object _lock = new(); public unsafe VulkanCommandBufferPool(Vk api, Device device, Queue queue, uint queueFamilyIndex) { @@ -167,7 +167,7 @@ namespace Avalonia.Vulkan ReadOnlySpan waitDstStageMask = default, ReadOnlySpan signalSemaphores = default, Fence? fence = null, - KeyedMutexSubmitInfo keyedMutex = null) + KeyedMutexSubmitInfo? keyedMutex = null) { EndRecording(); diff --git a/samples/GpuInterop/VulkanDemo/VulkanContent.cs b/samples/GpuInterop/VulkanDemo/VulkanContent.cs index 5805604f1b..a9a668d10b 100644 --- a/samples/GpuInterop/VulkanDemo/VulkanContent.cs +++ b/samples/GpuInterop/VulkanDemo/VulkanContent.cs @@ -39,7 +39,7 @@ unsafe class VulkanContent : IDisposable { _context = context; var name = typeof(VulkanContent).Assembly.GetManifestResourceNames().First(x => x.Contains("teapot.bin")); - using (var sr = new BinaryReader(typeof(VulkanContent).Assembly.GetManifestResourceStream(name))) + using (var sr = new BinaryReader(typeof(VulkanContent).Assembly.GetManifestResourceStream(name)!)) { var buf = new byte[sr.ReadInt32()]; sr.Read(buf, 0, buf.Length); @@ -115,7 +115,7 @@ unsafe class VulkanContent : IDisposable { var name = typeof(VulkanContent).Assembly.GetManifestResourceNames() .First(x => x.Contains((fragment ? "frag" : "vert") + ".spirv")); - using (var sr = typeof(VulkanContent).Assembly.GetManifestResourceStream(name)) + using (var sr = typeof(VulkanContent).Assembly.GetManifestResourceStream(name)!) { using (var mem = new MemoryStream()) { @@ -158,7 +158,7 @@ unsafe class VulkanContent : IDisposable var commandBuffer = _context.Pool.CreateCommandBuffer(); commandBuffer.BeginRecording(); - _colorAttachment.TransitionLayout(commandBuffer.InternalHandle, + _colorAttachment!.TransitionLayout(commandBuffer.InternalHandle, ImageLayout.Undefined, AccessFlags.None, ImageLayout.ColorAttachmentOptimal, AccessFlags.ColorAttachmentWriteBit); @@ -251,9 +251,9 @@ unsafe class VulkanContent : IDisposable } }; - api.CmdBlitImage(commandBuffer.InternalHandle, _colorAttachment.InternalHandle.Value, + api.CmdBlitImage(commandBuffer.InternalHandle, _colorAttachment.InternalHandle, ImageLayout.TransferSrcOptimal, - image.InternalHandle.Value, ImageLayout.TransferDstOptimal, 1, srcBlitRegion, Filter.Linear); + image.InternalHandle, ImageLayout.TransferDstOptimal, 1, srcBlitRegion, Filter.Linear); commandBuffer.Submit(); } @@ -393,7 +393,7 @@ unsafe class VulkanContent : IDisposable var view = Matrix4x4.CreateLookAt(new Vector3(25, 25, 25), new Vector3(), new Vector3(0, -1, 0)); var projection = - Matrix4x4.CreatePerspectiveFieldOfView((float)(Math.PI / 4), (float)((float)size.Width / size.Height), + Matrix4x4.CreatePerspectiveFieldOfView((float)(Math.PI / 4), (float)size.Width / size.Height, 0.01f, 1000); _colorAttachment = new VulkanImage(_context, (uint)Format.R8G8B8A8Unorm, size, false); @@ -808,7 +808,7 @@ unsafe class VulkanContent : IDisposable static Stopwatch St = Stopwatch.StartNew(); private bool _isInit; - private VulkanImage _colorAttachment; + private VulkanImage? _colorAttachment; private DescriptorSet _descriptorSet; [StructLayout(LayoutKind.Sequential, Pack = 4)] diff --git a/samples/GpuInterop/VulkanDemo/VulkanContext.cs b/samples/GpuInterop/VulkanDemo/VulkanContext.cs index a810a4b9f7..0983a373f3 100644 --- a/samples/GpuInterop/VulkanDemo/VulkanContext.cs +++ b/samples/GpuInterop/VulkanDemo/VulkanContext.cs @@ -2,34 +2,31 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using Avalonia; using Avalonia.Platform; using Avalonia.Rendering.Composition; using Avalonia.Vulkan; using Silk.NET.Core; -using Silk.NET.Core.Native; using Silk.NET.Vulkan; using Silk.NET.Vulkan.Extensions.EXT; using Silk.NET.Vulkan.Extensions.KHR; using SilkNetDemo; using SkiaSharp; using D3DDevice = SharpDX.Direct3D11.Device; -using DxgiDevice = SharpDX.DXGI.Device; namespace GpuInterop.VulkanDemo; public unsafe class VulkanContext : IDisposable { - public Vk Api { get; init; } - public Instance Instance { get; init; } - public PhysicalDevice PhysicalDevice { get; init; } - public Device Device { get; init; } - public Queue Queue { get; init; } - public uint QueueFamilyIndex { get; init; } - public VulkanCommandBufferPool Pool { get; init; } - public GRContext GrContext { get; init; } - public DescriptorPool DescriptorPool { get; init; } - public D3DDevice? D3DDevice { get; init; } + public required Vk Api { get; init; } + public required Instance Instance { get; init; } + public required PhysicalDevice PhysicalDevice { get; init; } + public required Device Device { get; init; } + public required Queue Queue { get; init; } + public required uint QueueFamilyIndex { get; init; } + public required VulkanCommandBufferPool Pool { get; init; } + public required GRContext GrContext { get; init; } + public required DescriptorPool DescriptorPool { get; init; } + public required D3DDevice? D3DDevice { get; init; } public static (VulkanContext? result, string info) TryCreate(ICompositionGpuInterop gpuInterop) { @@ -58,10 +55,8 @@ public unsafe class VulkanContext : IDisposable enabledExtensions.Add("VK_EXT_debug_utils"); if (IsLayerAvailable(api, "VK_LAYER_KHRONOS_validation")) enabledLayers.Add("VK_LAYER_KHRONOS_validation"); - - Instance vkInstance = default; - Silk.NET.Vulkan.PhysicalDevice physicalDevice = default; + Device device = default; DescriptorPool descriptorPool = default; VulkanCommandBufferPool? pool = null; @@ -78,7 +73,7 @@ public unsafe class VulkanContext : IDisposable EnabledExtensionCount = pRequiredExtensions.UCount, PpEnabledLayerNames = pEnabledLayers, EnabledLayerCount = pEnabledLayers.UCount - }, null, out vkInstance).ThrowOnError(); + }, null, out var vkInstance).ThrowOnError(); if (api.TryGetInstanceExtension(vkInstance, out ExtDebugUtils debugUtils)) @@ -95,7 +90,7 @@ public unsafe class VulkanContext : IDisposable PfnUserCallback = new PfnDebugUtilsMessengerCallbackEXT(LogCallback), }; - debugUtils.CreateDebugUtilsMessenger(vkInstance, debugCreateInfo, null, out var messenger); + debugUtils.CreateDebugUtilsMessenger(vkInstance, debugCreateInfo, null, out _); } var requireDeviceExtensions = new List @@ -158,11 +153,11 @@ public unsafe class VulkanContext : IDisposable else if (gpuInterop.DeviceUuid != null) { if (!new Span(physicalDeviceIDProperties.DeviceUuid, 16) - .SequenceEqual(gpuInterop?.DeviceUuid)) + .SequenceEqual(gpuInterop.DeviceUuid)) continue; } - physicalDevice = physicalDevices[c]; + var physicalDevice = physicalDevices[c]; var name = Marshal.PtrToStringAnsi(new IntPtr(physicalDeviceProperties2.Properties.DeviceName))!; @@ -251,8 +246,7 @@ public unsafe class VulkanContext : IDisposable RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) d3dDevice = D3DMemoryHelper.CreateDeviceByLuid( new Span(physicalDeviceIDProperties.DeviceLuid, 8)); - - var dxgiDevice = d3dDevice?.QueryInterface(); + return (new VulkanContext { Api = api, diff --git a/samples/GpuInterop/VulkanDemo/VulkanImage.cs b/samples/GpuInterop/VulkanDemo/VulkanImage.cs index c1865a817d..a385468b26 100644 --- a/samples/GpuInterop/VulkanDemo/VulkanImage.cs +++ b/samples/GpuInterop/VulkanDemo/VulkanImage.cs @@ -24,23 +24,23 @@ public unsafe class VulkanImage : IDisposable private ImageLayout _currentLayout; private AccessFlags _currentAccessFlags; private ImageUsageFlags _imageUsageFlags { get; } - private ImageView? _imageView { get; set; } + private ImageView _imageView { get; set; } private DeviceMemory _imageMemory { get; set; } - private SharpDX.Direct3D11.Texture2D? _d3dTexture2D; + private readonly SharpDX.Direct3D11.Texture2D? _d3dTexture2D; - internal Image? InternalHandle { get; private set; } + internal Image InternalHandle { get; private set; } internal Format Format { get; } - internal ImageAspectFlags AspectFlags { get; private set; } + internal ImageAspectFlags AspectFlags { get; } - public ulong Handle => InternalHandle?.Handle ?? 0; - public ulong ViewHandle => _imageView?.Handle ?? 0; + public ulong Handle => InternalHandle.Handle; + public ulong ViewHandle => _imageView.Handle; public uint UsageFlags => (uint) _imageUsageFlags; public ulong MemoryHandle => _imageMemory.Handle; public DeviceMemory DeviceMemory => _imageMemory; - public uint MipLevels { get; private set; } + public uint MipLevels { get; } public Vk Api { get; } public PixelSize Size { get; } - public ulong MemorySize { get; private set; } + public ulong MemorySize { get; } public uint CurrentLayout => (uint) _currentLayout; public VulkanImage(VulkanContext vk, uint format, PixelSize size, @@ -93,7 +93,7 @@ public unsafe class VulkanImage : IDisposable .CreateImage(_device, imageCreateInfo, null, out var image).ThrowOnError(); InternalHandle = image; - Api.GetImageMemoryRequirements(_device, InternalHandle.Value, + Api.GetImageMemoryRequirements(_device, InternalHandle, out var memoryRequirements); @@ -109,7 +109,7 @@ public unsafe class VulkanImage : IDisposable ImportMemoryWin32HandleInfoKHR handleImport = default; if (exportable && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - _d3dTexture2D = D3DMemoryHelper.CreateMemoryHandle(vk.D3DDevice, size, Format); + _d3dTexture2D = D3DMemoryHelper.CreateMemoryHandle(vk.D3DDevice!, size, Format); using var dxgi = _d3dTexture2D.QueryInterface(); handleImport = new ImportMemoryWin32HandleInfoKHR @@ -141,7 +141,7 @@ public unsafe class VulkanImage : IDisposable MemorySize = memoryRequirements.Size; - Api.BindImageMemory(_device, InternalHandle.Value, _imageMemory, 0).ThrowOnError(); + Api.BindImageMemory(_device, InternalHandle, _imageMemory, 0).ThrowOnError(); var componentMapping = new ComponentMapping( ComponentSwizzle.Identity, ComponentSwizzle.Identity, @@ -155,7 +155,7 @@ public unsafe class VulkanImage : IDisposable var imageViewCreateInfo = new ImageViewCreateInfo { SType = StructureType.ImageViewCreateInfo, - Image = InternalHandle.Value, + Image = InternalHandle, ViewType = ImageViewType.Type2D, Format = Format, Components = componentMapping, @@ -209,7 +209,7 @@ public unsafe class VulkanImage : IDisposable ImageLayout fromLayout, AccessFlags fromAccessFlags, ImageLayout destinationLayout, AccessFlags destinationAccessFlags) { - VulkanMemoryHelper.TransitionLayout(Api, commandBuffer, InternalHandle.Value, + VulkanMemoryHelper.TransitionLayout(Api, commandBuffer, InternalHandle, fromLayout, fromAccessFlags, destinationLayout, destinationAccessFlags, @@ -241,8 +241,8 @@ public unsafe class VulkanImage : IDisposable public unsafe void Dispose() { - Api.DestroyImageView(_device, _imageView.Value, null); - Api.DestroyImage(_device, InternalHandle.Value, null); + Api.DestroyImageView(_device, _imageView, null); + Api.DestroyImage(_device, InternalHandle, null); Api.FreeMemory(_device, _imageMemory, null); _imageView = default; diff --git a/samples/GpuInterop/VulkanDemo/VulkanSwapchain.cs b/samples/GpuInterop/VulkanDemo/VulkanSwapchain.cs index fc0e98b3e0..cd026b3972 100644 --- a/samples/GpuInterop/VulkanDemo/VulkanSwapchain.cs +++ b/samples/GpuInterop/VulkanDemo/VulkanSwapchain.cs @@ -146,6 +146,6 @@ class VulkanSwapchainImage : ISwapchainImage if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) _lastPresent = _target.UpdateWithKeyedMutexAsync(_importedImage, 1, 0); else - _lastPresent = _target.UpdateWithSemaphoresAsync(_importedImage, _renderCompletedSemaphore, _availableSemaphore); + _lastPresent = _target.UpdateWithSemaphoresAsync(_importedImage, _renderCompletedSemaphore!, _availableSemaphore!); } } diff --git a/samples/IntegrationTestApp/MainWindow.axaml.cs b/samples/IntegrationTestApp/MainWindow.axaml.cs index a858686ffb..170936f50d 100644 --- a/samples/IntegrationTestApp/MainWindow.axaml.cs +++ b/samples/IntegrationTestApp/MainWindow.axaml.cs @@ -42,23 +42,20 @@ namespace IntegrationTestApp private void InitializeViewMenu() { var mainTabs = this.Get("MainTabs"); - var viewMenu = (NativeMenuItem)NativeMenu.GetMenu(this).Items[1]; + var viewMenu = (NativeMenuItem?)NativeMenu.GetMenu(this)?.Items[1]; - if (mainTabs.Items is not null) + foreach (var tabItem in mainTabs.Items.Cast()) { - foreach (TabItem tabItem in mainTabs.Items) + var menuItem = new NativeMenuItem { - var menuItem = new NativeMenuItem - { - Header = (string)tabItem.Header!, - ToolTip = (string)tabItem.Header!, - IsChecked = tabItem.IsSelected, - ToggleType = NativeMenuItemToggleType.Radio, - }; - - menuItem.Click += (s, e) => tabItem.IsSelected = true; - viewMenu?.Menu?.Items.Add(menuItem); - } + Header = (string?)tabItem.Header, + ToolTip = (string?)tabItem.Header, + IsChecked = tabItem.IsSelected, + ToggleType = NativeMenuItemToggleType.Radio, + }; + + menuItem.Click += (_, _) => tabItem.IsSelected = true; + viewMenu?.Menu?.Items.Add(menuItem); } } @@ -77,7 +74,7 @@ namespace IntegrationTestApp var window = new ShowWindowTest { WindowStartupLocation = (WindowStartupLocation)locationComboBox.SelectedIndex, - CanResize = canResizeCheckBox.IsChecked.Value, + CanResize = canResizeCheckBox.IsChecked ?? false, }; if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) @@ -227,9 +224,9 @@ namespace IntegrationTestApp var gestureBorder2 = this.GetControl("GestureBorder2"); var lastGesture = this.GetControl("LastGesture"); var resetGestures = this.GetControl