// Size in bytes, and the usages private protected Buffer(uint size, BufferType type, Vk.BufferUsages usages) { Device = SpectrumApp.Instance.GraphicsDevice; Size = size; Type = type; // Create the buffer var bci = new Vk.BufferCreateInfo( size, Vk.BufferUsages.TransferDst | Vk.BufferUsages.TransferSrc | usages, flags: Vk.BufferCreateFlags.None, sharingMode: Vk.SharingMode.Exclusive ); VkBuffer = Device.VkDevice.CreateBuffer(bci); // Create the backing memory var memReq = VkBuffer.GetMemoryRequirements(); var memIdx = Device.FindMemoryTypeIndex(memReq.MemoryTypeBits, Vk.MemoryProperties.DeviceLocal); if (memIdx == -1) { throw new InvalidOperationException("Cannot find a memory type that supports buffers (this means bad or out-of-date hardware)"); } var mai = new Vk.MemoryAllocateInfo(memReq.Size, memIdx); VkMemory = Device.VkDevice.AllocateMemory(mai); VkBuffer.BindMemory(VkMemory); }
internal Buffer(Device parent, ref BufferCreateInfo createInfo, ref AllocationCallbacks?allocator) { Parent = parent; Allocator = allocator; fixed(int *queueFamilies = createInfo.QueueFamilyIndices) { createInfo.ToNative(out BufferCreateInfo.Native nativeCreateInfo, queueFamilies); long handle; Result result = vkCreateBuffer( parent, &nativeCreateInfo, NativeAllocator, &handle); VulkanException.ThrowForInvalidResult(result); Handle = handle; } }
/// <summary> /// Create a new buffer object. /// </summary> /// <param name="createInfo"> /// The structure containing parameters affecting creation of the buffer. /// </param> /// <param name="allocator">Controls host memory allocation.</param> /// <returns>Buffer object.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public Buffer CreateBuffer(BufferCreateInfo createInfo, AllocationCallbacks?allocator = null) { return(new Buffer(this, ref createInfo, ref allocator)); }