Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

144 рядки
6.5 KiB

  1. unit uvkuImageFactory;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuImage, uvkuDevice, uvkuAllocationHandler, uvkuTypes, uvkuFactoryBase;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuImageEx = class(TvkuImage)
  10. private
  11. fAllocHandler: TvkuAllocationHandler;
  12. fOwnsHandle: Boolean;
  13. public
  14. destructor Destroy; override;
  15. end;
  16. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. TvkuImageFactory = class(TvkuDeviceObjFactory)
  18. private
  19. fFlags: VkImageCreateFlags;
  20. fImageType: TVkImageType;
  21. fFormat: TVkFormat;
  22. fExtent: TVkExtent3D;
  23. fMipLevels: VkUint32;
  24. fArrayLayers: VkUint32;
  25. fSamples: TVkSampleCountFlagBits;
  26. fTiling: TVkImageTiling;
  27. fUsage: VkImageUsageFlags;
  28. fSharingMode: TVkSharingMode;
  29. fQueueFamilyIndices: TvkuUint32Arr;
  30. fInitialLayout: TVkImageLayout;
  31. function GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
  32. function GetQueueFamilyIndexCount: Integer;
  33. procedure SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
  34. public
  35. property Flags: VkImageCreateFlags read fFlags write fFlags;
  36. property ImageType: TVkImageType read fImageType write fImageType;
  37. property Format: TVkFormat read fFormat write fFormat;
  38. property Extent: TVkExtent3D read fExtent write fExtent;
  39. property MipLevels: VkUint32 read fMipLevels write fMipLevels;
  40. property ArrayLayers: VkUint32 read fArrayLayers write fArrayLayers;
  41. property Samples: TVkSampleCountFlagBits read fSamples write fSamples;
  42. property Tiling: TVkImageTiling read fTiling write fTiling;
  43. property Usage: VkImageUsageFlags read fUsage write fUsage;
  44. property SharingMode: TVkSharingMode read fSharingMode write fSharingMode;
  45. property InitialLayout: TVkImageLayout read fInitialLayout write fInitialLayout;
  46. property QueueFamilyIndices: TvkuUint32Arr read fQueueFamilyIndices;
  47. property QueueFamilyIndexCount: Integer read GetQueueFamilyIndexCount;
  48. property QueueFamilyIndex[const aIndex: Integer]: VkUint32 read GetQueueFamilyIndex write SetQueueFamilyIndex;
  49. function CreateImage: TvkuImageEx;
  50. function CreateImage(
  51. const aAllocHandler: TvkuAllocationHandler;
  52. const aOwnsHandler: Boolean): TvkuImageEx;
  53. end;
  54. implementation
  55. uses
  56. uvkuUtils;
  57. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58. //TvkuImageEx////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  60. destructor TvkuImageEx.Destroy;
  61. begin
  62. inherited Destroy;
  63. if fOwnsHandle then
  64. FreeAndNil(fAllocHandler);
  65. end;
  66. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67. //TvkuImageFactory///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  69. function TvkuImageFactory.GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
  70. begin
  71. if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
  72. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
  73. result := fQueueFamilyIndices[aIndex];
  74. end;
  75. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  76. function TvkuImageFactory.GetQueueFamilyIndexCount: Integer;
  77. begin
  78. result := Length(fQueueFamilyIndices);
  79. end;
  80. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81. procedure TvkuImageFactory.SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
  82. begin
  83. if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
  84. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
  85. fQueueFamilyIndices[aIndex] := aValue;
  86. end;
  87. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  88. function TvkuImageFactory.CreateImage: TvkuImageEx;
  89. begin
  90. result := CreateImage(nil, false);
  91. end;
  92. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  93. function TvkuImageFactory.CreateImage(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuImageEx;
  94. var
  95. CreateInfo: TVkImageCreateInfo;
  96. begin
  97. FillByte(CreateInfo, 0, SizeOf(CreateInfo));
  98. CreateInfo.sType := VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
  99. CreateInfo.pNext := nil;
  100. CreateInfo.flags := fFlags;
  101. CreateInfo.imageType := fImageType;
  102. CreateInfo.format := fFormat;
  103. CreateInfo.extent := fExtent;
  104. CreateInfo.mipLevels := fMipLevels;
  105. CreateInfo.arrayLayers := fArrayLayers;
  106. CreateInfo.samples := fSamples;
  107. CreateInfo.tiling := fTiling;
  108. CreateInfo.usage := fUsage;
  109. CreateInfo.sharingMode := fSharingMode;
  110. CreateInfo.queueFamilyIndexCount := Length(fQueueFamilyIndices);
  111. CreateInfo.pQueueFamilyIndices := @fQueueFamilyIndices[0];
  112. CreateInfo.initialLayout := fInitialLayout;
  113. if Assigned(aAllocHandler)
  114. then result := TvkuImageEx.Create(CreateInfo, DeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
  115. else result := TvkuImageEx.Create(CreateInfo, DeviceCommands);
  116. try
  117. TvkuImageEx(result).fAllocHandler := aAllocHandler;
  118. TvkuImageEx(result).fOwnsHandle := aOwnsHandler;
  119. except
  120. FreeAndNil(result);
  121. raise;
  122. end;
  123. end;
  124. end.