فهرست منبع

Disabling Floating-Point Exceptions for good :v:

Coldzer0 1 سال پیش
والد
کامیت
505a77ba51
6فایلهای تغییر یافته به همراه73 افزوده شده و 2089 حذف شده
  1. 0 10
      demo/ImGuiDemo.dpr
  2. BIN
      demo/ImGuiDemo.exe
  3. 70 52
      demo/ImGuiDemo.lps
  4. 0 24
      impl/CImGui.Impl.OpenGL3.pas
  5. 3 101
      src/PasImGui.Apis.pas
  6. 0 1902
      src/PasImGui.pas

+ 0 - 10
demo/ImGuiDemo.dpr

@@ -193,11 +193,6 @@ Var
     {$IFDEF FPC}cmem.Free(ptr);{$ELSE}FreeMem(ptr);{$ENDIF}
   End;
 
-{$IFDEF FPC}
-Var
-  saved_FpuFlags: Cardinal;
-{$ENDIF}  
-
 
   {$R *.res}
 
@@ -375,17 +370,12 @@ Begin
     ImGui.Render();
     SDL_GL_MakeCurrent(window, gl_context);
 
-
-    {$IFDEF FPC}saved_FpuFlags := SetFpuFlags();{$ENDIF}
     glViewport(0, 0, Trunc(ioptr^.DisplaySize.x), Trunc(ioptr^.DisplaySize.y));
     glClearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
     glClear(GL_COLOR_BUFFER_BIT);
-    {$IFDEF FPC}ResetFpuFlags(saved_FpuFlags);{$ENDIF}
-    
     ImGui_Impl_OpenGL3_RenderDrawData(ImGui.GetDrawData());
 
 
-
     // IMGUI_DOCK
     If Ord(ioptr^.ConfigFlags And ImGuiConfigFlags_ViewportsEnable) <> 0 Then
     Begin

BIN
demo/ImGuiDemo.exe


+ 70 - 52
demo/ImGuiDemo.lps

@@ -4,12 +4,13 @@
     <PathDelim Value="\"/>
     <Version Value="12"/>
     <BuildModes Active="Debug_windows"/>
-    <Units Count="55">
+    <Units Count="56">
       <Unit0>
         <Filename Value="ImGuiDemo.dpr"/>
         <IsPartOfProject Value="True"/>
         <IsVisibleTab Value="True"/>
-        <CursorPos X="2" Y="13"/>
+        <TopLine Value="187"/>
+        <CursorPos X="11" Y="201"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
       </Unit0>
@@ -25,7 +26,6 @@
         <Filename Value="imgui_extra.pas"/>
         <IsPartOfProject Value="True"/>
         <EditorIndex Value="-1"/>
-        <CursorPos X="2" Y="13"/>
         <UsageCount Value="200"/>
       </Unit2>
       <Unit3>
@@ -47,14 +47,16 @@
         <Filename Value="CustomNodeGraph.pas"/>
         <IsPartOfProject Value="True"/>
         <EditorIndex Value="-1"/>
-        <UsageCount Value="24"/>
+        <TopLine Value="216"/>
+        <CursorPos Y="174"/>
+        <UsageCount Value="26"/>
       </Unit5>
       <Unit6>
         <Filename Value="display.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="135"/>
         <CursorPos X="10" Y="143"/>
-        <UsageCount Value="194"/>
+        <UsageCount Value="193"/>
       </Unit6>
       <Unit7>
         <Filename Value="sdl2.pas"/>
@@ -62,92 +64,92 @@
         <EditorIndex Value="-1"/>
         <TopLine Value="9926"/>
         <CursorPos X="30" Y="9944"/>
-        <UsageCount Value="194"/>
+        <UsageCount Value="193"/>
       </Unit7>
       <Unit8>
         <Filename Value="..\fpimgui.pas"/>
         <EditorIndex Value="-1"/>
         <CursorPos X="16" Y="6"/>
-        <UsageCount Value="194"/>
+        <UsageCount Value="193"/>
       </Unit8>
       <Unit9>
         <Filename Value="..\examples\fpimgui_impl_sdlgl2.pas"/>
         <EditorIndex Value="-1"/>
-        <UsageCount Value="194"/>
+        <UsageCount Value="193"/>
       </Unit9>
       <Unit10>
         <Filename Value="..\ImGui.Types.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="518"/>
         <CursorPos X="23" Y="535"/>
