fSimpleTexD.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. unit fSimpleTexD;
  2. interface
  3. uses
  4. Winapi.Windows,
  5. Winapi.Messages,
  6. System.SysUtils,
  7. System.Variants,
  8. System.Classes,
  9. Vcl.Graphics,
  10. Vcl.Controls,
  11. Vcl.Forms,
  12. Vcl.Dialogs,
  13. Vcl.StdCtrls,
  14. GLS.Utils,
  15. GLS.FilePGM,
  16. CUDA.Context,
  17. CUDA.APIComps,
  18. CUDA.Compiler,
  19. CUDA.Utility,
  20. GLS.Graphics,
  21. GLS.TextureFormat;
  22. type
  23. TForm1 = class(TForm)
  24. GLCUDA1: TGLCUDA;
  25. GLCUDADevice1: TGLCUDADevice;
  26. GLCUDACompiler1: TGLCUDACompiler;
  27. Button1: TButton;
  28. Memo1: TMemo;
  29. procedure Button1Click(Sender: TObject);
  30. procedure FormCreate(Sender: TObject);
  31. procedure FormDestroy(Sender: TObject);
  32. public
  33. MainModule: TCUDAModule;
  34. TurnPicture: TCUDAFunction;
  35. Image: TCUDATexture;
  36. TextureArray: TCUDAMemData;
  37. ResultData: TCUDAMemData;
  38. pgm: TGLPGMImage;
  39. procedure TurnPictureParameterSetup(Sender: TObject);
  40. end;
  41. TGLBitmap32 = TGLImage; // comment if supported Graphics32
  42. var
  43. Form1: TForm1;
  44. Angle : Single = 0.5; // angle to rotate image by (in radians)
  45. //-----------------------------------------
  46. implementation
  47. //-----------------------------------------
  48. {$R *.dfm}
  49. const
  50. TestFileName = 'lena_bw.pgm';
  51. OutFileName = 'lena_bw_out.pgm';
  52. procedure TForm1.Button1Click(Sender: TObject);
  53. var
  54. timer: Cardinal;
  55. bmp32: TGLBitmap32;
  56. begin
  57. pgm.LoadFromFile( TestFileName );
  58. if not InitCUTIL then
  59. begin
  60. Memo1.Lines.Add('Can''t load cutil32.dll');
  61. exit;
  62. end;
  63. bmp32 := TGLBitmap32.Create;
  64. bmp32.Assign( pgm );
  65. Memo1.Lines.Add(Format('File %s - loaded', [TestFileName]));
  66. TextureArray.CopyFrom( bmp32 ); // <- error
  67. Memo1.Lines.Add('Copied from host to device array');
  68. TurnPicture.Launch; // <- failed
  69. Memo1.Lines.Add('Warmup launch finished');
  70. cutCreateTimer( timer );
  71. cutStartTimer( timer );
  72. TurnPicture.Launch;
  73. cutStopTimer( timer );
  74. Memo1.Lines.Add('Launch finished');
  75. Memo1.Lines.Add(Format('Processing time: %f (ms)', [cutGetTimerValue( timer )] ));
  76. Memo1.Lines.Add(Format('%.2f Mpixels/sec',
  77. [(pgm.LevelWidth[0]*pgm.LevelHeight[0] / (cutGetTimerValue( timer) / 1000.0)) / 1e6]));
  78. cutDeleteTimer( timer );
  79. ResultData.CopyTo( bmp32 );
  80. Memo1.Lines.Add('Copied from device global memory to host');
  81. pgm.Assign( bmp32 );
  82. pgm.SaveToFile( OutFileName );
  83. Memo1.Lines.Add(Format('Saving result to %s - done', [OutFileName]));
  84. bmp32.Free;
  85. end;
  86. procedure TForm1.FormCreate(Sender: TObject);
  87. begin
  88. SetCurrentDirToAsset();
  89. pgm := TGLPGMImage.Create;
  90. end;
  91. procedure TForm1.FormDestroy(Sender: TObject);
  92. begin
  93. pgm.Destroy;
  94. end;
  95. procedure TForm1.TurnPictureParameterSetup(Sender: TObject);
  96. begin
  97. with TurnPicture do
  98. begin
  99. SetParam(ResultData);
  100. SetParam(pgm.LevelWidth[0]);
  101. SetParam(pgm.LevelHeight[0]);
  102. SetParam(Angle);
  103. SetParam(Image);
  104. end;
  105. end;
  106. end.