Beispiel #1
0
        public static BufferWithMemory CreateBuffer(VkContext vulkan, Vk.DeviceSize size,
                                                    Vk.BufferUsageFlags usage, Vk.MemoryPropertyFlags memoryProps,
                                                    Vk.SharingMode sharingMode)
        {
            var bufferInfo = new Vk.BufferCreateInfo();

            bufferInfo.Size        = size;
            bufferInfo.Usage       = usage;
            bufferInfo.SharingMode = sharingMode;

            var container = new BufferWithMemory();

            container.Buffer = vulkan.Device.CreateBuffer(bufferInfo);

            var memoryReqs = vulkan.Device.GetBufferMemoryRequirements(container.Buffer);
            var allocInfo  = new Vk.MemoryAllocateInfo();

            allocInfo.AllocationSize  = memoryReqs.Size;
            allocInfo.MemoryTypeIndex = FindMemoryType(memoryReqs.MemoryTypeBits,
                                                       vulkan.PhysicalDevice, memoryProps);

            container.Memory = vulkan.Device.AllocateMemory(allocInfo);
            container.Bind(vulkan.Device, 0);

            return(container);
        }
Beispiel #2
0
        private unsafe IntPtr SetupCopy <T>(int mySize)
        {
            if (SizeOfBuffer == 0)
            {
                SizeOfInternalStructure = mySize;
                var memoryReq = myActiveDevice.LogicalDevice.GetBufferMemoryRequirements(this);
                SizeOfBuffer = memoryReq.Size;
                allocInfo    = new MemoryAllocateInfo {
                    AllocationSize = memoryReq.Size
                };
                var  memoryProperties = myActiveDevice.GetMemoryProperties();
                bool heapIndexSet     = false;
                var  memoryTypes      = memoryProperties.MemoryTypes;

                for (uint i = 0; i < memoryProperties.MemoryTypeCount; i++)
                {
                    if (((memoryReq.MemoryTypeBits >> (int)i) & 1) == 1 &&
                        (memoryTypes[i].PropertyFlags & MemoryPropertyFlags.HostVisible) == MemoryPropertyFlags.HostVisible)
                    {
                        allocInfo.MemoryTypeIndex = i;
                        heapIndexSet = true;
                    }
                }
                if (!heapIndexSet)
                {
                    allocInfo.MemoryTypeIndex = memoryProperties.MemoryTypes[0].HeapIndex;
                }
            }

            deviceMemory = new DeviceMemory(myActiveDevice.LogicalDevice, allocInfo);
            return(myActiveDevice.LogicalDevice.MapMemory(deviceMemory, 0, mySize, 0));
        }
Beispiel #3
0
 public void CmdBindVertexBuffer(UInt32 firstBinding, VulkanBuffer pBuffer, DeviceSize pOffset)
 {
     unsafe
     {
         fixed(UInt64 *ptrpBuffer = &pBuffer.m)
         {
             Interop.NativeMethods.vkCmdBindVertexBuffers(this.m, firstBinding, (UInt32)(pOffset != null ? 1 : 0), ptrpBuffer, &pOffset);
         }
     }
 }
        //static object BindMemoryLock()
        public void BindImageMemory(DeviceMemory memory, DeviceSize memoryOffset)
        {
            Result result;

            unsafe
            {
                result = Interop.NativeMethods.vkBindImageMemory(Device.LogicalDevice.m, this.m, memory != null ? memory.m : default(UInt64), memoryOffset);
                if (result != Result.Success)
                {
                    throw new ResultException(result);
                }
            }
        }
Beispiel #5
0
        public static void CopyBuffer(Vk.Buffer src, Vk.Buffer dest, Vk.DeviceSize size,
                                      VkContext state)
        {
            var commandBuffer = state.BeginSingleTimeCommands(state.TransferCommandPool);

            var copyRegion = new Vk.BufferCopy();

            copyRegion.SrcOffset = 0;
            copyRegion.DstOffset = 0;
            copyRegion.Size      = size;

            commandBuffer.CmdCopyBuffer(src, dest, copyRegion);

            state.EndSingleTimeCommands(state.TransferQueue, state.TransferCommandPool, commandBuffer);
        }
Beispiel #6
0
        protected unsafe void CreateBuffer(VulkanPhysicalDevice myDevice, BufferCreateInfo createBufferInfo, AllocationCallbacks pAllocator = null)
        {
            if (myDevice == null)
            {
                throw new VULKANDEVICE_NO_ACTIVE_DEVICE();
            }
            this.Allocator      = pAllocator;
            this.myActiveDevice = myDevice;

            SizeOfInternalStructure = createBufferInfo.Size;
            Result result;

            fixed(UInt64 *ptrpBuffer = &this.m)
            {
                result = Interop.NativeMethods.vkCreateBuffer(myDevice.LogicalDevice.m, createBufferInfo != null ? createBufferInfo.m : (Interop.BufferCreateInfo *) default(IntPtr), pAllocator != null ? pAllocator.m : null, ptrpBuffer);
            }

            if (result != Result.Success)
            {
                throw new ResultException(result);
            }
        }
