public unsafe void Begin(ref VkCommandBufferBeginInfo CommandBufferBeginInfo) { VkCommandBufferBeginInfo_Native commandBufferBeginInfo_Native = new VkCommandBufferBeginInfo_Native(); commandBufferBeginInfo_Native.sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; commandBufferBeginInfo_Native.pNext = new IntPtr(0); commandBufferBeginInfo_Native.flags = CommandBufferBeginInfo.flags; if (CommandBufferBeginInfo.inheritanceInfo != null) { } else { commandBufferBeginInfo_Native.pInheritanceInfo = new IntPtr(0); } VkResult result = _Parent.Device.vkBeginCommandBuffer(_Handle, new IntPtr(&commandBufferBeginInfo_Native)); if (CommandBufferBeginInfo.inheritanceInfo != null) { } if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } }
public unsafe VkCommandBuffer[] AllocateCommandBuffers(ref VkCommandBufferAllocateInfo commandBufferAllocateInfo) { IntPtr[] commandBufferHandles = new IntPtr[commandBufferAllocateInfo.commandBufferCount]; VkCommandBuffer[] commandBuffers = new VkCommandBuffer[commandBufferAllocateInfo.commandBufferCount]; VkCommandBufferAllocateInfo_Native commandBufferAllocateInfo_Native = new VkCommandBufferAllocateInfo_Native(); commandBufferAllocateInfo_Native.pNext = new IntPtr(0); commandBufferAllocateInfo_Native.sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; commandBufferAllocateInfo_Native.commandPoolHandle = _Handle; commandBufferAllocateInfo_Native.level = commandBufferAllocateInfo.level; commandBufferAllocateInfo_Native.commandBufferCount = commandBufferAllocateInfo.commandBufferCount; VkResult result = VkResult.VK_SUCCESS; fixed(IntPtr *pCommandBufferHandles = &commandBufferHandles[0]) { result = _Parent.vkAllocateCommandBuffers(_Parent._Handle, new IntPtr(&commandBufferAllocateInfo_Native), new IntPtr(pCommandBufferHandles)); } if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } for (int n = 0; n < commandBuffers.Length; n++) { commandBuffers[n] = new VkCommandBuffer(commandBufferHandles[n], this); } return(commandBuffers); }
public static void CheckErrors(VkResult result) { if (result != VkResult.VK_SUCCESS) { throw new InvalidOperationException(result.ToString()); } }
public static void CheckResult(VkResult result, string errorString = "Call failed") { if (result != VkResult.Success) { throw new InvalidOperationException(errorString + ": " + result.ToString()); } }
public void End() { VkResult result = _Parent.Device.vkEndCommandBuffer(_Handle); if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } }
public void BindMemory(VkDeviceMemory memory, UInt64 offset) { VkResult result = _Parent.vkBindImageMemory(_Parent._Handle, _Handle, memory._Handle, offset); if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } }
public unsafe void WaitIdle() { VkResult result = _Parent.vkQueueWaitIdle(_Handle); if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } }
public unsafe VkDevice CreateDevice(ref VkDeviceCreateInfo deviceCreateInfo) { if (vkCreateDevice != null) { VkDeviceCreateInfo_Native deviceQueueCreateInfo_native = new VkDeviceCreateInfo_Native(); deviceQueueCreateInfo_native.pNext = new IntPtr(0); deviceQueueCreateInfo_native.sType = VkStructureType.VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; deviceQueueCreateInfo_native.flags = 0; deviceQueueCreateInfo_native.pEnabledFeatures = new IntPtr(0); // For now it will stay unset deviceQueueCreateInfo_native.queueCreateInfoCount = deviceCreateInfo.queueCreateInfos == null ? 0 : (uint)deviceCreateInfo.queueCreateInfos.Length; deviceQueueCreateInfo_native.pQueueCreateInfos = System.Runtime.InteropServices.Marshal.AllocHGlobal(new IntPtr(sizeof(VkDeviceQueueCreateInfo_Native) * deviceQueueCreateInfo_native.queueCreateInfoCount)); if (deviceQueueCreateInfo_native.pQueueCreateInfos == null) { throw new OutOfMemoryException(); } VkDeviceQueueCreateInfo_Native *pQueueCreateInfos = (VkDeviceQueueCreateInfo_Native *)deviceQueueCreateInfo_native.pQueueCreateInfos.ToPointer(); for (int n = 0; n < deviceQueueCreateInfo_native.queueCreateInfoCount; n++) { pQueueCreateInfos[n].flags = 0; pQueueCreateInfos[n].pNext = new IntPtr(0); pQueueCreateInfos[n].sType = VkStructureType.VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; pQueueCreateInfos[n].queueCount = deviceCreateInfo.queueCreateInfos[n].queueCount; if (deviceCreateInfo.queueCreateInfos[n].queueFamily.physicalDevice != this) { throw new Exception("The queue family specified doesn't belong to this physical device"); } pQueueCreateInfos[n].queueFamilyIndex = deviceCreateInfo.queueCreateInfos[n].queueFamily.index; pQueueCreateInfos[n].pQueuePriorities = (float *)System.Runtime.InteropServices.Marshal.AllocHGlobal(new IntPtr(sizeof(float) * deviceCreateInfo.queueCreateInfos[n].queuePriorities.Length)).ToPointer(); for (int x = 0; x < deviceCreateInfo.queueCreateInfos[n].queuePriorities.Length; x++) { pQueueCreateInfos[n].pQueuePriorities[x] = deviceCreateInfo.queueCreateInfos[n].queuePriorities[x]; } } VkAllocationCallbacks allocator = Allocator.getAllocatorCallbacks(); IntPtr deviceHandle = new IntPtr(); VkResult result = vkCreateDevice(_Handle, ref deviceQueueCreateInfo_native, ref allocator, ref deviceHandle); for (int n = 0; n < deviceQueueCreateInfo_native.queueCreateInfoCount; n++) { System.Runtime.InteropServices.Marshal.FreeHGlobal(new IntPtr(pQueueCreateInfos[n].pQueuePriorities)); } System.Runtime.InteropServices.Marshal.FreeHGlobal(deviceQueueCreateInfo_native.pQueueCreateInfos); if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } return(new VkDevice(this, deviceHandle, deviceCreateInfo.queueCreateInfos)); } else { throw new Exception("The method vkCreateDevice can't be accessed"); } }
public bool AcquireNextImage(VkSemaphore presentCompleteSemaphore, out int imageIndex) { VkResult res = Device.AcquireNextImageKHR(swapchain, ulong.MaxValue, presentCompleteSemaphore, new VkFence(), out uint nextImageIndex); if (res == VkResult.ErrorOutOfDateKHR) { Log.Error(res.ToString()); //uint w = 0, h = 0; //Create(ref w, ref h, false); } else if (res == VkResult.SuboptimalKHR) { Log.Info(res.ToString()); } else if (res != VkResult.Success) { Log.Info(res.ToString()); imageIndex = 0; return(false); } imageIndex = (int)nextImageIndex; return(true); }
public unsafe bool WaitForFence(UInt64 timeout) { fixed(UInt64 *pHandle = &_Handle) { VkResult result = _Parent.vkWaitForFences(_Parent._Handle, 1, new IntPtr(pHandle), true, timeout); if (result == VkResult.VK_SUCCESS) { return(true); } else if (result == VkResult.VK_TIMEOUT) { return(false); } throw new Exception(result.ToString()); } }
public void BindMemory(VkDeviceMemory memory, UInt64 offset) { bool validMemory = false; for (int n = 0; n < MemoryRequirements.memoryTypes.Length; n++) { if (MemoryRequirements.memoryTypes[n].index == memory.MemoryType.index) { validMemory = true; break; } } if (!validMemory) { throw new Exception("The memory block provided for the binding doesn't match the memory requirement"); } VkResult result = _Parent.vkBindBufferMemory(_Parent._Handle, _Handle, memory._Handle, offset); if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } }
public unsafe void Submit(VkSubmitInfo[] submitInfo, VkFence Fence) { if (submitInfo == null || submitInfo.Length == 0) { return; } for (int n = 0; n < submitInfo.Length; n++) { int waitSemaphoreCount = submitInfo[n].waitSemaphores == null ? 0 : submitInfo[n].waitSemaphores.Length; int waitDstStageMaskCount = submitInfo[n].waitDstStageMask == null ? 0 : submitInfo[n].waitDstStageMask.Length; if (waitSemaphoreCount != waitDstStageMaskCount) { throw new Exception("There must be the same number of semaphore in waitSemaphores than the number of PipelineStageFlag in waitDstStageMask"); } } VkSubmitInfo_Native[] submitInfo_Native = new VkSubmitInfo_Native[submitInfo.Length]; for (int n = 0; n < submitInfo.Length; n++) { submitInfo_Native[n].pNext = new IntPtr(0); submitInfo_Native[n].sType = VkStructureType.VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo_Native[n].commandBufferCount = submitInfo[n].commandBuffers == null ? (uint)0 : (uint)submitInfo[n].commandBuffers.Length; submitInfo_Native[n].signalSemaphoreCount = submitInfo[n].signalSemaphores == null ? (uint)0 : (uint)submitInfo[n].signalSemaphores.Length; submitInfo_Native[n].waitSemaphoreCount = submitInfo[n].waitSemaphores == null ? (uint)0 : (uint)submitInfo[n].waitSemaphores.Length; submitInfo_Native[n].pCommandBuffers = System.Runtime.InteropServices.Marshal.AllocHGlobal(new IntPtr(submitInfo_Native[n].commandBufferCount * sizeof(void *))); // Ok this is extremely bad for perf. Especially because it will be called often. // Ultimatly we need speciallized method to do that quickly for (int x = 0; x < submitInfo_Native[n].commandBufferCount; x++) { ((IntPtr *)submitInfo_Native[n].pCommandBuffers)[x] = submitInfo[n].commandBuffers[x]._Handle; } submitInfo_Native[n].pWaitSemaphores = System.Runtime.InteropServices.Marshal.AllocHGlobal(new IntPtr(submitInfo_Native[n].waitSemaphoreCount * sizeof(UInt64))); submitInfo_Native[n].pWaitDstStageMask = System.Runtime.InteropServices.Marshal.AllocHGlobal(new IntPtr(submitInfo_Native[n].waitSemaphoreCount * sizeof(VkPipelineStageFlag))); for (int x = 0; x < submitInfo_Native[n].waitSemaphoreCount; x++) { ((UInt64 *)submitInfo_Native[n].pWaitSemaphores)[x] = submitInfo[n].waitSemaphores[x]._Handle; ((VkPipelineStageFlag *)submitInfo_Native[n].pWaitDstStageMask)[x] = submitInfo[n].waitDstStageMask[x]; } submitInfo_Native[n].pSignalSemaphores = System.Runtime.InteropServices.Marshal.AllocHGlobal(new IntPtr(submitInfo_Native[n].signalSemaphoreCount * sizeof(UInt64))); for (int x = 0; x < submitInfo_Native[n].signalSemaphoreCount; x++) { ((UInt64 *)submitInfo_Native[n].pSignalSemaphores)[x] = submitInfo[n].signalSemaphores[x]._Handle; } } VkResult result = VkResult.VK_SUCCESS; fixed(VkSubmitInfo_Native *pSubmitInfo = &submitInfo_Native[0]) { result = _Parent.vkQueueSubmit(_Handle, (uint)submitInfo_Native.Length, new IntPtr(pSubmitInfo), Fence._Handle); } for (int n = 0; n < submitInfo.Length; n++) { System.Runtime.InteropServices.Marshal.FreeHGlobal(submitInfo_Native[n].pWaitDstStageMask); System.Runtime.InteropServices.Marshal.FreeHGlobal(submitInfo_Native[n].pWaitSemaphores); System.Runtime.InteropServices.Marshal.FreeHGlobal(submitInfo_Native[n].pCommandBuffers); System.Runtime.InteropServices.Marshal.FreeHGlobal(submitInfo_Native[n].pSignalSemaphores); } if (result != VkResult.VK_SUCCESS) { throw new Exception(result.ToString()); } }
public VkNotSuccessException(VkResult result) : base(result.ToString()) { }