Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

129 wiersze
5.3 KiB

  1. unit uvkuCommandPool;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuBase, uvkuTypes;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuCommandPool = class(TvkuAllocHandle)
  10. private
  11. fHandle: VkCommandPool;
  12. fDeviceCommands: TVkDeviceCommands;
  13. procedure CreateHandle(const aCreateInfo: TVkCommandPoolCreateInfo);
  14. public
  15. property Handle: VkCommandPool read fHandle;
  16. property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
  17. function CreateCommandBuffer(
  18. const aLevel: TVkCommandBufferLevel): VkCommandBuffer;
  19. function CreateCommandBuffers(
  20. const aLevel: TVkCommandBufferLevel;
  21. const aCount: Integer): TvkuCommandBufferArr;
  22. procedure FreeCommandBuffer(
  23. const aBuffer: VkCommandBuffer);
  24. procedure FreeCommandBuffers(
  25. const aBuffers: TvkuCommandBufferArr);
  26. constructor Create(
  27. const aCreateInfo: TVkCommandPoolCreateInfo;
  28. const aDeviceCommands: TVkDeviceCommands;
  29. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  30. constructor Create(
  31. const aHandle: VkCommandPool;
  32. const aOwnsHandle: Boolean;
  33. const aDeviceCommands: TVkDeviceCommands;
  34. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  35. destructor Destroy; override;
  36. end;
  37. implementation
  38. uses
  39. uvkuUtils;
  40. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. //TvkuCommandPool////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43. procedure TvkuCommandPool.CreateHandle(const aCreateInfo: TVkCommandPoolCreateInfo);
  44. var err: TVkResult;
  45. begin
  46. err := fDeviceCommands.vkCreateCommandPool(fDeviceCommands.Device, @aCreateInfo, AllocCallbacks, @fHandle);
  47. if (err < VK_SUCCESS) then
  48. raise TvkuErrorException.Create('unable to create command pool', err);
  49. end;
  50. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. function TvkuCommandPool.CreateCommandBuffer(const aLevel: TVkCommandBufferLevel): VkCommandBuffer;
  52. begin
  53. result := CreateCommandBuffers(aLevel, 1)[0];
  54. end;
  55. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56. function TvkuCommandPool.CreateCommandBuffers(const aLevel: TVkCommandBufferLevel; const aCount: Integer): TvkuCommandBufferArr;
  57. var
  58. AllocInfo: TVkCommandBufferAllocateInfo;
  59. err: TVkResult;
  60. begin
  61. FillByte(AllocInfo, SizeOf(AllocInfo), 0);
  62. AllocInfo.sType := VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
  63. AllocInfo.pNext := nil;
  64. AllocInfo.commandPool := fHandle;
  65. AllocInfo.level := aLevel;
  66. AllocInfo.commandBufferCount := aCount;
  67. SetLength(result, aCount);
  68. err := fDeviceCommands.vkAllocateCommandBuffers(fDeviceCommands.Device, @AllocInfo, @result[0]);
  69. if (err < VK_SUCCESS) then
  70. raise TvkuErrorException.Create('unable to create command buffers', err);
  71. end;
  72. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  73. procedure TvkuCommandPool.FreeCommandBuffer(const aBuffer: VkCommandBuffer);
  74. begin
  75. FreeCommandBuffers(TvkuCommandBufferArr.Create(aBuffer));
  76. end;
  77. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. procedure TvkuCommandPool.FreeCommandBuffers(const aBuffers: TvkuCommandBufferArr);
  79. begin
  80. fDeviceCommands.vkFreeCommandBuffers(fDeviceCommands.Device, fHandle, Length(aBuffers), @aBuffers[0]);
  81. end;
  82. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  83. constructor TvkuCommandPool.Create(const aCreateInfo: TVkCommandPoolCreateInfo;
  84. const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
  85. begin
  86. inherited Create;
  87. fDeviceCommands := aDeviceCommands;
  88. SetAllocCallbacks(aAllocCallbacks);
  89. CreateHandle(aCreateInfo);
  90. end;
  91. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92. constructor TvkuCommandPool.Create(const aHandle: VkCommandPool; const aOwnsHandle: Boolean;
  93. const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
  94. begin
  95. inherited Create;
  96. fHandle := aHandle;
  97. fDeviceCommands := aDeviceCommands;
  98. OwnsHandle := aOwnsHandle;
  99. SetAllocCallbacks(aAllocCallbacks);
  100. end;
  101. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. destructor TvkuCommandPool.Destroy;
  103. begin
  104. if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
  105. fDeviceCommands.vkDestroyCommandPool(fDeviceCommands.Device, fHandle, AllocCallbacks);
  106. fHandle := VK_INVALID_NDP_HANDLE;
  107. inherited Destroy;
  108. end;
  109. end.