-        <UsageCount Value="194"/>
+        <UsageCount Value="193"/>
       </Unit10>
       <Unit11>
         <Filename Value="ImGui.Enums.pas"/>
         <EditorIndex Value="-1"/>
-        <UsageCount Value="196"/>
+        <UsageCount Value="195"/>
       </Unit11>
       <Unit12>
         <Filename Value="..\impl\PasImGui.Impl.SDL2.pas"/>
         <EditorIndex Value="-1"/>
         <CursorPos X="27" Y="16"/>
-        <UsageCount Value="194"/>
+        <UsageCount Value="193"/>
       </Unit12>
       <Unit13>
         <Filename Value="..\impl\PasImGui.Impl.OpenGL3.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="36"/>
         <CursorPos X="56" Y="45"/>
-        <UsageCount Value="194"/>
+        <UsageCount Value="193"/>
       </Unit13>
       <Unit14>
         <Filename Value="..\PasImGui.Gen.Types.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="163"/>
         <CursorPos Y="177"/>
-        <UsageCount Value="199"/>
+        <UsageCount Value="198"/>
       </Unit14>
       <Unit15>
         <Filename Value="..\PasImGui.SDL2.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="114"/>
         <CursorPos X="52" Y="143"/>
-        <UsageCount Value="160"/>
+        <UsageCount Value="159"/>
       </Unit15>
       <Unit16>
         <Filename Value="..\PasImGui.Apis.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="106"/>
         <CursorPos X="31" Y="122"/>
-        <UsageCount Value="102"/>
+        <UsageCount Value="101"/>
       </Unit16>
       <Unit17>
         <Filename Value="..\PasImGui.Types.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="30"/>
         <CursorPos X="24" Y="40"/>
-        <UsageCount Value="101"/>
+        <UsageCount Value="100"/>
       </Unit17>
       <Unit18>
         <Filename Value="..\PasImGui.Enums.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="703"/>
         <CursorPos X="40" Y="729"/>
-        <UsageCount Value="96"/>
+        <UsageCount Value="95"/>
       </Unit18>
       <Unit19>
         <Filename Value="..\PasImGui.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="42"/>
         <CursorPos X="20" Y="58"/>
-        <UsageCount Value="94"/>
+        <UsageCount Value="93"/>
       </Unit19>
       <Unit20>
         <Filename Value="..\..\PasGen\PasImGui.Apis.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="1423"/>
         <CursorPos X="7" Y="1515"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="9"/>
       </Unit20>
       <Unit21>
         <Filename Value="..\..\PasGen\Full.pas"/>
@@ -155,7 +157,7 @@
         <EditorIndex Value="-1"/>
         <TopLine Value="709"/>
         <CursorPos X="23" Y="722"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="9"/>
       </Unit21>
       <Unit22>
         <Filename Value="..\..\PasGen\PasImGui.Enums.pas"/>
@@ -169,101 +171,102 @@
         <EditorIndex Value="-1"/>
         <TopLine Value="135"/>
         <CursorPos X="6" Y="150"/>
-        <UsageCount Value="20"/>
+        <UsageCount Value="19"/>
       </Unit23>
       <Unit24>
         <Filename Value="F:\FPCross\fpcsrc\rtl\inc\systemh.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="517"/>
         <CursorPos X="3" Y="530"/>
-        <UsageCount Value="4"/>
+        <UsageCount Value="3"/>
       </Unit24>
       <Unit25>
         <Filename Value="F:\FPCross\fpcsrc\rtl\win\wininc\defines.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="3011"/>
         <CursorPos X="6" Y="3021"/>
-        <UsageCount Value="3"/>
+        <UsageCount Value="2"/>
       </Unit25>
       <Unit26>
         <Filename Value="F:\FPCross\fpcsrc\rtl\inc\resh.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="48"/>
         <CursorPos X="10" Y="64"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="6"/>
       </Unit26>
       <Unit27>
         <Filename Value="..\SDL2-for-Pascal\units\sdlkeycode.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="17"/>
         <CursorPos X="37" Y="37"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="7"/>
       </Unit27>
       <Unit28>
         <Filename Value="..\SDL2-for-Pascal\units\sdlsyswm.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="224"/>
         <CursorPos X="4" Y="240"/>
-        <UsageCount Value="20"/>
+        <UsageCount Value="19"/>
       </Unit28>
       <Unit29>
         <Filename Value="..\SDL2-for-Pascal\units\sdlversion.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="20"/>
         <CursorPos X="3" Y="34"/>
