private void DestroySwapchain() { if (swapchain != SharpVulkan.Swapchain.Null) { context.WaitForFence(swapchainDestroyFenceValue); swapchainDestroyFenceValue = context.NextFenceValue; foreach (var i in framebuffers) { context.Release(i); } foreach (var i in backbufferViews) { context.Release(i); } foreach (var i in acquirementSemaphores) { context.Release(i); } context.Release(depthStencilView); context.Release(depthStencilBuffer); context.Release(depthStencilMemory); context.Release(renderPass); context.Release(swapchain); context.Flush(); swapchain = SharpVulkan.Swapchain.Null; } }
private void SetDataDynamic(int offset, IntPtr data, int size, BufferSetDataMode mode) { if (mode == BufferSetDataMode.Discard) { backingBuffer.DiscardSlice(WriteFenceValue); WriteFenceValue = 0; } else { if (context.NextFenceValue <= WriteFenceValue) { context.Flush(); } context.WaitForFence(WriteFenceValue); } var dstData = backingBuffer.MapSlice() + offset; try { GraphicsUtility.CopyMemory(dstData, data, size); } finally { backingBuffer.UnmapSlice(); } }
public void SetData(int level, int x, int y, int width, int height, IntPtr data) { var dataSize = GraphicsUtility.CalculateImageDataSize(Format, width, height); if (IsPvrtc1Format(Format)) { if (x != 0 || y != 0 || width != Width || height != Height) { throw new NotSupportedException(); } if (context.NextFenceValue <= WriteFenceValue) { context.Flush(); } context.WaitForFence(WriteFenceValue); var dstData = Context.MemoryAllocator.Map(memory); try { GraphicsUtility.CopyMemory(dstData, data, dataSize); } finally { Context.MemoryAllocator.Unmap(memory); } } else { ulong bufferOffsetAlignment = 4; bufferOffsetAlignment = GraphicsUtility.CombineAlignment(bufferOffsetAlignment, (ulong)Format.GetSize()); bufferOffsetAlignment = GraphicsUtility.CombineAlignment(bufferOffsetAlignment, context.PhysicalDeviceLimits.OptimalBufferCopyOffsetAlignment); var uploadBufferAlloc = context.AllocateUploadBuffer((ulong)dataSize, bufferOffsetAlignment); GraphicsUtility.CopyMemory(uploadBufferAlloc.Data, data, dataSize); context.EndRenderPass(); context.EnsureCommandBuffer(); var preMemoryBarrier = new SharpVulkan.ImageMemoryBarrier { StructureType = SharpVulkan.StructureType.ImageMemoryBarrier, Image = image, OldLayout = SharpVulkan.ImageLayout.ShaderReadOnlyOptimal, NewLayout = SharpVulkan.ImageLayout.TransferDestinationOptimal, SourceAccessMask = SharpVulkan.AccessFlags.ShaderRead, DestinationAccessMask = SharpVulkan.AccessFlags.TransferWrite, SubresourceRange = new SharpVulkan.ImageSubresourceRange(SharpVulkan.ImageAspectFlags.Color, 0, 1, (uint)level, 1) }; context.CommandBuffer.PipelineBarrier( SharpVulkan.PipelineStageFlags.VertexShader | SharpVulkan.PipelineStageFlags.FragmentShader, SharpVulkan.PipelineStageFlags.Transfer, SharpVulkan.DependencyFlags.None, 0, null, 0, null, 1, &preMemoryBarrier); var copyRegion = new SharpVulkan.BufferImageCopy { BufferOffset = uploadBufferAlloc.BufferOffset, BufferRowLength = (uint)width, BufferImageHeight = (uint)height, ImageOffset = new SharpVulkan.Offset3D(x, y, 0), ImageExtent = new SharpVulkan.Extent3D((uint)width, (uint)height, 1), ImageSubresource = new SharpVulkan.ImageSubresourceLayers(SharpVulkan.ImageAspectFlags.Color, 0, 1, (uint)level) }; context.CommandBuffer.CopyBufferToImage( uploadBufferAlloc.Buffer, image, SharpVulkan.ImageLayout.TransferDestinationOptimal, 1, ©Region); var postMemoryBarrier = new SharpVulkan.ImageMemoryBarrier { StructureType = SharpVulkan.StructureType.ImageMemoryBarrier, Image = image, OldLayout = SharpVulkan.ImageLayout.TransferDestinationOptimal, NewLayout = SharpVulkan.ImageLayout.ShaderReadOnlyOptimal, SourceAccessMask = SharpVulkan.AccessFlags.TransferWrite, DestinationAccessMask = SharpVulkan.AccessFlags.ShaderRead, SubresourceRange = new SharpVulkan.ImageSubresourceRange(SharpVulkan.ImageAspectFlags.Color, 0, 1, (uint)level, 1) }; context.CommandBuffer.PipelineBarrier( SharpVulkan.PipelineStageFlags.Transfer, SharpVulkan.PipelineStageFlags.VertexShader | SharpVulkan.PipelineStageFlags.FragmentShader, SharpVulkan.DependencyFlags.None, 0, null, 0, null, 1, &postMemoryBarrier); } }