public void SetVertexBuffers(Buffer[] buffers, ulong offsets = 0) { VkBuffer *buffer = stackalloc VkBuffer[buffers.Length]; for (int i = 0; i < buffers.Length; i++) { buffer[i] = buffers[i].handle; } //fixed(VkBuffer* bufferptr = &buffers[0].Handle) //{ //} vkCmdBindVertexBuffers(handle, 0, 1, buffer, &offsets); }
/** * Create a buffer on the device * * @param usageFlags Usage flag bitmask for the buffer (i.e. index, vertex, uniform buffer) * @param memoryPropertyFlags Memory properties for this buffer (i.e. device local, host visible, coherent) * @param size Size of the buffer in byes * @param buffer Pointer to the buffer handle acquired by the function * @param memory Pointer to the memory handle acquired by the function * @param data Pointer to the data that should be copied to the buffer after creation (optional, if not set, no data is copied over) * * @return Success if buffer handle and memory have been created and (optionally passed) data has been copied */ public VkResult createBuffer(VkBufferUsageFlagBits usageFlags, VkMemoryPropertyFlagBits memoryPropertyFlags, ulong size, VkBuffer *buffer, VkDeviceMemory *memory, void *data = null) { // Create the buffer handle VkBufferCreateInfo bufferCreateInfo = new VkBufferCreateInfo(); bufferCreateInfo.sType = BufferCreateInfo; bufferCreateInfo.usage = usageFlags; bufferCreateInfo.size = size; bufferCreateInfo.sharingMode = VkSharingMode.Exclusive; vkCreateBuffer(LogicalDevice, &bufferCreateInfo, null, buffer); // Create the memory backing up the buffer handle VkMemoryRequirements memReqs; VkMemoryAllocateInfo memAlloc = new VkMemoryAllocateInfo(); memAlloc.sType = MemoryAllocateInfo; vkGetBufferMemoryRequirements(LogicalDevice, *buffer, &memReqs); memAlloc.allocationSize = memReqs.size; // Find a memory type index that fits the properties of the buffer memAlloc.memoryTypeIndex = getMemoryType(memReqs.memoryTypeBits, memoryPropertyFlags); vkAllocateMemory(LogicalDevice, &memAlloc, null, memory); // If a pointer to the buffer data has been passed, map the buffer and copy over the data if (data != null) { IntPtr mapped; vkMapMemory(LogicalDevice, *memory, 0, size, 0, &mapped); Unsafe.CopyBlock(mapped, data, (uint)size); // If host coherency hasn't been requested, do a manual flush to make writes visible if ((memoryPropertyFlags & VkMemoryPropertyFlagBits.HostCoherent) == 0) { VkMappedMemoryRange mappedRange = new VkMappedMemoryRange(); mappedRange.memory = *memory; mappedRange.offset = 0; mappedRange.size = size; vkFlushMappedMemoryRanges(LogicalDevice, 1, &mappedRange); } vkUnmapMemory(LogicalDevice, *memory); } // Attach the memory to the buffer object vkBindBufferMemory(LogicalDevice, *buffer, *memory, 0); return(VkResult.Success); }