-        <UsageCount Value="19"/>
+        <UsageCount Value="18"/>
       </Unit29>
       <Unit30>
         <Filename Value="..\SDL2-for-Pascal\units\sdl2.pas"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="186"/>
         <CursorPos X="10" Y="202"/>
-        <UsageCount Value="21"/>
+        <UsageCount Value="20"/>
       </Unit30>
       <Unit31>
         <Filename Value="..\SDL2-for-Pascal\units\sdlvideo.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="1333"/>
         <CursorPos X="10" Y="1348"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="4"/>
       </Unit31>
       <Unit32>
         <Filename Value="..\SDL2-for-Pascal\units\sdllog.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="76"/>
         <CursorPos Y="97"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="9"/>
       </Unit32>
       <Unit33>
         <Filename Value="..\SDL2-for-Pascal\units\sdlerror.inc"/>
         <EditorIndex Value="-1"/>
         <CursorPos X="10" Y="30"/>
-        <UsageCount Value="3"/>
+        <UsageCount Value="2"/>
       </Unit33>
       <Unit34>
         <Filename Value="F:\FPCross\fpcsrc\rtl\inc\currh.inc"/>
         <EditorIndex Value="-1"/>
         <CursorPos X="14" Y="22"/>
-        <UsageCount Value="3"/>
+        <UsageCount Value="2"/>
       </Unit34>
       <Unit35>
         <Filename Value="..\SDL2-for-Pascal\units\sdlmessagebox.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="92"/>
         <CursorPos X="10" Y="107"/>
-        <UsageCount Value="4"/>
+        <UsageCount Value="3"/>
       </Unit35>
       <Unit36>
         <Filename Value="..\impl\CImGui.Impl.OpenGL3.pas"/>
         <EditorIndex Value="-1"/>
-        <CursorPos X="51" Y="13"/>
+        <TopLine Value="37"/>
+        <CursorPos X="32" Y="63"/>
         <UsageCount Value="10"/>
       </Unit36>
       <Unit37>
         <Filename Value="..\impl\PasImGui.SDL2.pas"/>
         <EditorIndex Value="-1"/>
         <CursorPos X="2" Y="13"/>
-        <UsageCount Value="16"/>
+        <UsageCount Value="15"/>
       </Unit37>
       <Unit38>
         <Filename Value="..\impl\CImGui.Impl.SDL2.pas"/>
@@ -276,57 +279,60 @@
         <EditorIndex Value="-1"/>
         <TopLine Value="17"/>
         <CursorPos X="3" Y="30"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="7"/>
       </Unit39>
       <Unit40>
         <Filename Value="F:\FPCross\fpcsrc\rtl\unix\sysdlh.inc"/>
         <EditorIndex Value="-1"/>
         <CursorPos X="3" Y="28"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="7"/>
       </Unit40>
       <Unit41>
         <Filename Value="F:\FPCross\fpcsrc\rtl\win\sysdlh.inc"/>
         <EditorIndex Value="-1"/>
         <CursorPos X="3" Y="23"/>
-        <UsageCount Value="4"/>
+        <UsageCount Value="3"/>
       </Unit41>
       <Unit42>
         <Filename Value="F:\FPCross\fpcsrc\rtl\objpas\math.pp"/>
         <UnitName Value="Math"/>
         <EditorIndex Value="-1"/>
-        <TopLine Value="845"/>
-        <CursorPos X="3" Y="861"/>
-        <UsageCount Value="5"/>
+        <TopLine Value="852"/>
+        <CursorPos X="23" Y="870"/>
+        <UsageCount Value="10"/>
       </Unit42>
       <Unit43>
         <Filename Value="F:\FPCross\fpcsrc\rtl\inc\mathh.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="54"/>
-        <CursorPos X="45" Y="70"/>
-        <UsageCount Value="5"/>
+        <CursorPos X="5" Y="70"/>
+        <UsageCount Value="10"/>
       </Unit43>
       <Unit44>
         <Filename Value="..\src\PasImGui.Types.pas"/>
         <EditorIndex Value="-1"/>
-        <CursorPos X="2" Y="13"/>
+        <TopLine Value="111"/>
+        <CursorPos X="19" Y="126"/>
         <UsageCount Value="19"/>
       </Unit44>
       <Unit45>
         <Filename Value="..\src\PasImGui.Apis.pas"/>
         <EditorIndex Value="-1"/>
-        <CursorPos X="2" Y="13"/>
+        <TopLine Value="1381"/>
         <UsageCount Value="10"/>
       </Unit45>
       <Unit46>
         <Filename Value="..\src\PasImGui.Enums.pas"/>
         <EditorIndex Value="-1"/>
