Browse Source

DebugTools: make GLFrameProfiler::Values storeable in Configuration.

I want to use these in command-line arguments.
meshdata-cereal-killer
Vladimír Vondruš 6 years ago
parent
commit
c8a9422d1c
  1. 76
      src/Magnum/DebugTools/FrameProfiler.cpp
  2. 50
      src/Magnum/DebugTools/FrameProfiler.h
  3. 39
      src/Magnum/DebugTools/Test/FrameProfilerTest.cpp

76
src/Magnum/DebugTools/FrameProfiler.cpp

@ -31,6 +31,7 @@
#include <Corrade/Containers/GrowableArray.h> #include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/String.h>
#include "Magnum/Math/Functions.h" #include "Magnum/Math/Functions.h"
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
@ -629,22 +630,24 @@ Double GLFrameProfiler::primitiveClipRatioMean() const {
} }
#endif #endif
namespace {
constexpr const char* GLFrameProfilerValueNames[] {
"FrameTime",
"CpuDuration",
"GpuDuration",
"VertexFetchRatio",
"PrimitiveClipRatio"
};
}
Debug& operator<<(Debug& debug, const GLFrameProfiler::Value value) { Debug& operator<<(Debug& debug, const GLFrameProfiler::Value value) {
debug << "DebugTools::GLFrameProfiler::Value" << Debug::nospace; debug << "DebugTools::GLFrameProfiler::Value" << Debug::nospace;
switch(value) { const UnsignedInt bit = Math::log2(UnsignedShort(value));
/* LCOV_EXCL_START */ if(1 << bit == UnsignedShort(value))
#define _c(v) case GLFrameProfiler::Value::v: return debug << "::" #v; return debug << "::" << Debug::nospace << GLFrameProfilerValueNames[bit];
_c(FrameTime)
_c(CpuDuration)
_c(GpuDuration)
#ifndef MAGNUM_TARGET_GLES
_c(VertexFetchRatio)
_c(PrimitiveClipRatio)
#endif
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedShort(value)) << Debug::nospace << ")"; return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedShort(value)) << Debug::nospace << ")";
} }
@ -663,3 +666,50 @@ Debug& operator<<(Debug& debug, const GLFrameProfiler::Values value) {
#endif #endif
}} }}
namespace Corrade { namespace Utility {
using namespace Magnum;
std::string ConfigurationValue<DebugTools::GLFrameProfiler::Value>::toString(const DebugTools::GLFrameProfiler::Value value, ConfigurationValueFlags) {
const UnsignedInt bit = Math::log2(UnsignedShort(value));
if(1 << bit == UnsignedShort(value))
return DebugTools::GLFrameProfilerValueNames[bit];
return "";
}
DebugTools::GLFrameProfiler::Value ConfigurationValue<DebugTools::GLFrameProfiler::Value>::fromString(const std::string& value, ConfigurationValueFlags) {
for(std::size_t i = 0; i != Containers::arraySize(DebugTools::GLFrameProfilerValueNames); ++i)
if(DebugTools::GLFrameProfilerValueNames[i] == value)
return DebugTools::GLFrameProfiler::Value(1 << i);
return DebugTools::GLFrameProfiler::Value{};
}
std::string ConfigurationValue<DebugTools::GLFrameProfiler::Values>::toString(const DebugTools::GLFrameProfiler::Values value, ConfigurationValueFlags) {
std::string out;
for(std::size_t i = 0; i != Containers::arraySize(DebugTools::GLFrameProfilerValueNames); ++i) {
const auto bit = DebugTools::GLFrameProfiler::Value(1 << i);
if(value & bit) {
if(!out.empty()) out += ' ';
out += DebugTools::GLFrameProfilerValueNames[i];
}
}
return out;
}
DebugTools::GLFrameProfiler::Values ConfigurationValue<DebugTools::GLFrameProfiler::Values>::fromString(const std::string& value, ConfigurationValueFlags) {
const std::vector<std::string> bits = Utility::String::splitWithoutEmptyParts(value);
DebugTools::GLFrameProfiler::Values values;
for(const std::string& bit: bits)
for(std::size_t i = 0; i != Containers::arraySize(DebugTools::GLFrameProfilerValueNames); ++i)
if(DebugTools::GLFrameProfilerValueNames[i] == bit)
values |= DebugTools::GLFrameProfiler::Value(1 << i);
return values;
}
}}

50
src/Magnum/DebugTools/FrameProfiler.h

