Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

159 linhas
7.7 KiB

  1. unit uvkuPipelineLayoutFactory;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. Vulkan, uvkuFactoryBase, uvkuPipelineLayout, uvkuAllocationHandler, uvkuTypes;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TvkuPipelineLayoutEx = class(TvkuPipelineLayout)
  10. private
  11. fAllocHandler: TvkuAllocationHandler;
  12. fOwnsHandler: Boolean;
  13. public
  14. destructor Destroy; override;
  15. end;
  16. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. TvkuPipelineLayoutFactory = class(TvkuDeviceObjFactory)
  18. private
  19. fFlags: VkPipelineLayoutCreateFlags;
  20. fSetLayouts: TvkuDescriptorSetLayoutArr;
  21. fPushConstantRanges: TvkuPushConstantRangeArr;
  22. function GetPushConstantRange(const aIndex: Integer): TVkPushConstantRange;
  23. function GetPushConstantRangeCount: Integer;
  24. function GetSetLayout(const aIndex: Integer): VkDescriptorSetLayout;
  25. function GetSetLayoutCount: Integer;
  26. procedure SetPushConstantRange(const aIndex: Integer; aValue: TVkPushConstantRange);
  27. procedure SetPushConstantRangeCount(aValue: Integer);
  28. procedure SetSetLayout(const aIndex: Integer; aValue: VkDescriptorSetLayout);
  29. procedure SetSetLayoutCount(aValue: Integer);
  30. public
  31. property Flags: VkPipelineLayoutCreateFlags read fFlags write fFlags;
  32. property SetLayouts: TvkuDescriptorSetLayoutArr read fSetLayouts write fSetLayouts;
  33. property SetLayoutCount: Integer read GetSetLayoutCount write SetSetLayoutCount;
  34. property SetLayout[const aIndex: Integer]: VkDescriptorSetLayout read GetSetLayout write SetSetLayout;
  35. property PushConstantRanges: TvkuPushConstantRangeArr read fPushConstantRanges write fPushConstantRanges;
  36. property PushConstantRangeCount: Integer read GetPushConstantRangeCount write SetPushConstantRangeCount;
  37. property PushConstantRange[const aIndex: Integer]: TVkPushConstantRange read GetPushConstantRange write SetPushConstantRange;
  38. function CreatePipelineLayout: TvkuPipelineLayoutEx;
  39. function CreatePipelineLayout(
  40. const aAllocHandler: TvkuAllocationHandler;
  41. const aOwnsHandler: Boolean): TvkuPipelineLayoutEx;
  42. end;
  43. implementation
  44. uses
  45. uvkuUtils;
  46. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  47. //TvkuPipelineLayoutEx///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  48. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. destructor TvkuPipelineLayoutEx.Destroy;
  50. begin
  51. inherited Destroy;
  52. if fOwnsHandler then
  53. FreeAndNil(fAllocHandler);
  54. end;
  55. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56. //TvkuPipelineLayoutFactory//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  57. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58. function TvkuPipelineLayoutFactory.GetPushConstantRange(const aIndex: Integer): TVkPushConstantRange;
  59. begin
  60. if (aIndex < low(fPushConstantRanges)) or (aIndex > high(fPushConstantRanges)) then
  61. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fPushConstantRanges), High(fPushConstantRanges)]);
  62. result := fPushConstantRanges[aIndex];
  63. end;
  64. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. function TvkuPipelineLayoutFactory.GetPushConstantRangeCount: Integer;
  66. begin
  67. result := Length(fPushConstantRanges);
  68. end;
  69. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70. function TvkuPipelineLayoutFactory.GetSetLayout(const aIndex: Integer): VkDescriptorSetLayout;
  71. begin
  72. if (aIndex < low(fSetLayouts)) or (aIndex > high(fSetLayouts)) then
  73. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fSetLayouts), High(fSetLayouts)]);
  74. result := fSetLayouts[aIndex];
  75. end;
  76. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  77. function TvkuPipelineLayoutFactory.GetSetLayoutCount: Integer;
  78. begin
  79. result := Length(fSetLayouts);
  80. end;
  81. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  82. procedure TvkuPipelineLayoutFactory.SetPushConstantRange(const aIndex: Integer; aValue: TVkPushConstantRange);
  83. begin
  84. if (aIndex < low(fPushConstantRanges)) or (aIndex > high(fPushConstantRanges)) then
  85. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fPushConstantRanges), High(fPushConstantRanges)]);
  86. fPushConstantRanges[aIndex] := aValue;
  87. end;
  88. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89. procedure TvkuPipelineLayoutFactory.SetPushConstantRangeCount(aValue: Integer);
  90. begin
  91. SetLength(fPushConstantRanges, aValue);
  92. end;
  93. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  94. procedure TvkuPipelineLayoutFactory.SetSetLayout(const aIndex: Integer; aValue: VkDescriptorSetLayout);
  95. begin
  96. if (aIndex < low(fSetLayouts)) or (aIndex > high(fSetLayouts)) then
  97. raise TvkuException.CreateFmt('index (%d) out of range (%d : %d)', [aIndex, Low(fSetLayouts), High(fSetLayouts)]);
  98. fSetLayouts[aIndex] := aValue;
  99. end;
  100. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  101. procedure TvkuPipelineLayoutFactory.SetSetLayoutCount(aValue: Integer);
  102. begin
  103. SetLength(fSetLayouts, aValue);
  104. end;
  105. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. function TvkuPipelineLayoutFactory.CreatePipelineLayout: TvkuPipelineLayoutEx;
  107. begin
  108. result := CreatePipelineLayout(nil, false);
  109. end;
  110. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  111. function TvkuPipelineLayoutFactory.CreatePipelineLayout(const aAllocHandler: TvkuAllocationHandler;
  112. const aOwnsHandler: Boolean): TvkuPipelineLayoutEx;
  113. var CreateInfo: TVkPipelineLayoutCreateInfo;
  114. begin
  115. FillByte(CreateInfo, SizeOf(CreateInfo), 0);
  116. CreateInfo.sType := VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
  117. CreateInfo.pNext := nil;
  118. CreateInfo.flags := fFlags;
  119. CreateInfo.setLayoutCount := Length(fSetLayouts);
  120. CreateInfo.pSetLayouts := @fSetLayouts[0];
  121. CreateInfo.pushConstantRangeCount := Length(fPushConstantRanges);
  122. CreateInfo.pPushConstantRanges := @fPushConstantRanges[0];
  123. if Assigned(aAllocHandler)
  124. then result := TvkuPipelineLayoutEx.Create(CreateInfo, DeviceCommands, aAllocHandler.GetAllocationCallbacksPtr)
  125. else result := TvkuPipelineLayoutEx.Create(CreateInfo, DeviceCommands);
  126. try
  127. TvkuPipelineLayoutEx(result).fAllocHandler := aAllocHandler;
  128. TvkuPipelineLayoutEx(result).fOwnsHandler := aOwnsHandler;
  129. except
  130. FreeAndNil(result);
  131. raise;
  132. end;
  133. end;
  134. end.