-        <CursorPos X="2" Y="13"/>
+        <TopLine Value="1050"/>
+        <CursorPos X="23" Y="1065"/>
         <UsageCount Value="24"/>
       </Unit46>
       <Unit47>
         <Filename Value="..\src\PasImGui.pas"/>
         <EditorIndex Value="-1"/>
-        <CursorPos X="2" Y="13"/>
+        <TopLine Value="816"/>
+        <CursorPos X="36" Y="830"/>
         <UsageCount Value="15"/>
       </Unit47>
       <Unit48>
@@ -334,28 +340,28 @@
         <EditorIndex Value="-1"/>
         <TopLine Value="46"/>
         <CursorPos X="27" Y="59"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="6"/>
       </Unit48>
       <Unit49>
         <Filename Value="F:\FPCross\fpcsrc\rtl\inc\cmem.pp"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="155"/>
         <CursorPos X="16" Y="53"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="6"/>
       </Unit49>
       <Unit50>
         <Filename Value="F:\FPCross\fpcsrc\rtl\inc\heaph.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="79"/>
         <CursorPos X="10" Y="102"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="6"/>
       </Unit50>
       <Unit51>
         <Filename Value="..\SDL2-for-Pascal\units\sdlhints.inc"/>
         <EditorIndex Value="-1"/>
         <TopLine Value="2410"/>
         <CursorPos Y="2426"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="6"/>
       </Unit51>
       <Unit52>
         <Filename Value="F:\FPCross\fpcsrc\packages\rtl-generics\src\generics.collections.pas"/>
@@ -378,8 +384,20 @@
         <TopLine Value="28"/>
         <UsageCount Value="10"/>
       </Unit54>
+      <Unit55>
+        <Filename Value="F:\FPCross\fpcsrc\rtl\x86_64\mathu.inc"/>
+        <EditorIndex Value="-1"/>
+        <TopLine Value="229"/>
+        <CursorPos X="47" Y="245"/>
+        <UsageCount Value="10"/>
+      </Unit55>
     </Units>
-    <JumpHistory HistoryIndex="-1"/>
+    <JumpHistory Count="1">
+      <Position1>
+        <Filename Value="ImGuiDemo.dpr"/>
+        <Caret Line="373" Column="19" TopLine="358"/>
+      </Position1>
+    </JumpHistory>
     <RunParams>
       <FormatVersion Value="2"/>
       <Modes ActiveMode="default"/>

+ 0 - 24
impl/CImGui.Impl.OpenGL3.pas

@@ -44,47 +44,23 @@ function  ImGui_ImplOpenGL3_CreateDeviceObjects(): Boolean; cdecl; external CIMG
 Procedure ImGui_ImplOpenGL3_DestroyDeviceObjects(); cdecl; external CIMGUI_LIB;
 
 function ImGui_Impl_OpenGL3_Init(const glsl_version: PAnsiChar): Boolean;
-{$IFDEF FPC}
-Var
-  saved: Cardinal;
-{$ENDIF}
 Begin
-  {$IFDEF FPC}saved := SetFpuFlags();{$ENDIF}
   Result := ImGui_ImplOpenGL3_Init(glsl_version);
-  {$IFDEF FPC}ResetFpuFlags(saved);{$ENDIF}
 end;
 
 procedure ImGui_Impl_OpenGL3_RenderDrawData(draw_data: PImDrawData);
-{$IFDEF FPC}
-Var
-  saved: Cardinal;
-{$ENDIF}
 Begin
-  {$IFDEF FPC}saved := SetFpuFlags();{$ENDIF}
   ImGui_ImplOpenGL3_RenderDrawData(draw_data);
-  {$IFDEF FPC}ResetFpuFlags(saved);{$ENDIF}
 end;
 
 procedure ImGui_Impl_OpenGL3_NewFrame();
-{$IFDEF FPC}
-Var
-  saved: Cardinal;
-{$ENDIF}
 Begin
-  {$IFDEF FPC}saved := SetFpuFlags();{$ENDIF}
   ImGui_ImplOpenGL3_NewFrame();
-  {$IFDEF FPC}ResetFpuFlags(saved);{$ENDIF}
 end;
 
 procedure ImGui_Impl_OpenGL3_Shutdown();
-{$IFDEF FPC}
-Var
-  saved: Cardinal;
-{$ENDIF}
 Begin
-  {$IFDEF FPC}saved := SetFpuFlags();{$ENDIF}
   ImGui_ImplOpenGL3_Shutdown();
