|
- unit uvkuQueue;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils,
- Vulkan, uvkuBase, uvkuTypes;
-
- type
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- TvkuQueue = class(TvkuObject)
- private
- fHandle: VkQueue;
- fDeviceCommands: TVkDeviceCommands;
- public
- property Handle: VkQueue read fHandle;
- property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
-
- procedure Submit(
- const aWaitSemaphores: array of VkSemaphore;
- const aWaitDstStageMask: array of VkSemaphore;
- const aCommandBuffers: array of VkCommandBuffer;
- const aSignalSemaphores: array of VkSemaphore;
- const aFence: VkFence);
- function Present(
- const aWaitSemaphore: array of VkSemaphore;
- const aSwapChains: array of VkSwapchainKHR;
- const aImageIndices: array of VkUint32): TVkResultArr;
- procedure WaitIdle;
-
- constructor Create(
- const aHandle: VkQueue;
- const aDeviceCommands: TVkDeviceCommands);
- end;
-
- implementation
-
- uses
- uvkuUtils;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //TvkuQueue//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuQueue.Submit(
- const aWaitSemaphores: array of VkSemaphore;
- const aWaitDstStageMask: array of VkSemaphore;
- const aCommandBuffers: array of VkCommandBuffer;
- const aSignalSemaphores: array of VkSemaphore;
- const aFence: VkFence);
- var
- SubmitInfo: TVkSubmitInfo;
- err: TVkResult;
- begin
- if (Length(aWaitSemaphores) <> Length(aWaitDstStageMask))
- and (Length(aWaitDstStageMask) <> 0) then
- raise TvkuException.Create('aWaitDstStageMask must have the same number of elements as aWaitSemaphores or must be empty');
-
- FillByte(SubmitInfo, SizeOf(SubmitInfo), 0);
- SubmitInfo.sType := VK_STRUCTURE_TYPE_SUBMIT_INFO;
- SubmitInfo.pNext := nil;
- SubmitInfo.waitSemaphoreCount := Length(aWaitSemaphores);
- SubmitInfo.pWaitSemaphores := @aWaitSemaphores[0];
- SubmitInfo.pWaitDstStageMask := @aWaitDstStageMask[0];
- SubmitInfo.commandBufferCount := Length(aCommandBuffers);
- SubmitInfo.pCommandBuffers := @aCommandBuffers[0];
- SubmitInfo.signalSemaphoreCount := Length(aSignalSemaphores);
- SubmitInfo.pSignalSemaphores := @aSignalSemaphores[0];
- err := fDeviceCommands.vkQueueSubmit(fHandle, 1, @SubmitInfo, aFence);
- if (err <> VK_SUCCESS) then
- raise TvkuErrorException.Create('unable to submit queue', err);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function TvkuQueue.Present(
- const aWaitSemaphore: array of VkSemaphore;
- const aSwapChains: array of VkSwapchainKHR;
- const aImageIndices: array of VkUint32): TVkResultArr;
- var
- info: TVkPresentInfoKHR;
- err: TVkResult;
- begin
- if (Length(aSwapChains) <> Length(aImageIndices)) then
- raise TvkuException.Create('aSwapChains and aImageIndices must have the same number of elements');
-
- SetLength(result, Length(aSwapChains));
- FillByte(info, SizeOf(info), 0);
- info.sType := VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
- info.pNext := nil;
- info.waitSemaphoreCount := Length(aWaitSemaphore);
- info.pWaitSemaphores := @aWaitSemaphore[0];
- info.swapchainCount := Length(aSwapChains);
- info.pSwapchains := @aSwapChains[0];
- info.pImageIndices := @aImageIndices[0];
- info.pResults := @result[0];
- err := fDeviceCommands.vkQueuePresentKHR(fHandle, @info);
- if (err <> VK_SUCCESS) then
- raise TvkuErrorException.Create('unable to present queue', err);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- procedure TvkuQueue.WaitIdle;
- var err: TVkResult;
- begin
- err := fDeviceCommands.vkQueueWaitIdle(fHandle);
- if (err <> VK_SUCCESS) then
- raise TvkuErrorException.Create('error while waiting for queue', err);
- end;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- constructor TvkuQueue.Create(const aHandle: VkQueue; const aDeviceCommands: TVkDeviceCommands);
- begin
- inherited Create;
- fHandle := aHandle;
- fDeviceCommands := aDeviceCommands;
- end;
-
- end.
|