You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
5.4 KiB

  1. unit uvkuDescriptorSetLayoutFactory;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuFactoryBase, uvkuDescriptorSetLayout, uvkuAllocationHandler, uvkuTypes;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuDescriptorSetLayoutEx = class(TvkuDescriptorSetLayout)
  10. private
  11. fAllocHandler: TvkuAllocationHandler;
  12. fOwnsHandler: Boolean;
  13. public
  14. destructor Destroy; override;
  15. end;
  16. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. TvkuDescriptorSetLayoutFactory = class(TvkuDeviceObjFactory)
  18. private
  19. fFlags: VkDescriptorSetLayoutCreateFlags;
  20. fBindings: TvkuDescriptorSetLayoutBindingArr;
  21. function GetBinding(const aIndex: Integer): TVkDescriptorSetLayoutBinding;
  22. function GetBindingCount: Integer;
  23. procedure SetBinding(const aIndex: Integer; aValue: TVkDescriptorSetLayoutBinding);
  24. procedure SetBindingCount(aValue: Integer);
  25. public
  26. property Flags: VkDescriptorSetLayoutCreateFlags read fFlags write fFlags;
  27. property Bindings: TvkuDescriptorSetLayoutBindingArr read fBindings write fBindings;
  28. property BindingCount: Integer read GetBindingCount write SetBindingCount;
  29. property Binding[const aIndex: Integer]: TVkDescriptorSetLayoutBinding read GetBinding write SetBinding;
  30. function CreateDescriptorSetLayout: TvkuDescriptorSetLayoutEx;
  31. function CreateDescriptorSetLayout(
  32. const aAllocHandler: TvkuAllocationHandler;
  33. const aOwnsHandler: Boolean): TvkuDescriptorSetLayoutEx;
  34. end;
  35. implementation
  36. uses
  37. uvkuUtils;
  38. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  39. //TvkuDescriptorSetLayoutEx//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  40. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. destructor TvkuDescriptorSetLayoutEx.Destroy;
  42. begin
  43. inherited Destroy;
  44. if fOwnsHandler then
  45. FreeAndNil(fAllocHandler);
  46. end;
  47. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  48. //TvkuDescriptorSetLayoutFactory/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. function TvkuDescriptorSetLayoutFactory.GetBinding(const aIndex: Integer): TVkDescriptorSetLayoutBinding;
  51. begin
  52. if (aIndex < low(fBindings)) or (aIndex > high(fBindings)) then
  53. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fBindings), High(fBindings)]);
  54. result := fBindings[aIndex];
  55. end;
  56. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  57. function TvkuDescriptorSetLayoutFactory.GetBindingCount: Integer;
  58. begin
  59. result := Length(fBindings);
  60. end;
  61. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62. procedure TvkuDescriptorSetLayoutFactory.SetBinding(const aIndex: Integer; aValue: TVkDescriptorSetLayoutBinding);
  63. begin
  64. if (aIndex < low(fBindings)) or (aIndex > high(fBindings)) then
  65. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fBindings), High(fBindings)]);
  66. fBindings[aIndex] := aValue;
  67. end;
  68. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  69. procedure TvkuDescriptorSetLayoutFactory.SetBindingCount(aValue: Integer);
  70. begin
  71. SetLength(fBindings, aValue);
  72. end;
  73. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. function TvkuDescriptorSetLayoutFactory.CreateDescriptorSetLayout: TvkuDescriptorSetLayoutEx;
  75. begin
  76. result := CreateDescriptorSetLayout(nil, false);
  77. end;
  78. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79. function TvkuDescriptorSetLayoutFactory.CreateDescriptorSetLayout(const aAllocHandler: TvkuAllocationHandler;
  80. const aOwnsHandler: Boolean): TvkuDescriptorSetLayoutEx;
  81. var
  82. CreateInfo: TVkDescriptorSetLayoutCreateInfo;
  83. begin
  84. FillByte(CreateInfo, SizeOf(CreateInfo), 0);
  85. CreateInfo.sType := VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
  86. CreateInfo.pNext := nil;
  87. CreateInfo.flags := fFlags;
  88. CreateInfo.bindingCount := Length(fBindings);
  89. CreateInfo.pBindings := @fBindings[0];
  90. if Assigned(aAllocHandler)
  91. then result := TvkuDescriptorSetLayoutEx.Create(CreateInfo, DeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
  92. else result := TvkuDescriptorSetLayoutEx.Create(CreateInfo, DeviceCommands);
  93. try
  94. TvkuDescriptorSetLayoutEx(result).fAllocHandler := aAllocHandler;
  95. TvkuDescriptorSetLayoutEx(result).fOwnsHandler := aOwnsHandler;
  96. except
  97. FreeAndNil(result);
  98. raise;
  99. end;
  100. end;
  101. end.