Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

116 righe
4.7 KiB

  1. unit uvkuDescriptorPoolFactory;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuFactoryBase, uvkuDescriptorPool, uvkuTypes;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuDescriptorPoolSize = class(TvkuStructure)
  10. DescriptorType: TVkDescriptorType;
  11. DescriptorCount: VkUint32;
  12. function GetStructure: TVkDescriptorPoolSize;
  13. procedure SetStructure(const aData: TVkDescriptorPoolSize);
  14. end;
  15. TvkuDescriptorPoolSizeList = specialize TvkuObjList<TvkuDescriptorPoolSize>;
  16. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. TvkuDescriptorPoolFactory = class(TvkuDeviceObjFactory)
  18. private
  19. fPoolSizes: TvkuDescriptorPoolSizeList;
  20. fvkPoolSizes: TVkDescriptorPoolSizeArr;
  21. public
  22. Flags: VkDescriptorPoolCreateFlags;
  23. MaxSets: VkUint32;
  24. property PoolSizes: TvkuDescriptorPoolSizeList read fPoolSizes;
  25. function GetStructure: TVkDescriptorPoolCreateInfo;
  26. procedure SetStructure(const aData: TVkDescriptorPoolCreateInfo);
  27. function CreateDescriptorPool: TvkuDescriptorPool;
  28. procedure AfterConstruction; override;
  29. procedure BeforeDestruction; override;
  30. end;
  31. implementation
  32. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. //TvkuDescriptorPoolSize/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. function TvkuDescriptorPoolSize.GetStructure: TVkDescriptorPoolSize;
  36. begin
  37. FillByte(result, SizeOf(result), 0);
  38. result.dType := DescriptorType;
  39. result.descriptorCount := DescriptorCount;
  40. end;
  41. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. procedure TvkuDescriptorPoolSize.SetStructure(const aData: TVkDescriptorPoolSize);
  43. begin
  44. DescriptorType := aData.dType;
  45. DescriptorCount := aData.descriptorCount;
  46. end;
  47. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  48. //TvkuDescriptorPoolFactory//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. function TvkuDescriptorPoolFactory.GetStructure: TVkDescriptorPoolCreateInfo;
  51. var i: Integer;
  52. begin
  53. SetLength(fvkPoolSizes, fPoolSizes.Length);
  54. for i := low(fvkPoolSizes) to high(fvkPoolSizes) do
  55. fvkPoolSizes[i] := fPoolSizes[i].GetStructure;
  56. FillByte(result, SizeOf(result), 0);
  57. result.sType := VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
  58. result.pNext := nil;
  59. result.flags := Flags;
  60. result.maxSets := MaxSets;
  61. result.poolSizeCount := Length(fvkPoolSizes);
  62. result.pPoolSizes := @fvkPoolSizes[0];
  63. end;
  64. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. procedure TvkuDescriptorPoolFactory.SetStructure(const aData: TVkDescriptorPoolCreateInfo);
  66. var i: Integer;
  67. begin
  68. if Assigned(aData.pPoolSizes) then begin
  69. fPoolSizes.Length := aData.poolSizeCount;
  70. for i := 0 to fPoolSizes.Length-1 do
  71. fPoolSizes[i].SetStructure((aData.pPoolSizes + i)^);
  72. end;
  73. Flags := aData.flags;
  74. MaxSets := aData.maxSets;
  75. end;
  76. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  77. function TvkuDescriptorPoolFactory.CreateDescriptorPool: TvkuDescriptorPool;
  78. begin
  79. result := TvkuDescriptorPool.Create(GetStructure, DeviceCommands, AllocCallbacks);
  80. end;
  81. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  82. procedure TvkuDescriptorPoolFactory.AfterConstruction;
  83. begin
  84. inherited AfterConstruction;
  85. fPoolSizes := TvkuDescriptorPoolSizeList.Create;
  86. end;
  87. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  88. procedure TvkuDescriptorPoolFactory.BeforeDestruction;
  89. begin
  90. FreeAndNil(fPoolSizes);
  91. inherited BeforeDestruction;
  92. end;
  93. end.