Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123 rindas
5.4 KiB

  1. unit uvkuBufferFactory;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuBuffer, uvkuDevice, uvkuAllocationHandler, uvkuTypes, uvkuFactoryBase;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuBufferEx = class(TvkuBuffer)
  10. private
  11. fAllocHandler: TvkuAllocationHandler;
  12. fOwnsHandle: Boolean;
  13. public
  14. destructor Destroy; override;
  15. end;
  16. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. TvkuBufferFactory = class(TvkuDeviceObjFactory)
  18. private
  19. fFlags: VkBufferCreateFlags;
  20. fSize: VkDeviceSize;
  21. fUsage: VkBufferUsageFlags;
  22. fSharingMode: TVkSharingMode;
  23. fQueueFamilyIndices: TvkuUint32Arr;
  24. function GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
  25. function GetQueueFamilyIndexCount: Integer;
  26. procedure SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
  27. public
  28. property Flags: VkBufferCreateFlags read fFlags write fFlags;
  29. property Size: VkDeviceSize read fSize write fSize;
  30. property Usage: VkBufferUsageFlags read fUsage write fUsage;
  31. property SharingMode: TVkSharingMode read fSharingMode write fSharingMode;
  32. property QueueFamilyIndices: TvkuUint32Arr read fQueueFamilyIndices;
  33. property QueueFamilyIndexCount: Integer read GetQueueFamilyIndexCount;
  34. property QueueFamilyIndex[const aIndex: Integer]: VkUint32 read GetQueueFamilyIndex write SetQueueFamilyIndex;
  35. function CreateBuffer: TvkuBufferEx;
  36. function CreateBuffer(
  37. const aAllocHandler: TvkuAllocationHandler;
  38. const aOwnsHandler: Boolean): TvkuBufferEx;
  39. end;
  40. implementation
  41. uses
  42. uvkuUtils;
  43. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  44. //TvkuBufferEx///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  45. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  46. destructor TvkuBufferEx.Destroy;
  47. begin
  48. inherited Destroy;
  49. if fOwnsHandle then
  50. FreeAndNil(fAllocHandler);
  51. end;
  52. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  53. //TvkuBufferFactory//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  54. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. function TvkuBufferFactory.GetQueueFamilyIndex(const aIndex: Integer): VkUint32;
  56. begin
  57. if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
  58. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
  59. result := fQueueFamilyIndices[aIndex];
  60. end;
  61. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62. function TvkuBufferFactory.GetQueueFamilyIndexCount: Integer;
  63. begin
  64. result := Length(fQueueFamilyIndices);
  65. end;
  66. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67. procedure TvkuBufferFactory.SetQueueFamilyIndex(const aIndex: Integer; aValue: VkUint32);
  68. begin
  69. if (aIndex < low(fQueueFamilyIndices)) or (aIndex > high(fQueueFamilyIndices)) then
  70. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fQueueFamilyIndices), High(fQueueFamilyIndices)]);
  71. fQueueFamilyIndices[aIndex] := aValue;
  72. end;
  73. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. function TvkuBufferFactory.CreateBuffer: TvkuBufferEx;
  75. begin
  76. result := CreateBuffer(nil, false);
  77. end;
  78. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79. function TvkuBufferFactory.CreateBuffer(const aAllocHandler: TvkuAllocationHandler; const aOwnsHandler: Boolean): TvkuBufferEx;
  80. var
  81. CreateInfo: TVkBufferCreateInfo;
  82. begin
  83. FillByte(CreateInfo, 0, SizeOf(CreateInfo));
  84. CreateInfo.sType := VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  85. CreateInfo.pNext := nil;
  86. CreateInfo.flags := fFlags;
  87. CreateInfo.size := fSize;
  88. CreateInfo.usage := fUsage;
  89. CreateInfo.sharingMode := fSharingMode;
  90. CreateInfo.queueFamilyIndexCount := Length(fQueueFamilyIndices);
  91. CreateInfo.pQueueFamilyIndices := @fQueueFamilyIndices[0];
  92. if Assigned(aAllocHandler)
  93. then result := TvkuBufferEx.Create(CreateInfo, DeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
  94. else result := TvkuBufferEx.Create(CreateInfo, DeviceCommands);
  95. try
  96. TvkuBufferEx(result).fAllocHandler := aAllocHandler;
  97. TvkuBufferEx(result).fOwnsHandle := aOwnsHandler;
  98. except
  99. FreeAndNil(result);
  100. raise;
  101. end;
  102. end;
  103. end.