Ignore:
Timestamp:
Apr 9, 2015, 9:58:36 PM (10 years ago)
Author:
chronos
Message:
  • Fixed: Use csOpaque control style also to Image, PaintBox and OpenGLControl.
  • Modified: Change size of test frame with SpinEdits as delayed using timer.
  • Updated: BRGABitmap package to version 8.1.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgramatrix3d.pas

    r452 r472  
    33{$mode objfpc}{$H+}
    44
    5 {$ifdef CPUI386}
     5{$i bgrasse.inc}
     6{$ifdef BGRASSE_AVAILABLE}
    67  {$asmmode intel}
    78{$endif}
     
    1415type
    1516  TMatrix3D = packed array[1..3,1..4] of single;
     17  TProjection3D = packed record
     18    Zoom, Center: TPointF;
     19  end;
    1620
    1721operator*(const A: TMatrix3D; const M: TPoint3D): TPoint3D;
    18 operator*(const A: TMatrix3D; var M: TPoint3D_128): TPoint3D_128;
     22operator*(constref A: TMatrix3D; var M: TPoint3D_128): TPoint3D_128;
     23function MultiplyVect3DWithoutTranslation(constref A: TMatrix3D; constref M: TPoint3D_128): TPoint3D_128;
    1924operator*(A,B: TMatrix3D): TMatrix3D;
    2025
     
    3035function MatrixRotateZ(angle: single): TMatrix3D;
    3136
    32 {$IFDEF CPUI386}
     37{$IFDEF BGRASSE_AVAILABLE}
    3338procedure Matrix3D_SSE_Load(const A: TMatrix3D);
    3439procedure MatrixMultiplyVect3D_SSE_Aligned(var M: TPoint3D_128; out N: TPoint3D_128);
    3540procedure MatrixMultiplyVect3D_SSE3_Aligned(var M: TPoint3D_128; out N: TPoint3D_128);
     41procedure MatrixMultiplyVect3DWithoutTranslation_SSE_Aligned(var M: TPoint3D_128; out N: TPoint3D_128);
     42procedure MatrixMultiplyVect3DWithoutTranslation_SSE3_Aligned(var M: TPoint3D_128; out N: TPoint3D_128);
    3643{$ENDIF}
    3744
     
    5259end;
    5360
    54 {$IFDEF CPUI386}
     61{$IFDEF BGRASSE_AVAILABLE}
    5562var SingleConst1 : single = 1;
    5663
    57 procedure Matrix3D_SSE_Load(const A: TMatrix3D);
    58 begin
    59   asm
    60     mov eax, A
    61     movups xmm5, [eax]
    62     movups xmm6, [eax+16]
    63     movups xmm7, [eax+32]
    64   end;
    65 end;
     64  procedure Matrix3D_SSE_Load(const A: TMatrix3D);
     65  begin
     66    {$IFDEF cpux86_64}
     67    asm
     68      mov rax, A
     69      movups xmm5, [rax]
     70      movups xmm6, [rax+16]
     71      movups xmm7, [rax+32]
     72    end;
     73    {$ELSE}
     74    asm
     75      mov eax, A
     76      movups xmm5, [eax]
     77      movups xmm6, [eax+16]
     78      movups xmm7, [eax+32]
     79    end;
     80   {$ENDIF}
     81  end;
    6682
    6783procedure MatrixMultiplyVect3D_SSE_Aligned(var M: TPoint3D_128; out N: TPoint3D_128);
     
    7086  oldMt := M.t;
    7187  M.t := SingleConst1;
     88  {$IFDEF cpux86_64}
     89  asm
     90    mov rax, M
     91    movaps xmm0, [rax]
     92
     93    mov rax, N
     94
     95    movaps xmm2,xmm0
     96    mulps xmm2,xmm5
     97    //mix1
     98    movaps xmm3, xmm2
     99    shufps xmm3, xmm3, $4e
     100    addps xmm2, xmm3
     101    //mix2
     102    movaps xmm3, xmm2
     103    shufps xmm3, xmm3, $11
     104    addps xmm2, xmm3
     105
     106    movss [rax], xmm2
     107
     108    movaps xmm2,xmm0
     109    mulps xmm2,xmm6
     110    //mix1
     111    movaps xmm3, xmm2
     112    shufps xmm3, xmm3, $4e
     113    addps xmm2, xmm3
     114    //mix2
     115    movaps xmm3, xmm2
     116    shufps xmm3, xmm3, $11
     117    addps xmm2, xmm3
     118
     119    movss [rax+4], xmm2
     120
     121    mulps xmm0,xmm7
     122    //mix1
     123    movaps xmm3, xmm0
     124    shufps xmm3, xmm3, $4e
     125    addps xmm0, xmm3
     126    //mix2
     127    movaps xmm3, xmm0
     128    shufps xmm3, xmm3, $11
     129    addps xmm0, xmm3
     130
     131    movss [rax+8], xmm0
     132  end;
     133  {$ELSE}
     134    asm
     135    mov eax, M
     136    movaps xmm0, [eax]
     137
     138    mov eax, N
     139
     140    movaps xmm2,xmm0
     141    mulps xmm2,xmm5
     142    //mix1
     143    movaps xmm3, xmm2
     144    shufps xmm3, xmm3, $4e
     145    addps xmm2, xmm3
     146    //mix2
     147    movaps xmm3, xmm2
     148    shufps xmm3, xmm3, $11
     149    addps xmm2, xmm3
     150
     151    movss [eax], xmm2
     152
     153    movaps xmm2,xmm0
     154    mulps xmm2,xmm6
     155    //mix1
     156    movaps xmm3, xmm2
     157    shufps xmm3, xmm3, $4e
     158    addps xmm2, xmm3
     159    //mix2
     160    movaps xmm3, xmm2
     161    shufps xmm3, xmm3, $11
     162    addps xmm2, xmm3
     163
     164    movss [eax+4], xmm2
     165
     166    mulps xmm0,xmm7
     167    //mix1
     168    movaps xmm3, xmm0
     169    shufps xmm3, xmm3, $4e
     170    addps xmm0, xmm3
     171    //mix2
     172    movaps xmm3, xmm0
     173    shufps xmm3, xmm3, $11
     174    addps xmm0, xmm3
     175
     176    movss [eax+8], xmm0
     177  end;
     178  {$ENDIF}
     179  M.t := oldMt;
     180  N.t := 0;
     181end;
     182
     183procedure MatrixMultiplyVect3D_SSE3_Aligned(var M: TPoint3D_128; out N: TPoint3D_128);
     184var oldMt: single;
     185begin
     186  oldMt := M.t;
     187  M.t := SingleConst1;
     188  {$IFDEF cpux86_64}
     189  asm
     190    mov rax, M
     191    movaps xmm0, [rax]
     192
     193    mov rax, N
     194
     195    movaps xmm2,xmm0
     196    mulps xmm2,xmm5
     197    haddps xmm2,xmm2
     198    haddps xmm2,xmm2
     199    movss [rax], xmm2
     200
     201    movaps xmm2,xmm0
     202    mulps xmm2,xmm6
     203    haddps xmm2,xmm2
     204    haddps xmm2,xmm2
     205    movss [rax+4], xmm2
     206
     207    mulps xmm0,xmm7
     208    haddps xmm0,xmm0
     209    haddps xmm0,xmm0
     210    movss [rax+8], xmm0
     211  end;
     212  {$ELSE}
    72213  asm
    73214    mov eax, M
     
    78219    movaps xmm2,xmm0
    79220    mulps xmm2,xmm5
    80     //mix1
    81     movaps xmm3, xmm2
    82     shufps xmm3, xmm3, $4e
    83     addps xmm2, xmm3
    84     //mix2
    85     movaps xmm3, xmm2
    86     shufps xmm3, xmm3, $11
    87     addps xmm2, xmm3
    88 
     221    haddps xmm2,xmm2
     222    haddps xmm2,xmm2
    89223    movss [eax], xmm2
    90224
    91225    movaps xmm2,xmm0
    92226    mulps xmm2,xmm6
    93     //mix1
    94     movaps xmm3, xmm2
    95     shufps xmm3, xmm3, $4e
    96     addps xmm2, xmm3
    97     //mix2
    98     movaps xmm3, xmm2
    99     shufps xmm3, xmm3, $11
    100     addps xmm2, xmm3
    101 
     227    haddps xmm2,xmm2
     228    haddps xmm2,xmm2
    102229    movss [eax+4], xmm2
    103230
    104231    mulps xmm0,xmm7
    105     //mix1
    106     movaps xmm3, xmm0
    107     shufps xmm3, xmm3, $4e
    108     addps xmm0, xmm3
    109     //mix2
    110     movaps xmm3, xmm0
    111     shufps xmm3, xmm3, $11
    112     addps xmm0, xmm3
    113 
     232    haddps xmm0,xmm0
     233    haddps xmm0,xmm0
    114234    movss [eax+8], xmm0
    115235  end;
     236  {$ENDIF}
    116237  M.t := oldMt;
    117   N.t := 0;
    118 end;
    119 
    120 procedure MatrixMultiplyVect3D_SSE3_Aligned(var M: TPoint3D_128; out N: TPoint3D_128);
    121 var oldMt: single;
    122 begin
    123   oldMt := M.t;
    124   M.t := SingleConst1;
     238end;
     239
     240procedure MatrixMultiplyVect3DWithoutTranslation_SSE_Aligned(
     241  var M: TPoint3D_128; out N: TPoint3D_128);
     242begin
     243  {$IFDEF cpux86_64}
     244  asm
     245    mov rax, M
     246    movaps xmm0, [rax]
     247
     248    mov rax, N
     249
     250    movaps xmm2,xmm0
     251    mulps xmm2,xmm5
     252    //mix1
     253    movaps xmm3, xmm2
     254    shufps xmm3, xmm3, $4e
     255    addps xmm2, xmm3
     256    //mix2
     257    movaps xmm3, xmm2
     258    shufps xmm3, xmm3, $11
     259    addps xmm2, xmm3
     260
     261    movss [rax], xmm2
     262
     263    movaps xmm2,xmm0
     264    mulps xmm2,xmm6
     265    //mix1
     266    movaps xmm3, xmm2
     267    shufps xmm3, xmm3, $4e
     268    addps xmm2, xmm3
     269    //mix2
     270    movaps xmm3, xmm2
     271    shufps xmm3, xmm3, $11
     272    addps xmm2, xmm3
     273
     274    movss [rax+4], xmm2
     275
     276    mulps xmm0,xmm7
     277    //mix1
     278    movaps xmm3, xmm0
     279    shufps xmm3, xmm3, $4e
     280    addps xmm0, xmm3
     281    //mix2
     282    movaps xmm3, xmm0
     283    shufps xmm3, xmm3, $11
     284    addps xmm0, xmm3
     285
     286    movss [rax+8], xmm0
     287  end;
     288  {$ELSE}
     289    asm
     290    mov eax, M
     291    movaps xmm0, [eax]
     292
     293    mov eax, N
     294
     295    movaps xmm2,xmm0
     296    mulps xmm2,xmm5
     297    //mix1
     298    movaps xmm3, xmm2
     299    shufps xmm3, xmm3, $4e
     300    addps xmm2, xmm3
     301    //mix2
     302    movaps xmm3, xmm2
     303    shufps xmm3, xmm3, $11
     304    addps xmm2, xmm3
     305
     306    movss [eax], xmm2
     307
     308    movaps xmm2,xmm0
     309    mulps xmm2,xmm6
     310    //mix1
     311    movaps xmm3, xmm2
     312    shufps xmm3, xmm3, $4e
     313    addps xmm2, xmm3
     314    //mix2
     315    movaps xmm3, xmm2
     316    shufps xmm3, xmm3, $11
     317    addps xmm2, xmm3
     318
     319    movss [eax+4], xmm2
     320
     321    mulps xmm0,xmm7
     322    //mix1
     323    movaps xmm3, xmm0
     324    shufps xmm3, xmm3, $4e
     325    addps xmm0, xmm3
     326    //mix2
     327    movaps xmm3, xmm0
     328    shufps xmm3, xmm3, $11
     329    addps xmm0, xmm3
     330
     331    movss [eax+8], xmm0
     332  end;
     333  {$ENDIF}
     334end;
     335
     336procedure MatrixMultiplyVect3DWithoutTranslation_SSE3_Aligned(
     337  var M: TPoint3D_128; out N: TPoint3D_128);
     338begin
     339  {$IFDEF cpux86_64}
     340  asm
     341    mov rax, M
     342    movaps xmm0, [rax]
     343
     344    mov rax, N
     345
     346    movaps xmm2,xmm0
     347    mulps xmm2,xmm5
     348    haddps xmm2,xmm2
     349    haddps xmm2,xmm2
     350    movss [rax], xmm2
     351
     352    movaps xmm2,xmm0
     353    mulps xmm2,xmm6
     354    haddps xmm2,xmm2
     355    haddps xmm2,xmm2
     356    movss [rax+4], xmm2
     357
     358    mulps xmm0,xmm7
     359    haddps xmm0,xmm0
     360    haddps xmm0,xmm0
     361    movss [rax+8], xmm0
     362  end;
     363  {$ELSE}
    125364  asm
    126365    mov eax, M
     
    146385    movss [eax+8], xmm0
    147386  end;
    148   M.t := oldMt;
    149 end;
     387  {$ENDIF}
     388end;
     389
    150390{$ENDIF}
    151391
    152 operator*(const A: TMatrix3D; var M: TPoint3D_128): TPoint3D_128;
     392operator*(constref A: TMatrix3D; var M: TPoint3D_128): TPoint3D_128;
    153393{$IFDEF CPUI386}var oldMt: single; {$ENDIF}
    154394begin
     
    248488end;
    249489
     490function MultiplyVect3DWithoutTranslation(constref A: TMatrix3D; constref M: TPoint3D_128): TPoint3D_128;
     491begin
     492  {$IFDEF CPUI386}
     493  if UseSSE then
     494  begin
     495    if UseSSE3 then
     496    asm
     497      mov eax, A
     498      movups xmm5, [eax]
     499      movups xmm6, [eax+16]
     500      movups xmm7, [eax+32]
     501
     502      mov eax, M
     503      movups xmm0, [eax]
     504
     505      mov eax, result
     506
     507      movaps xmm4,xmm0
     508      mulps xmm4,xmm5
     509      haddps xmm4,xmm4
     510      haddps xmm4,xmm4
     511      movss [eax], xmm4
     512
     513      movaps xmm4,xmm0
     514      mulps xmm4,xmm6
     515      haddps xmm4,xmm4
     516      haddps xmm4,xmm4
     517      movss [eax+4], xmm4
     518
     519      mulps xmm0,xmm7
     520      haddps xmm0,xmm0
     521      haddps xmm0,xmm0
     522      movss [eax+8], xmm0
     523    end else
     524    asm
     525      mov eax, A
     526      movups xmm5, [eax]
     527      movups xmm6, [eax+16]
     528      movups xmm7, [eax+32]
     529
     530      mov eax, M
     531      movups xmm0, [eax]
     532
     533      mov eax, result
     534
     535      movaps xmm4,xmm0
     536      mulps xmm4,xmm5
     537      //mix1
     538      movaps xmm3, xmm4
     539      shufps xmm3, xmm3, $4e
     540      addps xmm4, xmm3
     541      //mix2
     542      movaps xmm3, xmm4
     543      shufps xmm3, xmm3, $11
     544      addps xmm4, xmm3
     545
     546      movss [eax], xmm4
     547
     548      movaps xmm4,xmm0
     549      mulps xmm4,xmm6
     550      //mix1
     551      movaps xmm3, xmm4
     552      shufps xmm3, xmm3, $4e
     553      addps xmm4, xmm3
     554      //mix2
     555      movaps xmm3, xmm4
     556      shufps xmm3, xmm3, $11
     557      addps xmm4, xmm3
     558
     559      movss [eax+4], xmm4
     560
     561      mulps xmm0,xmm7
     562      //mix1
     563      movaps xmm3, xmm0
     564      shufps xmm3, xmm3, $4e
     565      addps xmm0, xmm3
     566      //mix2
     567      movaps xmm3, xmm0
     568      shufps xmm3, xmm3, $11
     569      addps xmm0, xmm3
     570
     571      movss [eax+8], xmm0
     572    end;
     573  end else
     574  {$ENDIF}
     575  begin
     576    result.x := M.x * A[1,1] + M.y * A[1,2] + M.z * A[1,3];
     577    result.y := M.x * A[2,1] + M.y * A[2,2] + M.z * A[2,3];
     578    result.z := M.x * A[3,1] + M.y * A[3,2] + M.z * A[3,3];
     579    result.t := 0;
     580  end;
     581end;
     582
    250583operator*(A,B: TMatrix3D): TMatrix3D;
    251584begin
Note: See TracChangeset for help on using the changeset viewer.