Esempio n. 1
0
 public void CmdCopyBuffer(VulkanBuffer srcBuffer, VulkanBuffer dstBuffer, BufferCopy?pRegion)
 {
     unsafe {
         BufferCopy  valpRegion = pRegion ?? default(BufferCopy);
         BufferCopy *ptrpRegion = pRegion != null ? &valpRegion : (BufferCopy *)IntPtr.Zero;
         Interop.NativeMethods.vkCmdCopyBuffer(this.m, srcBuffer != null ? srcBuffer.m : default(UInt64), dstBuffer != null ? dstBuffer.m : default(UInt64), (UInt32)(pRegion != null ? 1 : 0), ptrpRegion);
     }
 }
Esempio n. 2
0
 public static extern unsafe void vkCmdCopyBuffer(IntPtr commandBuffer, ulong srcBuffer, ulong dstBuffer, uint regionCount, BufferCopy *pRegions);
Esempio n. 3
0
 internal static unsafe extern void vkCmdCopyBuffer(CommandBuffer commandBuffer, Buffer srcBuffer, Buffer dstBuffer, UInt32 regionCount, BufferCopy *Regions);
Esempio n. 4
0
 internal static unsafe extern void vkCmdCopyBuffer(IntPtr commandBuffer, UInt64 srcBuffer, UInt64 dstBuffer, UInt32 regionCount, BufferCopy *pRegions);
        private unsafe void CreateBuffers()
        {
            PositionColorVertex[] positionData = VertexData.IndexedCubeData;

            ushort[] indexData = VertexData.CubeIndexData;

            InstanceData[] instanceData = new InstanceData[]
            {
                new InstanceData(new Vector3(0, 0, 0)),
                new InstanceData(new Vector3(2, 0, 0)),
                new InstanceData(new Vector3(-2, 0, 0))
            };

            CreateHostBufferWithContent <PositionColorVertex>(positionData, out var hostBuffer1, out var hostAlloc1);
            CreateHostBufferWithContent <ushort>(indexData, out var hostBuffer2, out var hostAlloc2);
            CreateHostBufferWithContent <InstanceData>(instanceData, out var hostBuffer3, out var hostAlloc3);

            CreateDeviceLocalBuffer(BufferUsageFlags.BufferUsageVertexBufferBit, GetByteLength(positionData), out this.VertexBuffer, out this.VertexAllocation);
            CreateDeviceLocalBuffer(BufferUsageFlags.BufferUsageIndexBufferBit, GetByteLength(indexData), out this.IndexBuffer, out this.IndexAllocation);
            CreateDeviceLocalBuffer(BufferUsageFlags.BufferUsageVertexBufferBit, GetByteLength(instanceData), out this.InstanceBuffer, out this.InstanceAllocation);

            var cbuffer = AllocateCommandBuffer(CommandBufferLevel.Primary);

            BufferCopy *copies = stackalloc BufferCopy[1];

            BeginCommandBuffer(cbuffer, CommandBufferUsageFlags.CommandBufferUsageOneTimeSubmitBit);

            copies[0] = new BufferCopy(0, 0, (ulong)GetByteLength(positionData));
            VkApi.CmdCopyBuffer(cbuffer, hostBuffer1, this.VertexBuffer, 1, copies);

            copies[0] = new BufferCopy(0, 0, (ulong)GetByteLength(indexData));
            VkApi.CmdCopyBuffer(cbuffer, hostBuffer2, this.IndexBuffer, 1, copies);

            copies[0] = new BufferCopy(0, 0, (ulong)GetByteLength(instanceData));
            VkApi.CmdCopyBuffer(cbuffer, hostBuffer3, this.InstanceBuffer, 1, copies);

            EndCommandBuffer(cbuffer);

            var subInfo = new SubmitInfo(commandBufferCount: 1, pCommandBuffers: &cbuffer);

            var fence = CreateFence();

            var res = VkApi.QueueSubmit(GraphicsQueue, 1, &subInfo, fence);

            if (res != Result.Success)
            {
                throw new Exception("Unable to submit to queue. " + res);
            }

            var bufferTmp = cbuffer; //Allows the capture of this command buffer in a lambda

            BufferCopyPromise = this.scheduler.WaitForFenceAsync(fence);

            BufferCopyPromise.GetAwaiter().OnCompleted(() =>
            {
                VkApi.DestroyFence(Device, fence, null);

                FreeCommandBuffer(bufferTmp);

                VkApi.DestroyBuffer(Device, hostBuffer1, null);
                VkApi.DestroyBuffer(Device, hostBuffer2, null);
                VkApi.DestroyBuffer(Device, hostBuffer3, null);

                hostAlloc1.Dispose();
                hostAlloc2.Dispose();
                hostAlloc3.Dispose();
            });

            this.VertexCount   = (uint)positionData.Length;
            this.IndexCount    = (uint)indexData.Length;
            this.InstanceCount = (uint)instanceData.Length;
        }