Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

121 Zeilen
4.7 KiB

  1. unit uvkuQueue;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuBase, uvkuTypes;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuQueue = class(TvkuObject)
  10. private
  11. fHandle: VkQueue;
  12. fDeviceCommands: TVkDeviceCommands;
  13. public
  14. property Handle: VkQueue read fHandle;
  15. property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
  16. procedure Submit(
  17. const aWaitSemaphores: array of VkSemaphore;
  18. const aWaitDstStageMask: array of VkSemaphore;
  19. const aCommandBuffers: array of VkCommandBuffer;
  20. const aSignalSemaphores: array of VkSemaphore;
  21. const aFence: VkFence);
  22. function Present(
  23. const aWaitSemaphore: array of VkSemaphore;
  24. const aSwapChains: array of VkSwapchainKHR;
  25. const aImageIndices: array of VkUint32): TVkResultArr;
  26. procedure WaitIdle;
  27. constructor Create(
  28. const aHandle: VkQueue;
  29. const aDeviceCommands: TVkDeviceCommands);
  30. end;
  31. implementation
  32. uses
  33. uvkuUtils;
  34. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. //TvkuQueue//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. procedure TvkuQueue.Submit(
  38. const aWaitSemaphores: array of VkSemaphore;
  39. const aWaitDstStageMask: array of VkSemaphore;
  40. const aCommandBuffers: array of VkCommandBuffer;
  41. const aSignalSemaphores: array of VkSemaphore;
  42. const aFence: VkFence);
  43. var
  44. SubmitInfo: TVkSubmitInfo;
  45. err: TVkResult;
  46. begin
  47. if (Length(aWaitSemaphores) <> Length(aWaitDstStageMask))
  48. and (Length(aWaitDstStageMask) <> 0) then
  49. raise TvkuException.Create('aWaitDstStageMask must have the same number of elements as aWaitSemaphores or must be empty');
  50. FillByte(SubmitInfo, SizeOf(SubmitInfo), 0);
  51. SubmitInfo.sType := VK_STRUCTURE_TYPE_SUBMIT_INFO;
  52. SubmitInfo.pNext := nil;
  53. SubmitInfo.waitSemaphoreCount := Length(aWaitSemaphores);
  54. SubmitInfo.pWaitSemaphores := @aWaitSemaphores[0];
  55. SubmitInfo.pWaitDstStageMask := @aWaitDstStageMask[0];
  56. SubmitInfo.commandBufferCount := Length(aCommandBuffers);
  57. SubmitInfo.pCommandBuffers := @aCommandBuffers[0];
  58. SubmitInfo.signalSemaphoreCount := Length(aSignalSemaphores);
  59. SubmitInfo.pSignalSemaphores := @aSignalSemaphores[0];
  60. err := fDeviceCommands.vkQueueSubmit(fHandle, 1, @SubmitInfo, aFence);
  61. if (err <> VK_SUCCESS) then
  62. raise TvkuErrorException.Create('unable to submit queue', err);
  63. end;
  64. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. function TvkuQueue.Present(
  66. const aWaitSemaphore: array of VkSemaphore;
  67. const aSwapChains: array of VkSwapchainKHR;
  68. const aImageIndices: array of VkUint32): TVkResultArr;
  69. var
  70. info: TVkPresentInfoKHR;
  71. err: TVkResult;
  72. begin
  73. if (Length(aSwapChains) <> Length(aImageIndices)) then
  74. raise TvkuException.Create('aSwapChains and aImageIndices must have the same number of elements');
  75. SetLength(result, Length(aSwapChains));
  76. FillByte(info, SizeOf(info), 0);
  77. info.sType := VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
  78. info.pNext := nil;
  79. info.waitSemaphoreCount := Length(aWaitSemaphore);
  80. info.pWaitSemaphores := @aWaitSemaphore[0];
  81. info.swapchainCount := Length(aSwapChains);
  82. info.pSwapchains := @aSwapChains[0];
  83. info.pImageIndices := @aImageIndices[0];
  84. info.pResults := @result[0];
  85. err := fDeviceCommands.vkQueuePresentKHR(fHandle, @info);
  86. if (err <> VK_SUCCESS) then
  87. raise TvkuErrorException.Create('unable to present queue', err);
  88. end;
  89. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  90. procedure TvkuQueue.WaitIdle;
  91. var err: TVkResult;
  92. begin
  93. err := fDeviceCommands.vkQueueWaitIdle(fHandle);
  94. if (err <> VK_SUCCESS) then
  95. raise TvkuErrorException.Create('error while waiting for queue', err);
  96. end;
  97. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  98. constructor TvkuQueue.Create(const aHandle: VkQueue; const aDeviceCommands: TVkDeviceCommands);
  99. begin
  100. inherited Create;
  101. fHandle := aHandle;
  102. fDeviceCommands := aDeviceCommands;
  103. end;
  104. end.