/// <summary> /// load bitmap from pointer /// </summary> void load(Queue staggingQ, CommandPool staggingCmdPool, IntPtr bitmap, bool generateMipmaps = true) { long size = info.extent.width * info.extent.height * 4 * info.extent.depth; if (MemoryFlags.HasFlag(VkMemoryPropertyFlags.HostVisible)) { Map(); unsafe { System.Buffer.MemoryCopy(bitmap.ToPointer(), MappedData.ToPointer(), size, size); } Unmap(); if (generateMipmaps) { BuildMipmaps(staggingQ, staggingCmdPool); } } else { using (HostBuffer stagging = new HostBuffer(Dev, VkBufferUsageFlags.TransferSrc, (UInt64)size, bitmap)) { PrimaryCommandBuffer cmd = staggingCmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit); stagging.CopyTo(cmd, this); if (generateMipmaps) { BuildMipmaps(cmd); } cmd.End(); staggingQ.Submit(cmd); staggingQ.WaitIdle(); cmd.Free(); } } }
/// <summary> /// End command recording, submit, and wait queue idle /// </summary> public void EndSubmitAndWait(PrimaryCommandBuffer cmd, bool freeCommandBuffer = false) { cmd.End(); Submit(cmd); WaitIdle(); if (freeCommandBuffer) { cmd.Free(); } }
public void BuildMipmaps(Queue copyQ, CommandPool copyCmdPool) { if (info.mipLevels == 1) { Debug.WriteLine("Invoking BuildMipmaps on image that has only one mipLevel"); return; } PrimaryCommandBuffer cmd = copyCmdPool.AllocateCommandBuffer(); cmd.Start(VkCommandBufferUsageFlags.OneTimeSubmit); BuildMipmaps(cmd); cmd.End(); copyQ.Submit(cmd); copyQ.WaitIdle(); cmd.Free(); }