-  {$IFDEF FPC}ResetFpuFlags(saved);{$ENDIF}
 end;
 
 

+ 3 - 101
src/PasImGui.Apis.pas

@@ -1402,110 +1402,12 @@ procedure igWindowPosRelToAbs( pOut : PImVec2; window : PImGuiWindow; p : ImVec2
 procedure igWindowRectAbsToRel( pOut : PImRect; window : PImGuiWindow; r : ImRect ); cdecl; external CIMGUI_LIB;
 procedure igWindowRectRelToAbs( pOut : PImRect; window : PImGuiWindow; r : ImRect ); cdecl; external CIMGUI_LIB;
 
-{$IFDEF FPC}
-// From mORMot2 "mormot.lib.static.pas"
-type
-  /// define SetFpuFlags/ResetFpuFlags context
-  // - external libraries coded in C are likely to disable FPU exceptions,
-  // whereas Delphi/FPC code expects FPU exceptions to be raised ASAP
-  // - ffLibrary is used before calling an external library
-  // - ffPascal before calling pascal code from an external library callback
-  TFpuFlags = (
-    ffLibrary,
-    ffPascal);
-
-{$ifdef CPUINTEL}
-var
-  /// direct efficient x87 / SSE2 FPU flags for rounding and exceptions
-  _FPUFLAGS: array[TFpuFlags] of cardinal = (
-    {$ifdef CPU64}
-      $1FA0, $1920);
-    {$else}
-      $137F, $1372);
-    {$endif CPU64}
-
-{$else}
-var
-  /// on non Intel/AMD, use slower but cross-platform RTL Math unit
-  // - defined as var for runtime customization
-  _FPUFLAGS: array[TFpuFlags] of TFPUExceptionMask = (
-    // ffLibrary
-    [exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision],
-    // ffPascal
-    [exDenormalized, exUnderflow, exPrecision]);
-
-{$endif CPUINTEL}
-
-
-/// mask/unmask all FPU exceptions, according to the running CPU
-// - returns the previous exception flags, for ResetFpuFlags() call
-// - x87 flags are $1372 for pascal, or $137F for library
-// - sse flags are $1920 for pascal, or $1FA0 for library
-// - on non Intel/AMD CPUs, will use TFPUExceptionMask from the RTL Math unit
-// - do nothing and return -1 if the supplied flags are the one already set
-function SetFpuFlags(flags: TFpuFlags = ffLibrary): cardinal;
-
-/// restore the FPU exceptions flags as overriden by SetFpuFlags()
-// - do nothing if the saved flags are the one already set, i.e. -1
-procedure ResetFpuFlags(saved: cardinal);
-{$ELSE}
-
-{$ENDIF}
-
 implementation
-{$IFDEF FPC}
   uses
     math;
 
-{ ********************** Cross-Platform FPU Exceptions Masking }
-const
-  _FPUFLAGSIDEM = cardinal(-1); // fake value used for faster nested calls
-
-function _GetFlags: cardinal;
-  {$ifdef HASINLINE} inline; {$endif}
-begin
-  {$ifdef CPUINTEL}
-    {$ifdef CPU64}
-    result := GetMXCSR;
-    {$else}
-    result := Get8087CW;
-    {$endif CPU64}
-  {$else}
-    result := cardinal(GetExceptionMask);
-  {$endif CPUINTEL}
-end;
-
-procedure _SetFlags(flags: cardinal);
-  {$ifdef HASINLINE} inline; {$endif}
-begin
-  {$ifdef CPUINTEL}
-    {$ifdef CPU64}
-    SetMXCSR(flags);
-    {$else}
-    Set8087CW(flags);
-    {$endif CPU64}
-  {$else}
-    SetExceptionMask(TFPUExceptionMask(flags));
-  {$endif CPUINTEL}
-end;
-
-function SetFpuFlags(flags: TFpuFlags): cardinal;
-var
-  new: cardinal;
-begin
-  result := _GetFlags;
-  new := cardinal(_FPUFLAGS[flags]);
-  if new <> result then
-    _SetFlags(new)
-  else
-    result := _FPUFLAGSIDEM;
-end;
-
-procedure ResetFpuFlags(saved: cardinal);
-begin
-  if saved <> _FPUFLAGSIDEM then
-    _SetFlags(saved);
-end;
-{$ENDIF}
+initialization
+  // Disabling Floating-Point Exceptions
+  SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
 
 end.

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 1902
src/PasImGui.pas


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است