private async void GpuViewHost_ChildChanged(object sender, EventArgs e) { WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender; SwapChainPanel swapChainPanel = (SwapChainPanel)windowsXamlHost.Child; GpuView = swapChainPanel; Gpu = new Gpu(); #if DEBUG Gpu.EnableD3D12DebugLayer(); #endif GpuView.Width = this.Width; GpuView.Height = this.Height; await Init(); SizeChanged += MainWindow_SizeChanged; GpuFence fence = Device.DefaultQueue.CreateFence(); UInt64 currentFenceValue = 0; while (true) { if (SwapChain == null) { SwapChainDescriptor = new GpuSwapChainDescriptor(GpuTextureFormat.BGRA8UNorm, (uint)GpuView.Width, (uint)GpuView.Height); SwapChain = Device.ConfigureSwapChainForSwapChainPanel(SwapChainDescriptor, GpuView); DepthTexture = Device.CreateTexture(new GpuTextureDescriptor(new GpuExtend3DDict { Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1 }, GpuTextureFormat.Depth24PlusStencil8, GpuTextureUsageFlags.OutputAttachment)); } DrawFrame(); var fenceValueWaitFor = ++currentFenceValue; Device.DefaultQueue.Signal(fence, fenceValueWaitFor); await fence.OnCompletionAsync(fenceValueWaitFor); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { await Init(); GpuFence fence = Device.DefaultQueue.CreateFence(); UInt64 currentFenceValue = 0; while (true) { if (SwapChain == null) { SwapChainDescriptor = new GpuSwapChainDescriptor(GpuTextureFormat.BGRA8UNorm, (uint)GpuView.Width, (uint)GpuView.Height); SwapChain = Device.ConfigureSwapChainForSwapChainPanel(SwapChainDescriptor, GpuView); DepthTexture = Device.CreateTexture(new GpuTextureDescriptor(new GpuExtend3DDict { Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1 }, GpuTextureFormat.Depth24PlusStencil8, GpuTextureUsageFlags.OutputAttachment)); CubeTexture = Device.CreateTexture(new GpuTextureDescriptor(new GpuExtend3DDict { Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1 }, GpuTextureFormat.BGRA8UNorm, GpuTextureUsageFlags.Sampled | GpuTextureUsageFlags.CopyDst)); UniformBindGroup = Device.CreateBindGroup(new GpuBindGroupDescriptor(UniformBindGroupLayout, new GpuBindGroupEntry[] { new GpuBindGroupEntry(0, new GpuBufferBinding(UniformBuffer, UniformBufferSize)), new GpuBindGroupEntry(1, Sampler), new GpuBindGroupEntry(2, CubeTexture.CreateView()) })); } DrawFrame(); var fenceValueWaitFor = ++currentFenceValue; Device.DefaultQueue.Signal(fence, fenceValueWaitFor); await fence.OnCompletionAsync(fenceValueWaitFor); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { await Init(); GpuFence fence = Device.DefaultQueue.CreateFence(); UInt64 currentFenceValue = 0; while (true) { if (SwapChain == null) { SwapChainDescriptor = new GpuSwapChainDescriptor(SwapChainFormat, (uint)GpuView.Width, (uint)GpuView.Height); SwapChain = Device.ConfigureSwapChainForSwapChainPanel(SwapChainDescriptor, GpuView); var texture = Device.CreateTexture(new GpuTextureDescriptor(new GpuExtend3DDict { Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1 }, SwapChainFormat, GpuTextureUsageFlags.OutputAttachment) { SampleCount = SampleCount }); Attachment = texture.CreateView(); } DrawFrame(); var fenceValueWaitFor = ++currentFenceValue; Device.DefaultQueue.Signal(fence, fenceValueWaitFor); await fence.OnCompletionAsync(fenceValueWaitFor); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { await Init(); GpuFence fence = Device.DefaultQueue.CreateFence(); UInt64 currentFenceValue = 0; DateTime? previousFrameDateTime = null; double frameTimeAverage = 0; double doDrawTimeAverage = 0; Configure configure; while (true) { if (CurrentConfigure == null) { Settings settings = new Settings { DynmicOffsets = ViewModel.DynamicOffsets, NumTriangles = (uint)ViewModel.NumTriangles, RenderBundles = ViewModel.RenderBundles }; configure = CurrentConfigure = new Configure(Device, settings, BindGroupLayout, DynamicBindGroupLayout, TimeBindGroupLayout, Pipeline, DynamicPipeline, VertexBuffer, SwapChainFormat); } else { configure = CurrentConfigure; } if (SwapChain == null) { SwapChainDescriptor = new GpuSwapChainDescriptor(SwapChainFormat, (uint)GpuView.Width, (uint)GpuView.Height); SwapChain = Device.ConfigureSwapChainForSwapChainPanel(SwapChainDescriptor, GpuView); previousFrameDateTime = null; } var now = DateTime.Now; TimeSpan frameTime = TimeSpan.FromMilliseconds(0); if (previousFrameDateTime != null) { frameTime = now - previousFrameDateTime.Value; } previousFrameDateTime = now; var start = DateTime.Now; configure.DoDraw(now, SwapChain); var doDrawTimeSpan = DateTime.Now - start; var w = 0.2; frameTimeAverage = (1 - w) * frameTimeAverage + w * frameTime.TotalMilliseconds; doDrawTimeAverage = (1 - w) * doDrawTimeAverage + w * doDrawTimeSpan.TotalMilliseconds; ViewModel.FrameTimeAverage = (float)frameTimeAverage; ViewModel.CpuTimeAverage = (float)doDrawTimeAverage; SwapChain.Present(); var fenceValueWaitFor = ++currentFenceValue; Device.DefaultQueue.Signal(fence, fenceValueWaitFor); await fence.OnCompletionAsync(fenceValueWaitFor); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { await Init(); GpuFence fence = Device.DefaultQueue.CreateFence(); UInt64 currentFenceValue = 0; while (true) { if (SwapChain == null) { SwapChainDescriptor = new GpuSwapChainDescriptor(SwapChainFormat, (uint)GpuView.Width, (uint)GpuView.Height); SwapChain = Device.ConfigureSwapChainForSwapChainPanel(SwapChainDescriptor, GpuView); } DrawFrame(); var fenceValueWaitFor = ++currentFenceValue; Device.DefaultQueue.Signal(fence, fenceValueWaitFor); await fence.OnCompletionAsync(fenceValueWaitFor); } }