/// <summary> /// Bind device memory to a buffer object. /// </summary> public void BindMemory(DeviceMemory memory, DeviceSize memoryOffset) { unsafe { try { Result commandResult; Interop.DeviceMemory marshalledMemory = default(Interop.DeviceMemory); memory?.MarshalTo(&marshalledMemory); commandResult = Interop.Commands.vkBindBufferMemory(this.parent.handle, this.handle, marshalledMemory, memoryOffset); if (SharpVkException.IsError(commandResult)) { throw SharpVkException.Create(commandResult); } } finally { Interop.HeapUtil.FreeLog(); } } }
private void CreateBuffer(ulong size, BufferUsageFlags usage, MemoryPropertyFlags properties, out Buffer buffer, out DeviceMemory bufferMemory) { buffer = device.CreateBuffer(new BufferCreateInfo { Size = size, Usage = usage, SharingMode = SharingMode.Exclusive }); var memRequirements = buffer.GetMemoryRequirements(); bufferMemory = device.AllocateMemory(new MemoryAllocateInfo { AllocationSize = memRequirements.Size, MemoryTypeIndex = FindMemoryType(memRequirements.MemoryTypeBits, properties) }); buffer.BindMemory(bufferMemory, 0); }
private void TearDown() { device.WaitIdle(); this.renderFinishedSemaphore.Dispose(); this.renderFinishedSemaphore = null; this.imageAvailableSemaphore.Dispose(); this.imageAvailableSemaphore = null; this.descriptorPool.Dispose(); this.descriptorPool = null; this.descriptorSet = null; this.device.FreeMemory(this.uniformBufferMemory); this.uniformBufferMemory = null; this.uniformBuffer.Dispose(); this.uniformBuffer = null; this.device.FreeMemory(this.uniformStagingBufferMemory); this.uniformStagingBufferMemory = null; this.uniformStagingBuffer.Dispose(); this.uniformStagingBuffer = null; this.device.FreeMemory(this.indexBufferMemory); this.indexBufferMemory = null; this.indexBuffer.Dispose(); this.indexBuffer = null; this.device.FreeMemory(this.vertexBufferMemory); this.vertexBufferMemory = null; this.vertexBuffer.Dispose(); this.vertexBuffer = null; this.commandPool.Dispose(); this.commandPool = null; this.commandBuffers = null; this.transientCommandPool.Dispose(); this.transientCommandPool = null; foreach (var frameBuffer in this.frameBuffers) { frameBuffer.Dispose(); } this.frameBuffers = null; this.pipeline.Dispose(); this.pipeline = null; this.pipelineLayout.Dispose(); this.pipelineLayout = null; foreach (var imageView in this.swapChainImageViews) { imageView.Dispose(); } this.swapChainImageViews = null; this.descriptorSetLayout.Dispose(); this.descriptorSetLayout = null; this.renderPass.Dispose(); this.renderPass = null; this.swapChain.Dispose(); this.swapChain = null; this.device.Dispose(); this.device = null; this.surface.Dispose(); this.surface = null; this.debugCallback.Dispose(); this.debugCallback = null; this.instance.Dispose(); this.instance = null; }