void IInternalTexture.Upload( HostBuffer stagingBuffer, TransientExecutor executor, Image image, ImageAspects aspects) { if (stagingBuffer == null) { throw new ArgumentNullException(nameof(stagingBuffer)); } if (executor == null) { throw new ArgumentNullException(nameof(executor)); } //Write all the faces to the staging buffer and create copy commands long offset = 0; BufferImageCopy[] copyRegions = new BufferImageCopy[faces.Length]; for (int i = 0; i < faces.Length; i++) { copyRegions[i] = new BufferImageCopy { BufferOffset = offset, BufferRowLength = 0, BufferImageHeight = 0, ImageSubresource = new ImageSubresourceLayers( aspectMask: aspects, mipLevel: 0, baseArrayLayer: i, layerCount: 1), ImageOffset = new Offset3D(x: 0, y: 0, z: 0), ImageExtent = new Extent3D( width: size.X, height: size.Y, depth: 1) }; offset += faces[i].Write(stagingBuffer, offset); } //Copy our staging buffer to the image executor.ExecuteBlocking(commandBuffer => { commandBuffer.CmdCopyBufferToImage( srcBuffer: stagingBuffer.VulkanBuffer, dstImage: image, dstImageLayout: ImageLayout.TransferDstOptimal, regions: copyRegions); }); }
void IInternalTexture.Upload( HostBuffer stagingBuffer, TransientExecutor executor, Image image, ImageAspects aspects) { if (stagingBuffer == null) { throw new ArgumentNullException(nameof(stagingBuffer)); } if (executor == null) { throw new ArgumentNullException(nameof(executor)); } //Write to the staging buffer stagingBuffer.Write(pixels, offset: 0); //Copy the staging buffer to the image executor.ExecuteBlocking(commandBuffer => { commandBuffer.CmdCopyBufferToImage( srcBuffer: stagingBuffer.VulkanBuffer, dstImage: image, dstImageLayout: ImageLayout.TransferDstOptimal, regions: new BufferImageCopy { BufferOffset = 0, BufferRowLength = 0, BufferImageHeight = 0, ImageSubresource = new ImageSubresourceLayers( aspectMask: aspects, mipLevel: 0, baseArrayLayer: 0, layerCount: 1), ImageOffset = new Offset3D(x: 0, y: 0, z: 0), ImageExtent = new Extent3D( width: size.X, height: size.Y, depth: 1) }); }); }
internal static DeviceBuffer UploadData <T>( ReadOnlySpan <T> data, Device logicalDevice, Pool memoryPool, BufferUsages usages, HostBuffer stagingBuffer, TransientExecutor executor) where T : struct { //First write the data to the staging buffer int size = stagingBuffer.Write <T>(data, offset: 0); //Then create a device buffer with that size DeviceBuffer targetBuffer = new DeviceBuffer(logicalDevice, memoryPool, usages, size); //Then copy the data from the staging buffer to the devicebuffer executor.ExecuteBlocking(commandBuffer => { commandBuffer.CmdCopyBuffer( srcBuffer: stagingBuffer.VulkanBuffer, dstBuffer: targetBuffer.VulkanBuffer, new BufferCopy(size: size, srcOffset: 0, dstOffset: 0)); }); return(targetBuffer); }