1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +01:00

Remove dead code of TestPaint and remove BenchSpriteSort

This commit is contained in:
ζeh Matt
2023-06-26 21:59:27 +03:00
parent 3f603542ec
commit bcb0c069c3
7 changed files with 9 additions and 335 deletions

View File

@@ -1,235 +0,0 @@
/*****************************************************************************
* Copyright (c) 2014-2023 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "CommandLine.hpp"
#ifdef USE_BENCHMARK
# include "../Context.h"
# include "../Game.h"
# include "../Intro.h"
# include "../OpenRCT2.h"
# include "../audio/audio.h"
# include "../core/Console.hpp"
# include "../core/File.h"
# include "../core/Imaging.h"
# include "../drawing/Drawing.h"
# include "../interface/Viewport.h"
# include "../localisation/Localisation.h"
# include "../paint/Paint.h"
# include "../platform/Platform.h"
# include "../util/Util.h"
# include "../world/Climate.h"
# include "../world/Map.h"
# include "../world/Park.h"
# include "../world/Surface.h"
# include <benchmark/benchmark.h>
# include <cstdint>
# include <iterator>
# include <vector>
static void fixup_pointers(std::vector<RecordedPaintSession>& s)
{
for (size_t i = 0; i < s.size(); i++)
{
auto& entries = s[i].Entries;
auto& quadrants = s[i].Session.Quadrants;
for (size_t j = 0; j < entries.size(); j++)
{
if (entries[j].AsBasic()->NextQuadrantEntry == reinterpret_cast<PaintStruct*>(-1))
{
entries[j].AsBasic()->NextQuadrantEntry = nullptr;
}
else
{
auto nextQuadrantPs = reinterpret_cast<size_t>(entries[j].AsBasic()->NextQuadrantEntry) / sizeof(PaintEntry);
entries[j].AsBasic()->NextQuadrantEntry = s[i].Entries[nextQuadrantPs].AsBasic();
}
}
for (size_t j = 0; j < std::size(quadrants); j++)
{
if (quadrants[j] == reinterpret_cast<PaintStruct*>(-1))
{
quadrants[j] = nullptr;
}
else
{
auto ps = reinterpret_cast<size_t>(quadrants[j]) / sizeof(PaintEntry);
quadrants[j] = entries[ps].AsBasic();
}
}
}
}
static std::vector<RecordedPaintSession> extract_paint_session(std::string_view parkFileName)
{
gOpenRCT2Headless = true;
auto context = OpenRCT2::CreateContext();
std::vector<RecordedPaintSession> sessions;
LOG_INFO("Starting...");
if (context->Initialise())
{
DrawingEngineInit();
if (!context->LoadParkFromFile(std::string(parkFileName)))
{
LOG_ERROR("Failed to load park!");
return {};
}
gIntroState = IntroState::None;
gScreenFlags = SCREEN_FLAGS_PLAYING;
int32_t resolutionWidth = (gMapSize.x * COORDS_XY_STEP * 2);
int32_t resolutionHeight = (gMapSize.y * COORDS_XY_STEP * 1);
resolutionWidth += 8;
resolutionHeight += 128;
Viewport viewport;
viewport.pos = { 0, 0 };
viewport.width = resolutionWidth;
viewport.height = resolutionHeight;
viewport.view_width = viewport.width;
viewport.view_height = viewport.height;
viewport.var_11 = 0;
viewport.flags = 0;
auto customXY = TileCoordsXY(gMapSize.x / 2, gMapSize.y / 2).ToCoordsXY().ToTileCentre();
auto customXYZ = CoordsXYZ(customXY, TileElementHeight(customXY));
auto screenXY = Translate3DTo2DWithZ(0, customXYZ);
viewport.viewPos = { screenXY.x - (viewport.view_width / 2), screenXY.y - (viewport.view_height / 2) };
viewport.zoom = ZoomLevel{ 0 };
gCurrentRotation = 0;
// Ensure sprites appear regardless of rotation
ResetAllSpriteQuadrantPlacements();
DrawPixelInfo dpi;
dpi.x = 0;
dpi.y = 0;
dpi.width = resolutionWidth;
dpi.height = resolutionHeight;
dpi.pitch = 0;
dpi.bits = static_cast<uint8_t*>(malloc(dpi.width * dpi.height));
LOG_INFO("Obtaining sprite data...");
ViewportRender(dpi, &viewport, { { 0, 0 }, { viewport.width, viewport.height } }, &sessions);
free(dpi.bits);
DrawingEngineDispose();
}
LOG_INFO("Got %u paint sessions.", std::size(sessions));
return sessions;
}
// This function is based on BenchgfxRenderScreenshots
static void BM_paint_session_arrange(benchmark::State& state, const std::vector<RecordedPaintSession> inputSessions)
{
auto sessions = inputSessions;
// Fixing up the pointers continuously is wasteful. Fix it up once for `sessions` and store a copy.
// Keep in mind we need bit-exact copy, as the lists use pointers.
// Once sorted, just restore the copy with the original fixed-up version.
RecordedPaintSession* local_s = new RecordedPaintSession[std::size(sessions)];
fixup_pointers(sessions);
std::copy_n(sessions.cbegin(), std::size(sessions), local_s);
for (auto _ : state)
{
state.PauseTiming();
std::copy_n(local_s, std::size(sessions), sessions.begin());
state.ResumeTiming();
PaintSessionArrange(sessions[0].Session);
benchmark::DoNotOptimize(sessions);
}
state.SetItemsProcessed(state.iterations() * std::size(sessions));
delete[] local_s;
}
static int command_line_for_bench_sprite_sort(int argc, const char** argv)
{
{
// Register some basic "baseline" benchmark
std::vector<RecordedPaintSession> sessions(1);
for (auto& ps : sessions[0].Entries)
{
ps.AsBasic()->NextQuadrantEntry = reinterpret_cast<PaintStruct*>(-1);
}
for (auto& quad : sessions[0].Session.Quadrants)
{
quad = reinterpret_cast<PaintStruct*>(-1);
}
benchmark::RegisterBenchmark("baseline", BM_paint_session_arrange, sessions);
}
// Google benchmark does stuff to argv. It doesn't modify the pointees,
// but it wants to reorder the pointers, so present a copy of them.
std::vector<char*> argv_for_benchmark;
// argv[0] is expected to contain the binary name. It's only for logging purposes, don't bother.
argv_for_benchmark.push_back(nullptr);
// Extract file names from argument list. If there is no such file, consider it benchmark option.
for (int i = 0; i < argc; i++)
{
if (File::Exists(argv[i]))
{
// Register benchmark for sv6 if valid
std::vector<RecordedPaintSession> sessions = extract_paint_session(argv[i]);
if (!sessions.empty())
benchmark::RegisterBenchmark(argv[i], BM_paint_session_arrange, sessions);
}
else
{
argv_for_benchmark.push_back(const_cast<char*>(argv[i]));
}
}
// Update argc with all the changes made
argc = static_cast<int>(argv_for_benchmark.size());
::benchmark::Initialize(&argc, &argv_for_benchmark[0]);
if (::benchmark::ReportUnrecognizedArguments(argc, &argv_for_benchmark[0]))
return -1;
::benchmark::RunSpecifiedBenchmarks();
return 0;
}
static exitcode_t HandleBenchSpriteSort(CommandLineArgEnumerator* argEnumerator)
{
const char** argv = const_cast<const char**>(argEnumerator->GetArguments()) + argEnumerator->GetIndex();
int32_t argc = argEnumerator->GetCount() - argEnumerator->GetIndex();
int32_t result = command_line_for_bench_sprite_sort(argc, argv);
if (result < 0)
{
return EXITCODE_FAIL;
}
return EXITCODE_OK;
}
#else
static exitcode_t HandleBenchSpriteSort(CommandLineArgEnumerator* argEnumerator)
{
LOG_ERROR("Sorry, Google benchmark not enabled in this build");
return EXITCODE_FAIL;
}
#endif // USE_BENCHMARK
const CommandLineCommand CommandLine::BenchSpriteSortCommands[]{
#ifdef USE_BENCHMARK
DefineCommand(
"",
"[<file>]... [--benchmark_list_tests={true|false}] [--benchmark_filter=<regex>] [--benchmark_min_time=<min_time>] "
"[--benchmark_repetitions=<num_repetitions>] [--benchmark_report_aggregates_only={true|false}] "
"[--benchmark_format=<console|json|csv>] [--benchmark_out=<filename>] [--benchmark_out_format=<json|console|csv>] "
"[--benchmark_color={auto|true|false}] [--benchmark_counters_tabular={true|false}] [--v=<verbosity>]",
nullptr, HandleBenchSpriteSort),
CommandTableEnd
#else
DefineCommand("", "*** SORRY NOT ENABLED IN THIS BUILD ***", nullptr, HandleBenchSpriteSort), CommandTableEnd
#endif // USE_BENCHMARK
};

View File

@@ -117,7 +117,6 @@ namespace CommandLine
extern const CommandLineCommand ScreenshotCommands[];
extern const CommandLineCommand SpriteCommands[];
extern const CommandLineCommand BenchGfxCommands[];
extern const CommandLineCommand BenchSpriteSortCommands[];
extern const CommandLineCommand BenchUpdateCommands[];
extern const CommandLineCommand SimulateCommands[];
extern const CommandLineCommand ParkInfoCommands[];

View File

@@ -141,7 +141,6 @@ const CommandLineCommand CommandLine::RootCommands[]
DefineSubCommand("screenshot", CommandLine::ScreenshotCommands ),
DefineSubCommand("sprite", CommandLine::SpriteCommands ),
DefineSubCommand("benchgfx", CommandLine::BenchGfxCommands ),
DefineSubCommand("benchspritesort", CommandLine::BenchSpriteSortCommands ),
DefineSubCommand("benchsimulate", CommandLine::BenchUpdateCommands ),
DefineSubCommand("simulate", CommandLine::SimulateCommands ),
DefineSubCommand("parkinfo", CommandLine::ParkInfoCommands ),

View File

@@ -806,8 +806,7 @@ void ViewportUpdateSmartFollowVehicle(WindowBase* window)
* edi: dpi
* ebp: bottom
*/
void ViewportRender(
DrawPixelInfo& dpi, const Viewport* viewport, const ScreenRect& screenRect, std::vector<RecordedPaintSession>* sessions)
void ViewportRender(DrawPixelInfo& dpi, const Viewport* viewport, const ScreenRect& screenRect)
{
auto [topLeft, bottomRight] = screenRect;
@@ -837,7 +836,7 @@ void ViewportRender(
viewport->zoom.ApplyTo(std::min(bottomRight.y, viewport->height)),
} + viewport->viewPos;
ViewportPaint(viewport, dpi, { topLeft, bottomRight }, sessions);
ViewportPaint(viewport, dpi, { topLeft, bottomRight });
#ifdef DEBUG_SHOW_DIRTY_BOX
// FIXME g_viewport_list doesn't exist anymore
@@ -846,75 +845,11 @@ void ViewportRender(
#endif
}
static void RecordSession(
const PaintSession& session, std::vector<RecordedPaintSession>* recorded_sessions, size_t record_index)
{
// Perform a deep copy of the paint session, use relative offsets.
// This is done to extract the session for benchmark.
// Place the copied session at provided record_index, so the caller can decide which columns/paint sessions to copy;
// there is no column information embedded in the session itself.
auto& recordedSession = recorded_sessions->at(record_index);
recordedSession.Session = session;
recordedSession.Entries.resize(session.PaintEntryChain.GetCount());
// Mind the offset needs to be calculated against the original `session`, not `session_copy`
std::unordered_map<PaintStruct*, PaintStruct*> entryRemap;
// Copy all entries
auto paintIndex = 0;
auto chain = session.PaintEntryChain.Head;
while (chain != nullptr)
{
for (size_t i = 0; i < chain->Count; i++)
{
auto& src = chain->PaintStructs[i];
auto& dst = recordedSession.Entries[paintIndex++];
dst = src;
entryRemap[src.AsBasic()] = reinterpret_cast<PaintStruct*>(i * sizeof(PaintEntry));
}
chain = chain->Next;
}
entryRemap[nullptr] = reinterpret_cast<PaintStruct*>(-1);
// Remap all entries
for (auto& ps : recordedSession.Entries)
{
auto& ptr = ps.AsBasic()->NextQuadrantEntry;
auto it = entryRemap.find(ptr);
if (it == entryRemap.end())
{
assert(false);
ptr = nullptr;
}
else
{
ptr = it->second;
}
}
for (auto& ptr : recordedSession.Session.Quadrants)
{
auto it = entryRemap.find(ptr);
if (it == entryRemap.end())
{
assert(false);
ptr = nullptr;
}
else
{
ptr = it->second;
}
}
}
static void ViewportFillColumn(PaintSession& session, std::vector<RecordedPaintSession>* recorded_sessions, size_t record_index)
static void ViewportFillColumn(PaintSession& session)
{
PROFILED_FUNCTION();
PaintSessionGenerate(session);
if (recorded_sessions != nullptr)
{
RecordSession(session, recorded_sessions, record_index);
}
PaintSessionArrange(session);
}
@@ -959,9 +894,7 @@ static void ViewportPaintColumn(PaintSession& session)
* edi: dpi
* ebp: bottom
*/
void ViewportPaint(
const Viewport* viewport, DrawPixelInfo& dpi, const ScreenRect& screenRect,
std::vector<RecordedPaintSession>* recorded_sessions)
void ViewportPaint(const Viewport* viewport, DrawPixelInfo& dpi, const ScreenRect& screenRect)
{
PROFILED_FUNCTION();
@@ -1019,17 +952,8 @@ void ViewportPaint(
useParallelDrawing = true;
}
// Create space to record sessions and keep track which index is being drawn
size_t index = 0;
if (recorded_sessions != nullptr)
{
auto columnSize = rightBorder - alignedX;
auto columnCount = (columnSize + 31) / 32;
recorded_sessions->resize(columnCount);
}
// Generate and sort columns.
for (x = alignedX; x < rightBorder; x += 32, index++)
for (x = alignedX; x < rightBorder; x += 32)
{
PaintSession* session = PaintSessionAlloc(dpi1, viewFlags);
_paintColumns.push_back(session);
@@ -1055,12 +979,11 @@ void ViewportPaint(
if (useMultithreading)
{
_paintJobs->AddTask(
[session, recorded_sessions, index]() -> void { ViewportFillColumn(*session, recorded_sessions, index); });
_paintJobs->AddTask([session]() -> void { ViewportFillColumn(*session); });
}
else
{
ViewportFillColumn(*session, recorded_sessions, index);
ViewportFillColumn(*session);
}
}

View File

@@ -17,7 +17,6 @@
#include <vector>
struct PaintSession;
struct RecordedPaintSession;
struct PaintStruct;
struct DrawPixelInfo;
struct TileElement;
@@ -140,12 +139,8 @@ void ViewportUpdateSmartFollowEntity(WindowBase* window);
void ViewportUpdateSmartFollowGuest(WindowBase* window, const Guest* peep);
void ViewportUpdateSmartFollowStaff(WindowBase* window, const Staff* peep);
void ViewportUpdateSmartFollowVehicle(WindowBase* window);
void ViewportRender(
DrawPixelInfo& dpi, const Viewport* viewport, const ScreenRect& screenRect,
std::vector<RecordedPaintSession>* sessions = nullptr);
void ViewportPaint(
const Viewport* viewport, DrawPixelInfo& dpi, const ScreenRect& screenRect,
std::vector<RecordedPaintSession>* sessions = nullptr);
void ViewportRender(DrawPixelInfo& dpi, const Viewport* viewport, const ScreenRect& screenRect);
void ViewportPaint(const Viewport* viewport, DrawPixelInfo& dpi, const ScreenRect& screenRect);
CoordsXYZ ViewportAdjustForMapHeight(const ScreenCoordsXY& startCoords);

View File

@@ -691,7 +691,6 @@
<ClCompile Include="Cheats.cpp" />
<ClCompile Include="CommandLineSprite.cpp" />
<ClCompile Include="command_line\BenchGfxCommmands.cpp" />
<ClCompile Include="command_line\BenchSpriteSort.cpp" />
<ClCompile Include="command_line/BenchUpdate.cpp" />
<ClCompile Include="command_line\CommandLine.cpp" />
<ClCompile Include="command_line\ConvertCommand.cpp" />

View File

@@ -270,12 +270,6 @@ struct FootpathPaintInfo
colour_t SupportColour = 255;
};
struct RecordedPaintSession
{
PaintSessionCore Session;
std::vector<PaintEntry> Entries;
};
extern PaintSession gPaintSession;
// Globals for paint clipping