14 changed files with 177 additions and 140 deletions
@ -0,0 +1,16 @@
|
||||
#pragma once |
||||
|
||||
#include <cstddef> |
||||
|
||||
namespace devilution { |
||||
|
||||
#define MAXLIGHTS 32 |
||||
#define MAXVISION 4 |
||||
#define NO_LIGHT -1 |
||||
|
||||
constexpr char LightsMax = 15; |
||||
|
||||
/** @brief Number of supported light levels */ |
||||
constexpr size_t NumLightingLevels = LightsMax + 1; |
||||
|
||||
} // namespace devilution
|
||||
@ -0,0 +1,37 @@
|
||||
#pragma once |
||||
|
||||
#include <cstdint> |
||||
|
||||
#define DMAXX 40 |
||||
#define DMAXY 40 |
||||
|
||||
#define MAXDUNX (16 + DMAXX * 2 + 16) |
||||
#define MAXDUNY (16 + DMAXY * 2 + 16) |
||||
|
||||
namespace devilution { |
||||
|
||||
enum dungeon_type : int8_t { |
||||
DTYPE_TOWN, |
||||
DTYPE_CATHEDRAL, |
||||
DTYPE_CATACOMBS, |
||||
DTYPE_CAVES, |
||||
DTYPE_HELL, |
||||
DTYPE_NEST, |
||||
DTYPE_CRYPT, |
||||
|
||||
DTYPE_LAST = DTYPE_CRYPT, |
||||
DTYPE_NONE = -1, |
||||
}; |
||||
|
||||
enum lvl_entry : uint8_t { |
||||
ENTRY_MAIN, |
||||
ENTRY_PREV, |
||||
ENTRY_SETLVL, |
||||
ENTRY_RTNLVL, |
||||
ENTRY_LOAD, |
||||
ENTRY_WARPLVL, |
||||
ENTRY_TWARPDN, |
||||
ENTRY_TWARPUP, |
||||
}; |
||||
|
||||
} // namespace devilution
|
||||
@ -1,64 +1,66 @@
|
||||
#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
|
||||
#include <array> |
||||
#include <cstddef> |
||||
#include <cstdio> |
||||
|
||||
#include <benchmark/benchmark.h> |
||||
|
||||
#include "engine/lighting_defs.hpp" |
||||
#include "engine/render/light_render.hpp" |
||||
#include "engine/surface.hpp" |
||||
#include "levels/gendung_defs.hpp" |
||||
#include "utils/log.hpp" |
||||
#include "utils/paths.h" |
||||
#include "utils/sdl_wrap.h" |
||||
|
||||
namespace devilution { |
||||
namespace { |
||||
|
||||
void BM_BuildLightmap(benchmark::State &state) |
||||
{ |
||||
const std::string benchmarkDataPath = paths::BasePath() + "test/fixtures/light_render_benchmark/dLight.dmp"; |
||||
FILE *lightFile = std::fopen(benchmarkDataPath.c_str(), "rb"); |
||||
uint8_t dLight[MAXDUNX][MAXDUNY]; |
||||
std::array<std::array<uint8_t, 256>, LightsMax> lightTables; |
||||
if (lightFile != nullptr) { |
||||
if (std::fread(&dLight[0][0], sizeof(uint8_t) * MAXDUNX * MAXDUNY, 1, lightFile) != 1) { |
||||
std::perror("Failed to read dLight.dmp"); |
||||
exit(1); |
||||
} |
||||
std::fclose(lightFile); |
||||
} |
||||
|
||||
SDLSurfaceUniquePtr sdl_surface = SDLWrap::CreateRGBSurfaceWithFormat( |
||||
/*flags=*/0, /*width=*/640, /*height=*/480, /*depth=*/8, SDL_PIXELFORMAT_INDEX8); |
||||
if (sdl_surface == nullptr) { |
||||
std::fprintf(stderr, "Failed to create SDL Surface: %s\n", SDL_GetError()); |
||||
exit(1); |
||||
} |
||||
Surface out = Surface(sdl_surface.get()); |
||||
|
||||
const Point tilePosition { 48, 44 }; |
||||
const Point targetBufferPosition { 0, -17 }; |
||||
const int viewportWidth = 640; |
||||
const int viewportHeight = 352; |
||||
const int rows = 25; |
||||
const int columns = 10; |
||||
const uint8_t *outBuffer = out.at(0, 0); |
||||
const uint16_t outPitch = out.pitch(); |
||||
|
||||
for (auto _ : state) { |
||||
Lightmap lightmap = Lightmap::build(/*perPixelLighting=*/true, |
||||
tilePosition, targetBufferPosition, |
||||
viewportWidth, viewportHeight, rows, columns, |
||||
outBuffer, outPitch, lightTables[0].data(), lightTables[0].size(), |
||||
dLight, /*microTileLen=*/10); |
||||
|
||||
uint8_t lightLevel = *lightmap.getLightingAt(outBuffer + outPitch * 120 + 120); |
||||
benchmark::DoNotOptimize(lightLevel); |
||||
} |
||||
state.SetBytesProcessed(state.iterations() * viewportWidth * viewportHeight); |
||||
state.SetItemsProcessed(state.iterations() * rows * columns); |
||||
} |
||||
|
||||
BENCHMARK(BM_BuildLightmap); |
||||
|
||||
} // namespace
|
||||
} // namespace devilution
|
||||
|
||||
Loading…
Reference in new issue