mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-10 13:18:31 +09:00
[Fix] (...): Avoid some weird crashes.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
#include "Init.h"
|
||||
#include "MG_Impl/GLImpl/Buffer/GL_Buffer.h"
|
||||
#include "MG_State/GLState/Core.h"
|
||||
|
||||
@@ -19,8 +20,6 @@ constexpr GLuint BUFFER_COUNT = 32;
|
||||
constexpr GLsizeiptr BUFFER_SIZE = 1024 * 1024;
|
||||
|
||||
static void BM_GenerateAndDeleteBuffers(benchmark::State& state) {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
|
||||
GLuint n = static_cast<GLuint>(state.range(0));
|
||||
int repeat = static_cast<int>(state.range(1));
|
||||
std::vector<GLuint> buffers(n);
|
||||
@@ -33,7 +32,6 @@ static void BM_GenerateAndDeleteBuffers(benchmark::State& state) {
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * repeat * n);
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
|
||||
BENCHMARK(BM_GenerateAndDeleteBuffers)
|
||||
@@ -45,8 +43,6 @@ BENCHMARK(BM_GenerateAndDeleteBuffers)
|
||||
->UseRealTime();
|
||||
|
||||
static void BM_CreateBufferObjectsAndBindBuffer(benchmark::State& state) {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
|
||||
GLuint buffers[BUFFER_COUNT];
|
||||
GenBuffers(BUFFER_COUNT, buffers);
|
||||
|
||||
@@ -60,12 +56,11 @@ static void BM_CreateBufferObjectsAndBindBuffer(benchmark::State& state) {
|
||||
state.SetItemsProcessed(state.iterations() * BUFFER_COUNT);
|
||||
|
||||
DeleteBuffers(BUFFER_COUNT, buffers);
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
BENCHMARK(BM_CreateBufferObjectsAndBindBuffer)->Unit(benchmark::kMillisecond)->UseRealTime();
|
||||
|
||||
static void BM_DeleteBufferObjects(benchmark::State& state) {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
MG_Initialize();
|
||||
std::vector<GLuint> buffers(BUFFER_COUNT);
|
||||
|
||||
for (auto _ : state) {
|
||||
@@ -81,13 +76,10 @@ static void BM_DeleteBufferObjects(benchmark::State& state) {
|
||||
}
|
||||
|
||||
state.SetItemsProcessed(state.iterations() * BUFFER_COUNT);
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
BENCHMARK(BM_DeleteBufferObjects)->Unit(benchmark::kMillisecond)->UseRealTime();
|
||||
|
||||
static void BM_UpdateData(benchmark::State& state) {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
|
||||
GLuint buffers[BUFFER_COUNT];
|
||||
GenBuffers(BUFFER_COUNT, buffers);
|
||||
|
||||
@@ -106,13 +98,10 @@ static void BM_UpdateData(benchmark::State& state) {
|
||||
state.SetItemsProcessed(state.iterations() * BUFFER_COUNT);
|
||||
|
||||
DeleteBuffers(BUFFER_COUNT, buffers);
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
BENCHMARK(BM_UpdateData)->Unit(benchmark::kMillisecond)->UseRealTime();
|
||||
|
||||
static void BM_MapBuffer(benchmark::State& state) {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
|
||||
GLuint buffers[BUFFER_COUNT];
|
||||
GenBuffers(BUFFER_COUNT, buffers);
|
||||
for (GLuint i = 0; i < BUFFER_COUNT; i++)
|
||||
@@ -136,13 +125,10 @@ static void BM_MapBuffer(benchmark::State& state) {
|
||||
state.SetItemsProcessed(state.iterations() * BUFFER_COUNT);
|
||||
|
||||
DeleteBuffers(BUFFER_COUNT, buffers);
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
BENCHMARK(BM_MapBuffer)->Unit(benchmark::kMillisecond)->UseRealTime();
|
||||
|
||||
static void BM_CopyBufferSubData(benchmark::State& state) {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
|
||||
GLuint buffers[BUFFER_COUNT];
|
||||
GenBuffers(BUFFER_COUNT, buffers);
|
||||
|
||||
@@ -165,13 +151,10 @@ static void BM_CopyBufferSubData(benchmark::State& state) {
|
||||
state.SetItemsProcessed(state.iterations() * (BUFFER_COUNT / 2));
|
||||
|
||||
DeleteBuffers(BUFFER_COUNT, buffers);
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
BENCHMARK(BM_CopyBufferSubData)->Unit(benchmark::kMillisecond)->UseRealTime();
|
||||
|
||||
static void BM_UpdateDataPartially(benchmark::State& state) {
|
||||
MG_State::pGLContext = new MG_State::GLState::GLContext();
|
||||
|
||||
std::vector<GLuint> buffers(BUFFER_COUNT);
|
||||
std::vector<char> data(BUFFER_SIZE / 10, 1);
|
||||
|
||||
@@ -191,8 +174,21 @@ static void BM_UpdateDataPartially(benchmark::State& state) {
|
||||
state.SetItemsProcessed(state.iterations() * BUFFER_COUNT);
|
||||
|
||||
DeleteBuffers(BUFFER_COUNT, buffers.data());
|
||||
delete MG_State::pGLContext;
|
||||
}
|
||||
BENCHMARK(BM_UpdateDataPartially)->Unit(benchmark::kMillisecond)->UseRealTime();
|
||||
|
||||
BENCHMARK_MAIN();
|
||||
int main(int argc, char** argv) {
|
||||
MG_Initialize();
|
||||
benchmark ::MaybeReenterWithoutASLR(argc, argv);
|
||||
char arg0_default[] = "benchmark";
|
||||
char* args_default = reinterpret_cast<char*>(arg0_default);
|
||||
if (!argv) {
|
||||
argc = 1;
|
||||
argv = &args_default;
|
||||
}
|
||||
::benchmark ::Initialize(&argc, argv);
|
||||
if (::benchmark ::ReportUnrecognizedArguments(argc, argv)) return 1;
|
||||
::benchmark ::RunSpecifiedBenchmarks();
|
||||
::benchmark ::Shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user