Skip to content

Commit

Permalink
低性能GPUへ対応するため、TDoubleC → TSingleC へ変更。
Browse files Browse the repository at this point in the history
  • Loading branch information
luxidea committed Oct 13, 2024
1 parent 78f14ea commit 7263c64
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 49 deletions.
8 changes: 7 additions & 1 deletion Main.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object Form1: TForm1
CustomIcon = <
item
end>
TextSettings.Trimming = None
IsSelected = False
Size.Width = 58.000000000000000000
Size.Height = 26.000000000000000000
Expand Down Expand Up @@ -64,6 +65,7 @@ object Form1: TForm1
CustomIcon = <
item
end>
TextSettings.Trimming = None
IsSelected = False
Size.Width = 66.000000000000000000
Size.Height = 26.000000000000000000
Expand Down Expand Up @@ -96,6 +98,7 @@ object Form1: TForm1
CustomIcon = <
item
end>
TextSettings.Trimming = None
IsSelected = False
Size.Width = 56.000000000000000000
Size.Height = 26.000000000000000000
Expand Down Expand Up @@ -127,6 +130,7 @@ object Form1: TForm1
CustomIcon = <
item
end>
TextSettings.Trimming = None
IsSelected = True
Size.Width = 77.000000000000000000
Size.Height = 26.000000000000000000
Expand Down Expand Up @@ -158,6 +162,7 @@ object Form1: TForm1
CustomIcon = <
item
end>
TextSettings.Trimming = None
IsSelected = False
Size.Width = 47.000000000000000000
Size.Height = 26.000000000000000000
Expand Down Expand Up @@ -191,8 +196,9 @@ object Form1: TForm1
CustomIcon = <
item
end>
TextSettings.Trimming = None
IsSelected = True
Size.Width = 52.000000000000000000
Size.Width = 53.000000000000000000
Size.Height = 26.000000000000000000
Size.PlatformDefault = False
StyleLookup = ''
Expand Down
16 changes: 8 additions & 8 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TForm1 = class(TForm)
procedure ImageRMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
private
{ private 宣言 }
_AreaC :TDoubleAreaC;
_AreaC :TSingleAreaC;
///// メソッド
procedure ShowBuild;
public
Expand All @@ -45,7 +45,7 @@ TForm1 = class(TForm)
_Device :TCLDevice;
_Contex :TCLContex;
_Queuer :TCLQueuer;
_Buffer :TCLBuffer<TDoubleC>;
_Buffer :TCLBuffer<TSingleC>;
_Textur :TCLImager1DxBGRAxUFix8;
_TexFMX :ICLStream1DxBGRAxUFix8_FMX;
_Samplr :TCLSamplr;
Expand All @@ -72,7 +72,7 @@ implementation //###############################################################

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private

/////////////////////////////////////////////////////////////////////// メソッド
//////////////////////////////////////////////////////////////////// M E T H O D

procedure TForm1.ShowBuild;
begin
Expand All @@ -95,7 +95,7 @@ procedure TForm1.ShowBuild;

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public

/////////////////////////////////////////////////////////////////////// メソッド
//////////////////////////////////////////////////////////////////// M E T H O D

procedure TForm1.MakeContext;
begin
Expand Down Expand Up @@ -125,13 +125,13 @@ procedure TForm1.MakeArguments;
begin
////////// バッファー

_Buffer := TCLBuffer<TDoubleC>.Create( _Contex, _Queuer ); // 生成
_Buffer := TCLBuffer<TSingleC>.Create( _Contex, _Queuer ); // 生成

Assert( Assigned( _Buffer.Handle ), '_Buffer is Error!' ); // 検証

_Buffer.Count := 2; // 要素数の設定

_AreaC := TDoubleAreaC.Create( -2, -2, +2, +2 );
_AreaC := TSingleAreaC.Create( -2, -2, +2, +2 );

_Buffer.Data.Map; // 展開
_Buffer.Data[ 0 ] := _AreaC.Min; // 書き込み
Expand Down Expand Up @@ -256,8 +256,8 @@ procedure TForm1.Timer1Timer(Sender: TObject);
procedure TForm1.ImageRMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
var
P :TPointF;
C :TDoubleC;
S :Double;
C :TSingleC;
S :Single;
begin
P := ImageR.AbsoluteToLocal( ScreenToClient( Screen.MousePos ) );

Expand Down
33 changes: 12 additions & 21 deletions _DATA/Execut.cl
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,47 @@

#include<Librar.cl>

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【 T Y P E

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【 R O U T I N E

