Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

96 wiersze
3.9 KiB

  1. unit uMainForm;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
  6. Vulkan, uvkuInstanceEx, uvkuPhysicalDevice, uvkuUtils;
  7. type
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. TCustomAllocHandler = class(TvkuAllocationHandler)
  10. protected
  11. function AllocateMemory(const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid; override;
  12. function ReallocateMemory(const aOriginal: PVkVoid; const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid; override;
  13. procedure FreeMemory(const aMemory: PVkVoid); override;
  14. end;
  15. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. TMainForm = class(TForm)
  17. procedure FormCreate(Sender: TObject);
  18. procedure FormDestroy(Sender: TObject);
  19. private
  20. fIntance: TvkuInstanceEx;
  21. public
  22. { public declarations }
  23. end;
  24. var
  25. MainForm: TMainForm;
  26. implementation
  27. {$R *.lfm}
  28. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. //TCustomAllocHandler////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  31. function TCustomAllocHandler.AllocateMemory(const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid;
  32. begin
  33. result := inherited AllocateMemory(aSize, aAlignment, aScope);
  34. WriteLn(Format('%d bytes of memory allocated at %p', [ aSize, result ]));
  35. end;
  36. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. function TCustomAllocHandler.ReallocateMemory(const aOriginal: PVkVoid; const aSize: VkSize; const aAlignment: VkSize; const aScope: TVkSystemAllocationScope): PVkVoid;
  38. var p: PVkVoid;
  39. begin
  40. p := aOriginal;
  41. result := inherited ReallocateMemory(aOriginal, aSize, aAlignment, aScope);
  42. WriteLn(Format('%d bytes of memory (from %p) reallocated at %p', [ aSize, p, result ]));
  43. end;
  44. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  45. procedure TCustomAllocHandler.FreeMemory(const aMemory: PVkVoid);
  46. begin
  47. WriteLn(Format('free memory at %p', [ aMemory ]));
  48. inherited FreeMemory(aMemory);
  49. end;
  50. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. //TMainForm//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  53. procedure TMainForm.FormCreate(Sender: TObject);
  54. var
  55. i: Integer;
  56. d: TvkuPhysicalDevice;
  57. begin
  58. WriteLn('create vulkan instance');
  59. fIntance := TvkuInstanceEx.Create(
  60. 0,
  61. [],
  62. [],
  63. TvkuInstanceEx.DefaultApplicationInfo,
  64. TvkuAllocationHandler.Create,
  65. true);
  66. WriteLn('read vulkan devices:');
  67. for i := 0 to fIntance.PhysicalDeviceCount-1 do begin
  68. d := fIntance.PhysicalDevices[i];
  69. WriteLn(vkuMakeString(d.GetFeatures, ', '));
  70. WriteLn(vkuMakeString(d.GetProperties, true, true));
  71. WriteLn(vkuMakeString(d.GetMemoryProperties));
  72. end;
  73. end;
  74. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  75. procedure TMainForm.FormDestroy(Sender: TObject);
  76. begin
  77. FreeAndNil(fIntance);
  78. end;
  79. end.