@ -701,4 +701,54 @@ MAGNUM_DEBUGTOOLS_EXPORT Debug& operator<<(Debug& debug, GLFrameProfiler::Values
}} }}
namespace Corrade { namespace Utility {
/**
@configurationvalue{Magnum::DebugTools::GLFrameProfiler::Value}
@m_since_latest
*/
template<> struct MAGNUM_DEBUGTOOLS_EXPORT ConfigurationValue<Magnum::DebugTools::GLFrameProfiler::Value> {
ConfigurationValue() = delete;
/**
* @brief Writes enum value as a string
*
* If the value is invalid, returns an empty string.
*/
static std::string toString(Magnum::DebugTools::GLFrameProfiler::Value value, ConfigurationValueFlags);
/**
* @brief Reads enum value as a string
*
* If the string is invalid, returns a zero (invalid) value.
*/
static Magnum::DebugTools::GLFrameProfiler::Value fromString(const std::string& stringValue, ConfigurationValueFlags);
};
/**
@configurationvalue{Magnum::DebugTools::GLFrameProfiler::Values}
@m_since_latest
*/
template<> struct MAGNUM_DEBUGTOOLS_EXPORT ConfigurationValue<Magnum::DebugTools::GLFrameProfiler::Values> {
ConfigurationValue() = delete;
/**
* @brief Writes enum set value as a string
*
* Writes the enum set as a sequence of flag names separated by spaces. If
* the value is invalid, returns an empty string.
*/
static std::string toString(Magnum::DebugTools::GLFrameProfiler::Values value, ConfigurationValueFlags);
/**
* @brief Reads enum set value as a string
*
* Assumes the string is a sequence of flag names separated by spaces. If
* the value is invalid, returns an empty set.
*/
static Magnum::DebugTools::GLFrameProfiler::Values fromString(const std::string& stringValue, ConfigurationValueFlags);
};
}}
#endif #endif

39
src/Magnum/DebugTools/Test/FrameProfilerTest.cpp

@ -28,6 +28,7 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/Numeric.h> #include <Corrade/TestSuite/Compare/Numeric.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/ConfigurationGroup.h>
#include <Corrade/Utility/System.h> #include <Corrade/Utility/System.h>
#include "Magnum/DebugTools/FrameProfiler.h" #include "Magnum/DebugTools/FrameProfiler.h"
@ -67,6 +68,9 @@ struct FrameProfilerTest: TestSuite::Tester {
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
void debugGLValue(); void debugGLValue();
void debugGLValues(); void debugGLValues();
void configurationGLValue();
void configurationGLValues();
#endif #endif
}; };
@ -141,6 +145,9 @@ FrameProfilerTest::FrameProfilerTest() {
#ifdef MAGNUM_TARGET_GL #ifdef MAGNUM_TARGET_GL
&FrameProfilerTest::debugGLValue, &FrameProfilerTest::debugGLValue,
&FrameProfilerTest::debugGLValues, &FrameProfilerTest::debugGLValues,
&FrameProfilerTest::configurationGLValue,
&FrameProfilerTest::configurationGLValues
#endif #endif
}); });
} }
@ -1051,6 +1058,38 @@ void FrameProfilerTest::debugGLValues() {
Debug{&out} << (GLFrameProfiler::Value::CpuDuration|GLFrameProfiler::Value::FrameTime) << GLFrameProfiler::Values{}; Debug{&out} << (GLFrameProfiler::Value::CpuDuration|GLFrameProfiler::Value::FrameTime) << GLFrameProfiler::Values{};
CORRADE_COMPARE(out.str(), "DebugTools::GLFrameProfiler::Value::FrameTime|DebugTools::GLFrameProfiler::Value::CpuDuration DebugTools::GLFrameProfiler::Values{}\n"); CORRADE_COMPARE(out.str(), "DebugTools::GLFrameProfiler::Value::FrameTime|DebugTools::GLFrameProfiler::Value::CpuDuration DebugTools::GLFrameProfiler::Values{}\n");
} }
void FrameProfilerTest::configurationGLValue() {
Utility::ConfigurationGroup c;
c.setValue("value", GLFrameProfiler::Value::GpuDuration);
CORRADE_COMPARE(c.value("value"), "GpuDuration");
CORRADE_COMPARE(c.value<GLFrameProfiler::Value>("value"), GLFrameProfiler::Value::GpuDuration);
c.setValue("zero", GLFrameProfiler::Value{});
CORRADE_COMPARE(c.value("zero"), "");
CORRADE_COMPARE(c.value<GLFrameProfiler::Value>("zero"), GLFrameProfiler::Value{});
c.setValue("invalid", GLFrameProfiler::Value(0xdead));
CORRADE_COMPARE(c.value("invalid"), "");
CORRADE_COMPARE(c.value<GLFrameProfiler::Value>("invalid"), GLFrameProfiler::Value{});
}
void FrameProfilerTest::configurationGLValues() {
Utility::ConfigurationGroup c;
c.setValue("value", GLFrameProfiler::Value::FrameTime|GLFrameProfiler::Value::CpuDuration|GLFrameProfiler::Value::GpuDuration);
CORRADE_COMPARE(c.value("value"), "FrameTime CpuDuration GpuDuration");
CORRADE_COMPARE(c.value<GLFrameProfiler::Values>("value"), GLFrameProfiler::Value::FrameTime|GLFrameProfiler::Value::CpuDuration|GLFrameProfiler::Value::GpuDuration);
c.setValue("empty", GLFrameProfiler::Values{});
CORRADE_COMPARE(c.value("empty"), "");
CORRADE_COMPARE(c.value<GLFrameProfiler::Values>("empty"), GLFrameProfiler::Values{});
c.setValue("invalid", GLFrameProfiler::Value::CpuDuration|GLFrameProfiler::Value::GpuDuration|GLFrameProfiler::Value(0xff00));
CORRADE_COMPARE(c.value("invalid"), "CpuDuration GpuDuration");
CORRADE_COMPARE(c.value<GLFrameProfiler::Values>("invalid"), GLFrameProfiler::Value::CpuDuration|GLFrameProfiler::Value::GpuDuration);
}
#endif #endif
}}}} }}}}

Loading…
Cancel
Save