Compare commits

..

177 Commits

Author SHA1 Message Date
icex2
18f84e4751 merge commit for archive created by Sapling 2025-02-20 14:42:23 +01:00
icex2
19f0776627 doc: Dev journal entry about IIDX engine and syncbook
Due to recent development of tools and discussions, this
is something that came up and has probably been overdue
for ages.

Document key concepts of how the iidx engine works regaring
rendering, game loop and (song) sync.

Add a “syncbook” that provides context and guidelines how
to configure any (modern) system to work properly with iidx.
2025-02-20 14:42:15 +01:00
icex2
aad38449e3 merge commit for archive created by Sapling 2025-02-20 12:31:48 +01:00
icex2
1c0092c9be doc: Dev journal entry about IIDX engine and syncbook
Due to recent development of tools and discussions, this
is something that came up and has probably been overdue
for ages.

Document key concepts of how the iidx engine works regaring
rendering, game loop and (song) sync.

Add a “syncbook” that provides context and guidelines how
to configure any (modern) system to work properly with iidx.
2025-02-20 12:31:36 +01:00
icex2
1db5260a59 Merge c337bdb7c0 into sapling-pr-archive-icex2 2025-02-20 12:21:56 +01:00
icex2
c337bdb7c0 doc: Dev journal entry about IIDX engine and syncbook
Due to recent development of tools and discussions, this
is something that came up and has probably been overdue
for ages.

Document key concepts of how the iidx engine works regaring
rendering, game loop and (song) sync.

Add a “syncbook” that provides context and guidelines how
to configure any (modern) system to work properly with iidx.
2025-02-20 12:20:55 +01:00
icex2
9cb37ccc11 merge commit for archive created by Sapling 2025-02-19 19:48:42 +01:00
icex2
549e50dfa7 fix: Missing closing bracket
Fix mistake that happened during conflict resolution
before the merge.
2025-02-19 19:48:30 +01:00
icex2
d5e4cc3447 Merge ae02d6556b into sapling-pr-archive-icex2 2025-02-19 19:42:55 +01:00
icex2
ae02d6556b feat(nvgpu): Add —overwrite-exists flag for profile creation
When running this in a script on startup to ensure
whatever configuration is required to be created is
created, this avoids several commands to first
check if the profile exists, delete it, then re-create it.
2025-02-19 19:42:48 +01:00
icex2
071a3994ed Merge 5bee76e553 into sapling-pr-archive-icex2 2025-02-19 19:41:41 +01:00
icex2
5bee76e553 feat(nvgpu): Add —overwrite-exists flag for profile creation
When running this in a script on startup to ensure
whatever configuration is required to be created is
created, this avoids several commands to first
check if the profile exists, delete it, then re-create it.
2025-02-19 19:41:33 +01:00
icex2
3c2dda505e fix(nvgpu): Initialize value of parameter to fix INVALID_ARGUMENT
As stated by the documentation in nvapi.h, path_info_count
must be set to the value 0 in this case.
2025-02-19 19:41:33 +01:00
icex2
d840f7bb8f Merge df4f646b70 into sapling-pr-archive-icex2 2025-02-19 19:40:27 +01:00
icex2
df4f646b70 feat(nvgpu): Add —overwrite-exists flag for profile creation
When running this in a script on startup to ensure
whatever configuration is required to be created is
created, this avoids several commands to first
check if the profile exists, delete it, then re-create it.
2025-02-19 19:40:21 +01:00
icex2
ca9cac9c19 fix(nvgpu): Initialize value of parameter to fix INVALID_ARGUMENT
As stated by the documentation in nvapi.h, path_info_count
must be set to the value 0 in this case.
2025-02-19 19:40:21 +01:00
icex2
7943ecffcd fix(nvgpu): Missing error handling not returning
If fetching the configuration fails, don’t continue with
processing any non-existing data.
2025-02-19 19:40:21 +01:00
icex2
51ce7c739a Merge c6180bdf47 into sapling-pr-archive-icex2 2025-02-19 19:39:17 +01:00
icex2
c6180bdf47 feat(nvgpu): Add —overwrite-exists flag for profile creation
When running this in a script on startup to ensure
whatever configuration is required to be created is
created, this avoids several commands to first
check if the profile exists, delete it, then re-create it.
2025-02-19 19:39:10 +01:00
icex2
c3a337ceb4 fix(nvgpu): Initialize value of parameter to fix INVALID_ARGUMENT
As stated by the documentation in nvapi.h, path_info_count
must be set to the value 0 in this case.
2025-02-19 19:39:10 +01:00
icex2
a3d890dcd7 fix(nvgpu): Missing error handling not returning
If fetching the configuration fails, don’t continue with
processing any non-existing data.
2025-02-19 19:39:10 +01:00
icex2
ee3d1d2592 chore: Remove TODO
Forgot to remove that after adressing the issue of needing
three calls in nvgpu to get the config data correctly.
2025-02-19 19:39:10 +01:00
icex2
4159813873 merge commit for archive created by Sapling 2025-02-19 19:36:53 +01:00
icex2
c5083a6d4a feat(nvgpu): Add —overwrite-exists flag for profile creation
When running this in a script on startup to ensure
whatever configuration is required to be created is
created, this avoids several commands to first
check if the profile exists, delete it, then re-create it.
2025-02-19 19:36:36 +01:00
icex2
8752c7dcc5 fix(nvgpu): Initialize value of parameter to fix INVALID_ARGUMENT
As stated by the documentation in nvapi.h, path_info_count
must be set to the value 0 in this case.
2025-02-19 19:36:36 +01:00
icex2
6276cb4e97 fix(nvgpu): Missing error handling not returning
If fetching the configuration fails, don’t continue with
processing any non-existing data.
2025-02-19 19:36:36 +01:00
icex2
fcbb4160ee chore: Remove TODO
Forgot to remove that after adressing the issue of needing
three calls in nvgpu to get the config data correctly.
2025-02-19 19:36:36 +01:00
icex2
9bcbe9170f feat: Extend monitor check tool, vsync and response time tests
Adding two more tests that have been proven very useful
for debugging monitor issues that caused problems with IIDX.

The vsync test flickers a text snippet between red and cyan on
every even and uneven frame. If vsync works correctly, the text
appears grey to the human eye. If there are issues like re-displaying
a previous frame or a dropped frame, this appears as the text
rendering red or cyan.

The response time test scrolls two simple blocks/lines vertically
to check if they creating ghosting/smearing on the display.

The tool now supports an interactive and command line mode.

Interactive mode is useful for running different tests on the setup
while the command line mode can be used to ran these tests
with fixed parameters and for a fixed amount of time, e.g. in a shell
script, for automation purpose.

