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 <array> |
||||||
|
#include <cstddef> |
||||||
#include <benchmark/benchmark.h> |
#include <cstdio> |
||||||
|
|
||||||
#include "engine/render/light_render.hpp" |
#include <benchmark/benchmark.h> |
||||||
#include "engine/surface.hpp" |
|
||||||
#include "lighting.h" |
#include "engine/lighting_defs.hpp" |
||||||
#include "utils/log.hpp" |
#include "engine/render/light_render.hpp" |
||||||
#include "utils/paths.h" |
#include "engine/surface.hpp" |
||||||
#include "utils/sdl_wrap.h" |
#include "levels/gendung_defs.hpp" |
||||||
|
#include "utils/log.hpp" |
||||||
namespace devilution { |
#include "utils/paths.h" |
||||||
namespace { |
#include "utils/sdl_wrap.h" |
||||||
|
|
||||||
void BM_BuildLightmap(benchmark::State &state) |
namespace devilution { |
||||||
{ |
namespace { |
||||||
std::string benchmarkDataPath = paths::BasePath() + "test/fixtures/light_render_benchmark/dLight.dmp"; |
|
||||||
FILE *lightFile = std::fopen(benchmarkDataPath.c_str(), "rb"); |
void BM_BuildLightmap(benchmark::State &state) |
||||||
if (lightFile != nullptr) { |
{ |
||||||
std::fread(&dLight[0][0], sizeof(uint8_t), MAXDUNX * MAXDUNY, lightFile); |
const std::string benchmarkDataPath = paths::BasePath() + "test/fixtures/light_render_benchmark/dLight.dmp"; |
||||||
std::fclose(lightFile); |
FILE *lightFile = std::fopen(benchmarkDataPath.c_str(), "rb"); |
||||||
} |
uint8_t dLight[MAXDUNX][MAXDUNY]; |
||||||
|
std::array<std::array<uint8_t, 256>, LightsMax> lightTables; |
||||||
SDLSurfaceUniquePtr sdl_surface = SDLWrap::CreateRGBSurfaceWithFormat( |
if (lightFile != nullptr) { |
||||||
/*flags=*/0, /*width=*/640, /*height=*/480, /*depth=*/8, SDL_PIXELFORMAT_INDEX8); |
if (std::fread(&dLight[0][0], sizeof(uint8_t) * MAXDUNX * MAXDUNY, 1, lightFile) != 1) { |
||||||
if (sdl_surface == nullptr) { |
std::perror("Failed to read dLight.dmp"); |
||||||
LogError("Failed to create SDL Surface: {}", SDL_GetError()); |
exit(1); |
||||||
exit(1); |
} |
||||||
} |
std::fclose(lightFile); |
||||||
Surface out = Surface(sdl_surface.get()); |
} |
||||||
|
|
||||||
Point tilePosition { 48, 44 }; |
SDLSurfaceUniquePtr sdl_surface = SDLWrap::CreateRGBSurfaceWithFormat( |
||||||
Point targetBufferPosition { 0, -17 }; |
/*flags=*/0, /*width=*/640, /*height=*/480, /*depth=*/8, SDL_PIXELFORMAT_INDEX8); |
||||||
int viewportWidth = 640; |
if (sdl_surface == nullptr) { |
||||||
int viewportHeight = 352; |
std::fprintf(stderr, "Failed to create SDL Surface: %s\n", SDL_GetError()); |
||||||
int rows = 25; |
exit(1); |
||||||
int columns = 10; |
} |
||||||
const uint8_t *outBuffer = out.at(0, 0); |
Surface out = Surface(sdl_surface.get()); |
||||||
uint16_t outPitch = out.pitch(); |
|
||||||
const uint8_t *lightTables = LightTables[0].data(); |
const Point tilePosition { 48, 44 }; |
||||||
size_t lightTableSize = LightTables[0].size(); |
const Point targetBufferPosition { 0, -17 }; |
||||||
|
const int viewportWidth = 640; |
||||||
size_t numViewportTiles = rows * columns; |
const int viewportHeight = 352; |
||||||
size_t numPixels = viewportWidth * viewportHeight; |
const int rows = 25; |
||||||
size_t numBytesProcessed = 0; |
const int columns = 10; |
||||||
size_t numItemsProcessed = 0; |
const uint8_t *outBuffer = out.at(0, 0); |
||||||
for (auto _ : state) { |
const uint16_t outPitch = out.pitch(); |
||||||
Lightmap lightmap = Lightmap::build(tilePosition, targetBufferPosition, |
|
||||||
viewportWidth, viewportHeight, rows, columns, |
for (auto _ : state) { |
||||||
outBuffer, outPitch, lightTables, lightTableSize); |
Lightmap lightmap = Lightmap::build(/*perPixelLighting=*/true, |
||||||
|
tilePosition, targetBufferPosition, |
||||||
uint8_t lightLevel = *lightmap.getLightingAt(outBuffer + outPitch * 120 + 120); |
viewportWidth, viewportHeight, rows, columns, |
||||||
benchmark::DoNotOptimize(lightLevel); |
outBuffer, outPitch, lightTables[0].data(), lightTables[0].size(), |
||||||
numItemsProcessed += numViewportTiles; |
dLight, /*microTileLen=*/10); |
||||||
numBytesProcessed += numPixels; |
|
||||||
} |
uint8_t lightLevel = *lightmap.getLightingAt(outBuffer + outPitch * 120 + 120); |
||||||
state.SetBytesProcessed(numBytesProcessed); |
benchmark::DoNotOptimize(lightLevel); |
||||||
state.SetItemsProcessed(numItemsProcessed); |
} |
||||||
} |
state.SetBytesProcessed(state.iterations() * viewportWidth * viewportHeight); |
||||||
|
state.SetItemsProcessed(state.iterations() * rows * columns); |
||||||
BENCHMARK(BM_BuildLightmap); |
} |
||||||
|
|
||||||
} // namespace
|
BENCHMARK(BM_BuildLightmap); |
||||||
} // namespace devilution
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace devilution
|
||||||
|
|||||||
Loading…
Reference in new issue