25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

128 satır
6.0 KiB

  1. unit uvkuPipeline;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuBase;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuPipeline = class(TvkuAllocHandle)
  10. private
  11. fHandle: VkPipeline;
  12. fDeviceCommands: TVkDeviceCommands;
  13. public
  14. property Handle: VkPipeline read fHandle;
  15. property DeviceCommands: TVkDeviceCommands read fDeviceCommands;
  16. constructor Create(
  17. const aHandle: VkPipeline;
  18. const aOwnsHandle: Boolean;
  19. const aDeviceCommands: TVkDeviceCommands;
  20. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  21. destructor Destroy; override;
  22. end;
  23. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  24. TvkuGraphicsPipeline = class(TvkuPipeline)
  25. private
  26. procedure CreateHandle(const aCreateInfo: TVkGraphicsPipelineCreateInfo; const aPipelineCache: VkPipelineCache);
  27. public
  28. constructor Create(
  29. const aCreateInfo: TVkGraphicsPipelineCreateInfo;
  30. const aPipelineCache: VkPipelineCache;
  31. const aDeviceCommands: TVkDeviceCommands;
  32. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  33. end;
  34. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. TvkuComputePipeline = class(TvkuPipeline)
  36. private
  37. procedure CreateHandle(const aCreateInfo: TVkComputePipelineCreateInfo; const aPipelineCache: VkPipelineCache);
  38. public
  39. constructor Create(
  40. const aCreateInfo: TVkComputePipelineCreateInfo;
  41. const aPipelineCache: VkPipelineCache;
  42. const aDeviceCommands: TVkDeviceCommands;
  43. const aAllocCallbacks: PVkAllocationCallbacks = nil);
  44. end;
  45. implementation
  46. uses
  47. uvkuUtils;
  48. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. //TvkuPipeline///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. constructor TvkuPipeline.Create(const aHandle: VkPipeline; const aOwnsHandle: Boolean;
  52. const aDeviceCommands: TVkDeviceCommands; const aAllocCallbacks: PVkAllocationCallbacks);
  53. begin
  54. inherited Create;
  55. fHandle := aHandle;
  56. fDeviceCommands := aDeviceCommands;
  57. OwnsHandle := aOwnsHandle;
  58. SetAllocCallbacks(aAllocCallbacks);
  59. end;
  60. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61. destructor TvkuPipeline.Destroy;
  62. begin
  63. if OwnsHandle and (fHandle <> VK_INVALID_NDP_HANDLE) then
  64. fDeviceCommands.vkDestroyPipeline(fDeviceCommands.Device, fHandle, AllocCallbacks);
  65. fHandle := VK_INVALID_NDP_HANDLE;
  66. inherited Destroy;
  67. end;
  68. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  69. //TvkuGraphicsPipeline///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  71. procedure TvkuGraphicsPipeline.CreateHandle(const aCreateInfo: TVkGraphicsPipelineCreateInfo;
  72. const aPipelineCache: VkPipelineCache);
  73. var err: TVkResult;
  74. begin
  75. if not Assigned(fDeviceCommands.vkCreateGraphicsPipelines) then
  76. raise TvkuInvalidFuncPtrException.Create('vkCreateGraphicsPipelines');
  77. err := fDeviceCommands.vkCreateGraphicsPipelines(fDeviceCommands.Device, aPipelineCache, 1, @aCreateInfo, AllocCallbacks, @fHandle);
  78. if (err <> VK_SUCCESS) then
  79. raise TvkuErrorException.Create('unable to create graphics pipeline', err);
  80. end;
  81. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  82. constructor TvkuGraphicsPipeline.Create(const aCreateInfo: TVkGraphicsPipelineCreateInfo;
  83. const aPipelineCache: VkPipelineCache; const aDeviceCommands: TVkDeviceCommands;
  84. const aAllocCallbacks: PVkAllocationCallbacks);
  85. begin
  86. inherited Create(VK_INVALID_NDP_HANDLE, true, aDeviceCommands, aAllocCallbacks);
  87. CreateHandle(aCreateInfo, aPipelineCache);
  88. end;
  89. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  90. //TvkuComputePipeline////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  91. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92. procedure TvkuComputePipeline.CreateHandle(const aCreateInfo: TVkComputePipelineCreateInfo;
  93. const aPipelineCache: VkPipelineCache);
  94. var err: TVkResult;
  95. begin
  96. if not Assigned(fDeviceCommands.vkCreateComputePipelines) then
  97. raise TvkuInvalidFuncPtrException.Create('vkCreateComputePipelines');
  98. err := fDeviceCommands.vkCreateComputePipelines(fDeviceCommands.Device, aPipelineCache, 1, @aCreateInfo, AllocCallbacks, @fHandle);
  99. if (err <> VK_SUCCESS) then
  100. raise TvkuErrorException.Create('unable to create compute pipeline', err);
  101. end;
  102. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  103. constructor TvkuComputePipeline.Create(const aCreateInfo: TVkComputePipelineCreateInfo;
  104. const aPipelineCache: VkPipelineCache; const aDeviceCommands: TVkDeviceCommands;
  105. const aAllocCallbacks: PVkAllocationCallbacks);
  106. begin
  107. inherited Create(VK_INVALID_NDP_HANDLE, true, aDeviceCommands, aAllocCallbacks);
  108. CreateHandle(aCreateInfo, aPipelineCache);
  109. end;
  110. end.