The tool still has a few obvious imperfections like scaling issues on
different resolutions. Considering the basic functionality is given,
further improvements can follow in future iterations.
2025-02-19 19:36:27 +01:00
icex2
e74e3f1472 Merge 2062b803ff into sapling-pr-archive-icex2 2025-02-13 15:05:48 +01:00
icex2
2062b803ff feat: d3d9-frame-graph-hook, add frame rate graph view
Have a checkbox to switch to a frame graph focused view
which saves a bunch of math when it’s more useful to
focus on the frame/refresh rate than the frame time values.
2025-02-13 15:05:32 +01:00
icex2
7391cfa555 merge commit for archive created by Sapling 2025-02-13 14:53:12 +01:00
icex2
06d4467d5a feat: nvgpu, add option to enable gpu scaling
GPU scaling allows high quality upscaling of older games
to the native resolution of the screen. The output frame
quality is significantly sharper than the fairly simple
frame buffer upscaling of bemanitools.
2025-02-13 14:52:49 +01:00
icex2
b0b380e70c Merge f0b3556ac5 into sapling-pr-archive-icex2 2025-02-13 14:47:37 +01:00
icex2
f0b3556ac5 feat: nvgpu, make test timeout parameter optional
10 seconds is what the nvidia control panel also
has for the test timeout. Can still be changed if
shorter or longer timeouts are desired, but 10
seconds should be a general fine timeout value
to have this optional.
2025-02-13 14:47:22 +01:00
icex2
54284adf5f merge commit for archive created by Sapling 2025-02-13 14:42:06 +01:00
icex2
451f9d4021 feat: d3d9-monitor-check add result-timeout-secs parameter
Allow changing the time in seconds how long the results
are being displayed before exiting
2025-02-13 14:38:07 +01:00
icex2
1b0426941d merge commit for archive created by Sapling 2025-02-13 14:34:30 +01:00
icex2
f5a82fe049 feat: d3d9-monitor-check allow skip results
Allow pressing ESC to skip results and not having
to wait for 5 secs
2025-02-13 14:34:13 +01:00
icex2
2a5ddacb36 Merge 9246f72b80 into sapling-pr-archive-icex2 2025-02-13 14:30:12 +01:00
icex2
9246f72b80 feat: Improve d3d9-monitor-check command line args
Use more user-friendly seconds for total and warm-up time
instead of frames. Use the refresh rate to calculcate the
total frame count internally for the test.
2025-02-13 14:30:05 +01:00
icex2
f6d8e30671 Merge 8afab5c232 into sapling-pr-archive-icex2 2025-02-13 14:29:28 +01:00
icex2
8afab5c232 feat: Improve d3d9-monitor-check command line args
Use more user-friendly seconds for total and warm-up time
instead of frames. Use the refresh rate to calculcate the
total frame count internally for the test.
2025-02-13 14:29:21 +01:00
icex2
c0be02a24f feat: d3d9-monitor-check tool (#322)
A separate application to run the infamous IIDX “monitor check”.

The on-screen output has been enhanced to provide more
detailed information about the on-going process. The tool
furthermore allows basic querying of adapter and adapter
modes information from the command line. These additional
options can be useful to gather more debug information
or select correct parameters for the monitor test from actually
supported mode parameters by the adapter.

The tool has been tested on an actual cabinet with nvgpu
setting different custom timings. The accuracy seems to be
even higher than what IIDX’s monitor check is actually showing.
For example, with a custom timing of 59.900, the tool yields 59.902.
Meanwhile, the monitor check of iidx 29 59.8981 hz to 59.8997 hz
on screen.

This doesn’t mean the game’s getting inaccurate values. The game
actually syncs and plays just fine. However, the game’s monitor check
cannot be used as a reference for “getting the avg. refresh rate”
value as an input parameter for other tools, e.g. chart patching with
btools.

Co-authored-by: icex2 <djh.icex2@gmail.com>
2025-02-13 14:28:34 +01:00
icex2
e7459659dd merge commit for archive created by Sapling 2025-02-13 14:27:16 +01:00
icex2
3aa128e525 feat: Improve d3d9-monitor-check command line args
Use more user-friendly seconds for total and warm-up time
instead of frames. Use the refresh rate to calculcate the
total frame count internally for the test.
2025-02-13 14:26:33 +01:00
icex2
74bdd65098 Merge a66aba45b9 into sapling-pr-archive-icex2 2025-02-11 15:52:28 +01:00
icex2
a66aba45b9 feat: d3d9-monitor-check tool
A separate application to run the infamous IIDX “monitor check”.

The on-screen output has been enhanced to provide more
detailed information about the on-going process. The tool
furthermore allows basic querying of adapter and adapter
modes information from the command line. These additional
options can be useful to gather more debug information
or select correct parameters for the monitor test from actually
supported mode parameters by the adapter.

The tool has been tested on an actual cabinet with nvgpu
setting different custom timings. The accuracy seems to be
even higher than what IIDX’s monitor check is actually showing.
For example, with a custom timing of 59.900, the tool yields 59.902.
Meanwhile, the monitor check of iidx 29 59.8981 hz to 59.8997 hz
on screen.

This doesn’t mean the game’s getting inaccurate values. The game
actually syncs and plays just fine. However, the game’s monitor check
cannot be used as a reference for “getting the avg. refresh rate”
value as an input parameter for other tools, e.g. chart patching with
btools.
2025-02-11 15:52:15 +01:00
icex2
1373e9f1f4 Merge 9e2319bd13 into sapling-pr-archive-icex2 2025-02-11 15:34:43 +01:00
icex2
9e2319bd13 feat: Bump iidxhook9 supported versions, EPOLIS “support"
No changes required, just make support visible by reflecting
it in distribution package naming, documentation and
filenaming
2025-02-11 15:34:38 +01:00
icex2
5687392a92 merge commit for archive created by Sapling 2025-02-09 16:16:20 +01:00
icex2
addcdf8d16 doc: Dev journal entry about IIDX engine
Due to recent development of tools and discussions, this
is something that came up and has probably been overdue
for ages.
2025-02-09 16:16:13 +01:00
icex2
1fbb5ac39f merge commit for archive created by Sapling 2025-02-09 15:55:07 +01:00
icex2
191e1e74f0 doc: Dev journal entry about IIDX engine
Due to recent development of tools and discussions, this
is something that came up and has probably been overdue
for ages.
2025-02-09 15:54:58 +01:00
icex2
34807f0b9d Merge d442177f21 into sapling-pr-archive-icex2 2025-02-09 15:21:46 +01:00
icex2
d442177f21 doc: Dev journal entry about IIDX engine
Due to recent development of tools and discussions, this
is something that came up and has probably been overdue
for ages.
2025-02-09 15:21:40 +01:00
icex2
af372df06b Merge 4ed3c97c2a into sapling-pr-archive-icex2 2025-02-08 23:22:01 +01:00
icex2
4ed3c97c2a feat: Add separate d3d9-frame-graph-hook
Allow this to be hooked by any application with a d3d9
render backend. This is not compatible with d3d9ex.
2025-02-08 23:21:49 +01:00
icex2
0d876fc806 merge commit for archive created by Sapling 2025-02-08 23:20:46 +01:00
icex2
2b08a0cc1a feat: Add frame time performance graph imgui overlay
A overlay window showing the a frame time graph with
the current frame time, ~10 seconds of history as well
as reference lines for the current avg. and a configurable
target frame time.

This is considered a debug tool to support in any efforts
that are related to understanding current frame times
of the games. More specifically this can be used to asses
impact of any bemanitools hooking to the game’s main
(render) loop.
2025-02-08 23:20:31 +01:00
icex2
d8e604cdd9 Merge 95f792f655 into sapling-pr-archive-icex2 2025-02-08 23:18:31 +01:00
icex2
95f792f655 feat: Add bt d3d9 hook specific imgui overlay
For now, we focus on internal overlays for bemanitools
that hook into an existing d3d9 context. The current
abstraction is fairly thin and should be fine as a start.

Implementations are called “components” and hook
up with a single frame_update function to execute
and logic and drawing updates with imgui
2025-02-08 23:18:16 +01:00
icex2
7b8eec72d3 merge commit for archive created by Sapling 2025-02-08 23:16:47 +01:00
icex2
83621fa5d5 fix: Add missing hook_table_revert function
The function signature was already defined in the header
but the implementation in the module missing
2025-02-08 23:16:40 +01:00
icex2
563d6dd793 Merge e69c75bf7f into sapling-pr-archive-icex2 2025-02-08 23:14:58 +01:00
icex2
e69c75bf7f fix: Add missing hook_table_revert function
The function signature was already defined in the header
but the implementation in the module missing
2025-02-08 23:14:25 +01:00
icex2
847cc3322e Merge 48cd2bc687 into sapling-pr-archive-icex2 2025-02-08 23:12:42 +01:00
icex2
48cd2bc687 feat: Integrate imgui library
Version 1.91.7 of the imgui library with the cimgui wrapper.

imgui allows us to easily create minimal and powerful UI for
use-cases like in-game overlays or separate tooling.

The additional wrappers cimgui_impl_dx9 and cimgui_impl_win32
were added to provide a full C linkage integration for the rest
of the code base.

Tweaks to the makefile were kept to a minimum but enable
compilation of C++ since imgui is C++ based.

Remark: At this point bemanitools itself is still to be kept a pure
C codebase. Due to the lack of proper module/library management
with the current build system in bemanitools 5, proper separation
of concerns and clean integration with external libraries isn’t
possible with reasonable effort.
2025-02-08 23:11:59 +01:00
icex2
3db8bc4898 Merge 9b5f627dd1 into sapling-pr-archive-icex2 2025-02-08 23:02:32 +01:00
icex2
9b5f627dd1 feat: nvgpu tool for tweaking nvidia gpu driver settings
An open source re-implementation of the “NvDisplayConfigLDJ"
tool with additional enhancements.

This can be used to tweak your nvidia GPU driver settings to
create custom display timings to address IIDX’s requirement
if expecting proper display timings. This can also be used for
any legacy IIDX versions that even expect very specific display
timings, e.g. 59.95 or 60.05 hz.

Furthermore, creating application profiles allows further tweaks
to important GPU settings such as the current performance mode
setting. This is crucial to ensure the GPU is not going into any
kind of power saving states which results in non-smooth
scrolling during gameplay and micro stuttering that cannot
be measured on application level.
2025-02-08 23:02:27 +01:00
icex2
29f57065fe merge commit for archive created by Sapling 2025-02-08 23:01:49 +01:00
icex2
05889947fe feat: nvgpu tool for tweaking nvidia gpu driver settings
An open source re-implementation of the “NvDisplayConfigLDJ"
tool with additional enhancements.

This can be used to tweak your nvidia GPU driver settings to
create custom display timings to address IIDX’s requirement
if expecting proper display timings. This can also be used for
any legacy IIDX versions that even expect very specific display
timings, e.g. 59.95 or 60.05 hz.

Furthermore, creating application profiles allows further tweaks
to important GPU settings such as the current performance mode
setting. This is crucial to ensure the GPU is not going into any
kind of power saving states which results in non-smooth
scrolling during gameplay and micro stuttering that cannot
be measured on application level.
Summary:

Test Plan:
2025-02-08 23:00:58 +01:00
icex2
2a34bb19da Merge 8b22ef1e8c into sapling-pr-archive-icex2 2025-02-08 22:44:01 +01:00
icex2
8b22ef1e8c feat: Add iidxio-async implementation
A shim library implementing the same concept as the already
existing ddrio-async library. The iidxio implementation takes
another iidxio library and runs it asynchronously which may
improve performance for certain iidxio implementations,
e.g. if the send and receive functions are driving actual IO
calls synchrously and are expensive.

This is not a replacement for a well engineered and proper
implementation of a iidxio library for any specific use-case.
It does not fix bad performance of existing implementations,
i.e. if the poll rate is too low because actual IO is too slow.

Use with caution and know why and when you need to use
it.
2025-02-08 22:42:52 +01:00
icex2
b2006ec9be merge commit for archive created by Sapling 2025-02-08 22:39:49 +01:00
icex2
db6e7a6ad9 feat: d3d9-monitor-check tool
A separate application to run the infamous IIDX “monitor check”.

The on-screen output has been enhanced to provide more
detailed information about the on-going process. The tool
furthermore allows basic querying of adapter and adapter
modes information from the command line. These additional
options can be useful to gather more debug information
or select correct parameters for the monitor test from actually
supported mode parameters by the adapter.

The tool has been tested on an actual cabinet with nvgpu
setting different custom timings. The accuracy seems to be
even higher than what IIDX’s monitor check is actually showing.
For example, with a custom timing of 59.900, the tool yields 59.902.
Meanwhile, the monitor check of iidx 29 59.8981 hz to 59.8997 hz
on screen.

This doesn’t mean the game’s getting inaccurate values. The game
actually syncs and plays just fine. However, the game’s monitor check
cannot be used as a reference for “getting the avg. refresh rate”
value as an input parameter for other tools, e.g. chart patching with
btools.
2025-02-08 22:39:41 +01:00
icex2
f15eec50fe Merge 27bb8a0e2d into sapling-pr-archive-icex2 2025-02-08 22:17:30 +01:00
icex2
27bb8a0e2d feat: d3d9-monitor-check tool
A separate application to run the infamous IIDX “monitor check”.

The on-screen output has been enhanced to provide more
detailed information about the on-going process. The tool
furthermore allows basic querying of adapter and adapter
modes information from the command line. These additional
options can be useful to gather more debug information
or select correct parameters for the monitor test from actually
supported mode parameters by the adapter.

The tool has been tested on an actual cabinet with nvgpu
setting different custom timings. The accuracy seems to be
even higher than what IIDX’s monitor check is actually showing.
For example, with a custom timing of 59.900, the tool yields 59.902.
Meanwhile, the monitor check of iidx 30 yields ~XXX TODO.
2025-02-08 22:17:27 +01:00
icex2
e0c7141896 Merge 5f5824f9f8 into sapling-pr-archive-icex2 2025-02-08 22:17:05 +01:00
icex2
5f5824f9f8 feat: d3d9-monitor-check tool
Summary:

Test Plan:
A separate application to run the infamous IIDX “monitor check”.

The on-screen output has been enhanced to provide more
detailed information about the on-going process. The tool
furthermore allows basic querying of adapter and adapter
modes information from the command line. These additional
options can be useful to gather more debug information
or select correct parameters for the monitor test from actually
supported mode parameters by the adapter.

The tool has been tested on an actual cabinet with nvgpu
setting different custom timings. The accuracy seems to be
even higher than what IIDX’s monitor check is actually showing.
For example, with a custom timing of 59.900, the tool yields 59.902.
Meanwhile, the monitor check of iidx 30 yields ~XXX TODO.
2025-02-08 22:16:55 +01:00
icex2
9cf9cac4e3 merge commit for archive created by Sapling 2025-02-07 22:41:56 +01:00
icex2
a11c7a0704 feat: Add separate d3d9-frame-graph-hook
Allow this to be hooked by any application with a d3d9
render backend. This is not compatible with d3d9ex.
2025-02-07 22:41:44 +01:00
icex2
83473a83be feat: nvgpu tool for tweaking nvidia gpu driver settings
An open source re-implementation of the “NvDisplayConfigLDJ"
tool with additional enhancements.

This can be used to tweak your nvidia GPU driver settings to
create custom display timings to address IIDX’s requirement
if expecting proper display timings. This can also be used for
any legacy IIDX versions that even expect very specific display
timings, e.g. 59.95 or 60.05 hz.

Furthermore, creating application profiles allows further tweaks
to important GPU settings such as the current performance mode
setting. This is crucial to ensure the GPU is not going into any
kind of power saving states which results in non-smooth
scrolling during gameplay and micro stuttering that cannot
be measured on application level.
Summary:

Test Plan:
2025-02-07 22:41:44 +01:00
icex2
aa3e7d307d feat: Add frame time performance graph imgui overlay
A overlay window showing the a frame time graph with
the current frame time, ~10 seconds of history as well
as reference lines for the current avg. and a configurable
target frame time.

This is considered a debug tool to support in any efforts
that are related to understanding current frame times
of the games. More specifically this can be used to asses
impact of any bemanitools hooking to the game’s main
(render) loop.
2025-02-07 22:41:44 +01:00
icex2
1800f75f3d feat: Add bt d3d9 hook specific imgui overlay
For now, we focus on internal overlays for bemanitools
that hook into an existing d3d9 context. The current
abstraction is fairly thin and should be fine as a start.

Implementations are called “components” and hook
up with a single frame_update function to execute
and logic and drawing updates with imgui
2025-02-07 22:41:44 +01:00
icex2
c0289b14d3 fix: Add missing hook_table_revert function
The function signature was already defined in the header
but the implementation in the module missing
2025-02-07 22:41:44 +01:00
icex2
d17dcea594 feat: Integrate imgui library, squash to initial integration
Version 1.91.7 of the imgui library with the cimgui wrapper.

imgui allows us to easily create minimal and powerful UI for
use-cases like in-game overlays or separate tooling.

The additional wrappers cimgui_impl_dx9 and cimgui_impl_win32
were added to provide a full C linkage integration for the rest
of the code base.

Tweaks to the makefile were kept to a minimum but enable
compilation of C++ since imgui is C++ based.

Remark: At this point bemanitools itself is still to be kept a pure
C codebase. Due to the lack of proper module/library management
with the current build system in bemanitools 5, proper separation
of concerns and clean integration with external libraries isn’t
possible with reasonable effort.


Summary:

Test Plan:
2025-02-07 22:41:44 +01:00
icex2
002a5727ef Merge 1e4fffb5f9 into sapling-pr-archive-icex2 2025-02-07 16:17:23 +01:00
icex2
1e4fffb5f9 feat: Add separate d3d9-frame-graph-hook
Allow this to be hooked by any application with a d3d9
render backend. This is not compatible with d3d9ex.
2025-02-07 16:17:13 +01:00
icex2
93fe44b46e Merge e12eb2b969 into sapling-pr-archive-icex2 2025-02-07 16:15:55 +01:00
icex2
e12eb2b969 feat: Add separate d3d9-frame-graph-hook
Allow this to be hooked by any application with a d3d9
render backend. This is not compatible with d3d9ex.
2025-02-07 16:15:44 +01:00
icex2
0afadc6576 Merge 8b82b32894 into sapling-pr-archive-icex2 2025-02-07 15:19:17 +01:00
icex2
8b82b32894 feat: Integrate frame time performance graph into iidxhook 1-8
Integrate the previously created frame time graph component
into iidxhook 1 to 8. iidxhook9 uses d3d9ex which still requires
a separate hook implementation for imgui.

Guard the feature with a switch as it might have some performance
impact and it’s something that is only required to be turned on
when needed.
2025-02-07 15:19:02 +01:00
icex2
8efeb68c75 feat: Add frame time performance graph imgui overlay
A overlay window showing the a frame time graph with
the current frame time, ~10 seconds of history as well
as reference lines for the current avg. and a configurable
target frame time.

This is considered a debug tool to support in any efforts
that are related to understanding current frame times
of the games. More specifically this can be used to asses
impact of any bemanitools hooking to the game’s main
(render) loop.
2025-02-07 15:14:25 +01:00
icex2
d482acd533 feat: Add bt d3d9 hook specific imgui overlay
For now, we focus on internal overlays for bemanitools
that hook into an existing d3d9 context. The current
abstraction is fairly thin and should be fine as a start.

Implementations are called “components” and hook
up with a single frame_update function to execute
and logic and drawing updates with imgui
2025-02-07 15:12:21 +01:00
icex2
8d49bd8f40 fix: Add missing hook_table_revert function
The function signature was already defined in the header
but the implementation in the module missing
2025-02-07 15:10:31 +01:00
icex2
d977a0bf35 feat: Integrate imgui library, squash to initial integration
Version 1.91.7 of the imgui library with the cimgui wrapper.

imgui allows us to easily create minimal and powerful UI for
use-cases like in-game overlays or separate tooling.

The additional wrappers cimgui_impl_dx9 and cimgui_impl_win32
were added to provide a full C linkage integration for the rest
of the code base.

Tweaks to the makefile were kept to a minimum but enable
compilation of C++ since imgui is C++ based.

Remark: At this point bemanitools itself is still to be kept a pure
C codebase. Due to the lack of proper module/library management
with the current build system in bemanitools 5, proper separation
of concerns and clean integration with external libraries isn’t
possible with reasonable effort.


Summary:

Test Plan:
2025-02-07 15:10:31 +01:00
icex2
dab2230a1c merge commit for archive created by Sapling 2025-02-07 15:04:02 +01:00
icex2
d25d49b668 fix: Add missing hook_table_revert function
The function signature was already defined in the header
but the implementation in the module missing
2025-02-07 15:03:46 +01:00
icex2
8282a9f3f4 TODO split to two features: imgui-bt abstraction layer + first component frame graph
Summary:

Test Plan:
Summary:

Test Plan:
2025-02-07 15:02:36 +01:00
icex2
2c00da6232 feat: Integrate imgui library
Version 1.91.7 of the imgui library with the cimgui wrapper.

imgui allows us to easily create minimal and powerful UI for
use-cases like in-game overlays or separate tooling.

The additional wrappers cimgui_impl_dx9 and cimgui_impl_win32
were added to provide a full C linkage integration for the rest
of the code base.

Tweaks to the makefile were kept to a minimum but enable
compilation of C++ since imgui is C++ based.

Remark: At this point bemanitools itself is still to be kept a pure
C codebase. Due to the lack of proper module/library management
with the current build system in bemanitools 5, proper separation
of concerns and clean integration with external libraries isn’t
possible with reasonable effort.
2025-02-07 13:23:21 +01:00
icex2
cf8df078f5 Merge 4d8c9359a1 into sapling-pr-archive-icex2 2025-02-07 13:22:26 +01:00
icex2
4d8c9359a1 feat: Add warning if vsync is not enabled
Something I ran into by accident during testing and
development that I had vsync turned off by accident.
Increase visibility in the logs.
2025-02-07 13:22:11 +01:00
icex2
c33e9bb06a Merge 77ff211c68 into sapling-pr-archive-icex2 2025-02-07 13:11:56 +01:00
icex2
77ff211c68 feat: Integrate imgui library
Version 1.91.7 of the imgui library with the cimgui wrapper.

imgui allows us to easily create minimal and powerful UI for
use-cases like in-game overlays or separate tooling.

The additional wrappers cimgui_impl_dx9 and cimgui_impl_win32
were added to provide a full C linkage integration for the rest
of the code base.

Tweaks to the makefile were kept to a minimum but enable
compilation of C++ since imgui is C++ based.

Remark: At this point bemanitools itself is still to be kept a pure
C codebase. Due to the lack of proper module/library management
with the current build system in bemanitools 5, proper separation
of concerns and clean integration with external libraries isn’t
possible with reasonable effort.
2025-02-07 13:11:48 +01:00
icex2
0257ad6b42 Merge 15a1762837 into sapling-pr-archive-icex2 2025-02-07 13:00:37 +01:00
icex2
15a1762837 feat: nvgpu tool for tweaking nvidia gpu driver settings
An open source re-implementation of the “NvDisplayConfigLDJ"
tool with additional enhancements.

This can be used to tweak your nvidia GPU driver settings to
create custom display timings to address IIDX’s requirement
if expecting proper display timings. This can also be used for
any legacy IIDX versions that even expect very specific display
timings, e.g. 59.95 or 60.05 hz.

Furthermore, creating application profiles allows further tweaks
to important GPU settings such as the current performance mode
setting. This is crucial to ensure the GPU is not going into any
kind of power saving states which results in non-smooth
scrolling during gameplay and micro stuttering that cannot
be measured on application level.
2025-02-07 13:00:29 +01:00
icex2
d92987b229 Merge 5f9aaeddf9 into sapling-pr-archive-icex2 2025-02-07 12:59:34 +01:00
icex2
5f9aaeddf9 feat: nvgpu tool for tweaking nvidia gpu driver settings
An open source re-implementation of the “NvDisplayConfigLDJ"
tool with additional enhancements.

This can be used to tweak your nvidia GPU driver settings to
create custom display timings to address IIDX’s requirement
if expecting proper display timings. This can also be used for
any legacy IIDX versions that even expect very specific display
timings, e.g. 59.95 or 60.05 hz.

Furthermore, creating application profiles allows further tweaks
to important GPU settings such as the current performance mode
setting. This is crucial to ensure the GPU is not going into any
kind of power saving states which results in non-smooth
scrolling during gameplay and micro stuttering that cannot
be measured on application level.
Summary:

Test Plan:
2025-02-07 12:59:28 +01:00
icex2
4cbef617a8 Merge 218ffe72c1 into sapling-pr-archive-icex2 2025-02-07 12:38:42 +01:00
icex2
2ca95ab6d8 Merge 61691f06a7 into sapling-pr-archive-icex2 2025-02-07 12:38:30 +01:00
icex2
61691f06a7 feat: nvgpu tool for tweaking nvidia gpu driver settings
An open source re-implementation of the “NvDisplayConfigLDJ"
tool with additional enhancements.

This can be used to tweak your nvidia GPU driver settings to
create custom display timings to address IIDX’s requirement
if expecting proper display timings. This can also be used for
any legacy IIDX versions that even expect very specific display
timings, e.g. 59.95 or 60.05 hz.

Furthermore, creating application profiles allows further tweaks
to important GPU settings such as the current performance mode
setting. This is crucial to ensure the GPU is not going into any
kind of power saving states which results in non-smooth
scrolling during gameplay and micro stuttering that cannot
be measured on application level.
2025-02-07 12:33:16 +01:00
icex2
218ffe72c1 feat: Add iidxio-async implementation
A shim library implementing the same concept as the already
existing ddrio-async library. The iidxio implementation takes
another iidxio library and runs it asynchronously which may
improve performance for certain iidxio implementations,
e.g. if the send and receive functions are driving actual IO
calls synchrously and are expensive.

This is not a replacement for a well engineered and proper
implementation of a iidxio library for any specific use-case.
It does not fix bad performance of existing implementations,
i.e. if the poll rate is too low because actual IO is too slow.

Use with caution and know why and when you need to use
it.
2025-02-07 12:18:55 +01:00
icex2
8c5cf383b6 Merge 94aa0bdda3 into sapling-pr-archive-icex2 2024-02-25 09:36:13 +01:00
icex2
075381481d merge commit for archive created by Sapling 2024-02-25 09:35:20 +01:00
icex2
94aa0bdda3 feat(avs-util): Add helper to translate property errors 2024-02-25 09:34:37 +01:00
icex2
70e8e2a965 fix(avs): Incorrect function signature
After getting doubts, I looked this one up again on the
assembly. The decompiled output confused me
and no actual value is being returned there.
2024-02-25 09:34:37 +01:00
icex2
d1db1d816f Merge d3273bf1d8 into sapling-pr-archive-icex2 2024-02-25 09:33:50 +01:00
icex2
d3273bf1d8 fix(avs): Incorrect function signature
After getting doubts, I looked this one up again on the
assembly. The decompiled output confused me
and no actual value is being returned there.
2024-02-25 09:33:42 +01:00
icex2
f4f8e7d8e2 Merge c369412f70 into sapling-pr-archive-icex2 2024-02-25 09:32:24 +01:00
icex2
84ff799024 Merge e12cd63ba2 into sapling-pr-archive-icex2 2024-02-25 09:31:08 +01:00
icex2
c369412f70 fix(mingw): Version upgrade caused this to error
HRESULT not defined fixed by including windows header
2024-02-25 09:30:53 +01:00
icex2
26d1da8660 refactor(dist): Config and .bat files
Move everything to new launcher.xml configuration
files. Adjust the bootstrapping of launcher in the
.bat files. Features such as copying the default
props/ files to nvram are now handled by launcher.

Using the PATH variable, bemanitools binaries can
live in their own dedicated bemanitools/ subfolder
next to props/ and modules/ now. All original
binaries are expected to be kept in a modules/
folder like on stock data.
2024-02-25 09:30:53 +01:00
icex2
04310f49fd refactor(launcher): Major re-work of launcher
Kudos to Shiz for providing the groundwork for this.

Fundamentally re-think how launcher operates and
bootstrapping the games is managed and configured.

This brings it significantly closer to how the original
bootstrap is doing the job: launcher now utilizes the
data (structures) provided by the bootstrap.xml configuration
file. This creates compatibility with vanilla data dumps
and original stock images. Note that bemanitools does not
include any code or means to run DRM'd data, only decrypted.

But, this allows users to keep decrypted dumps as stock as
possible which means:

* No copying around of property files anymore
* Keep the modules/ folder with the binaries
* Have bemanitools binaries separate in the data
* No need to edit/customize the original configuration files

A list of key features of the "new" launcher:

* Boostrap games by following the configuration provided by
  stock game's bootstrap.xml files
* Custom launcher.xml configuration file that adds further
  launcher configurable features, composability of
  bootstrap.xml configuration(s) as well as configuration
  overriding/stacking of selected types of configurations,
  e.g. eamuse config, avs-config. The latter eliminates
  the need for modifying stock config files in the prop/
  folder
* Unified logging system: launcher and AVS logging uses
  the same logger, all output can now be in a single file
* Original features such as various hook types still
  available

Due to the significant architectural changes, this also
breaks with any backwards compatibility to existing
launcher setups. Thus, users need to migrate by re-applying
the new configuration format and migrating their config
parameters accordingly.

Further migration instructions and updated documentation
will be provided upon release.

Co-authored-by: Shiz <hi@shiz.me>
2024-02-25 09:30:53 +01:00
icex2
d72996c5d9 refactor(inject): Use new core thread and log modules
Keep this a separate commit because this also removes
inject's own logging engine and replaces it with the
streamlined core API. The core API provides all the
features of inject's own logging engine which also
performed horribly. The entire logging operation
was locked which included expensive operations
that formatted the log messages and required
memory allocations and copying around data.

The core API's implementation at least only
synchronizes the actual IO operations
(though this can be improved further with an
actual async logging sink, TBD)
2024-02-25 09:30:53 +01:00
icex2
5ac858e15d chore: Delete old log and thread modules in util
The log API stopped scaling already a while ago and needs
considerable refactoring to consider the various use-cases
that emerged since it was first created on alpha versions
of bemanitools.
2024-02-25 09:30:53 +01:00
icex2
e4a221e15b refactor: Entire code base, thread and log usage
Boils down to:
- Include headers
- Reduce boiler plate with helpers
- Swap out explicit usages with core API layer
  and ensure the right API is configured beforehand
2024-02-25 09:30:53 +01:00
icex2
ea835b32ee refactor(api): Thread and log API
Split files and add name spacing.
2024-02-25 09:30:53 +01:00
icex2
fb1442b734 feat: Add helper to set avs implementations
Doesn't really reduce boiler plate but adds
clarity with a more meaningful function name
what the operation does.
2024-02-25 09:30:53 +01:00
icex2
87b7e53973 feat: Add core module
This module contains the "core" (API) of
bemanitools which includes an abstraction
layer for threads and logging at this time.

The threads API is very close to what
util/thread already was with some structural
enhancements which make it easier to understand
and work with the API, I hope. Some additional
helpers (*-ext module) support in doing common
tasks, e.g. setting up the thread API with other
modules.

The log(ging) part receives a major overhaul to
address known limitations and issues with the
util/log module:
- Cleaner API layer
- Separate sinks from actual logging engine
- Sinks are composable
- Improved and cleaner compatibility layer
  with AVS logging API

Additional "extensions" (*-ext modules) add
various helper functions for common tasks like
setting up the logging engine with a file and stdout
sink.

The sinks also improved significantly with the file
sink now supporting proper appending and log rotation.
Logging to stdout/stderr supports coloring of log
messages which works across logging engines.

Overall, this refactored foundation is expected to
support future developments and removes known
limitations at the current scale of bemanitools such as:
- Reducing boiler plate code across hooks
- Interop of bemanitools and AVS (and setting the foundation
  for addressing currently missing interop, e.g. for
  dealing with property structures without AVS)
- Addressing performance issues in the logging engine
  due to incorrect interop with AVS
2024-02-25 09:30:53 +01:00
icex2
2e45f095ba feat(avs-util): Add helper to translate property errors 2024-02-25 09:30:53 +01:00
icex2
e12cd63ba2 Fix(avs): Incorrect function signature
After getting doubts, I looked this one up again on the
assembly. The decompiled output confused me
and no actual value is being returned there.
2024-02-25 09:30:47 +01:00
icex2
a4b3f92935 feat(avs): Add property get and clear error functions
Use these to improve error handling by allowing
one to provide additional error information on
property related operations.
2024-02-25 09:23:02 +01:00
icex2
1126011d99 Merge 8804e667b3 into sapling-pr-archive-icex2 2024-02-25 09:22:54 +01:00
icex2
6a98ce1f59 feat(dev): Add a separate docker dev container
Improve the development experience by providing
an additional docker container that can be started
and used as an interactive development environment.
It provides all the tools and a stable environment
for building (identical to the build container).
2024-02-25 09:14:59 +01:00
icex2
dc6e745533 Merge f5b8af3f2a into sapling-pr-archive-icex2 2024-02-25 09:14:52 +01:00
icex2
8804e667b3 feat(avs): Add property get and clear error functions
Use these to improve error handling by allowing
one to provide additional error information on
property related operations.
2024-02-25 09:14:42 +01:00
icex2
f5b8af3f2a feat(dev): Add a separate docker dev container
Improve the development experience by providing
an additional docker container that can be started
and used as an interactive development environment.
It provides all the tools and a stable environment
for building (identical to the build container).
2024-02-25 09:14:42 +01:00
icex2
5833197b03 fix(hook): Add missing hook_table_revert impl
Allow hooks to cleanup when they are shut down.
2024-02-25 09:09:12 +01:00
icex2
339bf0dfed merge commit for archive created by Sapling 2024-02-25 09:08:50 +01:00
icex2
6a320a38c0 fix(mingw): Version upgrade caused this to error
HRESULT not defined fixed by including windows header
2024-02-25 09:08:26 +01:00
icex2
d8a5619a51 refactor(dist): Config and .bat files
Move everything to new launcher.xml configuration
files. Adjust the bootstrapping of launcher in the
.bat files. Features such as copying the default
props/ files to nvram are now handled by launcher.

Using the PATH variable, bemanitools binaries can
live in their own dedicated bemanitools/ subfolder
next to props/ and modules/ now. All original
binaries are expected to be kept in a modules/
folder like on stock data.
2024-02-25 09:08:26 +01:00
icex2
ab6c3fc8bc fix(hook): Add missing hook_table_revert impl
Allow hooks to cleanup when they are shut down.
2024-02-25 09:07:54 +01:00
icex2
215a4bdb15 refactor(launcher): Major re-work of launcher
Kudos to Shiz for providing the groundwork for this.

Fundamentally re-think how launcher operates and
bootstrapping the games is managed and configured.

This brings it significantly closer to how the original
bootstrap is doing the job: launcher now utilizes the
data (structures) provided by the bootstrap.xml configuration
file. This creates compatibility with vanilla data dumps
and original stock images. Note that bemanitools does not
include any code or means to run DRM'd data, only decrypted.

But, this allows users to keep decrypted dumps as stock as
possible which means:

* No copying around of property files anymore
* Keep the modules/ folder with the binaries
* Have bemanitools binaries separate in the data
* No need to edit/customize the original configuration files

A list of key features of the "new" launcher:

* Boostrap games by following the configuration provided by
  stock game's bootstrap.xml files
* Custom launcher.xml configuration file that adds further
  launcher configurable features, composability of
  bootstrap.xml configuration(s) as well as configuration
  overriding/stacking of selected types of configurations,
  e.g. eamuse config, avs-config. The latter eliminates
  the need for modifying stock config files in the prop/
  folder
* Unified logging system: launcher and AVS logging uses
  the same logger, all output can now be in a single file
* Original features such as various hook types still
  available

Due to the significant architectural changes, this also
breaks with any backwards compatibility to existing
launcher setups. Thus, users need to migrate by re-applying
the new configuration format and migrating their config
parameters accordingly.

Further migration instructions and updated documentation
will be provided upon release.

Co-authored-by: Shiz <hi@shiz.me>
2024-02-25 09:07:54 +01:00
icex2
4ac1399923 refactor(inject): Use new core thread and log modules
Keep this a separate commit because this also removes
inject's own logging engine and replaces it with the
streamlined core API. The core API provides all the
features of inject's own logging engine which also
performed horribly. The entire logging operation
was locked which included expensive operations
that formatted the log messages and required
memory allocations and copying around data.

The core API's implementation at least only
synchronizes the actual IO operations
(though this can be improved further with an
actual async logging sink, TBD)
2024-02-25 09:07:54 +01:00
icex2
f688eead44 chore: Delete old log and thread modules in util
The log API stopped scaling already a while ago and needs
considerable refactoring to consider the various use-cases
that emerged since it was first created on alpha versions
of bemanitools.
2024-02-25 09:07:54 +01:00
icex2
e8221631f9 refactor: Entire code base, thread and log usage
Boils down to:
- Include headers
- Reduce boiler plate with helpers
- Swap out explicit usages with core API layer
  and ensure the right API is configured beforehand
2024-02-25 09:07:54 +01:00
icex2
0afca1da49 refactor(api): Thread and log API
Split files and add name spacing.
2024-02-25 09:07:54 +01:00
icex2
734c17a0a2 feat: Add helper to set avs implementations
Doesn't really reduce boiler plate but adds
clarity with a more meaningful function name
what the operation does.
2024-02-25 09:07:54 +01:00
icex2
6940a9de4b feat: Add core module
This module contains the "core" (API) of
bemanitools which includes an abstraction
layer for threads and logging at this time.

The threads API is very close to what
util/thread already was with some structural
enhancements which make it easier to understand
and work with the API, I hope. Some additional
helpers (*-ext module) support in doing common
tasks, e.g. setting up the thread API with other
modules.

The log(ging) part receives a major overhaul to
address known limitations and issues with the
util/log module:
- Cleaner API layer
- Separate sinks from actual logging engine
- Sinks are composable
- Improved and cleaner compatibility layer
  with AVS logging API

Additional "extensions" (*-ext modules) add
various helper functions for common tasks like
setting up the logging engine with a file and stdout
sink.

The sinks also improved significantly with the file
sink now supporting proper appending and log rotation.
Logging to stdout/stderr supports coloring of log
messages which works across logging engines.

Overall, this refactored foundation is expected to
support future developments and removes known
limitations at the current scale of bemanitools such as:
- Reducing boiler plate code across hooks
- Interop of bemanitools and AVS (and setting the foundation
  for addressing currently missing interop, e.g. for
  dealing with property structures without AVS)
- Addressing performance issues in the logging engine
  due to incorrect interop with AVS
2024-02-25 09:07:54 +01:00
icex2
1d489643d1 feat(avs-util): Add helper to translate property errors 2024-02-25 09:07:54 +01:00
icex2
33fee83aff feat(avs): Add property get and clear error functions
Use these to improve error handling by allowing
one to provide additional error information on
property related operations.
2024-02-25 09:07:54 +01:00
icex2
8b377f256a feat(dev): Add a separate docker dev cotainer
Improve the development experience by providing
an additional docker container that can be started
and used as an interactive development environment.
It provides all the tools and a stable environment
for building (identical to the build container).
2024-02-25 09:07:54 +01:00
icex2
64cc7084dc merge commit for archive created by Sapling 2024-02-25 09:02:50 +01:00
icex2
7a086ea60b fix(hook): Add missing hook_table_revert impl
Allow hooks to cleanup when they are shut down.
2024-02-25 09:02:35 +01:00
icex2
7ee9a2e219 fix(dist): Incorrect versioning for ddr distribution packages
Apparently forgotten to get updated to reflect the
currently supported versions correctly.
2024-02-25 08:52:00 +01:00
icex2
fa5a50167f Merge 7a56fab96e into sapling-pr-archive-icex2 2024-02-25 08:51:32 +01:00
icex2
7a56fab96e fix(dist): Incorrect versioning for ddr distribution packages
Apparently forgotten to get updated to reflect the
currently supported versions correctly.
2024-02-25 08:51:25 +01:00
icex2
0c08d19276 merge commit for archive created by Sapling 2024-02-23 18:56:01 +01:00
icex2
c78639f094 fix(mingw): Version upgrade caused this to error
HRESULT not defined fixed by including windows header
2024-02-23 18:53:59 +01:00
icex2
2ebfd39bea refactor(dist): Config and .bat files
Move everything to new launcher.xml configuration
files. Adjust the bootstrapping of launcher in the
.bat files. Features such as copying the default
props/ files to nvram are now handled by launcher.

Using the PATH variable, bemanitools binaries can
live in their own dedicated bemanitools/ subfolder
next to props/ and modules/ now. All original
binaries are expected to be kept in a modules/
folder like on stock data.
2024-02-23 18:53:59 +01:00
icex2
2fe21ae6b7 refactor(launcher): Major re-work of launcher
Kudos to Shiz for providing the groundwork for this.

Fundamentally re-think how launcher operates and
bootstrapping the games is managed and configured.

This brings it significantly closer to how the original
bootstrap is doing the job: launcher now utilizes the
data (structures) provided by the bootstrap.xml configuration
file. This creates compatibility with vanilla data dumps
and original stock images. Note that bemanitools does not
include any code or means to run DRM'd data, only decrypted.

But, this allows users to keep decrypted dumps as stock as
possible which means:

* No copying around of property files anymore
* Keep the modules/ folder with the binaries
* Have bemanitools binaries separate in the data
* No need to edit/customize the original configuration files

A list of key features of the "new" launcher:

* Boostrap games by following the configuration provided by
  stock game's bootstrap.xml files
* Custom launcher.xml configuration file that adds further
  launcher configurable features, composability of
  bootstrap.xml configuration(s) as well as configuration
  overriding/stacking of selected types of configurations,
  e.g. eamuse config, avs-config. The latter eliminates
  the need for modifying stock config files in the prop/
  folder
* Unified logging system: launcher and AVS logging uses
  the same logger, all output can now be in a single file
* Original features such as various hook types still
  available

Due to the significant architectural changes, this also
breaks with any backwards compatibility to existing
launcher setups. Thus, users need to migrate by re-applying
the new configuration format and migrating their config
parameters accordingly.

Further migration instructions and updated documentation
will be provided upon release.

Co-authored-by: Shiz <hi@shiz.me>
2024-02-23 18:53:58 +01:00
icex2
daba638bb0 Merge 359ab5a541 into sapling-pr-archive-icex2 2024-02-23 18:48:44 +01:00
icex2
359ab5a541 refactor(inject): Use new core thread and log modules
Keep this a separate commit because this also removes
inject's own logging engine and replaces it with the
streamlined core API. The core API provides all the
features of inject's own logging engine which also
performed horribly. The entire logging operation
was locked which included expensive operations
that formatted the log messages and required
memory allocations and copying around data.

The core API's implementation at least only
synchronizes the actual IO operations
(though this can be improved further with an
actual async logging sink, TBD)
2024-02-23 18:48:21 +01:00
icex2
6dd3669559 Merge fbadcc9b41 into sapling-pr-archive-icex2 2024-02-23 17:43:06 +01:00
icex2
fbadcc9b41 refactor(dist): Config and .bat files
Move everything to new launcher.xml configuration
files. Adjust the bootstrapping of launcher in the
.bat files. Features such as copying the default
props/ files to nvram are now handled by launcher.

Using the PATH variable, bemanitools binaries can
live in their own dedicated bemanitools/ subfolder
next to props/ and modules/ now. All original
binaries are expected to be kept in a modules/
folder like on stock data.
2024-02-23 17:17:18 +01:00
icex2
ca91e4c4ae refactor(launcher): Major re-work of launcher
Kudos to Shiz for providing the groundwork for this.

Fundamentally re-think how launcher operates and
bootstrapping the games is managed and configured.

This brings it significantly closer to how the original
bootstrap is doing the job: launcher now utilizes the
data (structures) provided by the bootstrap.xml configuration
file. This creates compatibility with vanilla data dumps
and original stock images. Note that bemanitools does not
include any code or means to run DRM'd data, only decrypted.

But, this allows users to keep decrypted dumps as stock as
possible which means:

* No copying around of property files anymore
* Keep the modules/ folder with the binaries
* Have bemanitools binaries separate in the data
* No need to edit/customize the original configuration files

A list of key features of the "new" launcher:

* Boostrap games by following the configuration provided by
  stock game's bootstrap.xml files
* Custom launcher.xml configuration file that adds further
  launcher configurable features, composability of
  bootstrap.xml configuration(s) as well as configuration
  overriding/stacking of selected types of configurations,
  e.g. eamuse config, avs-config. The latter eliminates
  the need for modifying stock config files in the prop/
  folder
* Unified logging system: launcher and AVS logging uses
  the same logger, all output can now be in a single file
* Original features such as various hook types still
  available

Due to the significant architectural changes, this also
breaks with any backwards compatibility to existing
launcher setups. Thus, users need to migrate by re-applying
the new configuration format and migrating their config
parameters accordingly.

Further migration instructions and updated documentation
will be provided upon release.

Co-authored-by: Shiz <hi@shiz.me>
2024-02-23 17:17:17 +01:00
icex2
08a72abb58 refactor(inject): Use new core thread and log modules
Keep this a separate commit because this also removes
inject's own logging engine and replaces it with the
streamlined core API. The core API provides all the
features of inject's own logging engine which also
performed horribly. The entire logging operation
was locked which included expensive operations
that formatted the log messages and required
memory allocations and copying around data.

The core API's implementation at least only
synchronizes the actual IO operations
(though this can be improved further with an
actual async logging sink, TBD)
2024-02-23 17:17:17 +01:00
icex2
7e49fad175 chore: Delete old log and thread modules in util
The log API stopped scaling already a while ago and needs
considerable refactoring to consider the various use-cases
that emerged since it was first created on alpha versions
of bemanitools.
2024-02-23 17:09:15 +01:00
icex2
0adec478cc refactor: Entire code base, thread and log usage
Boils down to:
- Include headers
- Reduce boiler plate with helpers
- Swap out explicit usages with core API layer
  and ensure the right API is configured beforehand
2024-02-23 13:29:53 +01:00
icex2
bc9b8b508e refactor(api): Thread and log API
Split files and add name spacing.
2024-02-23 13:29:53 +01:00
icex2
33372f3ef2 feat(avs-util): Add helper to translate property errors 2024-02-23 12:42:29 +01:00
icex2
dedbdaf729 feat: Add helper to set avs implementations
Doesn't really reduce boiler plate but adds
clarity with a more meaningful function name
what the operation does.
2024-02-23 12:42:29 +01:00
icex2
3865e09f06 feat: Add core module
This module contains the "core" (API) of
bemanitools which includes an abstraction
layer for threads and logging at this time.

The threads API is very close to what
util/thread already was with some structural
enhancements which make it easier to understand
and work with the API, I hope. Some additional
helpers (*-ext module) support in doing common
tasks, e.g. setting up the thread API with other
modules.

The log(ging) part receives a major overhaul to
address known limitations and issues with the
util/log module:
- Cleaner API layer
- Separate sinks from actual logging engine
- Sinks are composable
- Improved and cleaner compatibility layer
  with AVS logging API

Additional "extensions" (*-ext modules) add
various helper functions for common tasks like
setting up the logging engine with a file and stdout
sink.

The sinks also improved significantly with the file
sink now supporting proper appending and log rotation.
Logging to stdout/stderr supports coloring of log
messages which works across logging engines.

Overall, this refactored foundation is expected to
support future developments and removes known
limitations at the current scale of bemanitools such as:
- Reducing boiler plate code across hooks
- Interop of bemanitools and AVS (and setting the foundation
  for addressing currently missing interop, e.g. for
  dealing with property structures without AVS)
- Addressing performance issues in the logging engine
  due to incorrect interop with AVS
2024-02-23 12:42:29 +01:00
icex2
517f8e885f feat(avs): Add property get and clear error functions
Use these to improve error handling by allowing
one to provide additional error information on
property related operations.
2024-02-23 11:15:17 +01:00
icex2
560aba3133 feat(dev): Add a separate docker dev cotainer
Improve the development experience by providing
an additional docker container that can be started
and used as an interactive development environment.
It provides all the tools and a stable environment
for building (identical to the build container).
2024-02-22 23:18:26 +01:00
icex2
6b75b33253 fix(hook): Add missing hook_table_revert impl 2024-02-22 23:17:17 +01:00
icex2
312aa619c6 fix(dist): Incorrect versioning for ddr distribution packages
Apparently forgotten to get updated to reflect the
currently supported versions correctly.
2024-02-22 23:16:28 +01:00
52 changed files with 573 additions and 6540 deletions

View File

@@ -135,7 +135,6 @@ include src/main/ezusb2-popn-shim/Module.mk
include src/main/ezusb2-tool/Module.mk
include src/main/ezusb2/Module.mk
include src/main/geninput/Module.mk
include src/main/hdr-histogram/Module.mk
include src/main/hook/Module.mk
include src/main/hooklib/Module.mk
include src/main/iidx-bio2-exit-hook/Module.mk
@@ -155,11 +154,9 @@ include src/main/iidxhook6/Module.mk
include src/main/iidxhook7/Module.mk
include src/main/iidxhook8/Module.mk
include src/main/iidxhook9/Module.mk
include src/main/iidxio-async/Module.mk
include src/main/iidxio-bio2/Module.mk
include src/main/iidxio-ezusb/Module.mk
include src/main/iidxio-ezusb2/Module.mk
include src/main/iidxio-perf/Module.mk
include src/main/iidxio/Module.mk
include src/main/iidxiotest/Module.mk
include src/main/inject/Module.mk
@@ -459,11 +456,9 @@ $(zipdir)/iidx-27-to-30.zip: \
$(zipdir)/iidx-hwio-x86.zip: \
build/bin/indep-32/aciomgr.dll \
build/bin/indep-32/eamio-icca.dll \
build/bin/indep-32/iidxio-async.dll \
build/bin/indep-32/iidxio-bio2.dll \
build/bin/indep-32/iidxio-ezusb.dll \
build/bin/indep-32/iidxio-ezusb2.dll \
build/bin/indep-32/iidxio-perf.dll \
dist/iidx/iidxio-bio2.conf \
build/bin/indep-32/vigem-iidxio.exe \
dist/iidx/vigem-iidxio.conf \
@@ -474,11 +469,9 @@ $(zipdir)/iidx-hwio-x86.zip: \
$(zipdir)/iidx-hwio-x64.zip: \
build/bin/indep-64/aciomgr.dll \
build/bin/indep-64/eamio-icca.dll \
build/bin/indep-64/iidxio-async.dll \
build/bin/indep-64/iidxio-bio2.dll \
build/bin/indep-64/iidxio-ezusb.dll \
build/bin/indep-64/iidxio-ezusb2.dll \
build/bin/indep-64/iidxio-perf.dll \
dist/iidx/iidxio-bio2.conf \
build/bin/indep-64/vigem-iidxio.exe \
dist/iidx/vigem-iidxio.conf \

View File

@@ -0,0 +1,319 @@
# IIDX engine overview and how game-play is impacted by hardware and software
Date: 2025-02-09 Author: icex2
This document provides information and explains the following:
* A sort-of taxonomy of the different major IIDX game engine versions
* How the core game-play part of the engine works regarding
* Threading model
* Main render loop
* Timing and synchronization
The goal is to capture key knowledge about how the game's engine works to enable a better
understanding for developing bemanitools and how certain features can impact performance and
synchronization during game-play.
This document is not claiming to be complete or 100% accurate. It is based on my own personal
research and understanding of the IIDX game engine. It is very likely that some of the information
is wrong or misunderstood. Feel free to raise any questions or concerns in an issue as I want
this document to be as accurate as possible.
## Taxonomy of IIDX game engine versions
With every version, there have been numerous changes and improvements to the game engine. The
following is a rough taxonomy that is focused on cabinet and hardware changes. As these are likely
the main driver for key changes to the software and game engine, they create fairly distinct
stages throughout the different versions of the game. The key attributes to be considered here are:
* Main PCB
* IO board
* Monitor
All of these had significant impact on key software features appearing or changing.
### Twinkle hardware era: 1st Style to 8th Style
* [Twinkle PCB](https://github.com/shizmob/arcade-docs/blob/main/konami/boards.md#twinkle)
* [Original rear projection monitor](https://github.com/shizmob/arcade-docs/blob/main/konami/products.md#iidx-rear-projection-monitor)
* Homogenous hardware and software
### 1st gen PC-based upgrade only: 9th Style
* 9th Style came as an upgrade kit only to existing twinkle-based cabinet hardware
* [KNM-845G3-A02 PCB](https://github.com/shizmob/arcade-docs/blob/main/konami/boards.md#knm-845g3-a02)
* [C02 EZUSB FX USB IO board](https://github.com/shizmob/arcade-docs/blob/main/konami/io.md#gec02-pwbaa)
* Magnetic card readers connected to ezusb IO board
### 1st gen PC-based with dedicated cabinet: 10th Style to DistorteD (13)
* From here on, old cabinets that received the "Twinkle hardware" upgrade kit could always receive software only
upgrades
* [CRT monitor](https://github.com/shizmob/arcade-docs/blob/main/konami/products.md#iidx-crt-monitor) with new dedicated
cabinets
* [D01 EZUSB FX USB IO board](https://github.com/shizmob/arcade-docs/blob/main/konami/io.md#d01-io)
* Slotted card readers starting version 13
### 2nd gen PC: GOLD (14) to Lincle (19)
* [FAB-e945-KN205](https://github.com/shizmob/arcade-docs/blob/main/konami/boards.md#fab-e945-kn205)
* All prior cabinet configurations can be upgraded with a PCB and software upgrade
* New LCD monitor starting version 15
* Further variants of the LCD monitor appear starting version 18
* [IO2 EZUSB FX2 USB IO board](https://github.com/shizmob/arcade-docs/blob/main/konami/io.md#usbio2) introduced with
version 14
* Switch to wave pass readers on version 19
### 3rd gen PC: Tricoro (20) to Sinobuz (24)
* All prior cabinet configurations can be upgraded with a PCB and software upgrade
* [ADE-HM65](https://github.com/shizmob/arcade-docs/blob/main/konami/boards.md#hm65)
* Game engine supports HD mode (720p)
* Many new LCD monitor variants appear with every new version
### 4th gen PC: CANNON BALLERS (25) to RESIDENT (30)
* All prior cabinet configurations can be upgraded with a PCB and software upgrade
* [ADE-6291](https://github.com/shizmob/arcade-docs/blob/main/konami/boards.md#ade-6291)
* [BIO2 IO board](https://github.com/shizmob/arcade-docs/blob/main/konami/boards.md#hm65)
* Upgrade cabinets required the [BIO2 sub-IO board](https://github.com/shizmob/arcade-docs/blob/main/konami/io.md#bio2-ldj-sub-io)
* Drop of SD mode support starting version 27
* Supporting 120 hz monitors starting version 27
* Many new LCD monitor variants appear with every new version
* 42" 120 hz for lightning cabinets starting version 27
* 42" 60 hz for non-lightning cabinets starting version 25
### 5th gen PC: RESIDENT (30) to EPOLIS (31)
* All prior cabinet configurations can be upgraded with a PCB and software upgrade
* [C300-xonarae](https://github.com/shizmob/arcade-docs/blob/main/konami/boards.md#c300-xonarae)
* Game engine supports FHD mode (1080p)
## Threading model and core responsibilities in PC-based games
Since the early days of 9th Style to today (as of time of writing this: EPOLIS), the threading model
hasn't changed significantly:
* Main and rendering thread
* Runs your typical D3D9 render loop
* Using D3D9ex starting version 27
* Starting and managing other threads
* Any file and game asset loading
* Handles all the core game logic of the different screens starting from the initial boot screen
to the core game-play screen
* IO thread
* Polls the main IO hardware and synchronizes the in-memory input and output state with the
hardware
* Executes commands issued by the main thread to the IO board such as dongle or card reader
commands (ezusb generation of IO only)
* Card reader thread (not applicable to versions 9 to 12)
* Runs the protocol to read/write the hardware of the readers
* Async execution of higher level commands issued by the main thread to the card reader hardware,
e.g. card read, card eject etc.
* Audio thread
* Streaming of audio data to the sound API
* DirectSound for versions 9 to 26
* WASAPI for versions 27 to 30 for non-lighting cabinets with ADE-6291 hardware
* ASIO for versions 27 and newer for lighting cabinets
* ASIO for version 30/31 and newer for non-lighting cabinets with C300-xonarae hardware
* Async execution of higher level commands issued by the main thread to the audio backend, e.g.
play audio, stop audio, etc.
* Network thread
* Network plumbing with the xrpc protocol
* Async execution of request-response commands issued by the main thread
## Main and rendering thread
With the game having transitioning to different screens throughout it's lifecycle, the main render
loop might contain different logic such as asset loading. The following focuses on the main
game-play screen, only. Common rendering logic still applies to other screens.
This follows your typical D3D9 single threaded rendering loop which boils down to the following:
* Begin the scene (`BeginScene`)
* Set the render target (`SetRenderTarget`)
* Clear the back buffer (`Clear`)
* Run engine step. This includes and is mixed with
* IO input evaluation
* Game engine state and (re-) drawing the scene
* Commands to the audio playback, e.g. play key sounds
* Setting IO outputs
* End the scene (`EndScene`)
* Target a minimum frame time
* Introduced with version 11
* Sleep (`Sleep` or `SleepEx`) to fill up the frame up to either 13 ms or 14 ms (depending on the
version)
* This was likely introduced to not have the game run at hundreds of FPS if v-sync was disabled
(probably when running in window mode for development/testing purposes)
* Swapping the back buffers (`Present`)
* D3D9 is configured with v-sync enabled by default and targets 60 hz
* With this configuration, the call to `Present` fills up the remaining frame time to target the
configured 60 hz refresh rate
### Rendering resolutions
The game engine went through a couple of different rendering resolutions:
* 640x240: version 1 to 8 (all twinkle hardware)
* 640x480: version 9 to 19 (1st and 2nd gen PC-based)
* 1280x720 (HD mode) and 640x480 (SD mode): version 20 to 27 (3rd and 4th gen PC-based)
* 1280x720 (HD mode) only for version 28 to 29 (4th gen PC-based)
* 1280x720 (HD mode) and 1920x1080 (FHD mode) for version 30 (4th gen PC-based)
* 1920x1080 (FHD mode) only for version 30+ (5th gen PC-based)
## Core engine timing and synchronization
The following outlines and explains the core engine concepts related to timing and synchronization.
### The origins, twinkle hardware
* It appears that the game has been on the same codebase since it's inception.
* This can be reasoned by the following observations
* 9th style as the first PC-based game very buggy on initial release
* 9th style threading model very clunky with various thread settings showing they tried to
prioritize different processing on a single core CPU
* Coming from twinkle hardware that is a realtime system vs. a Windows XP system
* Fixed playstation 1 based hardware with a refresh rate of
[59.8260978565 hz](https://github.com/mamedev/mame/blob/bf9df04e005697788ae988ef5aea91a1878fd631/src/devices/video/psx.cpp#L435)
* No need to assume getting anything else if the resource budget per frame is not exceeded
* All sub-systems were driven synchronously to that fixed time step
* No need for the engine to synchronize audio during the song. When the song is started
correctly, it stayed sync throughout the song
* Observations and assumptions
* It appears the developers struggled a lot with the significant platform shift to PC as indicated
by various core engine improvements throughout the years still
* Switches of hardware generations further complicated the situation as these forced them to further
drift away from how the game engine was initially designed on the twinkle system
### Frame time/timing and engine step
* The game's engine step and timing is frame based
* The main render loop defines the minimum valid timing window for the game engine to be able to
evaluate
* 60 hz/fps = 16.667 ms (rounded to three decimal places)
* 120 hz/fps = 8.333 ms (rounded to three decimal places), only relevant for lightning cabinets with their 120 hz
screen/mode
* Depending on the GPU hardware and configuration, the GPU might drive the screen not exactly at
perfectly 60 hz/fps = 16.667 ms
* As outlined in the [main render loop](#main-and-rendering-thread), the `Present` call is the
key function call to determine the frame time for the game engine
* Just having v-sync enabled and telling D3D9 to **target** 60 hz, it still depends on how the GPU
driver is implemented and how the GPU driver's implementation of D3D9 executes on the `Present`
call
* This is primarily determined by how the GPU driver is operating and driving connected display
hardware
* The following factors can contribute to that either directly or indirectly
* Different monitor types analog vs. digital (CRT vs. LCD)
* Different monitor connections VGA vs. DVI/HDMI/DP
* Different GPU drivers
* Different GPU hardware and vendors
* Different GPU settings
### Monitor check screen
The monitor check screen was introduced with version 14. This was a solution to the problem of not
guaranteeing a single fixed refresh rate throughout different GPU and monitor combinations. See
a detailed explanation in the previous sub-subsection about
[what influences the frame time](#frame-timetiming-and-engine-step) of the game.
The goal of the monitor check is to measure the frame time of the main render loop and use the
results for [driving the core engine step](#engine-step-and-synchronization).
The monitor check evolved slightly as different GPU and monitor hardware, and GPU drivers yielded
varying refresh rates that determined the frame times of the main game loop.
Actual values are outlined further down in the [engine step time](#engine-step-time) section.
There are two main versions of the monitor check, all of them have always been part of the boot
process:
* 14
* Measures a total of 3000 frames
* If total time this took < 50004 ms -> so average of 16.668 ms per frame = 59.9952 hz
* S-Video mode -> 59.95 hz (also shows S-VIDEO when the monitor check completes)
* Otherwise VGA mode -> 60.05 hz
* If VGA is determined, the game patches the chart event data when loading
* `event_timestamp * 0.99817199 + 0.40000001`
* When S-Video no charts are patched and the timing data in the chart is used as is
* 15 to 18
* Identical to 14 except that chart patching now happens in milliseconds instead of frames
* VGA mode: `16.65279`
* S-Video mode: `16.680567`
* `event_timestamp * (1.0 / frame_time) + 0.40000001)`
* 19
* Identical to previous version
* Monitor check screen shows current FPS on the last revision of that version. However, it doesn't
use the value shown there by any means. Assuming this was added before the introduction of the
new monitor check on 20.
* 20 to 26
* Runs on boot or when switching monitor modes SD vs. HD
* Measures only 1200 frames
* Takes the average refresh rate of 1200 frames
* Applies the measured avg. frame time directly to the charts before song
* 27 to 30
* Frame rate measuring identical to prior versions
* Added additional logic after the frame time measurements for handling of 120 hz displays
* Includes checking the monitor and if the framerate matches as expected
* 30/31 LDJ-010 upgrade
* Added NvDisplayConfigLDJ tool which runs on system start and configures a custom timing in the
NVIDIA GPU driver to ensure a fixed monitor refresh rate
* 31
* Same code as before
* Consider the first 460 frames of the measurement as warm-up frames
* Discard these for the actual measurement to get more stable frame times
* Use a base avg. value of 119.982 for the 120 hz monitors and 59.9 for 60 hz monitors. Further
frames measured are counted towards the average with the given base value
### Engine core game-play with visual and audio synchronization
#### Chart data
* Chart data encodes note timing and timing window information
* Chart data consists of *note events* encoding a timestamp and note information such as type
and key-sound information
* Timing windows are defined per chart
* Most infamous example: GAMBOL (7Key/Another)
* Game engine timestamp evaluation and note event timestamp encoding
* 9 to 14: Refresh rate in hz
* 15 to 31: Milliseconds (equivalent to assuming 1000 fps)
* Fundamentally, that doesn't change game play experience as it's just a different way of
evaluating the timestamps since refresh rate in hz/frame rate in fps can be converted lossless to
frame time in ms
#### Engine step time
The engine uses the following source for frame rate/time to drive internal logic on the following
versions
* 9 to 13: Hardcoded 59.95 hz
* 14: Either 59.95 hz or 60.05 hz determined by which value is determined to be closer to the
measured one during the monitor check screen on startup
* 15 to 19: 59.95 hz or 60.05 hz
* Monitor check on startup measures the frame time and picks the value closest to what's been
measured
* Monitor check result can be overridden with the *Output Type* setting in the operator menu
* *S-Video* to force to 59.95 hz
* *VGA* to force to 60.05 hz
* 20 to 31: Monitor check on boot determines the frame time and uses the result throughout the
entire game session
#### Engine step and synchronization
Per frame engine step advancing and synchronization during game-play
* Game-play needs synchronization of the following aspects
* Drawn content on the screen
* Background audio playback track
* Key sound effects
* The game engine synchronizes these only at the start of a song
* It takes known/determined refresh rate/frame time as the fixed time for every frame cycle
throughout the entire song
* It starts playback of the background audio track together with playback of the chart data
* With every engine step/frame it advances internal calculations by that fixed amount of time.
Thus, the game engine expects this to be constant/stable throughout an entire song
* The chart data is advanced every frame by the engine
* Key sound events are turned into audio playback on command as the chart advances
* No re-synchronization or check-pointing between main rendering thread and audio is happening
throughout the song
* Remark: The above does not consider any kind of offsetting and timing adjustments for the sake
of keeping this simple and focus on the absolute core concepts

View File

@@ -0,0 +1,224 @@
# IIDX "Syncbook": A guide to ensuring sync and performant gameplay
This is a guide applicable to all IIDX versions that are native Windows PC-based. The goal is to
enable proper configuration of those games to ensure the game engine "runs in-sync" with any of its
IO (visual GPU/display output, audio output, user input) resulting in high and stable performance
for smooth game-play.
This document won't go into the implementation details of the game engine. Please refer to the
[IIDX engine details journal](../dev/journal/2025-02-09-iidx-engine.md) for a more in-depth
information.
## Understanding the problems and options to address them
First, let's understand what the key problems are and how they contribute to different issues
that impact game-play.
### Song de-syncing
Symptom: Throughout playing a song, the audio is de-syncing even it was fine when the song started.
Cause: The game engine is fundamentally designed to run on a fixed and consistent frame
rate/time per engine step. A mismatch of expected frame time by the game engine and actually delivered
frame time by the GPU driver. This can come either as a stable frame time that just mismatches in
general or (highly) fluctuating frame times.
* G-sync on modern displays causes known fluctuations because it adjusts dynamically the monitor
refresh rate
* V-sync not correctly configured/enforced or even vsync-off override in driver is causing
inconsistent frame times
* Incorrect display timings causing refresh rate fluctuations resulting in inconsistent frame times
Stable frame times but not having the correct ones that the game engine expects is a different
problem that can be addressed by:
* Knowing the refresh rates expected by the game engine of the different game versions
* Configuring your GPU driver's display timings to match the expected frame times
* Or, patch the game's chart data with your custom display timings so the game engine gets uses
*your* "correct" frame times
* Note: Offline patching the chart data doesn't work for several game versions as the monitor
check does override this data, but not as flexible as required
* Use the chart patch feature of bemanitools instead
### Micro-stuttering and non-smooth note scrolling
This is a trickier problem as it can be caused by a few different things.
* GPU related
* Fluctuating refresh rates result in fluctuating frame times in the main game loop
* GPU power configuration in non-performance mode (e.g. "power saving") causes processing latency
due to sleep states
* Display related
* Display firmware buggy and/or internal scalers that expect to run at very specific refresh rates
and cannot adapt to any custom display timings enforced by the GPU
* A known example is the official
[PENDUAL LCD monitor](https://github.com/shizmob/arcade-docs/blob/6ac99975cdb2bf668362f65fa9fa3ffb2127308b/konami/product/GULDJ-JI.md#notes-and-known-issues) that does not v-sync correctly to any other refresh-rate than 60.000 hz
* CPU related
* CPU power configuration on Windows in non-performance mode (e.g. "power saving") causes
processing latency due to sleep states
* Correct CPU C-states configuration in BIOS/UEFI
* These cannot be configured in Windows and are separate from Windows's power configuration
* Other stuff running in the background of the system causing fluctuations
* (Synchronous) Disk I/O heavy applications stealing CPU time
* Or any other process creating a considerable amount of CPU or GPU load
## Configuration guide for different game versions
### Measuring monitor refresh rate
Let's start with configuring the system to meet the game engine's expectation regarding the
target monitor refresh rate and requiring vsync.
First, use the [d3d9-monitor-check tool](../tools/d3d9-monitor-check.md) to measure the currently
configured refresh rate of your monitor. Note that your monitor might yield different timings on
different resolutions and different game versions run on
[different rendering resolutions](../dev/journal/2025-02-09-iidx-engine.md#rendering-resolutions).
For example, the game version is 31 with the rendering resolution of 1920x1080 in FHD mode that you
want to target:
```bat
d3d9-monitor-check.exe cmdline refresh-rate-test 1920 1080 60
```
The test shows the current monitor refresh rate and the average refresh rate over the course of
the test. Check that the avg. refresh rate is stable during the measuring phase (during warm-up,
it's ok if it fluctuates).
This test allows you to determine/check:
* Refresh rate/frame time fluctuations: if you see (high) fluctuations on the first or second
decimal place
* What's your current target refresh rate the GPU is driving your monitor at
* If vsync isn't overridden by some other driver setting as you want to see a refresh rate around
the 60 hz mark
### Measuring vsync issues
Some displays or the GPU configuration might lead to vsync issues which can be detected with the
`d3d9-monitor-check.exe` tool as well.
```bat
d3d9-monitor-check.exe cmdline vsync-test 1920 1080 60
```
This runs a test with a VSYNC text that alternates red and cyan colors. If the text appears grey
all the time, everything's fine. If you spot brief red or cyan text either occasionally or
periodically, your current configuration has vsync issues resulting in skipped frames or old
frames displaying longer.
### Configuration
The following are recommended configurations for the different game versions. If any of these
don't work as expected, you have to troubleshoot and tweak these potentially. Please refer to the
[guidelines above](#configuration-guide-for-different-game-versions) to understand how to use
the tooling and test your changes.
#### Recommended configuration with NVIDIA GPU and driver
We want to achieve the following configuration on the GPU driver:
* Turn-off g-sync if you have a monitor that supports it
* Disable power saving mode on GPU driver
* V-sync is not forced off
* Run the display on a target refresh rate of `59.950 hz` which has been determined to be
[the most compatible across all PC-based versions](../dev/journal/2025-02-09-iidx-engine.md#engine-step-time).
##### Turn-off g-sync
Create a new GPU profile for IIDX, if it doesn't exist yet:
```bat
nvgpu.exe profile create iidx
```
Add the application names when the profile needs to be applied:
```bat
:: For iidx versions 9 to 17
nvgpu.exe profile application-add iidx bm2dx.exe
:: For iidx versions 18+
nvgpu.exe profile application-add iidx launcher.exe
```
Disable G-SYNC for the profile:
```bat
nvgpu.exe profile gsync-disable iidx
```
##### Disable power saving mode
Set GPU power state to maximum for the profile (assumes you have a
[GPU profile called `iidx` already created](#turn-off-g-sync)):
```bat
nvgpu.exe profile gpu-power-state-max iidx
```
##### Configure and verify target refresh rate of 59.950 hz and vsync
Get display ID of your primary display:
```bat
nvgpu.exe display primary-display-id
```
Copy the hex-value of the display ID and use it in the following commands.
Test the custom display timing first, e.g. for versions that run in 1920x1080
(Replace `<DISPLAY_ID> ` with the primary display ID you got):
```bat
nvgpu.exe display custom-resolution-test <DISPLAY_ID> 1920 1080 59.95 10
```
This will test it for 10 seconds and then revert. If the result looked good, i.e. the screen didn't
go blank or the display output was garbage, apply it:
```bat
nvgpu.exe display custom-resolution-set <DISPLAY_ID> 1920 1080 59.95
```
Test and verify the configuration is applied and works correctly:
```bat
d3d9-monitor-check.exe cmdline refresh-rate-test 1920 1080 60
```
Test if the enforced refresh rate is compatible with your display and vsync is working correctly:
```bat
d3d9-monitor-check.exe cmdline vsync-test 1920 1080 60
```
##### Alternative refresh rate configuration
If for some reason your display doesn't support 59.950 hz properly, i.e. display artifacts or vsync
issues, you can use any other 60 hz compatible refresh rate, e.g. anything between 59.900 hz and
60.100 hz that your display supports properly.
Follow the same steps [as above](#configure-and-verify-target-refresh-rate-of-59950-hz-and-vsync)
but use a different refresh rate, e.g. 60.000 hz.
Verify using the `d3d9-monitor-check.exe` with the outlined steps if you need to play around to find
a refresh rate that works for your setup.
For the game versions 9 to 19, you have to use the chart patch feature of bemanitools to patch
the charts to your custom refresh rate. Otherwise, the game engine will run on your configured
refresh rate, but it will take the non-matching refresh rate from the chart data which causes
song de-syncing.
For example, to configure a refresh rate of 60.000 hz in the iidxhook config file:
```text
gfx.monitor_check=60.000
```
##### ATI/AMD
Currently, there is no tooling provided by bemanitools to configure the AMD GPU driver. The basic
concepts of what needs to be configured still applies as outlined in the NVIDIA sections above
though, e.g. through AMD's GPU control panel.
Further steps and instructions TBD

View File

@@ -146,16 +146,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
- Use iidxhook's frame rate limiter feature (see further below) to software lock the refresh rate.
This might be necessary on Windows 7 and newer for D3D8 games, e.g. iidx 9 to 12, which seem to
ignore GPU side v-sync.
- Use iidxhook's auto timebase feature (see further below) or set a pre-determined value to cut down
start-up times.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
### The game still stutters (randomly) and drifts off-sync
@@ -173,9 +164,7 @@ This can be caused by:
## My songs are offsync
- Make sure your machine's refresh rate is stable
- If you don't get a close to 59.94hz refresh rate, use the software monitor check/auto timebase
that's built into iidxhook (refer to help/config file)
Refer to the [iidx-syncbook](iidx-syncbook.md).
## The game crashes instantly (10th, RED, HAPPY SKY)
@@ -233,6 +222,8 @@ file) or use a CLVSD.ax codec which has the debugger checks removed.
## I used the auto timebase option and/or limited my refresh rate but the songs are still going offsync
Refer to the [iidx-syncbook](iidx-syncbook.md) if you haven't already.
There aren't many options left. The old games were developed for specific hardware and are not
guaranteed to work well on (especially) newer hardware. Multiple monitor setups can also have a bad
impact on a stable refresh rate. Try a setup with just a single monitor you want to use for gameplay

View File

@@ -115,16 +115,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
- Use iidxhook's frame rate limiter feature (see further below) to software lock the refresh rate.
This might be necessary on Windows 7 and newer for D3D8 games, e.g. iidx 9 to 12, which seem to
ignore GPU side v-sync.
- Use iidxhook's auto timebase feature (see further below) or set a pre-determined value to cut down
start-up times.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
### The game still stutters (randomly) and drifts off-sync
@@ -142,9 +133,7 @@ This can be caused by:
## My songs are offsync
- Make sure your machine's refresh rate is stable
- If you don't get a close to 59.94hz refresh rate, use the software monitor check/auto timebase
that's built into iidxhook (refer to help/config file)
Refer to the [iidx-syncbook](iidx-syncbook.md).
## The game crashes instantly
@@ -192,6 +181,8 @@ CLVSD.ax codec which has the debugger checks removed.
## I used the auto timebase option and/or limited my refresh rate but the songs are still going offsync
Refer to the [iidx-syncbook](iidx-syncbook.md) if you haven't already.
There aren't many options left. The old games were developed for specific hardware and are not
guaranteed to work well on (especially) newer hardware. Multiple monitor setups can also have a bad
impact on a stable refresh rate. Try a setup with just a single monitor you want to use for gameplay

View File

@@ -132,16 +132,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
- Use iidxhook's frame rate limiter feature (see further below) to software lock the refresh rate.
This might be necessary on Windows 7 and newer for D3D8 games, e.g. iidx 9 to 12, which seem to
ignore GPU side v-sync.
- Use iidxhook's auto timebase feature (see further below) or set a pre-determined value to cut down
start-up times.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
## "NETWORK WARNING" instead of "NETWORK OK"
@@ -154,15 +145,7 @@ This can be caused by:
## My songs are offsync
The built-in monitor check just determines if the game should sync to either 59.94 hz (S-Video
setting) or 60.04 hz (VGA setting). If you don't have a setup that runs on (as close as possible)
these values:
- Make sure your machine's refresh rate is stable, e.g. 60.00x hz.
- If you don't get a close to 59.94hz (S-Video setting) or 60.04 hz (VGA setting) refresh rate, go
an set the output mode in the operator menu to "VGA" to enforce the game to run chart syncing on
60.04 hz refresh rate (even if your setup does not have that value). Next, use the software
monitor check/auto timebase that's built into iidxhook (refer to cmd help/configfile).
Refer to the [iidx-syncbook](iidx-syncbook.md).
## My game runs too fast
@@ -205,6 +188,8 @@ CLVSD.ax codec which has the debugger checks removed.
## I used the auto timebase option and/or limited my refresh rate but the songs are still going offsync
Refer to the [iidx-syncbook](iidx-syncbook.md) if you haven't already.
There aren't many options left. The old games were developed for specific hardware and are not
guaranteed to work well on (especially) newer hardware. Multiple monitor setups can also have a bad
impact on a stable refresh rate. Try a setup with just a single monitor you want to use for gameplay

View File

@@ -143,16 +143,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
- Use iidxhook's frame rate limiter feature (see further below) to software lock the refresh rate.
This might be necessary on Windows 7 and newer for D3D8 games, e.g. iidx 9 to 12, which seem to
ignore GPU side v-sync.
- Use iidxhook's auto timebase feature (see further below) or set a pre-determined value to cut down
start-up times.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
## "NETWORK WARNING" instead of "NETWORK OK"
@@ -165,15 +156,7 @@ This can be caused by:
## My songs are offsync
The built-in monitor check just determines if the game should sync to either 59.94 hz (S-Video
setting) or 60.04 hz (VGA setting). If you don't have a setup that runs on (as close as possible)
these values:
- Make sure your machine's refresh rate is stable, e.g. 60.00x hz.
- If you don't get a close to 59.94hz (S-Video setting) or 60.04 hz (VGA setting) refresh rate, go
an set the output mode in the operator menu to "VGA" to enforce the game to run chart syncing on
60.04 hz refresh rate (even if your setup does not have that value). Next, use the software
monitor check/auto timebase that's built into iidxhook (refer to cmd help/configfile).
Refer to the [iidx-syncbook](iidx-syncbook.md).
## My game runs too fast
@@ -211,6 +194,8 @@ CLVSD.ax codec which has the debugger checks removed.
## I used the auto timebase option and/or limited my refresh rate but the songs are still going offsync
Refer to the [iidx-syncbook](iidx-syncbook.md) if you haven't already.
There aren't many options left. The old games were developed for specific hardware and are not
guaranteed to work well on (especially) newer hardware. Multiple monitor setups can also have a bad
impact on a stable refresh rate. Try a setup with just a single monitor you want to use for gameplay

View File

@@ -143,16 +143,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
- Use iidxhook's frame rate limiter feature (see further below) to software lock the refresh rate.
This might be necessary on Windows 7 and newer for D3D8 games, e.g. iidx 9 to 12, which seem to
ignore GPU side v-sync.
- Use iidxhook's auto timebase feature (see further below) or set a pre-determined value to cut down
start-up times.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
## "NETWORK WARNING" instead of "NETWORK OK"
@@ -165,11 +156,7 @@ This can be caused by:
## My songs are offsync
From this version onwards (if you use the very final data of Lincle), the game comes with a built-in
auto timebase option ("monitor check" on startup) which dynamically, detects the refresh rate of
your current setup. Thus, BT5's timebase option is not included from this hook version onwards,
anymore. Ensure that refresh rate displayed is very stable, e.g. 60.00x hz, and the game should be
able to provide you with a smooth and sync game experience.
Refer to the [iidx-syncbook](iidx-syncbook.md).
## My game runs too fast

View File

@@ -155,11 +155,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
## "NETWORK WARNING" instead of "NETWORK OK"
@@ -172,11 +168,7 @@ This can be caused by:
## My songs are offsync
From this version onwards (or Lincle very final revision), the game comes with a built-in auto
timebase option ("monitor check" on startup) which dynamically, detects the refresh rate of your
current setup. Thus, BT5's timebase option is not included from this hook version onwards, anymore.
Ensure that refresh rate displayed is very stable, e.g. 60.00x hz, and the game should be able to
provide you with a smooth and sync game experience.
Refer to the [iidx-syncbook](iidx-syncbook.md).
## My game runs too fast

View File

@@ -159,11 +159,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
## "NETWORK WARNING" instead of "NETWORK OK"
@@ -176,11 +172,7 @@ This can be caused by:
## My songs are offsync
From IIDX 20 (or Lincle very final revision) onwards, the game comes with a built-in auto timebase
option ("monitor check" on startup) which dynamically, detects the refresh rate of your current
setup. Thus, BT5's timebase option is not included from this hook version onwards, anymore. Ensure
that refresh rate displayed is very stable, e.g. 60.00x hz, and the game should be able to provide
you with a smooth and sync game experience.
Refer to the [iidx-syncbook](iidx-syncbook.md).
## My game runs too fast

View File

@@ -158,11 +158,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
## "NETWORK WARNING" instead of "NETWORK OK"
@@ -175,11 +171,7 @@ This can be caused by:
## My songs are offsync
From IIDX 20 (or Lincle very final revision) onwards, the game comes with a built-in auto timebase
option ("monitor check" on startup) which dynamically, detects the refresh rate of your current
setup. Thus, BT5's timebase option is not included from this hook version onwards, anymore. Ensure
that refresh rate displayed is very stable, e.g. 60.00x hz, and the game should be able to provide
you with a smooth and sync game experience.
Refer to the [iidx-syncbook](iidx-syncbook.md).
## My game runs too fast

View File

@@ -205,11 +205,7 @@ This can be related to various issues:
start "" /relatime "gamestart.bat"
```
- Enforce v-sync enabled in your GPU settings.
- Ensure that you have a constant refresh rate around the 60 hz (59.9xx or 60.0xx) that is not
jumping around. Use the timebase feature of one of the newer games to check that or enable
iidxhook's timebase and check the log output for the determined value. Run this a few times and
check if the results differ.
Also refer to the [iidx-syncbook](iidx-syncbook.md).
## "NETWORK WARNING" instead of "NETWORK OK"
@@ -222,11 +218,7 @@ This can be caused by:
## My songs are offsync
From IIDX 20 (or Lincle very final revision) onwards, the game comes with a built-in auto timebase
option ("monitor check" on startup) which dynamically, detects the refresh rate of your current
setup. Thus, BT5's timebase option is not included from this hook version onwards, anymore. Ensure
that refresh rate displayed is very stable, e.g. 60.00x hz, and the game should be able to provide
you with a smooth and sync game experience.
Refer to the [iidx-syncbook](iidx-syncbook.md).
## My game runs too fast

View File

@@ -1,3 +0,0 @@
// TODO have a separate dll that acts as a debug
// overlay for btools in general providing stuff
// like frame graph, text sections for IO timings etc.

View File

@@ -1,10 +0,0 @@
libs += hdr-histogram
src_hdr-histogram := \
hdr_encoding.c \
hdr_histogram_log_no_op.c \
hdr_histogram.c \
hdr_interval_recorder.c \
hdr_thread.c \
hdr_time.c \
hdr_writer_reader_phaser.c \

View File

@@ -1,146 +0,0 @@
/**
* hdr_atomic.h
* Written by Philip Orwig and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_ATOMIC_H__
#define HDR_ATOMIC_H__
#if defined(_MSC_VER) && !(defined(__clang__) && (defined(_M_ARM) || defined(_M_ARM64)))
#include <stdint.h>
#include <intrin.h>
#include <stdbool.h>
static void __inline * hdr_atomic_load_pointer(void** pointer)
{
_ReadBarrier();
return *pointer;
}
static void hdr_atomic_store_pointer(void** pointer, void* value)
{
_WriteBarrier();
*pointer = value;
}
static int64_t __inline hdr_atomic_load_64(int64_t* field)
{
_ReadBarrier();
return *field;
}
static void __inline hdr_atomic_store_64(int64_t* field, int64_t value)
{
_WriteBarrier();
*field = value;
}
static int64_t __inline hdr_atomic_exchange_64(volatile int64_t* field, int64_t value)
{
#if defined(_WIN64)
return _InterlockedExchange64(field, value);
#else
int64_t comparand;
int64_t initial_value = *field;
do
{
comparand = initial_value;
initial_value = _InterlockedCompareExchange64(field, value, comparand);
}
while (comparand != initial_value);
return initial_value;
#endif
}
static int64_t __inline hdr_atomic_add_fetch_64(volatile int64_t* field, int64_t value)
{
#if defined(_WIN64)
return _InterlockedExchangeAdd64(field, value) + value;
#else
int64_t comparand;
int64_t initial_value = *field;
do
{
comparand = initial_value;
initial_value = _InterlockedCompareExchange64(field, comparand + value, comparand);
}
while (comparand != initial_value);
return initial_value + value;
#endif
}
static bool __inline hdr_atomic_compare_exchange_64(volatile int64_t* field, int64_t* expected, int64_t desired)
{
return *expected == _InterlockedCompareExchange64(field, desired, *expected);
}
#elif defined(__ATOMIC_SEQ_CST)
#define hdr_atomic_load_pointer(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
#define hdr_atomic_store_pointer(f,v) __atomic_store_n(f,v, __ATOMIC_SEQ_CST)
#define hdr_atomic_load_64(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
#define hdr_atomic_store_64(f,v) __atomic_store_n(f,v, __ATOMIC_SEQ_CST)
#define hdr_atomic_exchange_64(f,i) __atomic_exchange_n(f,i, __ATOMIC_SEQ_CST)
#define hdr_atomic_add_fetch_64(field, value) __atomic_add_fetch(field, value, __ATOMIC_SEQ_CST)
#define hdr_atomic_compare_exchange_64(field, expected, desired) __atomic_compare_exchange_n(field, expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
#elif defined(__x86_64__)
#include <stdint.h>
#include <stdbool.h>
static inline void* hdr_atomic_load_pointer(void** pointer)
{
void* p = *pointer;
asm volatile ("" ::: "memory");
return p;
}
static inline void hdr_atomic_store_pointer(void** pointer, void* value)
{
asm volatile ("lock; xchgq %0, %1" : "+q" (value), "+m" (*pointer));
}
static inline int64_t hdr_atomic_load_64(int64_t* field)
{
int64_t i = *field;
asm volatile ("" ::: "memory");
return i;
}
static inline void hdr_atomic_store_64(int64_t* field, int64_t value)
{
asm volatile ("lock; xchgq %0, %1" : "+q" (value), "+m" (*field));
}
static inline int64_t hdr_atomic_exchange_64(volatile int64_t* field, int64_t value)
{
int64_t result = 0;
asm volatile ("lock; xchgq %1, %2" : "=r" (result), "+q" (value), "+m" (*field));
return result;
}
static inline int64_t hdr_atomic_add_fetch_64(volatile int64_t* field, int64_t value)
{
return __sync_add_and_fetch(field, value);
}
static inline bool hdr_atomic_compare_exchange_64(volatile int64_t* field, int64_t* expected, int64_t desired)
{
int64_t original;
asm volatile( "lock; cmpxchgq %2, %1" : "=a"(original), "+m"(*field) : "q"(desired), "0"(*expected));
return original == *expected;
}
#else
#error "Unable to determine atomic operations for your platform"
#endif
#endif /* HDR_ATOMIC_H__ */

View File

@@ -1,322 +0,0 @@
/**
* hdr_encoding.c
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <errno.h>
#include <stddef.h>
#include <math.h>
#include "hdr-histogram/hdr_encoding.h"
#include "hdr-histogram/hdr_tests.h"
int zig_zag_encode_i64(uint8_t* buffer, int64_t signed_value)
{
int bytesWritten;
int64_t value = signed_value;
value = (value << 1) ^ (value >> 63);
if (value >> 7 == 0)
{
buffer[0] = (uint8_t) value;
bytesWritten = 1;
}
else
{
buffer[0] = (uint8_t) ((value & 0x7F) | 0x80);
if (value >> 14 == 0)
{
buffer[1] = (uint8_t) (value >> 7);
bytesWritten = 2;
}
else
{
buffer[1] = (uint8_t) ((value >> 7 | 0x80));
if (value >> 21 == 0)
{
buffer[2] = (uint8_t) (value >> 14);
bytesWritten = 3;
}
else
{
buffer[2] = (uint8_t) (value >> 14 | 0x80);
if (value >> 28 == 0)
{
buffer[3] = (uint8_t) (value >> 21);
bytesWritten = 4;
}
else
{
buffer[3] = (uint8_t) (value >> 21 | 0x80);
if (value >> 35 == 0)
{
buffer[4] = (uint8_t) (value >> 28);
bytesWritten = 5;
}
else
{
buffer[4] = (uint8_t) (value >> 28 | 0x80);
if (value >> 42 == 0)
{
buffer[5] = (uint8_t) (value >> 35);
bytesWritten = 6;
}
else
{
buffer[5] = (uint8_t) (value >> 35 | 0x80);
if (value >> 49 == 0)
{
buffer[6] = (uint8_t) (value >> 42);
bytesWritten = 7;
}
else
{
buffer[6] = (uint8_t) (value >> 42 | 0x80);
if (value >> 56 == 0)
{
buffer[7] = (uint8_t) (value >> 49);
bytesWritten = 8;
}
else
{
buffer[7] = (uint8_t) (value >> 49 | 0x80);
buffer[8] = (uint8_t) (value >> 56);
bytesWritten = 9;
}
}
}
}
}
}
}
}
return bytesWritten;
}
int zig_zag_decode_i64(const uint8_t* buffer, int64_t* signed_value)
{
uint64_t v = buffer[0];
uint64_t value = v & 0x7F;
int bytesRead = 1;
if ((v & 0x80) != 0)
{
bytesRead = 2;
v = buffer[1];
value |= (v & 0x7F) << 7;
if ((v & 0x80) != 0)
{
bytesRead = 3;
v = buffer[2];
value |= (v & 0x7F) << 14;
if ((v & 0x80) != 0)
{
bytesRead = 4;
v = buffer[3];
value |= (v & 0x7F) << 21;
if ((v & 0x80) != 0)
{
bytesRead = 5;
v = buffer[4];
value |= (v & 0x7F) << 28;
if ((v & 0x80) != 0)
{
bytesRead = 6;
v = buffer[5];
value |= (v & 0x7F) << 35;
if ((v & 0x80) != 0)
{
bytesRead = 7;
v = buffer[6];
value |= (v & 0x7F) << 42;
if ((v & 0x80) != 0)
{
bytesRead = 8;
v = buffer[7];
value |= (v & 0x7F) << 49;
if ((v & 0x80) != 0)
{
bytesRead = 9;
v = buffer[8];
value |= v << 56;
}
}
}
}
}
}
}
}
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4146) /* C4146: unary minus operator applied to unsigned type, result still unsigned */
#endif
value = (value >> 1) ^ (-(value & 1));
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
*signed_value = (int64_t) value;
return bytesRead;
}
static const char base64_table[] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
};
static char get_base_64(uint32_t _24_bit_value, int shift)
{
uint32_t _6_bit_value = 0x3F & (_24_bit_value >> shift);
return base64_table[_6_bit_value];
}
static int from_base_64(int c)
{
if ('A' <= c && c <= 'Z')
{
return c - 'A';
}
else if ('a' <= c && c <= 'z')
{
return (c - 'a') + 26;
}
else if ('0' <= c && c <= '9')
{
return (c - '0') + 52;
}
else if ('+' == c)
{
return 62;
}
else if ('/' == c)
{
return 63;
}
else if ('=' == c)
{
return 0;
}
return EINVAL;
}
size_t hdr_base64_encoded_len(size_t decoded_size)
{
return (size_t) (ceil(decoded_size / 3.0) * 4.0);
}
size_t hdr_base64_decoded_len(size_t encoded_size)
{
return (encoded_size / 4) * 3;
}
static void hdr_base64_encode_block_pad(const uint8_t* input, char* output, size_t pad)
{
uint32_t _24_bit_value = 0;
switch (pad)
{
case 2:
_24_bit_value = (input[0] << 16) + (input[1] << 8);
output[0] = get_base_64(_24_bit_value, 18);
output[1] = get_base_64(_24_bit_value, 12);
output[2] = get_base_64(_24_bit_value, 6);
output[3] = '=';
break;
case 1:
_24_bit_value = (input[0] << 16);
output[0] = get_base_64(_24_bit_value, 18);
output[1] = get_base_64(_24_bit_value, 12);
output[2] = '=';
output[3] = '=';
break;
default:
/* No-op */
break;
}
}
/**
* Assumes that there is 3 input bytes and 4 output chars.
*/
void hdr_base64_encode_block(const uint8_t* input, char* output)
{
uint32_t _24_bit_value = (input[0] << 16) + (input[1] << 8) + (input[2]);
output[0] = get_base_64(_24_bit_value, 18);
output[1] = get_base_64(_24_bit_value, 12);
output[2] = get_base_64(_24_bit_value, 6);
output[3] = get_base_64(_24_bit_value, 0);
}
int hdr_base64_encode(
const uint8_t* input, size_t input_len, char* output, size_t output_len)
{
size_t i, j, remaining;
if (hdr_base64_encoded_len(input_len) != output_len)
{
return EINVAL;
}
for (i = 0, j = 0; input_len - i >= 3 && j < output_len; i += 3, j += 4)
{
hdr_base64_encode_block(&input[i], &output[j]);
}
remaining = input_len - i;
hdr_base64_encode_block_pad(&input[i], &output[j], remaining);
return 0;
}
/**
* Assumes that there is 4 input chars available and 3 output chars.
*/
void hdr_base64_decode_block(const char* input, uint8_t* output)
{
uint32_t _24_bit_value = 0;
_24_bit_value |= from_base_64(input[0]) << 18;
_24_bit_value |= from_base_64(input[1]) << 12;
_24_bit_value |= from_base_64(input[2]) << 6;
_24_bit_value |= from_base_64(input[3]);
output[0] = (uint8_t) ((_24_bit_value >> 16) & 0xFF);
output[1] = (uint8_t) ((_24_bit_value >> 8) & 0xFF);
output[2] = (uint8_t) ((_24_bit_value) & 0xFF);
}
int hdr_base64_decode(
const char* input, size_t input_len, uint8_t* output, size_t output_len)
{
size_t i, j;
if (input_len < 4 ||
(input_len & 3u) != 0 ||
(input_len / 4) * 3 != output_len)
{
return -EINVAL;
}
for (i = 0, j = 0; i < input_len; i += 4, j += 3)
{
hdr_base64_decode_block(&input[i], &output[j]);
}
return 0;
}

View File

@@ -1,79 +0,0 @@
/**
* hdr_encoding.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_ENCODING_H
#define HDR_ENCODING_H
#include <stdint.h>
#define MAX_BYTES_LEB128 9
#ifdef __cplusplus
extern "C" {
#endif
/**
* Writes a int64_t value to the given buffer in LEB128 ZigZag encoded format
*
* @param buffer the buffer to write to
* @param signed_value the value to write to the buffer
* @return the number of bytes written to the buffer
*/
int zig_zag_encode_i64(uint8_t* buffer, int64_t signed_value);
/**
* Read an LEB128 ZigZag encoded long value from the given buffer
*
* @param buffer the buffer to read from
* @param retVal out value to capture the read value
* @return the number of bytes read from the buffer
*/
int zig_zag_decode_i64(const uint8_t* buffer, int64_t* signed_value);
/**
* Gets the length in bytes of base64 data, given the input size.
*
* @param decoded_size the size of the unencoded values.
* @return the encoded size
*/
size_t hdr_base64_encoded_len(size_t decoded_size);
/**
* Encode into base64.
*
* @param input the data to encode
* @param input_len the length of the data to encode
* @param output the buffer to write the output to
* @param output_len the number of bytes to write to the output
*/
int hdr_base64_encode(
const uint8_t* input, size_t input_len, char* output, size_t output_len);
/**
* Gets the length in bytes of decoded base64 data, given the size of the base64 encoded
* data.
*
* @param encoded_size the size of the encoded value.
* @return the decoded size
*/
size_t hdr_base64_decoded_len(size_t encoded_size);
/**
* Decode from base64.
*
* @param input the base64 encoded data
* @param input_len the size in bytes of the endcoded data
* @param output the buffer to write the decoded data to
* @param output_len the number of bytes to write to the output data
*/
int hdr_base64_decode(
const char* input, size_t input_len, uint8_t* output, size_t output_len);
#ifdef __cplusplus
}
#endif
#endif /* HDR_HISTOGRAM_HDR_ENCODING_H */

View File

@@ -1,116 +0,0 @@
/**
* hdr_time.h
* Released to the public domain, as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_ENDIAN_H__
#define HDR_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
# define __WINDOWS__
#endif
#if defined(__linux__) || defined(__CYGWIN__)
# include <endian.h>
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define htobe16(x) OSSwapHostToBigInt16(x)
# define htole16(x) OSSwapHostToLittleInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x)
# define le16toh(x) OSSwapLittleToHostInt16(x)
# define htobe32(x) OSSwapHostToBigInt32(x)
# define htole32(x) OSSwapHostToLittleInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x)
# define htole64(x) OSSwapHostToLittleInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#elif defined(__OpenBSD__)
# include <sys/endian.h>
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/endian.h>
# define be16toh(x) betoh16(x)
# define le16toh(x) letoh16(x)
# define be32toh(x) betoh32(x)
# define le32toh(x) letoh32(x)
# define be64toh(x) betoh64(x)
# define le64toh(x) letoh64(x)
#elif defined(__WINDOWS__)
# include <winsock2.h>
# if BYTE_ORDER == LITTLE_ENDIAN
# define htobe16(x) htons(x)
# define htole16(x) (x)
# define be16toh(x) ntohs(x)
# define le16toh(x) (x)
# define htobe32(x) htonl(x)
# define htole32(x) (x)
# define be32toh(x) ntohl(x)
# define le32toh(x) (x)
# define htobe64(x) htonll(x)
# define htole64(x) (x)
# define be64toh(x) ntohll(x)
# define le64toh(x) (x)
# elif BYTE_ORDER == BIG_ENDIAN
/* that would be xbox 360 */
# define htobe16(x) (x)
# define htole16(x) __builtin_bswap16(x)
# define be16toh(x) (x)
# define le16toh(x) __builtin_bswap16(x)
# define htobe32(x) (x)
# define htole32(x) __builtin_bswap32(x)
# define be32toh(x) (x)
# define le32toh(x) __builtin_bswap32(x)
# define htobe64(x) (x)
# define htole64(x) __builtin_bswap64(x)
# define be64toh(x) (x)
# define le64toh(x) __builtin_bswap64(x)
# else
# error byte order not supported
# endif
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#else
# error platform not supported
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,516 +0,0 @@
/**
* hdr_histogram.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*
* The source for the hdr_histogram utilises a few C99 constructs, specifically
* the use of stdint/stdbool and inline variable declaration.
*/
#ifndef HDR_HISTOGRAM_H
#define HDR_HISTOGRAM_H 1
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
struct hdr_histogram
{
int64_t lowest_discernible_value;
int64_t highest_trackable_value;
int32_t unit_magnitude;
int32_t significant_figures;
int32_t sub_bucket_half_count_magnitude;
int32_t sub_bucket_half_count;
int64_t sub_bucket_mask;
int32_t sub_bucket_count;
int32_t bucket_count;
int64_t min_value;
int64_t max_value;
int32_t normalizing_index_offset;
double conversion_ratio;
int32_t counts_len;
int64_t total_count;
int64_t* counts;
};
#ifdef __cplusplus
extern "C" {
#endif
/**
* Allocate the memory and initialise the hdr_histogram.
*
* Due to the size of the histogram being the result of some reasonably
* involved math on the input parameters this function it is tricky to stack allocate.
* The histogram should be released with hdr_close
*
* @param lowest_discernible_value The smallest possible value that is distinguishable from 0.
* Must be a positive integer that is >= 1. May be internally rounded down to nearest power of 2.
* @param highest_trackable_value The largest possible value to be put into the
* histogram.
* @param significant_figures The level of precision for this histogram, i.e. the number
* of figures in a decimal number that will be maintained. E.g. a value of 3 will mean
* the results from the histogram will be accurate up to the first three digits. Must
* be a value between 1 and 5 (inclusive).
* @param result Output parameter to capture allocated histogram.
* @return 0 on success, EINVAL if lowest_discernible_value is < 1 or the
* significant_figure value is outside of the allowed range, ENOMEM if malloc
* failed.
*/
int hdr_init(
int64_t lowest_discernible_value,
int64_t highest_trackable_value,
int significant_figures,
struct hdr_histogram** result);
/**
* Free the memory and close the hdr_histogram.
*
* @param h The histogram you want to close.
*/
void hdr_close(struct hdr_histogram* h);
/**
* Allocate the memory and initialise the hdr_histogram. This is the equivalent of calling
* hdr_init(1, highest_trackable_value, significant_figures, result);
*
* @deprecated use hdr_init.
*/
int hdr_alloc(int64_t highest_trackable_value, int significant_figures, struct hdr_histogram** result);
/**
* Reset a histogram to zero - empty out a histogram and re-initialise it
*
* If you want to re-use an existing histogram, but reset everything back to zero, this
* is the routine to use.
*
* @param h The histogram you want to reset to empty.
*
*/
void hdr_reset(struct hdr_histogram* h);
/**
* Get the memory size of the hdr_histogram.
*
* @param h "This" pointer
* @return The amount of memory used by the hdr_histogram in bytes
*/
size_t hdr_get_memory_size(struct hdr_histogram* h);
/**
* Records a value in the histogram, will round this value of to a precision at or better
* than the significant_figure specified at construction time.
*
* @param h "This" pointer
* @param value Value to add to the histogram
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_value(struct hdr_histogram* h, int64_t value);
/**
* Records a value in the histogram, will round this value of to a precision at or better
* than the significant_figure specified at construction time.
*
* Will record this value atomically, however the whole structure may appear inconsistent
* when read concurrently with this update. Do NOT mix calls to this method with calls
* to non-atomic updates.
*
* @param h "This" pointer
* @param value Value to add to the histogram
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_value_atomic(struct hdr_histogram* h, int64_t value);
/**
* Records count values in the histogram, will round this value of to a
* precision at or better than the significant_figure specified at construction
* time.
*
* @param h "This" pointer
* @param value Value to add to the histogram
* @param count Number of 'value's to add to the histogram
* @return false if any value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_values(struct hdr_histogram* h, int64_t value, int64_t count);
/**
* Records count values in the histogram, will round this value of to a
* precision at or better than the significant_figure specified at construction
* time.
*
* Will record this value atomically, however the whole structure may appear inconsistent
* when read concurrently with this update. Do NOT mix calls to this method with calls
* to non-atomic updates.
*
* @param h "This" pointer
* @param value Value to add to the histogram
* @param count Number of 'value's to add to the histogram
* @return false if any value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_values_atomic(struct hdr_histogram* h, int64_t value, int64_t count);
/**
* Record a value in the histogram and backfill based on an expected interval.
*
* Records a value in the histogram, will round this value of to a precision at or better
* than the significant_figure specified at construction time. This is specifically used
* for recording latency. If the value is larger than the expected_interval then the
* latency recording system has experienced co-ordinated omission. This method fills in the
* values that would have occurred had the client providing the load not been blocked.
* @param h "This" pointer
* @param value Value to add to the histogram
* @param expected_interval The delay between recording values.
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_corrected_value(struct hdr_histogram* h, int64_t value, int64_t expected_interval);
/**
* Record a value in the histogram and backfill based on an expected interval.
*
* Records a value in the histogram, will round this value of to a precision at or better
* than the significant_figure specified at construction time. This is specifically used
* for recording latency. If the value is larger than the expected_interval then the
* latency recording system has experienced co-ordinated omission. This method fills in the
* values that would have occurred had the client providing the load not been blocked.
*
* Will record this value atomically, however the whole structure may appear inconsistent
* when read concurrently with this update. Do NOT mix calls to this method with calls
* to non-atomic updates.
*
* @param h "This" pointer
* @param value Value to add to the histogram
* @param expected_interval The delay between recording values.
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_corrected_value_atomic(struct hdr_histogram* h, int64_t value, int64_t expected_interval);
/**
* Record a value in the histogram 'count' times. Applies the same correcting logic
* as 'hdr_record_corrected_value'.
*
* @param h "This" pointer
* @param value Value to add to the histogram
* @param count Number of 'value's to add to the histogram
* @param expected_interval The delay between recording values.
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_corrected_values(struct hdr_histogram* h, int64_t value, int64_t count, int64_t expected_interval);
/**
* Record a value in the histogram 'count' times. Applies the same correcting logic
* as 'hdr_record_corrected_value'.
*
* Will record this value atomically, however the whole structure may appear inconsistent
* when read concurrently with this update. Do NOT mix calls to this method with calls
* to non-atomic updates.
*
* @param h "This" pointer
* @param value Value to add to the histogram
* @param count Number of 'value's to add to the histogram
* @param expected_interval The delay between recording values.
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_corrected_values_atomic(struct hdr_histogram* h, int64_t value, int64_t count, int64_t expected_interval);
/**
* Adds all of the values from 'from' to 'this' histogram. Will return the
* number of values that are dropped when copying. Values will be dropped
* if they around outside of h.lowest_discernible_value and
* h.highest_trackable_value.
*
* @param h "This" pointer
* @param from Histogram to copy values from.
* @return The number of values dropped when copying.
*/
int64_t hdr_add(struct hdr_histogram* h, const struct hdr_histogram* from);
/**
* Adds all of the values from 'from' to 'this' histogram. Will return the
* number of values that are dropped when copying. Values will be dropped
* if they around outside of h.lowest_discernible_value and
* h.highest_trackable_value.
*
* @param h "This" pointer
* @param from Histogram to copy values from.
* @return The number of values dropped when copying.
*/
int64_t hdr_add_while_correcting_for_coordinated_omission(
struct hdr_histogram* h, struct hdr_histogram* from, int64_t expected_interval);
/**
* Get minimum value from the histogram. Will return 2^63-1 if the histogram
* is empty.
*
* @param h "This" pointer
*/
int64_t hdr_min(const struct hdr_histogram* h);
/**
* Get maximum value from the histogram. Will return 0 if the histogram
* is empty.
*
* @param h "This" pointer
*/
int64_t hdr_max(const struct hdr_histogram* h);
/**
* Get the value at a specific percentile.
*
* @param h "This" pointer.
* @param percentile The percentile to get the value for
*/
int64_t hdr_value_at_percentile(const struct hdr_histogram* h, double percentile);
/**
* Get the values at the given percentiles.
*
* @param h "This" pointer.
* @param percentiles The ordered percentiles array to get the values for.
* @param length Number of elements in the arrays.
* @param values Destination array containing the values at the given percentiles.
* The values array should be allocated by the caller.
* @return 0 on success, ENOMEM if the provided destination array is null.
*/
int hdr_value_at_percentiles(const struct hdr_histogram *h, const double *percentiles, int64_t *values, size_t length);
/**
* Gets the standard deviation for the values in the histogram.
*
* @param h "This" pointer
* @return The standard deviation
*/
double hdr_stddev(const struct hdr_histogram* h);
/**
* Gets the mean for the values in the histogram.
*
* @param h "This" pointer
* @return The mean
*/
double hdr_mean(const struct hdr_histogram* h);
/**
* Determine if two values are equivalent with the histogram's resolution.
* Where "equivalent" means that value samples recorded for any two
* equivalent values are counted in a common total count.
*
* @param h "This" pointer
* @param a first value to compare
* @param b second value to compare
* @return 'true' if values are equivalent with the histogram's resolution.
*/
bool hdr_values_are_equivalent(const struct hdr_histogram* h, int64_t a, int64_t b);
/**
* Get the lowest value that is equivalent to the given value within the histogram's resolution.
* Where "equivalent" means that value samples recorded for any two
* equivalent values are counted in a common total count.
*
* @param h "This" pointer
* @param value The given value
* @return The lowest value that is equivalent to the given value within the histogram's resolution.
*/
int64_t hdr_lowest_equivalent_value(const struct hdr_histogram* h, int64_t value);
/**
* Get the count of recorded values at a specific value
* (to within the histogram resolution at the value level).
*
* @param h "This" pointer
* @param value The value for which to provide the recorded count
* @return The total count of values recorded in the histogram within the value range that is
* {@literal >=} lowestEquivalentValue(<i>value</i>) and {@literal <=} highestEquivalentValue(<i>value</i>)
*/
int64_t hdr_count_at_value(const struct hdr_histogram* h, int64_t value);
int64_t hdr_count_at_index(const struct hdr_histogram* h, int32_t index);
int64_t hdr_value_at_index(const struct hdr_histogram* h, int32_t index);
struct hdr_iter_percentiles
{
bool seen_last_value;
int32_t ticks_per_half_distance;
double percentile_to_iterate_to;
double percentile;
};
struct hdr_iter_recorded
{
int64_t count_added_in_this_iteration_step;
};
struct hdr_iter_linear
{
int64_t value_units_per_bucket;
int64_t count_added_in_this_iteration_step;
int64_t next_value_reporting_level;
int64_t next_value_reporting_level_lowest_equivalent;
};
struct hdr_iter_log
{
double log_base;
int64_t count_added_in_this_iteration_step;
int64_t next_value_reporting_level;
int64_t next_value_reporting_level_lowest_equivalent;
};
/**
* The basic iterator. This is a generic structure
* that supports all of the types of iteration. Use
* the appropriate initialiser to get the desired
* iteration.
*
* @
*/
struct hdr_iter
{
const struct hdr_histogram* h;
/** raw index into the counts array */
int32_t counts_index;
/** snapshot of the length at the time the iterator is created */
int64_t total_count;
/** value directly from array for the current counts_index */
int64_t count;
/** sum of all of the counts up to and including the count at this index */
int64_t cumulative_count;
/** The current value based on counts_index */
int64_t value;
int64_t highest_equivalent_value;
int64_t lowest_equivalent_value;
int64_t median_equivalent_value;
int64_t value_iterated_from;
int64_t value_iterated_to;
union
{
struct hdr_iter_percentiles percentiles;
struct hdr_iter_recorded recorded;
struct hdr_iter_linear linear;
struct hdr_iter_log log;
} specifics;
bool (* _next_fp)(struct hdr_iter* iter);
};
/**
* Initalises the basic iterator.
*
* @param itr 'This' pointer
* @param h The histogram to iterate over
*/
void hdr_iter_init(struct hdr_iter* iter, const struct hdr_histogram* h);
/**
* Initialise the iterator for use with percentiles.
*/
void hdr_iter_percentile_init(struct hdr_iter* iter, const struct hdr_histogram* h, int32_t ticks_per_half_distance);
/**
* Initialise the iterator for use with recorded values.
*/
void hdr_iter_recorded_init(struct hdr_iter* iter, const struct hdr_histogram* h);
/**
* Initialise the iterator for use with linear values.
*/
void hdr_iter_linear_init(
struct hdr_iter* iter,
const struct hdr_histogram* h,
int64_t value_units_per_bucket);
/**
* Initialise the iterator for use with logarithmic values
*/
void hdr_iter_log_init(
struct hdr_iter* iter,
const struct hdr_histogram* h,
int64_t value_units_first_bucket,
double log_base);
/**
* Iterate to the next value for the iterator. If there are no more values
* available return faluse.
*
* @param itr 'This' pointer
* @return 'false' if there are no values remaining for this iterator.
*/
bool hdr_iter_next(struct hdr_iter* iter);
typedef enum
{
CLASSIC,
CSV
} format_type;
/**
* Print out a percentile based histogram to the supplied stream. Note that
* this call will not flush the FILE, this is left up to the user.
*
* @param h 'This' pointer
* @param stream The FILE to write the output to
* @param ticks_per_half_distance The number of iteration steps per half-distance to 100%
* @param value_scale Scale the output values by this amount
* @param format_type Format to use, e.g. CSV.
* @return 0 on success, error code on failure. EIO if an error occurs writing
* the output.
*/
int hdr_percentiles_print(
struct hdr_histogram* h, FILE* stream, int32_t ticks_per_half_distance,
double value_scale, format_type format);
/**
* Internal allocation methods, used by hdr_dbl_histogram.
*/
struct hdr_histogram_bucket_config
{
int64_t lowest_discernible_value;
int64_t highest_trackable_value;
int64_t unit_magnitude;
int64_t significant_figures;
int32_t sub_bucket_half_count_magnitude;
int32_t sub_bucket_half_count;
int64_t sub_bucket_mask;
int32_t sub_bucket_count;
int32_t bucket_count;
int32_t counts_len;
};
int hdr_calculate_bucket_config(
int64_t lowest_discernible_value,
int64_t highest_trackable_value,
int significant_figures,
struct hdr_histogram_bucket_config* cfg);
void hdr_init_preallocated(struct hdr_histogram* h, struct hdr_histogram_bucket_config* cfg);
int64_t hdr_size_of_equivalent_value_range(const struct hdr_histogram* h, int64_t value);
int64_t hdr_next_non_equivalent_value(const struct hdr_histogram* h, int64_t value);
int64_t hdr_median_equivalent_value(const struct hdr_histogram* h, int64_t value);
/**
* Used to reset counters after importing data manually into the histogram, used by the logging code
* and other custom serialisation tools.
*/
void hdr_reset_internal_counters(struct hdr_histogram* h);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,236 +0,0 @@
/**
* hdr_histogram_log.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*
* The implementation makes use of zlib to provide compression. You will need
* to link against -lz in order to link applications that include this header.
*/
#ifndef HDR_HISTOGRAM_H_LOG
#define HDR_HISTOGRAM_H_LOG 1
#define HDR_COMPRESSION_COOKIE_MISMATCH -29999
#define HDR_ENCODING_COOKIE_MISMATCH -29998
#define HDR_DEFLATE_INIT_FAIL -29997
#define HDR_DEFLATE_FAIL -29996
#define HDR_INFLATE_INIT_FAIL -29995
#define HDR_INFLATE_FAIL -29994
#define HDR_LOG_INVALID_VERSION -29993
#define HDR_TRAILING_ZEROS_INVALID -29992
#define HDR_VALUE_TRUNCATED -29991
#define HDR_ENCODED_INPUT_TOO_LONG -29990
#define HDR_LOG_TAG_MAX_BUFFER_LEN (1024)
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "hdr-histogram/hdr_time.h"
#include "hdr-histogram/hdr_histogram.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Encode and compress the histogram with gzip.
*/
int hdr_log_encode(struct hdr_histogram* histogram, char** encoded_histogram);
/**
* Decode and decompress the histogram with gzip.
*/
int hdr_log_decode(struct hdr_histogram** histogram, char* base64_histogram, size_t base64_len);
struct hdr_log_entry
{
hdr_timespec start_timestamp;
hdr_timespec interval;
hdr_timespec max;
char *tag;
size_t tag_len;
};
struct hdr_log_writer
{
uint32_t nonce;
};
/**
* Initialise the log writer.
*
* @param writer 'This' pointer
* @return 0 on success.
*/
int hdr_log_writer_init(struct hdr_log_writer* writer);
/**
* Write the header to the log, this will constist of a user defined string,
* the current timestamp, version information and the CSV header.
*
* @param writer 'This' pointer
* @param file The stream to output the log header to.
* @param user_prefix User defined string to include in the header.
* @param timestamp The start time that the histogram started recording from.
* @return Will return 0 if it successfully completed or an error number if there
* was a failure. EIO if the write failed.
*/
int hdr_log_write_header(
struct hdr_log_writer* writer,
FILE* file,
const char* user_prefix,
hdr_timespec* timestamp);
/**
* Write an hdr_histogram entry to the log. It will be encoded in a similar
* fashion to the approach used by the Java version of the HdrHistogram. It will
* be a CSV line consisting of <start timestamp>,<end timestamp>,<max>,<histogram>
* where <histogram> is the binary histogram gzip compressed and base64 encoded.
*
* Timestamp is a bit of misnomer for the start_timestamp and end_timestamp values
* these could be offsets, e.g. start_timestamp could be offset from process start
* time and end_timestamp could actually be the length of the recorded interval.
*
* @param writer 'This' pointer
* @param file The stream to write the entry to.
* @param start_timestamp The start timestamp to include in the logged entry.
* @param end_timestamp The end timestamp to include in the logged entry.
* @param histogram The histogram to encode and log.
* @return Will return 0 if it successfully completed or an error number if there
* was a failure. Errors include HDR_DEFLATE_INIT_FAIL, HDR_DEFLATE_FAIL if
* something when wrong during gzip compression. ENOMEM if we failed to allocate
* or reallocate the buffer used for encoding (out of memory problem). EIO if
* write failed.
*/
int hdr_log_write(
struct hdr_log_writer* writer,
FILE* file,
const hdr_timespec* start_timestamp,
const hdr_timespec* end_timestamp,
struct hdr_histogram* histogram);
/**
* Write an hdr_histogram entry to the log. It will be encoded in a similar
* fashion to the approach used by the Java version of the HdrHistogram. It will
* be a CSV line consisting of [Tag=XXX,]<start timestamp>,<end timestamp>,<max>,<histogram>
* where <histogram> is the binary histogram gzip compressed and base64 encoded.
*
* The tag is option and will only be written if the tag is non-NULL and the tag_len is
* greater than 0.
*
* Timestamp is a bit of misnomer for the start_timestamp and end_timestamp values
* these could be offsets, e.g. start_timestamp could be offset from process start
* time and end_timestamp could actually be the length of the recorded interval.
*
* @param writer 'This' pointer
* @param file The stream to write the entry to.
* @param entry Prefix information for the log line, including timestamps and tag.
* @param histogram The histogram to encode and log.
* @return Will return 0 if it successfully completed or an error number if there
* was a failure. Errors include HDR_DEFLATE_INIT_FAIL, HDR_DEFLATE_FAIL if
* something when wrong during gzip compression. ENOMEM if we failed to allocate
* or reallocate the buffer used for encoding (out of memory problem). EIO if
* write failed.
*/
int hdr_log_write_entry(
struct hdr_log_writer* writer,
FILE* file,
struct hdr_log_entry* entry,
struct hdr_histogram* histogram);
struct hdr_log_reader
{
int major_version;
int minor_version;
hdr_timespec start_timestamp;
};
/**
* Initialise the log reader.
*
* @param reader 'This' pointer
* @return 0 on success
*/
int hdr_log_reader_init(struct hdr_log_reader* reader);
/**
* Reads the the header information from the log. Will capure information
* such as version number and start timestamp from the header.
*
* @param hdr_log_reader 'This' pointer
* @param file The data stream to read from.
* @return 0 on success. An error number on failure.
*/
int hdr_log_read_header(struct hdr_log_reader* reader, FILE* file);
/**
* Reads an entry from the log filling in the specified histogram, timestamp and
* interval values. If the supplied pointer to the histogram for this method is
* NULL then a new histogram will be allocated for the caller, however it will
* become the callers responsibility to free it later. If the pointer is non-null
* the histogram read from the log will be merged with the supplied histogram.
*
* @param reader 'This' pointer
* @param file The stream to read the histogram from.
* @param histogram Pointer to allocate a histogram to or merge into.
* @param timestamp The first timestamp from the CSV entry.
* @param interval The second timestamp from the CSV entry
* @return Will return 0 on success or an error number if there was some wrong
* when reading in the histogram. EOF (-1) will indicate that there are no more
* histograms left to be read from 'file'.
* HDR_INFLATE_INIT_FAIL or HDR_INFLATE_FAIL if
* there was a problem with Gzip. HDR_COMPRESSION_COOKIE_MISMATCH or
* HDR_ENCODING_COOKIE_MISMATCH if the cookie values are incorrect.
* HDR_LOG_INVALID_VERSION if the log can not be parsed. ENOMEM if buffer space
* or the histogram can not be allocated. EIO if there was an error during
* the read. EINVAL in any input values are incorrect.
*/
int hdr_log_read(
struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram,
hdr_timespec* timestamp, hdr_timespec* interval);
/**
* Reads an entry from the log filling in the specified histogram and log entry struct.
* If the supplied pointer to the histogram for this method is
* NULL then a new histogram will be allocated for the caller, however it will
* become the callers responsibility to free it later. If the pointer is non-null
* the histogram read from the log will be merged with the supplied histogram.
* The entry struct contains a pointer to a buffer to load the tag into. If this
* is NULL or the tag_len is 0 then it won't store the tag there. The tag value will be
* NULL-terminated if there available space in the supplied buffer. If the tag is larger
* than the supplied buffer then it will be truncated. If the caller sets the last element
* in the buffer to '\0' before calling this function and it is not '\0' after the function
* returns then the value has been truncated.
*
* @param reader 'This' pointer
* @param file The stream to read the histogram from.
* @param entry Contains all of the information from the log line that is not the histogram.
* @param histogram Pointer to allocate a histogram to or merge into.
* @return Will return 0 on success or an error number if there was some wrong
* when reading in the histogram. EOF (-1) will indicate that there are no more
* histograms left to be read from 'file'.
* HDR_INFLATE_INIT_FAIL or HDR_INFLATE_FAIL if
* there was a problem with Gzip. HDR_COMPRESSION_COOKIE_MISMATCH or
* HDR_ENCODING_COOKIE_MISMATCH if the cookie values are incorrect.
* HDR_LOG_INVALID_VERSION if the log can not be parsed. ENOMEM if buffer space
* or the histogram can not be allocated. EIO if there was an error during
* the read. EINVAL in any input values are incorrect.
*/
int hdr_log_read_entry(
struct hdr_log_reader* reader, FILE* file, struct hdr_log_entry *entry, struct hdr_histogram** histogram);
/**
* Returns a string representation of the error number.
*
* @param errnum The error response from a previous call.
* @return The user readable representation of the error.
*/
const char* hdr_strerror(int errnum);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,171 +0,0 @@
/**
* hdr_histogram_log.c
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "hdr-histogram/hdr_histogram.h"
#include "hdr-histogram/hdr_histogram_log.h"
#include "hdr-histogram/hdr_tests.h"
#define UNUSED(x) (void)(x)
const char* hdr_strerror(int errnum)
{
switch (errnum)
{
case HDR_COMPRESSION_COOKIE_MISMATCH:
return "Compression cookie mismatch";
case HDR_ENCODING_COOKIE_MISMATCH:
return "Encoding cookie mismatch";
case HDR_DEFLATE_INIT_FAIL:
return "Deflate initialisation failed";
case HDR_DEFLATE_FAIL:
return "Deflate failed";
case HDR_INFLATE_INIT_FAIL:
return "Inflate initialisation failed";
case HDR_INFLATE_FAIL:
return "Inflate failed";
case HDR_LOG_INVALID_VERSION:
return "Log - invalid version in log header";
case HDR_TRAILING_ZEROS_INVALID:
return "Invalid number of trailing zeros";
case HDR_VALUE_TRUNCATED:
return "Truncated value found when decoding";
case HDR_ENCODED_INPUT_TOO_LONG:
return "The encoded input exceeds the size of the histogram";
default:
return strerror(errnum);
}
}
int hdr_encode_compressed(
struct hdr_histogram* h,
uint8_t** compressed_histogram,
size_t* compressed_len)
{
UNUSED(h);
UNUSED(compressed_histogram);
UNUSED(compressed_len);
return -1;
}
int hdr_decode_compressed(
uint8_t* buffer, size_t length, struct hdr_histogram** histogram)
{
UNUSED(buffer);
UNUSED(length);
UNUSED(histogram);
return -1;
}
int hdr_log_writer_init(struct hdr_log_writer* writer)
{
UNUSED(writer);
return -1;
}
int hdr_log_write_header(
struct hdr_log_writer* writer, FILE* file,
const char* user_prefix, hdr_timespec* timestamp)
{
UNUSED(writer);
UNUSED(file);
UNUSED(user_prefix);
UNUSED(timestamp);
return -1;
}
int hdr_log_write(
struct hdr_log_writer* writer,
FILE* file,
const hdr_timespec* start_timestamp,
const hdr_timespec* end_timestamp,
struct hdr_histogram* histogram)
{
UNUSED(writer);
UNUSED(file);
UNUSED(start_timestamp);
UNUSED(end_timestamp);
UNUSED(histogram);
return -1;
}
int hdr_log_write_entry(
struct hdr_log_writer* writer,
FILE* file,
struct hdr_log_entry* entry,
struct hdr_histogram* histogram)
{
UNUSED(writer);
UNUSED(file);
UNUSED(entry);
UNUSED(histogram);
return -1;
}
int hdr_log_reader_init(struct hdr_log_reader* reader)
{
UNUSED(reader);
return -1;
}
int hdr_log_read_header(struct hdr_log_reader* reader, FILE* file)
{
UNUSED(reader);
UNUSED(file);
return -1;
}
int hdr_log_read(
struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram,
hdr_timespec* timestamp, hdr_timespec* interval)
{
UNUSED(reader);
UNUSED(file);
UNUSED(histogram);
UNUSED(timestamp);
UNUSED(interval);
return -1;
}
int hdr_log_read_entry(
struct hdr_log_reader* reader, FILE* file, struct hdr_log_entry *entry, struct hdr_histogram** histogram)
{
UNUSED(reader);
UNUSED(file);
UNUSED(entry);
UNUSED(histogram);
return -1;
}
int hdr_log_encode(struct hdr_histogram* histogram, char** encoded_histogram)
{
UNUSED(histogram);
UNUSED(encoded_histogram);
return -1;
}
int hdr_log_decode(struct hdr_histogram** histogram, char* base64_histogram, size_t base64_len)
{
UNUSED(histogram);
UNUSED(base64_histogram);
UNUSED(base64_len);
return -1;
}

View File

@@ -1,12 +0,0 @@
/**
* hdr_histogram_version.h
* Written by Marco Ippolito, Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_HISTOGRAM_VERSION_H
#define HDR_HISTOGRAM_VERSION_H
#define HDR_HISTOGRAM_VERSION "0.11.8"
#endif // HDR_HISTOGRAM_VERSION_H

View File

@@ -1,227 +0,0 @@
/**
* hdr_interval_recorder.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "hdr-histogram/hdr_interval_recorder.h"
#include "hdr-histogram/hdr_atomic.h"
#ifndef HDR_MALLOC_INCLUDE
#define HDR_MALLOC_INCLUDE "hdr-histogram/hdr_malloc.h"
#endif
#include HDR_MALLOC_INCLUDE
int hdr_interval_recorder_init(struct hdr_interval_recorder* r)
{
r->active = r->inactive = NULL;
return hdr_writer_reader_phaser_init(&r->phaser);
}
int hdr_interval_recorder_init_all(
struct hdr_interval_recorder* r,
int64_t lowest_discernible_value,
int64_t highest_trackable_value,
int significant_figures)
{
int result;
r->active = r->inactive = NULL;
result = hdr_writer_reader_phaser_init(&r->phaser);
result = result == 0
? hdr_init(lowest_discernible_value, highest_trackable_value, significant_figures, &r->active)
: result;
return result;
}
void hdr_interval_recorder_destroy(struct hdr_interval_recorder* r)
{
hdr_writer_reader_phaser_destroy(&r->phaser);
if (r->active) {
hdr_close(r->active);
}
if (r->inactive) {
hdr_close(r->inactive);
}
}
struct hdr_histogram* hdr_interval_recorder_sample_and_recycle(
struct hdr_interval_recorder* r,
struct hdr_histogram* histogram_to_recycle)
{
struct hdr_histogram* old_active;
if (NULL == histogram_to_recycle)
{
int64_t lo = r->active->lowest_discernible_value;
int64_t hi = r->active->highest_trackable_value;
int significant_figures = r->active->significant_figures;
hdr_init(lo, hi, significant_figures, &histogram_to_recycle);
}
else
{
hdr_reset(histogram_to_recycle);
}
hdr_phaser_reader_lock(&r->phaser);
/* volatile read */
old_active = hdr_atomic_load_pointer(&r->active);
/* volatile write */
hdr_atomic_store_pointer(&r->active, histogram_to_recycle);
hdr_phaser_flip_phase(&r->phaser, 0);
hdr_phaser_reader_unlock(&r->phaser);
return old_active;
}
struct hdr_histogram* hdr_interval_recorder_sample(struct hdr_interval_recorder* r)
{
r->inactive = hdr_interval_recorder_sample_and_recycle(r, r->inactive);
return r->inactive;
}
static void hdr_interval_recorder_update(
struct hdr_interval_recorder* r,
void(*update_action)(struct hdr_histogram*, void*),
void* arg)
{
int64_t val = hdr_phaser_writer_enter(&r->phaser);
void* active = hdr_atomic_load_pointer(&r->active);
update_action(active, arg);
hdr_phaser_writer_exit(&r->phaser, val);
}
static void update_values(struct hdr_histogram* data, void* arg)
{
struct hdr_histogram* h = data;
int64_t* params = arg;
params[2] = hdr_record_values(h, params[0], params[1]);
}
static void update_values_atomic(struct hdr_histogram* data, void* arg)
{
struct hdr_histogram* h = data;
int64_t* params = arg;
params[2] = hdr_record_values_atomic(h, params[0], params[1]);
}
int64_t hdr_interval_recorder_record_values(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count
)
{
int64_t params[3];
params[0] = value;
params[1] = count;
params[2] = 0;
hdr_interval_recorder_update(r, update_values, &params[0]);
return params[2];
}
int64_t hdr_interval_recorder_record_value(
struct hdr_interval_recorder* r,
int64_t value
)
{
return hdr_interval_recorder_record_values(r, value, 1);
}
static void update_corrected_values(struct hdr_histogram* data, void* arg)
{
struct hdr_histogram* h = data;
int64_t* params = arg;
params[3] = hdr_record_corrected_values(h, params[0], params[1], params[2]);
}
static void update_corrected_values_atomic(struct hdr_histogram* data, void* arg)
{
struct hdr_histogram* h = data;
int64_t* params = arg;
params[3] = hdr_record_corrected_values_atomic(h, params[0], params[1], params[2]);
}
int64_t hdr_interval_recorder_record_corrected_values(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count,
int64_t expected_interval
)
{
int64_t params[4];
params[0] = value;
params[1] = count;
params[2] = expected_interval;
params[3] = 0;
hdr_interval_recorder_update(r, update_corrected_values, &params[0]);
return params[3];
}
int64_t hdr_interval_recorder_record_corrected_value(
struct hdr_interval_recorder* r,
int64_t value,
int64_t expected_interval
)
{
return hdr_interval_recorder_record_corrected_values(r, value, 1, expected_interval);
}
int64_t hdr_interval_recorder_record_value_atomic(
struct hdr_interval_recorder* r,
int64_t value
)
{
return hdr_interval_recorder_record_values_atomic(r, value, 1);
}
int64_t hdr_interval_recorder_record_values_atomic(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count
)
{
int64_t params[3];
params[0] = value;
params[1] = count;
params[2] = 0;
hdr_interval_recorder_update(r, update_values_atomic, &params[0]);
return params[2];
}
int64_t hdr_interval_recorder_record_corrected_value_atomic(
struct hdr_interval_recorder* r,
int64_t value,
int64_t expected_interval
)
{
return hdr_interval_recorder_record_corrected_values_atomic(r, value, 1, expected_interval);
}
int64_t hdr_interval_recorder_record_corrected_values_atomic(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count,
int64_t expected_interval
)
{
int64_t params[4];
params[0] = value;
params[1] = count;
params[2] = expected_interval;
params[3] = 0;
hdr_interval_recorder_update(r, update_corrected_values_atomic, &params[0]);
return params[3];
}

View File

@@ -1,109 +0,0 @@
/**
* hdr_interval_recorder.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_INTERVAL_RECORDER_H
#define HDR_INTERVAL_RECORDER_H 1
#include "hdr-histogram/hdr_writer_reader_phaser.h"
#include "hdr-histogram/hdr_histogram.h"
HDR_ALIGN_PREFIX(8)
struct hdr_interval_recorder
{
struct hdr_histogram* active;
struct hdr_histogram* inactive;
struct hdr_writer_reader_phaser phaser;
}
HDR_ALIGN_SUFFIX(8);
#ifdef __cplusplus
extern "C" {
#endif
int hdr_interval_recorder_init(struct hdr_interval_recorder* r);
int hdr_interval_recorder_init_all(
struct hdr_interval_recorder* r,
int64_t lowest_trackable_value,
int64_t highest_trackable_value,
int significant_figures);
void hdr_interval_recorder_destroy(struct hdr_interval_recorder* r);
int64_t hdr_interval_recorder_record_value(
struct hdr_interval_recorder* r,
int64_t value
);
int64_t hdr_interval_recorder_record_values(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count
);
int64_t hdr_interval_recorder_record_corrected_value(
struct hdr_interval_recorder* r,
int64_t value,
int64_t expected_interval
);
int64_t hdr_interval_recorder_record_corrected_values(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count,
int64_t expected_interval
);
int64_t hdr_interval_recorder_record_value_atomic(
struct hdr_interval_recorder* r,
int64_t value
);
int64_t hdr_interval_recorder_record_values_atomic(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count
);
int64_t hdr_interval_recorder_record_corrected_value_atomic(
struct hdr_interval_recorder* r,
int64_t value,
int64_t expected_interval
);
int64_t hdr_interval_recorder_record_corrected_values_atomic(
struct hdr_interval_recorder* r,
int64_t value,
int64_t count,
int64_t expected_interval
);
/**
* This is generally the preferred approach for recycling histograms through
* the recorder as it is safe when used from callers in multiple threads and
* the returned histogram won't automatically become active without being
* passed back into this method.
*
* @param r 'this' recorder
* @param histogram_to_recycle
* @return the histogram that was previous being recorded to.
*/
struct hdr_histogram* hdr_interval_recorder_sample_and_recycle(
struct hdr_interval_recorder* r,
struct hdr_histogram* histogram_to_recycle);
/**
* @deprecated Prefer hdr_interval_recorder_sample_and_recycle
* @param r 'this' recorder
* @return the histogram that was previous being recorded to.
*/
struct hdr_histogram* hdr_interval_recorder_sample(struct hdr_interval_recorder* r);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,19 +0,0 @@
/**
* hdr_malloc.h
* Written by Filipe Oliveira and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*
* Allocator selection.
*
* This file is used in order to change the HdrHistogram allocator at compile time.
* Just define the following defines to what you want to use. Also add
* the include of your alternate allocator if needed (not needed in order
* to use the default libc allocator). */
#ifndef HDR_MALLOC_H__
#define HDR_MALLOC_H__
#define hdr_malloc malloc
#define hdr_calloc calloc
#define hdr_realloc realloc
#define hdr_free free
#endif

View File

@@ -1,22 +0,0 @@
#ifndef HDR_TESTS_H
#define HDR_TESTS_H
/* These are functions used in tests and are not intended for normal usage. */
#include "hdr-histogram/hdr_histogram.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t counts_index_for(const struct hdr_histogram* h, int64_t value);
int hdr_encode_compressed(struct hdr_histogram* h, uint8_t** compressed_histogram, size_t* compressed_len);
int hdr_decode_compressed(uint8_t* buffer, size_t length, struct hdr_histogram** histogram);
void hdr_base64_decode_block(const char* input, uint8_t* output);
void hdr_base64_encode_block(const uint8_t* input, char* output);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,108 +0,0 @@
/**
* hdr_thread.c
* Written by Philip Orwig and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <stdlib.h>
#include "hdr-histogram/hdr_thread.h"
#ifndef HDR_MALLOC_INCLUDE
#define HDR_MALLOC_INCLUDE "hdr-histogram/hdr_malloc.h"
#endif
#include HDR_MALLOC_INCLUDE
struct hdr_mutex* hdr_mutex_alloc(void)
{
return hdr_malloc(sizeof(hdr_mutex));
}
void hdr_mutex_free(struct hdr_mutex* mutex)
{
hdr_free(mutex);
}
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
int hdr_mutex_init(struct hdr_mutex* mutex)
{
InitializeCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
return 0;
}
void hdr_mutex_destroy(struct hdr_mutex* mutex)
{
DeleteCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
}
void hdr_mutex_lock(struct hdr_mutex* mutex)
{
EnterCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
}
void hdr_mutex_unlock(struct hdr_mutex* mutex)
{
LeaveCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
}
void hdr_yield()
{
Sleep(0);
}
int hdr_usleep(unsigned int useconds)
{
struct timeval tv;
tv.tv_sec = (long)useconds / 1000000;
tv.tv_usec = useconds % 1000000;
select(0, NULL, NULL, NULL, &tv);
return 0;
}
#else
#include <pthread.h>
#include <unistd.h>
int hdr_mutex_init(struct hdr_mutex* mutex)
{
return pthread_mutex_init(&mutex->_mutex, NULL);
}
void hdr_mutex_destroy(struct hdr_mutex* mutex)
{
pthread_mutex_destroy(&mutex->_mutex);
}
void hdr_mutex_lock(struct hdr_mutex* mutex)
{
pthread_mutex_lock(&mutex->_mutex);
}
void hdr_mutex_unlock(struct hdr_mutex* mutex)
{
pthread_mutex_unlock(&mutex->_mutex);
}
void hdr_yield(void)
{
sched_yield();
}
int hdr_usleep(unsigned int useconds)
{
return usleep(useconds);
}
#endif

View File

@@ -1,55 +0,0 @@
/**
* hdr_thread.h
* Written by Philip Orwig and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_THREAD_H__
#define HDR_THREAD_H__
#include <stdint.h>
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#define HDR_ALIGN_PREFIX(alignment) __declspec( align(alignment) )
#define HDR_ALIGN_SUFFIX(alignment)
typedef struct hdr_mutex
{
uint8_t _critical_section[40];
} hdr_mutex;
#else
#include <pthread.h>
#define HDR_ALIGN_PREFIX(alignment)
#define HDR_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
typedef struct hdr_mutex
{
pthread_mutex_t _mutex;
} hdr_mutex;
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct hdr_mutex* hdr_mutex_alloc(void);
void hdr_mutex_free(struct hdr_mutex*);
int hdr_mutex_init(struct hdr_mutex* mutex);
void hdr_mutex_destroy(struct hdr_mutex* mutex);
void hdr_mutex_lock(struct hdr_mutex* mutex);
void hdr_mutex_unlock(struct hdr_mutex* mutex);
void hdr_yield(void);
int hdr_usleep(unsigned int useconds);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,107 +0,0 @@
/**
* hdr_time.h
* Written by Michael Barker and Philip Orwig and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <math.h>
#include "hdr-histogram/hdr_time.h"
#if defined(_WIN32) || defined(_WIN64)
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
static int s_clockPeriodSet = 0;
static double s_clockPeriod = 1.0;
void hdr_gettime(hdr_timespec* t)
{
LARGE_INTEGER num;
/* if this is distasteful, we can add in an hdr_time_init() */
if (!s_clockPeriodSet)
{
QueryPerformanceFrequency(&num);
s_clockPeriod = 1.0 / (double) num.QuadPart;
s_clockPeriodSet = 1;
}
QueryPerformanceCounter(&num);
double seconds = num.QuadPart * s_clockPeriod;
double integral;
double remainder = modf(seconds, &integral);
t->tv_sec = (long) integral;
t->tv_nsec = (long) (remainder * 1000000000);
}
#elif defined(__APPLE__)
#include <mach/clock.h>
#include <mach/mach.h>
void hdr_gettime(hdr_timespec* ts)
{
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
}
void hdr_getnow(hdr_timespec* ts)
{
hdr_gettime(ts);
}
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__OpenBSD__)
void hdr_gettime(hdr_timespec* t)
{
clock_gettime(CLOCK_MONOTONIC, (struct timespec*)t);
}
void hdr_getnow(hdr_timespec* t)
{
clock_gettime(CLOCK_REALTIME, (struct timespec*)t);
}
#else
#warning "Platform not supported\n"
#endif
double hdr_timespec_as_double(const hdr_timespec* t)
{
double d = t->tv_sec;
return d + (t->tv_nsec / 1000000000.0);
}
void hdr_timespec_from_double(hdr_timespec* t, double value)
{
int seconds = (int) value;
int milliseconds = (int) round((value - seconds) * 1000);
t->tv_sec = seconds;
t->tv_nsec = milliseconds * 1000000;
}
int64_t hdr_timespec_diff_us(const hdr_timespec* t0, const hdr_timespec* t1)
{
int64_t delta_us;
delta_us = (t1->tv_sec - t0->tv_sec) * 1000000;
delta_us += (t1->tv_nsec - t0->tv_nsec) / 1000;
return delta_us;
}

View File

@@ -1,50 +0,0 @@
/**
* hdr_time.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_TIME_H__
#define HDR_TIME_H__
#include <stdint.h>
#include <time.h>
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
typedef struct hdr_timespec
{
long tv_sec;
long tv_nsec;
} hdr_timespec;
#else
typedef struct timespec hdr_timespec;
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_MSC_VER)
void hdr_gettime(hdr_timespec* t);
#else
void hdr_gettime(hdr_timespec* t);
#endif
void hdr_getnow(hdr_timespec* t);
double hdr_timespec_as_double(const hdr_timespec* t);
/* Assumes only millisecond accuracy. */
void hdr_timespec_from_double(hdr_timespec* t, double value);
int64_t hdr_timespec_diff_us(const hdr_timespec* t0, const hdr_timespec* t1);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,142 +0,0 @@
/**
* hdr_writer_reader_phaser.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include "hdr-histogram/hdr_thread.h"
#include "hdr-histogram/hdr_writer_reader_phaser.h"
#include "hdr-histogram/hdr_atomic.h"
#ifndef HDR_MALLOC_INCLUDE
#define HDR_MALLOC_INCLUDE "hdr-histogram/hdr_malloc.h"
#endif
#include HDR_MALLOC_INCLUDE
static int64_t _hdr_phaser_get_epoch(int64_t* field)
{
return hdr_atomic_load_64(field);
}
static void _hdr_phaser_set_epoch(int64_t* field, int64_t val)
{
hdr_atomic_store_64(field, val);
}
static int64_t _hdr_phaser_reset_epoch(int64_t* field, int64_t initial_value)
{
return hdr_atomic_exchange_64(field, initial_value);
}
int hdr_writer_reader_phaser_init(struct hdr_writer_reader_phaser* p)
{
int rc;
if (NULL == p)
{
return EINVAL;
}
p->start_epoch = 0;
p->even_end_epoch = 0;
p->odd_end_epoch = INT64_MIN;
p->reader_mutex = hdr_mutex_alloc();
if (!p->reader_mutex)
{
return ENOMEM;
}
rc = hdr_mutex_init(p->reader_mutex);
if (0 != rc)
{
return rc;
}
/* TODO: Should I fence here. */
return 0;
}
void hdr_writer_reader_phaser_destroy(struct hdr_writer_reader_phaser* p)
{
hdr_mutex_destroy(p->reader_mutex);
hdr_mutex_free(p->reader_mutex);
}
int64_t hdr_phaser_writer_enter(struct hdr_writer_reader_phaser* p)
{
return hdr_atomic_add_fetch_64(&p->start_epoch, 1);
}
void hdr_phaser_writer_exit(
struct hdr_writer_reader_phaser* p, int64_t critical_value_at_enter)
{
int64_t* end_epoch =
(critical_value_at_enter < 0) ? &p->odd_end_epoch : &p->even_end_epoch;
hdr_atomic_add_fetch_64(end_epoch, 1);
}
void hdr_phaser_reader_lock(struct hdr_writer_reader_phaser* p)
{
hdr_mutex_lock(p->reader_mutex);
}
void hdr_phaser_reader_unlock(struct hdr_writer_reader_phaser* p)
{
hdr_mutex_unlock(p->reader_mutex);
}
void hdr_phaser_flip_phase(
struct hdr_writer_reader_phaser* p, int64_t sleep_time_ns)
{
bool caught_up;
int64_t start_value_at_flip;
/* TODO: is_held_by_current_thread */
unsigned int sleep_time_us = sleep_time_ns < 1000000000 ? (unsigned int) (sleep_time_ns / 1000) : 1000000;
int64_t start_epoch = _hdr_phaser_get_epoch(&p->start_epoch);
bool next_phase_is_even = (start_epoch < 0);
/* Clear currently used phase end epoch.*/
int64_t initial_start_value;
if (next_phase_is_even)
{
initial_start_value = 0;
_hdr_phaser_set_epoch(&p->even_end_epoch, initial_start_value);
}
else
{
initial_start_value = INT64_MIN;
_hdr_phaser_set_epoch(&p->odd_end_epoch, initial_start_value);
}
/* Reset start value, indicating new phase.*/
start_value_at_flip = _hdr_phaser_reset_epoch(&p->start_epoch, initial_start_value);
do
{
int64_t* end_epoch =
next_phase_is_even ? &p->odd_end_epoch : &p->even_end_epoch;
caught_up = _hdr_phaser_get_epoch(end_epoch) == start_value_at_flip;
if (!caught_up)
{
if (sleep_time_us <= 0)
{
hdr_yield();
}
else
{
hdr_usleep(sleep_time_us);
}
}
}
while (!caught_up);
}

View File

@@ -1,51 +0,0 @@
/**
* hdr_writer_reader_phaser.h
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef HDR_WRITER_READER_PHASER_H
#define HDR_WRITER_READER_PHASER_H 1
#include <stdlib.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include "hdr-histogram/hdr_thread.h"
HDR_ALIGN_PREFIX(8)
struct hdr_writer_reader_phaser
{
int64_t start_epoch;
int64_t even_end_epoch;
int64_t odd_end_epoch;
hdr_mutex* reader_mutex;
}
HDR_ALIGN_SUFFIX(8);
#ifdef __cplusplus
extern "C" {
#endif
int hdr_writer_reader_phaser_init(struct hdr_writer_reader_phaser* p);
void hdr_writer_reader_phaser_destroy(struct hdr_writer_reader_phaser* p);
int64_t hdr_phaser_writer_enter(struct hdr_writer_reader_phaser* p);
void hdr_phaser_writer_exit(
struct hdr_writer_reader_phaser* p, int64_t critical_value_at_enter);
void hdr_phaser_reader_lock(struct hdr_writer_reader_phaser* p);
void hdr_phaser_reader_unlock(struct hdr_writer_reader_phaser* p);
void hdr_phaser_flip_phase(
struct hdr_writer_reader_phaser* p, int64_t sleep_time_ns);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -6,4 +6,3 @@ libs_iidxhook-d3d9 := \
src_iidxhook-d3d9 := \
bb-scale-hd.c \
frame-pace.c \

View File

@@ -1,194 +0,0 @@
#define LOG_MODULE "iidxhook-d3d-frame-pace"
#include <windows.h>
#include <stdbool.h>
#include "hook/table.h"
#include "util/log.h"
#include "frame-pace.h"
static void STDCALL my_Sleep(DWORD dwMilliseconds);
static void (STDCALL *real_Sleep)(DWORD dwMilliseconds);
static DWORD STDCALL my_SleepEx(DWORD dwMilliseconds, BOOL bAlertable);
static DWORD (STDCALL *real_SleepEx)(DWORD dwMilliseconds, BOOL bAlertable);
static const struct hook_symbol iidxhok_d3d9_frame_pace_hook_syms[] = {
{
.name = "Sleep",
.patch = my_Sleep,
.link = (void **) &real_Sleep,
},
{
.name = "SleepEx",
.patch = my_SleepEx,
.link = (void **) &real_SleepEx,
},
};
static bool iidxhook_d3d9_frame_pace_initialized;
static DWORD iidxhook_d3d9_frame_pace_main_thread_id = -1;
static int64_t iidxhook_d3d9_frame_pace_target_frame_time_cpu_ticks;
static int64_t iidxhook_d3d9_frame_pace_frame_time_start_cpu_ticks;
static uint64_t iidxhook_d3d9_frame_pace_get_cpu_tick_frequency()
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
return freq.QuadPart;
}
static uint64_t iidxhook_d3d9_frame_pace_get_cpu_ticks()
{
LARGE_INTEGER tick;
QueryPerformanceCounter(&tick);
return tick.QuadPart;
}
// Source and reference implementation:
// https://github.com/PCSX2/pcsx2/blob/f26031cada6893ac306af73255d337e50a8f73f9/pcsx2/Counters.cpp#L563
static void iidxhook_d3d9_frame_pace_do_post_frame()
{
// -----------------------------------------------------------------------
const int64_t m_iTicks = iidxhook_d3d9_frame_pace_target_frame_time_cpu_ticks;
int64_t m_iStart = iidxhook_d3d9_frame_pace_frame_time_start_cpu_ticks;
// Compute when we would expect this frame to end, assuming everything goes perfectly perfect.
const uint64_t uExpectedEnd = m_iStart + m_iTicks;
// The current tick we actually stopped on.
const uint64_t iEnd = iidxhook_d3d9_frame_pace_get_cpu_ticks();
// The diff between when we stopped and when we expected to.
const int64_t sDeltaTime = iEnd - uExpectedEnd;
// If frame ran too long...
if (sDeltaTime >= m_iTicks)
{
// ... Fudge the next frame start over a bit. Prevents fast forward zoomies.
m_iStart += (sDeltaTime / m_iTicks) * m_iTicks;
iidxhook_d3d9_frame_pace_frame_time_start_cpu_ticks = m_iStart;
return;
}
// Conversion of delta from CPU ticks (microseconds) to milliseconds
int32_t msec = (int32_t) ((sDeltaTime * -1000) / (int64_t) iidxhook_d3d9_frame_pace_get_cpu_tick_frequency());
// If any integer value of milliseconds exists, sleep it off.
// Prior comments suggested that 1-2 ms sleeps were inaccurate on some OSes;
// further testing suggests instead that this was utter bullshit.
if (msec > 1)
{
real_Sleep(msec - 1);
}
// Conversion to milliseconds loses some precision; after sleeping off whole milliseconds,
// spin the thread without sleeping until we finally reach our expected end time.
while (iidxhook_d3d9_frame_pace_get_cpu_ticks() < uExpectedEnd)
{
// SKREEEEEEEE
}
// Finally, set our next frame start to when this one ends
m_iStart = uExpectedEnd;
iidxhook_d3d9_frame_pace_frame_time_start_cpu_ticks = m_iStart;
}
// TODO must be renamed to framerate monitor with smoother/pacer
// TODO have feature flag to print framerate performance counters etc every X seconds
// as misc debug log output
// TODO make sure to record a decent amount of data/frame time accordingly over these
// seconds to report proper avg. frame time/rate, min, max, p95, p99, p999
// TODO move this to a separate module that can be re-used on d3d9ex
// fill up unused frametime on short frames to simulate hardware accuracy
// and match the timing of the target monitor's refresh rate as close as possible
// this fixes frame pacing issues with too short frames not being smoothened
// correctly by the game which either relies entirely on the hardware/GPU driver
// to do that or on tricoro+ era games, on SleepEx which only has max of 1 ms
// accuracy. the further the target monitor refresh rate is away from the desired
// refresh rate, e.g. 60 hz vsync, the more apparent the frame pacing issues
// become in the form of "random stuttering during gameplay"
static void STDCALL my_Sleep(DWORD dwMilliseconds)
{
// Heuristic, but seems to kill the poorly implemented frame pacing code
// fairly reliable without impacting other parts of the code negatively
if (iidxhook_d3d9_frame_pace_main_thread_id == GetCurrentThreadId()) {
if (dwMilliseconds <= 16) {
return;
}
}
real_Sleep(dwMilliseconds);
}
static DWORD STDCALL my_SleepEx(DWORD dwMilliseconds, BOOL bAlertable)
{
// Heuristic, but applies only in two spots
// - frame pacing code (dynamic value)
// - Another spot with sleep time set to 1 -> reduces CPU banging
if (iidxhook_d3d9_frame_pace_main_thread_id == GetCurrentThreadId()) {
if (dwMilliseconds <= 16) {
return 0;
}
}
return real_SleepEx(dwMilliseconds, bAlertable);
}
static void iidxhook_d3d9_frame_pace_timings_init(double target_frame_rate_hz)
{
double tick_rate;
tick_rate = iidxhook_d3d9_frame_pace_get_cpu_tick_frequency();
iidxhook_d3d9_frame_pace_target_frame_time_cpu_ticks = (int64_t) (tick_rate / target_frame_rate_hz);
iidxhook_d3d9_frame_pace_frame_time_start_cpu_ticks = iidxhook_d3d9_frame_pace_get_cpu_ticks();
}
void iidxhook_d3d9_frame_pace_init(DWORD main_thread_id, double target_frame_rate_hz)
{
log_assert(main_thread_id != -1);
iidxhook_d3d9_frame_pace_timings_init(target_frame_rate_hz);
iidxhook_d3d9_frame_pace_main_thread_id = main_thread_id;
iidxhook_d3d9_frame_pace_initialized = true;
hook_table_apply(
NULL, "kernel32.dll", iidxhok_d3d9_frame_pace_hook_syms, lengthof(iidxhok_d3d9_frame_pace_hook_syms));
log_info("Initialized, target frame rate in hz %f, target frame time in cpu ticks %llu", target_frame_rate_hz, iidxhook_d3d9_frame_pace_target_frame_time_cpu_ticks);
}
HRESULT iidxhook_d3d9_frame_pace_d3d9_irp_handler(struct hook_d3d9_irp *irp)
{
HRESULT hr;
log_assert(irp);
if (!iidxhook_d3d9_frame_pace_initialized) {
return hook_d3d9_irp_invoke_next(irp);
}
if (irp->op == HOOK_D3D9_IRP_OP_DEV_PRESENT) {
hr = hook_d3d9_irp_invoke_next(irp);
if (hr == S_OK) {
iidxhook_d3d9_frame_pace_do_post_frame();
}
return hr;
} else {
return hook_d3d9_irp_invoke_next(irp);
}
}

View File

@@ -1,13 +0,0 @@
#ifndef IIDXHOOK_D3D9_FRAME_PACE_H
#define IIDXHOOK_D3D9_FRAME_PCE_H
#include <stdbool.h>
#include <stdint.h>
#include "hook/d3d9.h"
void iidxhook_d3d9_frame_pace_init(DWORD main_thread_id, double target_frame_rate_hz);
HRESULT iidxhook_d3d9_frame_pace_d3d9_irp_handler(struct hook_d3d9_irp *irp);
#endif

View File

@@ -16,6 +16,5 @@ src_iidxhook-util := \
d3d9.c \
eamuse.c \
effector.c \
frame-graph.c \
log-server.c \
settings.c \

View File

@@ -13,7 +13,6 @@
#include "hook/table.h"
#include "iidxhook-util/d3d9.h"
#include "iidxhook-util/frame-graph.h"
#include "iidxhook-util/vertex-shader.h"
#include "util/defs.h"
@@ -233,7 +232,7 @@ iidxhook_util_d3d9_log_create_device_params(struct hook_d3d9_irp *irp)
"hDeviceWindow %p, Windowed %d, "
"EnableAutoDepthStencil "
"%d, AutoDepthStencilFormat %d, Flags %lX, "
"FullScreen_RefreshRateInHz %d, PresentationInterval %d",
"FullScreen_RefreshRateInHz %d",
irp->args.ctx_create_device.pp->BackBufferWidth,
irp->args.ctx_create_device.pp->BackBufferHeight,
irp->args.ctx_create_device.pp->BackBufferFormat,
@@ -245,8 +244,7 @@ iidxhook_util_d3d9_log_create_device_params(struct hook_d3d9_irp *irp)
irp->args.ctx_create_device.pp->EnableAutoDepthStencil,
irp->args.ctx_create_device.pp->AutoDepthStencilFormat,
irp->args.ctx_create_device.pp->Flags,
irp->args.ctx_create_device.pp->FullScreen_RefreshRateInHz,
irp->args.ctx_create_device.pp->PresentationInterval);
irp->args.ctx_create_device.pp->FullScreen_RefreshRateInHz);
}
static void
@@ -269,9 +267,6 @@ static void iidxhook_util_d3d9_fix_create_device_apply_window_mode(
log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE);
D3DPRESENT_PARAMETERS *pp = irp->args.ctx_create_device.pp;
// TODO temporarily remove vsync for testing
pp->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
if (iidxhook_util_d3d9_config.windowed) {
pp->Windowed = TRUE;
pp->FullScreen_RefreshRateInHz = 0;
@@ -1195,14 +1190,7 @@ iidxhook_util_d3d9_irp_handler(struct hook_d3d9_irp *irp)
return hook_d3d9_irp_invoke_next(irp);
// TODO is there always ever just a single scene being rendered?
case HOOK_D3D9_IRP_OP_DEV_END_SCENE:
DrawFrameGraph(irp->args.dev_present.self);
return hook_d3d9_irp_invoke_next(irp);
case HOOK_D3D9_IRP_OP_DEV_PRESENT:
iidxhook_util_d3d9_scale_render_target_to_back_buffer(irp);
iidxhook_util_d3d9_set_back_buffer_rt(irp);

View File

@@ -1,374 +0,0 @@
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "util/log.h"
#include "util/time.h"
#define MAX_SAMPLES 600 // 10 seconds at 60 FPS
#define GRAPH_WIDTH 300
#define GRAPH_HEIGHT 100
#define GRAPH_X 300 // Left position of graph
#define GRAPH_Y 30 // Top position of graph
#define AXIS_COLOR D3DCOLOR_XRGB(128, 128, 128) // Gray color for axes
#define GRAPH_COLOR D3DCOLOR_XRGB(255, 255, 0) // Yellow color for the graph
#define TEXT_COLOR D3DCOLOR_XRGB(255, 255, 0) // Yellow color for text
// // TODO have a separate module that wraps all of these somewhat
typedef HRESULT WINAPI (*func_D3DXCreateFontA)(
struct IDirect3DDevice9 *device,
INT height,
UINT width,
UINT weight,
UINT miplevels,
BOOL italic,
DWORD charset,
DWORD precision,
DWORD quality,
DWORD pitchandfamily,
const char *facename,
struct ID3DXFont **font);
typedef HRESULT WINAPI (*func_D3DXCreateLine)(
struct IDirect3DDevice9 *device,
struct ID3DXLine **line);
typedef struct {
double frameTimes[MAX_SAMPLES];
int currentIndex;
double minTime;
double maxTime;
double avgTime;
int sampleCount;
ID3DXFont* font; // For regular text
ID3DXFont* smallFont; // For axis labels
ID3DXLine* line;
bool resourcesInitialized;
} PerfMetrics;
PerfMetrics g_metrics = {0};
static HRESULT createLine(
IDirect3DDevice9 *dev,
struct ID3DXLine **line)
{
HMODULE d3d9_24;
d3d9_24 = GetModuleHandleA("d3dx9_24.dll");
if (d3d9_24 == NULL) {
log_fatal(
"Failed to load d3dx9_24.dll to create a font for displaying "
"framerate on monitor check.");
return 0;
}
func_D3DXCreateLine d3dxCreateLine =
(func_D3DXCreateLine) GetProcAddress(d3d9_24, "D3DXCreateLine");
if (d3dxCreateLine == NULL) {
log_fatal("Failed to find function D3DXCreateLine");
return 0;
}
return d3dxCreateLine(
dev,
line);
}
static HRESULT createFontA(
IDirect3DDevice9 *dev,
INT height,
UINT width,
UINT weight,
UINT miplevels,
BOOL italic,
DWORD charset,
DWORD precision,
DWORD quality,
DWORD pitchandfamily,
const char *facename,
ID3DXFont **font)
{
HMODULE d3d9_24;
d3d9_24 = GetModuleHandleA("d3dx9_24.dll");
if (d3d9_24 == NULL) {
log_fatal(
"Failed to load d3dx9_24.dll to create a font for displaying "
"framerate on monitor check.");
return 0;
}
func_D3DXCreateFontA d3dxCreateFontA =
(func_D3DXCreateFontA) GetProcAddress(d3d9_24, "D3DXCreateFontA");
if (d3dxCreateFontA == NULL) {
log_fatal("Failed to find function D3DXCreateFontA");
return 0;
}
return d3dxCreateFontA(
dev,
height,
width,
weight,
miplevels,
italic,
charset,
precision,
quality,
pitchandfamily,
facename,
font);
}
// Update performance metrics with new frame time
void UpdateMetrics(double frameTime) {
g_metrics.frameTimes[g_metrics.currentIndex] = frameTime;
g_metrics.currentIndex = (g_metrics.currentIndex + 1) % MAX_SAMPLES;
if (g_metrics.sampleCount < MAX_SAMPLES)
g_metrics.sampleCount++;
// Update min/max/avg
g_metrics.minTime = frameTime;
g_metrics.maxTime = frameTime;
g_metrics.avgTime = 0;
for (int i = 0; i < g_metrics.sampleCount; i++) {
double time = g_metrics.frameTimes[i];
g_metrics.minTime = min(g_metrics.minTime, time);
g_metrics.maxTime = max(g_metrics.maxTime, time);
g_metrics.avgTime += time;
}
g_metrics.avgTime /= g_metrics.sampleCount;
}
bool InitializeOverlayResources(IDirect3DDevice9* device) {
if (g_metrics.resourcesInitialized) return true;
// Create main font (larger, for FPS display)
if (FAILED(createFontA(device, 20, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
"Arial", &g_metrics.font))) {
return false;
}
// Create smaller font for axis labels
if (FAILED(createFontA(device, 12, 0, FW_NORMAL, 1, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
"Arial", &g_metrics.smallFont))) {
ID3DXFont_Release(g_metrics.font);
return false;
}
if (FAILED(createLine(device, &g_metrics.line))) {
ID3DXFont_Release(g_metrics.font);
ID3DXFont_Release(g_metrics.smallFont);
return false;
}
g_metrics.resourcesInitialized = true;
return true;
}
void DrawGraph(IDirect3DDevice9* device) {
// Draw the frame time graph
D3DXVECTOR2 points[MAX_SAMPLES];
float xStep = (float)GRAPH_WIDTH / (MAX_SAMPLES - 1);
// Find min/max times in current sample range
double minTime = g_metrics.frameTimes[0];
double maxTime = g_metrics.frameTimes[0];
for (int i = 0; i < g_metrics.sampleCount; i++) {
int idx = (g_metrics.currentIndex - g_metrics.sampleCount + i + MAX_SAMPLES) % MAX_SAMPLES;
double time = g_metrics.frameTimes[idx];
minTime = min(minTime, time);
maxTime = max(maxTime, time);
}
// Add small padding to prevent graph from touching edges
double padding = (maxTime - minTime) * 0.1;
maxTime += padding;
minTime = max(0, minTime - padding);
float yScale = (float)GRAPH_HEIGHT / (maxTime - minTime);
for (int i = 0; i < g_metrics.sampleCount; i++) {
int idx = (g_metrics.currentIndex - g_metrics.sampleCount + i + MAX_SAMPLES) % MAX_SAMPLES;
points[i].x = GRAPH_X + i * xStep;
points[i].y = GRAPH_Y + GRAPH_HEIGHT - (g_metrics.frameTimes[idx] - minTime) * yScale;
}
ID3DXLine_SetWidth(g_metrics.line, 1.0f);
ID3DXLine_Draw(g_metrics.line, points, g_metrics.sampleCount, GRAPH_COLOR);
}
// TODO add option to have fixed min and max for the Y scale (so that the graph doesn't scale when the frame rate changes)
// keep this an option though with uncapped to also see really bad frame times on screen
void DrawOverlay(IDirect3DDevice9* device) {
if (!InitializeOverlayResources(device))
return;
// Draw black background
D3DRECT rect = {GRAPH_X, GRAPH_Y - 30, GRAPH_X + GRAPH_WIDTH, GRAPH_Y + GRAPH_HEIGHT};
IDirect3DDevice9_Clear(device, 1, &rect, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 0, 0), 0, 0);
// Draw X and Y axes
D3DXVECTOR2 xAxis[] = {
{ .x = GRAPH_X, .y = GRAPH_Y + GRAPH_HEIGHT },
{ .x = GRAPH_X + GRAPH_WIDTH, .y = GRAPH_Y + GRAPH_HEIGHT }
};
D3DXVECTOR2 yAxis[] = {
{ .x = GRAPH_X, .y = GRAPH_Y },
{ .x = GRAPH_X, .y = GRAPH_Y + GRAPH_HEIGHT }
};
ID3DXLine_SetWidth(g_metrics.line, 1.0f);
ID3DXLine_Draw(g_metrics.line, xAxis, 2, AXIS_COLOR);
ID3DXLine_Draw(g_metrics.line, yAxis, 2, AXIS_COLOR);
// Draw X axis labels (time)
char buffer[32];
RECT textRect;
for (int i = 0; i <= 10; i++) {
float x = GRAPH_X + (GRAPH_WIDTH * i / 10.0f);
sprintf(buffer, "%.1fs", (10.0f - i));
textRect.left = (LONG)x - 15;
textRect.top = GRAPH_Y + GRAPH_HEIGHT + 5;
textRect.right = (LONG)x + 15;
textRect.bottom = GRAPH_Y + GRAPH_HEIGHT + 20;
ID3DXFont_DrawTextA(g_metrics.smallFont, NULL, buffer, -1, &textRect, DT_CENTER, AXIS_COLOR);
}
// Find min/max times in current sample range
double minTime = g_metrics.frameTimes[0];
double maxTime = g_metrics.frameTimes[0];
for (int i = 0; i < g_metrics.sampleCount; i++) {
int idx = (g_metrics.currentIndex - g_metrics.sampleCount + i + MAX_SAMPLES) % MAX_SAMPLES;
double time = g_metrics.frameTimes[idx];
minTime = min(minTime, time);
maxTime = max(maxTime, time);
}
float yScale = (float)GRAPH_HEIGHT / (maxTime - minTime);
// Draw Y axis labels (frame time)
for (int i = 0; i <= 8; i++) {
float y = GRAPH_Y + GRAPH_HEIGHT - (GRAPH_HEIGHT * i / 8.0f);
float ms = minTime + ((maxTime - minTime) * i / 8.0f);
sprintf(buffer, "%.1fms", ms);
textRect.left = GRAPH_X - 45;
textRect.top = (LONG)y - 6;
textRect.right = GRAPH_X - 5;
textRect.bottom = (LONG)y + 6;
ID3DXFont_DrawTextA(g_metrics.smallFont, NULL, buffer, -1, &textRect, DT_RIGHT, AXIS_COLOR);
}
// TODO add some kind of coloring to the frame rate graph/line whenever the line is above or below a certain threshold of the reference line
// Draw 60 FPS reference line (16.67ms)
const float targetFrameTime = 1000.0f/60.0f; // 16.67ms
float y60fps = GRAPH_Y + GRAPH_HEIGHT - ((targetFrameTime - minTime) * yScale);
// Only draw reference line if it's within the visible range
if (targetFrameTime >= minTime && targetFrameTime <= maxTime) {
D3DXVECTOR2 refLine[2];
refLine[0].x = GRAPH_X;
refLine[0].y = y60fps;
refLine[1].x = GRAPH_X + GRAPH_WIDTH;
refLine[1].y = y60fps;
ID3DXLine_SetWidth(g_metrics.line, 1.0f);
ID3DXLine_Draw(g_metrics.line, refLine, 2, D3DCOLOR_ARGB(128, 255, 255, 0)); // Semi-transparent yellow
// Draw reference line label
char refBuffer[32];
sprintf(refBuffer, "16.67ms (60 FPS)");
RECT refTextRect;
refTextRect.left = GRAPH_X + GRAPH_WIDTH + 5;
refTextRect.top = y60fps - 8; // Center text vertically with line
refTextRect.right = refTextRect.left + 100;
refTextRect.bottom = refTextRect.top + 16;
ID3DXFont_DrawTextA(g_metrics.smallFont, NULL, refBuffer, -1, &refTextRect, DT_LEFT, D3DCOLOR_ARGB(128, 255, 255, 0));
}
// -------------------------------------------------------------------------
// Draw the frame time graph
D3DXVECTOR2 points[MAX_SAMPLES];
float xStep = (float)GRAPH_WIDTH / (MAX_SAMPLES - 1);
// Add small padding to prevent graph from touching edges
double padding = (maxTime - minTime) * 0.1;
maxTime += padding;
minTime = max(0, minTime - padding);
for (int i = 0; i < g_metrics.sampleCount; i++) {
int idx = (g_metrics.currentIndex - g_metrics.sampleCount + i + MAX_SAMPLES) % MAX_SAMPLES;
points[i].x = GRAPH_X + i * xStep;
points[i].y = GRAPH_Y + GRAPH_HEIGHT - (g_metrics.frameTimes[idx] - minTime) * yScale;
}
ID3DXLine_SetWidth(g_metrics.line, 1.0f);
ID3DXLine_Draw(g_metrics.line, points, g_metrics.sampleCount, GRAPH_COLOR);
// -------------------------------------------------------------------------
// Calculate current FPS
double currentFrameTime = g_metrics.frameTimes[(g_metrics.currentIndex - 1 + MAX_SAMPLES) % MAX_SAMPLES];
double fps = 1000.0 / currentFrameTime;
// Draw FPS text
sprintf(buffer, "%.3f FPS", fps);
textRect.left = GRAPH_X + GRAPH_WIDTH - 100;
textRect.top = GRAPH_Y - 25;
textRect.right = GRAPH_X + GRAPH_WIDTH;
textRect.bottom = GRAPH_Y - 5;
ID3DXFont_DrawTextA(g_metrics.font, NULL, buffer, -1, &textRect, DT_RIGHT, TEXT_COLOR);
// Draw current frame time in ms
sprintf(buffer, "%.3f ms", currentFrameTime);
textRect.left = GRAPH_X + GRAPH_WIDTH - 200; // Position to the left of FPS
textRect.top = GRAPH_Y - 25;
textRect.right = GRAPH_X + GRAPH_WIDTH - 110; // Leave space for FPS text
textRect.bottom = GRAPH_Y - 5;
ID3DXFont_DrawTextA(g_metrics.font, NULL, buffer, -1, &textRect, DT_RIGHT, TEXT_COLOR);
// TODO draw derivation graph and average derivation time over the current frame scope
// Draw "Framerate" label
textRect.left = GRAPH_X;
textRect.top = GRAPH_Y - 25;
textRect.right = GRAPH_X + 100;
textRect.bottom = GRAPH_Y - 5;
ID3DXFont_DrawTextA(g_metrics.font, NULL, "Framerate", -1, &textRect, DT_LEFT, TEXT_COLOR);
}
// Hooked Present function
void DrawFrameGraph(IDirect3DDevice9* device) {
static uint64_t lastTime = 0;
uint64_t currentTime = time_get_counter();
if (lastTime != 0) {
uint64_t frameTime = currentTime - lastTime;
double frameTimeMs = time_get_elapsed_us(frameTime) / 1000.0;
UpdateMetrics(frameTimeMs);
}
lastTime = currentTime;
//IDirect3DDevice9_BeginScene(device);
DrawOverlay(device);
//IDirect3DDevice9_EndScene(device);
}

View File

@@ -1,10 +0,0 @@
#ifndef IIDXHOOK_FRAME_GRAPH_H
#define IIDXHOOK_FRAME_GRAPH_H
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
void DrawFrameGraph(IDirect3DDevice9* device);
#endif

View File

@@ -116,8 +116,6 @@ static int log_thread_proc(void *ctx)
static void
log_post(char level, const char *module, const char *fmt, va_list ap)
{
// TODO test if this addresses performance issues and stuttering
// TODO measure time how long waiting takes here?
if (WaitForSingleObject(log_rv_producer, INFINITE)) {
return;
}

View File

@@ -261,8 +261,7 @@ skip:
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
// TODO switched to null writer to see if it addresses performance issues
log_to_writer(log_writer_null, NULL);
log_to_writer(log_writer_debug, NULL);
/* Bootstrap hook for further init tasks (see above) */

View File

@@ -254,8 +254,7 @@ skip:
BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
{
if (reason == DLL_PROCESS_ATTACH) {
// TODO switched to null writer to see if it addresses performance issues
log_to_writer(log_writer_null, NULL);
log_to_writer(log_writer_debug, NULL);
/* Bootstrap hook for further init tasks (see above) */

View File

@@ -6,7 +6,6 @@ ldflags_iidxhook3 := \
libs_iidxhook3 := \
iidxhook-util \
iidxhook-d3d9 \
ezusb-emu \
ezusb-iidx-16seg-emu \
ezusb2-emu \

View File

@@ -27,8 +27,6 @@
#include "hooklib/rs232.h"
#include "hooklib/setupapi.h"
#include "iidxhook-d3d9/frame-pace.h"
#include "iidxhook-util/acio.h"
#include "iidxhook-util/chart-patch.h"
#include "iidxhook-util/clock.h"
@@ -54,9 +52,6 @@
static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = {
iidxhook_util_d3d9_irp_handler,
// Order is important for performance, frame pacing must come at the very end
// to include all timings from any prior hooks
//iidxhook_d3d9_frame_pace_d3d9_irp_handler,
};
static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD);
@@ -74,8 +69,6 @@ iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
{
struct iidxhook_util_d3d9_config d3d9_config;
iidxhook_d3d9_frame_pace_init(GetCurrentThreadId(), 60.0);
iidxhook_util_d3d9_init_config(&d3d9_config);
d3d9_config.windowed = config_gfx->windowed;

View File

@@ -1,9 +0,0 @@
dlls += iidxio-async
ldflags_iidxio-async := \
libs_iidxio-async := \
util \
src_iidxio-async := \
iidxio.c \

View File

@@ -1,18 +0,0 @@
LIBRARY iidxio
EXPORTS
iidx_io_ep1_send
iidx_io_ep1_set_deck_lights
iidx_io_ep1_set_panel_lights
iidx_io_ep1_set_top_lamps
iidx_io_ep1_set_top_neons
iidx_io_ep2_get_keys
iidx_io_ep2_get_panel
iidx_io_ep2_get_sys
iidx_io_ep2_get_slider
iidx_io_ep2_get_turntable
iidx_io_ep2_recv
iidx_io_ep3_write_16seg
iidx_io_fini
iidx_io_init
iidx_io_set_loggers

View File

@@ -1,414 +0,0 @@
#define LOG_MODULE "iidxio-async"
#include <windows.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "bemanitools/iidxio.h"
#include "util/log.h"
#include "util/thread.h"
#include "util/time.h"
typedef void (*iidx_io_set_loggers_t)(
log_formatter_t misc,
log_formatter_t info,
log_formatter_t warning,
log_formatter_t fatal);
typedef bool (*iidx_io_init_t)(
thread_create_t thread_create,
thread_join_t thread_join,
thread_destroy_t thread_destroy);
typedef void (*iidx_io_fini_t)(void);
typedef void (*iidx_io_ep1_set_deck_lights_t)(uint16_t deck_lights);
typedef void (*iidx_io_ep1_set_panel_lights_t)(uint8_t panel_lights);
typedef void (*iidx_io_ep1_set_top_lamps_t)(uint8_t top_lamps);
typedef void (*iidx_io_ep1_set_top_neons_t)(bool top_neons);
typedef bool (*iidx_io_ep1_send_t)(void);
typedef bool (*iidx_io_ep2_recv_t)(void);
typedef uint8_t (*iidx_io_ep2_get_turntable_t)(uint8_t player_no);
typedef uint8_t (*iidx_io_ep2_get_slider_t)(uint8_t slider_no);
typedef uint8_t (*iidx_io_ep2_get_sys_t)(void);
typedef uint8_t (*iidx_io_ep2_get_panel_t)(void);
typedef uint16_t (*iidx_io_ep2_get_keys_t)(void);
typedef bool (*iidx_io_ep3_write_16seg_t)(const char *text);
static HMODULE _child_iidx_io_module;
static iidx_io_set_loggers_t _child_iidx_io_set_loggers;
static iidx_io_init_t _child_iidx_io_init;
static iidx_io_fini_t _child_iidx_io_fini;
static iidx_io_ep1_set_deck_lights_t _child_iidx_io_ep1_set_deck_lights;
static iidx_io_ep1_set_panel_lights_t _child_iidx_io_ep1_set_panel_lights;
static iidx_io_ep1_set_top_lamps_t _child_iidx_io_ep1_set_top_lamps;
static iidx_io_ep1_set_top_neons_t _child_iidx_io_ep1_set_top_neons;
static iidx_io_ep1_send_t _child_iidx_io_ep1_send;
static iidx_io_ep2_recv_t _child_iidx_io_ep2_recv;
static iidx_io_ep2_get_turntable_t _child_iidx_io_ep2_get_turntable;
static iidx_io_ep2_get_slider_t _child_iidx_io_ep2_get_slider;
static iidx_io_ep2_get_sys_t _child_iidx_io_ep2_get_sys;
static iidx_io_ep2_get_panel_t _child_iidx_io_ep2_get_panel;
static iidx_io_ep2_get_keys_t _child_iidx_io_ep2_get_keys;
static iidx_io_ep3_write_16seg_t _child_iidx_io_ep3_write_16seg;
static log_formatter_t _log_formatter_misc;
static log_formatter_t _log_formatter_info;
static log_formatter_t _log_formatter_warning;
static log_formatter_t _log_formatter_fatal;
static _Atomic(bool) _io_thread_proc_loop;
static _Atomic(bool) _io_thread_proc_running;
static _Atomic(uint16_t) _child_iidx_io_deck_lights;
static _Atomic(uint8_t) _child_iidx_io_panel_lights;
static _Atomic(uint8_t) _child_iidx_io_top_lamps;
static _Atomic(bool) _child_iidx_io_top_neons;
static _Atomic(uint8_t) _child_iidx_io_turntable_p1;
static _Atomic(uint8_t) _child_iidx_io_turntable_p2;
static _Atomic(uint8_t) _child_iidx_io_slider_1;
static _Atomic(uint8_t) _child_iidx_io_slider_2;
static _Atomic(uint8_t) _child_iidx_io_slider_3;
static _Atomic(uint8_t) _child_iidx_io_slider_4;
static _Atomic(uint8_t) _child_iidx_io_slider_5;
static _Atomic(uint8_t) _child_iidx_io_sys;
static _Atomic(uint8_t) _child_iidx_io_panel;
static _Atomic(uint16_t) _child_iidx_io_keys;
static int _io_thread_proc(void *ctx)
{
uint64_t time_start;
uint64_t time_end;
uint64_t loop_counter;
uint64_t total_time;
bool result;
// TODO compare previous outputs with new ones and only apply if changed? doesn't make sense for iidx as setting the values is not supposed to trigger any actual IO driving
// uint32_t prev_child_ddr_io_data_extio_lights;
// uint32_t prev_child_ddr_io_data_p3io_lights;
// uint32_t local_tmp;
atomic_store_explicit(&_io_thread_proc_running, true, memory_order_seq_cst);
log_info("IO thread running");
time_start = time_get_counter();
loop_counter = 0;
// TODO have a setting to configure polling rates of inputs, outputs and 16seg separately
while (atomic_load_explicit(&_io_thread_proc_loop, memory_order_seq_cst)) {
// TODO measure time of expensive calls independently
result = _child_iidx_io_ep2_recv();
if (!result) {
log_warning("_child_iidx_io_ep2_recv returned false");
atomic_store_explicit(
&_io_thread_proc_running, false, memory_order_seq_cst);
log_info("IO thread shut down");
return 0;
}
atomic_store_explicit(&_child_iidx_io_turntable_p1, _child_iidx_io_ep2_get_turntable(0), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_turntable_p2, _child_iidx_io_ep2_get_turntable(1), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_slider_1, _child_iidx_io_ep2_get_slider(0), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_slider_2, _child_iidx_io_ep2_get_slider(1), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_slider_3, _child_iidx_io_ep2_get_slider(2), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_slider_4, _child_iidx_io_ep2_get_slider(3), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_slider_5, _child_iidx_io_ep2_get_slider(4), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_sys, _child_iidx_io_ep2_get_sys(), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_panel, _child_iidx_io_ep2_get_panel(), memory_order_relaxed);
atomic_store_explicit(&_child_iidx_io_keys, _child_iidx_io_ep2_get_keys(), memory_order_relaxed);
_child_iidx_io_ep1_set_deck_lights(atomic_load_explicit(&_child_iidx_io_deck_lights, memory_order_relaxed));
_child_iidx_io_ep1_set_panel_lights(atomic_load_explicit(&_child_iidx_io_panel_lights, memory_order_relaxed));
_child_iidx_io_ep1_set_top_lamps(atomic_load_explicit(&_child_iidx_io_top_lamps, memory_order_relaxed));
_child_iidx_io_ep1_set_top_neons(atomic_load_explicit(&_child_iidx_io_top_neons, memory_order_relaxed));
// TODO guard and only update every X loops? -> configurable?
result = _child_iidx_io_ep1_send();
if (!result) {
log_warning("_child_iidx_io_ep1_send returned false");
atomic_store_explicit(
&_io_thread_proc_running, false, memory_order_seq_cst);
log_info("IO thread shut down");
return 0;
}
// TODO atomic write of 16seg with mutex?
// result = _child_iidx_io_ep3_write_16seg();
// if (!result) {
// log_warning("_child_iidx_io_ep3_write_16seg returned false");
// atomic_store_explicit(
// &_io_thread_proc_running, false, memory_order_seq_cst);
// log_info("IO thread shut down");
// return 0;
// }
// local_tmp = _child_ddr_io_read_pad();
// atomic_store_explicit(
// &_child_ddr_io_data_pad, local_tmp, memory_order_relaxed);
// local_tmp = atomic_load_explicit(
// &_child_ddr_io_data_extio_lights, memory_order_relaxed);
// if (local_tmp != prev_child_ddr_io_data_extio_lights) {
// _child_ddr_io_set_lights_extio(local_tmp);
// prev_child_ddr_io_data_extio_lights = local_tmp;
// }
// local_tmp = atomic_load_explicit(
// &_child_ddr_io_data_p3io_lights, memory_order_relaxed);
// if (local_tmp != prev_child_ddr_io_data_p3io_lights) {
// _child_ddr_io_set_lights_p3io(local_tmp);
// prev_child_ddr_io_data_p3io_lights = local_tmp;
// }
// Don't hog the CPU
SwitchToThread();
loop_counter++;
}
time_end = time_get_counter();
total_time = time_get_elapsed_us(time_end - time_start);
log_info(
"IO thread performance: total iterations %lld, avg. loop cycle time %f "
"us",
loop_counter,
((double) total_time) / loop_counter);
atomic_store_explicit(
&_io_thread_proc_running, false, memory_order_seq_cst);
log_info("IO thread shut down");
return 0;
}
static void *_load_function(HMODULE module, const char *name)
{
void *ptr;
ptr = GetProcAddress(module, name);
if (ptr == NULL) {
log_fatal("Could not find function %s in iidxio child library", name);
}
return ptr;
}
void iidx_io_set_loggers(
log_formatter_t misc,
log_formatter_t info,
log_formatter_t warning,
log_formatter_t fatal)
{
_log_formatter_misc = misc;
_log_formatter_info = info;
_log_formatter_warning = warning;
_log_formatter_fatal = fatal;
log_to_external(misc, info, warning, fatal);
}
bool iidx_io_init(
thread_create_t thread_create,
thread_join_t thread_join,
thread_destroy_t thread_destroy)
{
log_info("Loading iidxio-async-child.dll as child iidxio library...");
_child_iidx_io_module = LoadLibraryA("iidxio-async-child.dll");
if (_child_iidx_io_module == NULL) {
log_warning("Loading iidxio-async-child.dll failed");
return false;
}
_child_iidx_io_set_loggers =
_load_function(_child_iidx_io_module, "iidx_io_set_loggers");
_child_iidx_io_init = _load_function(_child_iidx_io_module, "iidx_io_init");
_child_iidx_io_fini = _load_function(_child_iidx_io_module, "iidx_io_fini");
_child_iidx_io_ep1_set_deck_lights =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_deck_lights");
_child_iidx_io_ep1_set_panel_lights =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_panel_lights");
_child_iidx_io_ep1_set_top_lamps =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_top_lamps");
_child_iidx_io_ep1_set_top_neons =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_top_neons");
_child_iidx_io_ep1_send =
_load_function(_child_iidx_io_module, "iidx_io_ep1_send");
_child_iidx_io_ep2_recv =
_load_function(_child_iidx_io_module, "iidx_io_ep2_recv");
_child_iidx_io_ep2_get_turntable =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_turntable");
_child_iidx_io_ep2_get_slider =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_slider");
_child_iidx_io_ep2_get_sys =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_sys");
_child_iidx_io_ep2_get_panel =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_panel");
_child_iidx_io_ep2_get_keys =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_keys");
_child_iidx_io_ep3_write_16seg =
_load_function(_child_iidx_io_module, "iidx_io_ep3_write_16seg");
_child_iidx_io_set_loggers(
_log_formatter_misc,
_log_formatter_info,
_log_formatter_warning,
_log_formatter_fatal);
log_info("Calling child iidx_io_init...");
if (!_child_iidx_io_init(thread_create, thread_join, thread_destroy)) {
log_warning("Child iidx_io_init failed");
FreeLibrary(_child_iidx_io_module);
return false;
}
atomic_store_explicit(&_io_thread_proc_loop, true, memory_order_seq_cst);
if (!thread_create(_io_thread_proc, NULL, 16384, 0)) {
log_warning("Creating IO thread failed");
_child_iidx_io_fini();
FreeLibrary(_child_iidx_io_module);
return false;
}
return true;
}
void iidx_io_fini(void)
{
atomic_store_explicit(&_io_thread_proc_loop, false, memory_order_seq_cst);
log_info("Shutting down IO thread and waiting for it to finish...");
while (
atomic_load_explicit(&_io_thread_proc_running, memory_order_seq_cst)) {
Sleep(1);
}
log_info("IO thread finished");
_child_iidx_io_fini();
FreeLibrary(_child_iidx_io_module);
}
void iidx_io_ep1_set_deck_lights(uint16_t deck_lights)
{
atomic_store_explicit(
&_child_iidx_io_deck_lights, deck_lights, memory_order_relaxed);
}
void iidx_io_ep1_set_panel_lights(uint8_t panel_lights)
{
atomic_store_explicit(
&_child_iidx_io_panel_lights, panel_lights, memory_order_relaxed);
}
void iidx_io_ep1_set_top_lamps(uint8_t top_lamps)
{
atomic_store_explicit(
&_child_iidx_io_top_lamps, top_lamps, memory_order_relaxed);
}
void iidx_io_ep1_set_top_neons(bool top_neons)
{
atomic_store_explicit(
&_child_iidx_io_top_neons, top_neons, memory_order_relaxed);
}
bool iidx_io_ep1_send(void)
{
// Any sending and receiving is executed async in a separate thread
return true;
}
bool iidx_io_ep2_recv(void)
{
// Any sending and receiving is executed async in a separate thread
return true;
}
uint8_t iidx_io_ep2_get_turntable(uint8_t player_no)
{
switch (player_no)
{
case 0:
return atomic_load_explicit(&_child_iidx_io_turntable_p1, memory_order_relaxed);
case 1:
return atomic_load_explicit(&_child_iidx_io_turntable_p2, memory_order_relaxed);
default:
return 0;
}
}
uint8_t iidx_io_ep2_get_slider(uint8_t slider_no)
{
switch (slider_no)
{
case 0:
return atomic_load_explicit(&_child_iidx_io_slider_1, memory_order_relaxed);
case 1:
return atomic_load_explicit(&_child_iidx_io_slider_2, memory_order_relaxed);
case 2:
return atomic_load_explicit(&_child_iidx_io_slider_3, memory_order_relaxed);
case 3:
return atomic_load_explicit(&_child_iidx_io_slider_4, memory_order_relaxed);
case 4:
return atomic_load_explicit(&_child_iidx_io_slider_5, memory_order_relaxed);
default:
return 0;
}
}
uint8_t iidx_io_ep2_get_sys(void)
{
return atomic_load_explicit(&_child_iidx_io_sys, memory_order_relaxed);
}
uint8_t iidx_io_ep2_get_panel(void)
{
return atomic_load_explicit(&_child_iidx_io_panel, memory_order_relaxed);
}
uint16_t iidx_io_ep2_get_keys(void)
{
return atomic_load_explicit(&_child_iidx_io_keys, memory_order_relaxed);
}
bool iidx_io_ep3_write_16seg(const char *text)
{
// TODO atomic copy with mutex?
return true;
}

View File

@@ -1,11 +0,0 @@
dlls += iidxio-perf
ldflags_iidxio-perf := \
-lws2_32
libs_iidxio-perf := \
hdr-histogram \
util \
src_iidxio-perf := \
iidxio.c \

View File

@@ -1,18 +0,0 @@
LIBRARY iidxio
EXPORTS
iidx_io_ep1_send
iidx_io_ep1_set_deck_lights
iidx_io_ep1_set_panel_lights
iidx_io_ep1_set_top_lamps
iidx_io_ep1_set_top_neons
iidx_io_ep2_get_keys
iidx_io_ep2_get_panel
iidx_io_ep2_get_sys
iidx_io_ep2_get_slider
iidx_io_ep2_get_turntable
iidx_io_ep2_recv
iidx_io_ep3_write_16seg
iidx_io_fini
iidx_io_init
iidx_io_set_loggers

View File

@@ -1,306 +0,0 @@
#define LOG_MODULE "iidxio-perf"
#include <windows.h>
#include <inttypes.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "bemanitools/iidxio.h"
#include "hdr-histogram/hdr_histogram.h"
#include "hdr-histogram/hdr_time.h"
#include "util/log.h"
#include "util/thread.h"
#include "util/time.h"
typedef void (*iidx_io_set_loggers_t)(
log_formatter_t misc,
log_formatter_t info,
log_formatter_t warning,
log_formatter_t fatal);
typedef bool (*iidx_io_init_t)(
thread_create_t thread_create,
thread_join_t thread_join,
thread_destroy_t thread_destroy);
typedef void (*iidx_io_fini_t)(void);
typedef void (*iidx_io_ep1_set_deck_lights_t)(uint16_t deck_lights);
typedef void (*iidx_io_ep1_set_panel_lights_t)(uint8_t panel_lights);
typedef void (*iidx_io_ep1_set_top_lamps_t)(uint8_t top_lamps);
typedef void (*iidx_io_ep1_set_top_neons_t)(bool top_neons);
typedef bool (*iidx_io_ep1_send_t)(void);
typedef bool (*iidx_io_ep2_recv_t)(void);
typedef uint8_t (*iidx_io_ep2_get_turntable_t)(uint8_t player_no);
typedef uint8_t (*iidx_io_ep2_get_slider_t)(uint8_t slider_no);
typedef uint8_t (*iidx_io_ep2_get_sys_t)(void);
typedef uint8_t (*iidx_io_ep2_get_panel_t)(void);
typedef uint16_t (*iidx_io_ep2_get_keys_t)(void);
typedef bool (*iidx_io_ep3_write_16seg_t)(const char *text);
static HMODULE _child_iidx_io_module;
static iidx_io_set_loggers_t _child_iidx_io_set_loggers;
static iidx_io_init_t _child_iidx_io_init;
static iidx_io_fini_t _child_iidx_io_fini;
static iidx_io_ep1_set_deck_lights_t _child_iidx_io_ep1_set_deck_lights;
static iidx_io_ep1_set_panel_lights_t _child_iidx_io_ep1_set_panel_lights;
static iidx_io_ep1_set_top_lamps_t _child_iidx_io_ep1_set_top_lamps;
static iidx_io_ep1_set_top_neons_t _child_iidx_io_ep1_set_top_neons;
static iidx_io_ep1_send_t _child_iidx_io_ep1_send;
static iidx_io_ep2_recv_t _child_iidx_io_ep2_recv;
static iidx_io_ep2_get_turntable_t _child_iidx_io_ep2_get_turntable;
static iidx_io_ep2_get_slider_t _child_iidx_io_ep2_get_slider;
static iidx_io_ep2_get_sys_t _child_iidx_io_ep2_get_sys;
static iidx_io_ep2_get_panel_t _child_iidx_io_ep2_get_panel;
static iidx_io_ep2_get_keys_t _child_iidx_io_ep2_get_keys;
static iidx_io_ep3_write_16seg_t _child_iidx_io_ep3_write_16seg;
static log_formatter_t _log_formatter_misc;
static log_formatter_t _log_formatter_info;
static log_formatter_t _log_formatter_warning;
static log_formatter_t _log_formatter_fatal;
struct hdr_histogram* _histogram_ep1_send;
struct hdr_histogram* _histogram_ep2_recv;
struct hdr_histogram* _histogram_ep3_write_16seg;
static void *_load_function(HMODULE module, const char *name)
{
void *ptr;
ptr = GetProcAddress(module, name);
if (ptr == NULL) {
log_fatal("Could not find function %s in iidxio child library", name);
}
return ptr;
}
void iidx_io_set_loggers(
log_formatter_t misc,
log_formatter_t info,
log_formatter_t warning,
log_formatter_t fatal)
{
_log_formatter_misc = misc;
_log_formatter_info = info;
_log_formatter_warning = warning;
_log_formatter_fatal = fatal;
log_to_external(misc, info, warning, fatal);
}
bool iidx_io_init(
thread_create_t thread_create,
thread_join_t thread_join,
thread_destroy_t thread_destroy)
{
size_t histogram_memory_usage_bytes;
log_info("Loading iidxio-perf-child.dll as child iidxio library...");
_child_iidx_io_module = LoadLibraryA("iidxio-perf-child.dll");
if (_child_iidx_io_module == NULL) {
log_warning("Loading iidxio-perf-child.dll failed");
return false;
}
_child_iidx_io_set_loggers =
_load_function(_child_iidx_io_module, "iidx_io_set_loggers");
_child_iidx_io_init = _load_function(_child_iidx_io_module, "iidx_io_init");
_child_iidx_io_fini = _load_function(_child_iidx_io_module, "iidx_io_fini");
_child_iidx_io_ep1_set_deck_lights =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_deck_lights");
_child_iidx_io_ep1_set_panel_lights =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_panel_lights");
_child_iidx_io_ep1_set_top_lamps =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_top_lamps");
_child_iidx_io_ep1_set_top_neons =
_load_function(_child_iidx_io_module, "iidx_io_ep1_set_top_neons");
_child_iidx_io_ep1_send =
_load_function(_child_iidx_io_module, "iidx_io_ep1_send");
_child_iidx_io_ep2_recv =
_load_function(_child_iidx_io_module, "iidx_io_ep2_recv");
_child_iidx_io_ep2_get_turntable =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_turntable");
_child_iidx_io_ep2_get_slider =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_slider");
_child_iidx_io_ep2_get_sys =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_sys");
_child_iidx_io_ep2_get_panel =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_panel");
_child_iidx_io_ep2_get_keys =
_load_function(_child_iidx_io_module, "iidx_io_ep2_get_keys");
_child_iidx_io_ep3_write_16seg =
_load_function(_child_iidx_io_module, "iidx_io_ep3_write_16seg");
_child_iidx_io_set_loggers(
_log_formatter_misc,
_log_formatter_info,
_log_formatter_warning,
_log_formatter_fatal);
log_info("Initialising histograms...");
hdr_init(1, INT64_C(3600000000), 3, &_histogram_ep1_send);
hdr_init(1, INT64_C(3600000000), 3, &_histogram_ep2_recv);
hdr_init(1, INT64_C(3600000000), 3, &_histogram_ep3_write_16seg);
histogram_memory_usage_bytes =
hdr_get_memory_size(_histogram_ep1_send) +
hdr_get_memory_size(_histogram_ep2_recv) +
hdr_get_memory_size(_histogram_ep3_write_16seg);
log_misc("Histogram total memory usage: %" PRIdPTR " bytes", histogram_memory_usage_bytes);
log_info("Calling child iidx_io_init...");
if (!_child_iidx_io_init(thread_create, thread_join, thread_destroy)) {
log_warning("Child iidx_io_init failed");
FreeLibrary(_child_iidx_io_module);
return false;
} else {
return true;
}
}
void iidx_io_fini(void)
{
_child_iidx_io_fini();
log_info("----------------------------------------------------------------");
log_info("Printing histograms...");
log_info("All values are times in microseconds (us)");
log_info("----------------------------------------------------------------");
log_info(">>> EP1 send");
hdr_percentiles_print(_histogram_ep1_send, stdout, 5, 1.0, CLASSIC);
log_info("----------------------------------------------------------------");
log_info(">>> EP2 recv");
hdr_percentiles_print(_histogram_ep2_recv, stdout, 5, 1.0, CLASSIC);
log_info("----------------------------------------------------------------");
log_info(">>> EP3 write 16seg");
hdr_percentiles_print(_histogram_ep3_write_16seg, stdout, 5, 1.0, CLASSIC);
log_info("----------------------------------------------------------------");
fflush(stdout);
hdr_close(_histogram_ep1_send);
hdr_close(_histogram_ep2_recv);
hdr_close(_histogram_ep3_write_16seg);
FreeLibrary(_child_iidx_io_module);
}
void iidx_io_ep1_set_deck_lights(uint16_t deck_lights)
{
return _child_iidx_io_ep1_set_deck_lights(deck_lights);
}
void iidx_io_ep1_set_panel_lights(uint8_t panel_lights)
{
return _child_iidx_io_ep1_set_panel_lights(panel_lights);
}
void iidx_io_ep1_set_top_lamps(uint8_t top_lamps)
{
return _child_iidx_io_ep1_set_top_lamps(top_lamps);
}
void iidx_io_ep1_set_top_neons(bool top_neons)
{
return _child_iidx_io_ep1_set_top_neons(top_neons);
}
bool iidx_io_ep1_send(void)
{
hdr_timespec start_time;
hdr_timespec end_time;
int64_t diff_us;
bool result;
hdr_gettime(&start_time);
result = _child_iidx_io_ep1_send();
hdr_gettime(&end_time);
diff_us = hdr_timespec_diff_us(&start_time, &end_time);
hdr_record_value(_histogram_ep1_send, diff_us);
return result;
}
bool iidx_io_ep2_recv(void)
{
hdr_timespec start_time;
hdr_timespec end_time;
int64_t diff_us;
bool result;
hdr_gettime(&start_time);
result = _child_iidx_io_ep2_recv();
hdr_gettime(&end_time);
diff_us = hdr_timespec_diff_us(&start_time, &end_time);
hdr_record_value(_histogram_ep2_recv, diff_us);
return result;
}
uint8_t iidx_io_ep2_get_turntable(uint8_t player_no)
{
return _child_iidx_io_ep2_get_turntable(player_no);
}
uint8_t iidx_io_ep2_get_slider(uint8_t slider_no)
{
return _child_iidx_io_ep2_get_slider(slider_no);
}
uint8_t iidx_io_ep2_get_sys(void)
{
return _child_iidx_io_ep2_get_sys();
}
uint8_t iidx_io_ep2_get_panel(void)
{
return _child_iidx_io_ep2_get_panel();
}
uint16_t iidx_io_ep2_get_keys(void)
{
return _child_iidx_io_ep2_get_keys();
}
bool iidx_io_ep3_write_16seg(const char *text)
{
hdr_timespec start_time;
hdr_timespec end_time;
int64_t diff_us;
bool result;
hdr_gettime(&start_time);
result = _child_iidx_io_ep3_write_16seg(text);
hdr_gettime(&end_time);
diff_us = hdr_timespec_diff_us(&start_time, &end_time);
hdr_record_value(_histogram_ep3_write_16seg, diff_us);
return result;
}