TDoubleC ScreenToComplex( const int2 P, const int2 S, const TDoubleAreaC A )
TSingleC ScreenToComplex( const int2 P, const int2 S, const TSingleAreaC A )
{
TDoubleC Result;
TSingleC Result;

Result.R = ( A.Max.R - A.Min.R ) * ( P.x + 0.5 ) / S.x + A.Min.R;
Result.I = ( A.Min.I - A.Max.I ) * ( P.y + 0.5 ) / S.y + A.Max.I;
Result.R = ( A.Max.R - A.Min.R ) * ( P.x + 0.5f ) / S.x + A.Min.R;
Result.I = ( A.Min.I - A.Max.I ) * ( P.y + 0.5f ) / S.y + A.Max.I;

return Result;
}

float ComplexToCount( const TDoubleC C, const int MaxN )
float ComplexToCount( const TSingleC C, const int MaxN )
{
TDoubleC Z = { 0, 0 };
TSingleC Z = { 0, 0 };

for ( int N = 1; N < MaxN; N++ )
{
Z = Add( Pow2( Z ), C );

if ( Abs( Z ) > 10 )
{
N++; Z = Add( Pow2( Z ), C );
N++; Z = Add( Pow2( Z ), C );
N++; Z = Add( Pow2( Z ), C );
N++; Z = Add( Pow2( Z ), C );
N++; Z = Add( Pow2( Z ), C );

return (float)N + 1 - log( log2( Abs( Z ) ) );
}
if ( Abs( Z ) > 2 ) return (float)N + 1 - log( log2( Abs( Z ) ) );
}

return MaxN;
}

//############################################################################## ■

kernel void Main( global TDoubleC* Buffer,
kernel void Main( global TSingleC* Buffer,
read_only image1d_t Textur,
const sampler_t Samplr,
write_only image2d_t Imager )
{
const int2 P = { get_global_id ( 0 ), get_global_id ( 1 ) };
const int2 S = { get_global_size( 0 ), get_global_size( 1 ) };
const TDoubleAreaC A = { Buffer[0], Buffer[1] };
const TSingleAreaC A = { Buffer[0], Buffer[1] };
const int MaxN = 1000;

TDoubleC C = ScreenToComplex( P, S, A );
TSingleC C = ScreenToComplex( P, S, A );

float N = ComplexToCount( C, MaxN );

Expand Down
36 changes: 17 additions & 19 deletions _DATA/Librar.cl
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,67 @@
#define LIBRAR
//############################################################################## ■

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【 T Y P E

typedef struct
{
double R;
double I;
float R;
float I;
}
TDoubleC;
TSingleC;

typedef struct
{
TDoubleC Min;
TDoubleC Max;
TSingleC Min;
TSingleC Max;
}
TDoubleAreaC;
TSingleAreaC;

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【 R O U T I N E

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TDoubleC
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TSingleC

///////////////////////////////////////////////////////////////////////// 演算子

TDoubleC __attribute__((overloadable)) Add( const TDoubleC A, const TDoubleC B )
TSingleC __attribute__((overloadable)) Add( const TSingleC A, const TSingleC B )
{
TDoubleC Result;
TSingleC Result;

Result.R = A.R + B.R;
Result.I = A.I + B.I;

return Result;
}

TDoubleC __attribute__((overloadable)) Sub( const TDoubleC A, const TDoubleC B )
TSingleC __attribute__((overloadable)) Sub( const TSingleC A, const TSingleC B )
{
TDoubleC Result;
TSingleC Result;

Result.R = A.R - B.R;
Result.I = A.I - B.I;

return Result;
}

TDoubleC __attribute__((overloadable)) Mul( const TDoubleC A, const TDoubleC B )
TSingleC __attribute__((overloadable)) Mul( const TSingleC A, const TSingleC B )
{
TDoubleC Result;
TSingleC Result;

Result.R = A.R * B.R - A.I * B.I;
Result.I = A.R * B.I + A.I * B.R;

return Result;
}

TDoubleC __attribute__((overloadable)) Pow2( const TDoubleC C )
TSingleC __attribute__((overloadable)) Pow2( const TSingleC C )
{
return Mul( C, C );
}

double __attribute__((overloadable)) Abs( const TDoubleC C )
float __attribute__((overloadable)) Abs( const TSingleC C )
{
return sqrt( C.R * C.R + C.I * C.I );
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TDoubleAreaC

//############################################################################## ■
#endif

0 comments on commit 7263c64

Please sign in to comment.