Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/levels/gendung.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
#define MAXTILES 1379

enum _setlevels : int8_t {
SL_NONE,

Check warning on line 39 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:39:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_NONE'
SL_SKELKING,

Check warning on line 40 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:40:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_SKELKING'
SL_BONECHAMB,

Check warning on line 41 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:41:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_BONECHAMB'
SL_MAZE,

Check warning on line 42 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:42:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_MAZE'
SL_POISONWATER,

Check warning on line 43 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:43:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_POISONWATER'
SL_VILEBETRAYER,

Check warning on line 44 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:44:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_VILEBETRAYER'

SL_ARENA_CHURCH,

Check warning on line 46 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:46:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_ARENA_CHURCH'
SL_ARENA_HELL,

Check warning on line 47 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:47:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_ARENA_HELL'
SL_ARENA_CIRCLE_OF_LIFE,

Check warning on line 48 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:48:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_ARENA_CIRCLE_OF_LIFE'

SL_FIRST_ARENA = SL_ARENA_CHURCH,

Check warning on line 50 in Source/levels/gendung.h

View workflow job for this annotation

GitHub Actions / tidy-check

Source/levels/gendung.h:50:2 [readability-identifier-naming]

invalid case style for enum constant 'SL_FIRST_ARENA'
SL_LAST = SL_ARENA_CIRCLE_OF_LIFE,
};

Expand Down Expand Up @@ -181,7 +181,7 @@
/** Specifies the transparency at each coordinate of the map. */
extern DVL_API_FOR_TEST int8_t dTransVal[MAXDUNX][MAXDUNY];
/** Current realtime lighting. Per tile. */
extern uint8_t dLight[MAXDUNX][MAXDUNY];
extern DVL_API_FOR_TEST uint8_t dLight[MAXDUNX][MAXDUNY];
/** Precalculated static lights. dLight uses this as a base before applying lights. Per tile. */
extern uint8_t dPreLight[MAXDUNX][MAXDUNY];
/** Holds various information about dungeon tiles, @see DungeonFlag */
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ set(benchmarks
clx_render_benchmark
crawl_benchmark
dun_render_benchmark
light_render_benchmark
palette_blending_benchmark
path_benchmark
)
Expand Down Expand Up @@ -106,6 +107,7 @@ target_link_dependencies(dun_render_benchmark PRIVATE libdevilutionx_so)
target_link_dependencies(file_util_test PRIVATE libdevilutionx_file_util app_fatal_for_testing)
target_link_dependencies(format_int_test PRIVATE libdevilutionx_format_int language_for_testing)
target_link_dependencies(ini_test PRIVATE libdevilutionx_ini app_fatal_for_testing)
target_link_dependencies(light_render_benchmark PRIVATE libdevilutionx_so)
target_link_dependencies(palette_blending_test PRIVATE libdevilutionx_palette_blending DevilutionX::SDL libdevilutionx_strings GTest::gmock app_fatal_for_testing)
target_link_dependencies(palette_blending_benchmark PRIVATE libdevilutionx_palette_blending DevilutionX::SDL app_fatal_for_testing)
target_link_dependencies(parse_int_test PRIVATE libdevilutionx_parse_int)
Expand Down
Binary file added test/fixtures/light_render_benchmark/dLight.dmp
Binary file not shown.
64 changes: 64 additions & 0 deletions test/light_render_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <cstddef>

#include <benchmark/benchmark.h>

#include "engine/render/light_render.hpp"
#include "engine/surface.hpp"
#include "lighting.h"
#include "utils/log.hpp"
#include "utils/paths.h"
#include "utils/sdl_wrap.h"

namespace devilution {
namespace {

void BM_BuildLightmap(benchmark::State &state)
{
std::string benchmarkDataPath = paths::BasePath() + "test/fixtures/light_render_benchmark/dLight.dmp";
FILE *lightFile = std::fopen(benchmarkDataPath.c_str(), "rb");
if (lightFile != nullptr) {
std::fread(&dLight[0][0], sizeof(uint8_t), MAXDUNX * MAXDUNY, lightFile);
std::fclose(lightFile);
}

SDLSurfaceUniquePtr sdl_surface = SDLWrap::CreateRGBSurfaceWithFormat(
/*flags=*/0, /*width=*/640, /*height=*/480, /*depth=*/8, SDL_PIXELFORMAT_INDEX8);
if (sdl_surface == nullptr) {
LogError("Failed to create SDL Surface: {}", SDL_GetError());
exit(1);
}
Surface out = Surface(sdl_surface.get());

Point tilePosition { 48, 44 };
Point targetBufferPosition { 0, -17 };
int viewportWidth = 640;
int viewportHeight = 352;
int rows = 25;
int columns = 10;
const uint8_t *outBuffer = out.at(0, 0);
uint16_t outPitch = out.pitch();
const uint8_t *lightTables = LightTables[0].data();
size_t lightTableSize = LightTables[0].size();

size_t numViewportTiles = rows * columns;
size_t numPixels = viewportWidth * viewportHeight;
size_t numBytesProcessed = 0;
size_t numItemsProcessed = 0;
for (auto _ : state) {
Lightmap lightmap = Lightmap::build(tilePosition, targetBufferPosition,
viewportWidth, viewportHeight, rows, columns,
outBuffer, outPitch, lightTables, lightTableSize);

uint8_t lightLevel = *lightmap.getLightingAt(outBuffer + outPitch * 120 + 120);
benchmark::DoNotOptimize(lightLevel);
numItemsProcessed += numViewportTiles;
numBytesProcessed += numPixels;
}
state.SetBytesProcessed(numBytesProcessed);
state.SetItemsProcessed(numItemsProcessed);
}

BENCHMARK(BM_BuildLightmap);

} // namespace
} // namespace devilution