Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

111 строки
4.3 KiB

  1. unit uvkuCommandBuffer;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuBase, uvkuTypes;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuCommandBuffer = class(TvkuHandle)
  10. private
  11. fHandle: VkCommandBuffer;
  12. fCommandPool: VkCommandPool;
  13. fDeviceCommands: TVkDeviceCommands;
  14. public
  15. property Handle: VkCommandBuffer read fHandle;
  16. property CommandPool: VkCommandPool read fCommandPool;
  17. property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
  18. procedure BeginCommand;
  19. procedure EndCommand;
  20. procedure PipelineBarrier(
  21. const aSrcStageMask: VkPipelineStageFlags;
  22. const aDstStageMask: VkPipelineStageFlags;
  23. const aDependencyFlags: VkDependencyFlags;
  24. const aMemoryBarriers: array of TVkMemoryBarrier;
  25. const aBufferMemoryBarriers: array of TVkBufferMemoryBarrier;
  26. const aImageMemoryBarriers: array of TVkImageMemoryBarrier);
  27. constructor Create(
  28. const aHandle: VkCommandBuffer;
  29. const aOwnsHandle: Boolean;
  30. const aCommandPool: VkCommandPool;
  31. const aDeviceCommands: TVkDeviceCommands);
  32. destructor Destroy; override;
  33. end;
  34. implementation
  35. uses
  36. uvkuUtils;
  37. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. //TvkuCommandBuffer//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  39. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  40. procedure TvkuCommandBuffer.BeginCommand;
  41. var
  42. Info: TVkCommandBufferBeginInfo;
  43. err: TVkResult;
  44. begin
  45. FillByte(Info, SizeOf(Info), 0);
  46. Info.sType := VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
  47. Info.pNext := nil;
  48. Info.flags := []; // TODO
  49. Info.pInheritanceInfo := nil; // TODO
  50. err := DeviceCommands.vkBeginCommandBuffer(fHandle, @Info);
  51. if (err < VK_SUCCESS) then
  52. raise TvkuErrorException.Create('unable to begin command buffer', err);
  53. end;
  54. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. procedure TvkuCommandBuffer.EndCommand;
  56. var err: TVkResult;
  57. begin
  58. err := fDeviceCommands.vkEndCommandBuffer(fHandle);
  59. if (err < VK_SUCCESS) then
  60. raise TvkuErrorException.Create('unable to end command buffer', err);
  61. end;
  62. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  63. procedure TvkuCommandBuffer.PipelineBarrier(const aSrcStageMask: VkPipelineStageFlags;
  64. const aDstStageMask: VkPipelineStageFlags; const aDependencyFlags: VkDependencyFlags;
  65. const aMemoryBarriers: array of TVkMemoryBarrier; const aBufferMemoryBarriers: array of TVkBufferMemoryBarrier;
  66. const aImageMemoryBarriers: array of TVkImageMemoryBarrier);
  67. begin
  68. DeviceCommands.vkCmdPipelineBarrier(
  69. fHandle,
  70. aSrcStageMask,
  71. aDstStageMask,
  72. aDependencyFlags,
  73. Length(aMemoryBarriers), @aMemoryBarriers[0],
  74. Length(aBufferMemoryBarriers), @aBufferMemoryBarriers[0],
  75. Length(aImageMemoryBarriers), @aImageMemoryBarriers[0]);
  76. end;
  77. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. constructor TvkuCommandBuffer.Create(const aHandle: VkCommandBuffer; const aOwnsHandle: Boolean;
  79. const aCommandPool: VkCommandPool; const aDeviceCommands: TVkDeviceCommands);
  80. begin
  81. inherited Create;
  82. fHandle := aHandle;
  83. fCommandPool := aCommandPool;
  84. fDeviceCommands := aDeviceCommands;
  85. OwnsHandle := aOwnsHandle;
  86. end;
  87. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  88. destructor TvkuCommandBuffer.Destroy;
  89. begin
  90. if OwnsHandle and (fHandle <> VK_INVALID_HANDLE) then
  91. fDeviceCommands.vkFreeCommandBuffers(fDeviceCommands.Device, fCommandPool, 1, @fHandle);
  92. fHandle := VK_INVALID_HANDLE;
  93. inherited Destroy;
  94. end;
  95. end.