Beispiel #7
0
 public void CmdWriteBufferMarkerAMD(PipelineStageFlags pipelineStage, VulkanBuffer dstBuffer, DeviceSize dstOffset, UInt32 marker)
 {
     unsafe {
         Interop.NativeMethods.vkCmdWriteBufferMarkerAMD(this.m, pipelineStage, dstBuffer != null ? dstBuffer.m : default(UInt64), dstOffset, marker);
     }
 }
Beispiel #8
0
 public void CmdDrawIndexedIndirectCountAMD(VulkanBuffer buffer, DeviceSize offset, VulkanBuffer countBuffer, DeviceSize countBufferOffset, UInt32 maxDrawCount, UInt32 stride)
 {
     unsafe {
         Interop.NativeMethods.vkCmdDrawIndexedIndirectCountAMD(this.m, buffer != null ? buffer.m : default(UInt64), offset, countBuffer != null ? countBuffer.m : default(UInt64), countBufferOffset, maxDrawCount, stride);
     }
 }
Beispiel #9
0
 public void CmdCopyQueryPoolResults(QueryPool queryPool, UInt32 firstQuery, UInt32 queryCount, VulkanBuffer dstBuffer, DeviceSize dstOffset, DeviceSize stride, QueryResultFlags flags = (QueryResultFlags)0)
 {
     unsafe {
         Interop.NativeMethods.vkCmdCopyQueryPoolResults(this.m, queryPool != null ? queryPool.m : default(UInt64), firstQuery, queryCount, dstBuffer != null ? dstBuffer.m : default(UInt64), dstOffset, stride, flags);
     }
 }
Beispiel #10
0
 public void CmdFillBuffer(VulkanBuffer dstBuffer, DeviceSize dstOffset, DeviceSize size, UInt32 data)
 {
     unsafe {
         Interop.NativeMethods.vkCmdFillBuffer(this.m, dstBuffer != null ? dstBuffer.m : default(UInt64), dstOffset, size, data);
     }
 }
Beispiel #11
0
 public void CmdUpdateBuffer(VulkanBuffer dstBuffer, DeviceSize dstOffset, DeviceSize dataSize, IntPtr pData)
 {
     unsafe {
         Interop.NativeMethods.vkCmdUpdateBuffer(this.m, dstBuffer != null ? dstBuffer.m : default(UInt64), dstOffset, dataSize, pData);
     }
 }
Beispiel #12
0
 public void CmdDispatchIndirect(VulkanBuffer buffer, DeviceSize offset)
 {
     unsafe {
         Interop.NativeMethods.vkCmdDispatchIndirect(this.m, buffer != null ? buffer.m : default(UInt64), offset);
     }
 }
Beispiel #13
0
 public void CmdDrawIndexedIndirect(VulkanBuffer buffer, DeviceSize offset, UInt32 drawCount, UInt32 stride)
 {
     unsafe {
         Interop.NativeMethods.vkCmdDrawIndexedIndirect(this.m, buffer != null ? buffer.m : default(UInt64), offset, drawCount, stride);
     }
 }
Beispiel #14
0
 public void CmdBindIndexBuffer(VulkanBuffer buffer, DeviceSize offset, IndexType indexType)
 {
     unsafe {
         Interop.NativeMethods.vkCmdBindIndexBuffer(this.m, buffer != null ? buffer.m : default(UInt64), offset, indexType);
     }
 }
Beispiel #15
0
 /// <summary>
 ///     Wrapper around <see cref="Vk.Device.BindImageMemory"/>
 /// </summary>
 /// <param name="device">
 ///     The Vulkan logical device which created the image and allocated
 ///     its memory.
 /// </param>
 /// <param name="offset">
 ///     The offset in the allocated memory block at which the image's data
 ///     should be written.
 /// </param>
 public void Bind(Vk.Device device, Vk.DeviceSize offset)
 {
     device.BindImageMemory(this.Image, this.Memory, offset);
 }
Beispiel #16
0
 /// <summary>
 ///     Wrapper around <see cref="Vk.Device.BindBufferMemory"/>
 /// </summary>
 /// <param name="device">
 ///     The Vulkan logical device which created the buffer and allocated
 ///     its memory.
 /// </param>
 /// <param name="offset">
 ///     The offset in the allocated memory block at which the buffer's data
 ///     should be written.
 /// </param>
 public void Bind(Vk.Device device, Vk.DeviceSize offset)
 {
     device.BindBufferMemory(this.Buffer, this.Memory, offset);
 }