Merge pull request #9000 from samcake/punk

Add Frame Timing and GPU memory to the Stats and user activity log
This commit is contained in:
Chris Collins 2016-11-07 16:17:20 -08:00 committed by GitHub
commit eec8e2f19b
6 changed files with 63 additions and 1 deletions

View file

@ -189,6 +189,15 @@ Item {
Column { Column {
id: octreeCol id: octreeCol
spacing: 4; x: 4; y: 4; spacing: 4; x: 4; y: 4;
StatText {
text: " Frame timing:"
}
StatText {
text: " Batch: " + root.batchFrameTime.toFixed(1) + " ms"
}
StatText {
text: " GPU: " + root.gpuFrameTime.toFixed(1) + " ms"
}
StatText { StatText {
text: "Triangles: " + root.triangles + text: "Triangles: " + root.triangles +
" / Material Switches: " + root.materialSwitches " / Material Switches: " + root.materialSwitches

View file

@ -1238,7 +1238,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
auto glInfo = getGLContextData(); auto glInfo = getGLContextData();
properties["gl_info"] = glInfo; properties["gl_info"] = glInfo;
properties["gpu_used_memory"] = (int)BYTES_TO_MB(gpu::Context::getUsedGPUMemory());
properties["gpu_free_memory"] = (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory()); properties["gpu_free_memory"] = (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory());
properties["gpu_frame_time"] = (float)(qApp->getGPUContext()->getFrameTimerGPUAverage());
properties["batch_frame_time"] = (float)(qApp->getGPUContext()->getFrameTimerBatchAverage());
properties["ideal_thread_count"] = QThread::idealThreadCount(); properties["ideal_thread_count"] = QThread::idealThreadCount();
auto hmdHeadPose = getHMDSensorPose(); auto hmdHeadPose = getHMDSensorPose();

View file

@ -290,6 +290,12 @@ void Stats::updateStats(bool force) {
STAT_UPDATE(sendingMode, sendingModeResult); STAT_UPDATE(sendingMode, sendingModeResult);
} }
auto gpuContext = qApp->getGPUContext();
// Update Frame timing (in ms)
STAT_UPDATE(gpuFrameTime, (float)gpuContext->getFrameTimerGPUAverage());
STAT_UPDATE(batchFrameTime, (float)gpuContext->getFrameTimerBatchAverage());
STAT_UPDATE(gpuBuffers, (int)gpu::Context::getBufferGPUCount()); STAT_UPDATE(gpuBuffers, (int)gpu::Context::getBufferGPUCount());
STAT_UPDATE(gpuBufferMemory, (int)BYTES_TO_MB(gpu::Context::getBufferGPUMemoryUsage())); STAT_UPDATE(gpuBufferMemory, (int)BYTES_TO_MB(gpu::Context::getBufferGPUMemoryUsage()));
STAT_UPDATE(gpuTextures, (int)gpu::Context::getTextureGPUCount()); STAT_UPDATE(gpuTextures, (int)gpu::Context::getTextureGPUCount());
@ -302,7 +308,7 @@ void Stats::updateStats(bool force) {
STAT_UPDATE(gpuTextureVirtualMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUVirtualMemoryUsage())); STAT_UPDATE(gpuTextureVirtualMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUVirtualMemoryUsage()));
STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUFramebufferMemoryUsage())); STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUFramebufferMemoryUsage()));
STAT_UPDATE(gpuTextureSparseMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUSparseMemoryUsage())); STAT_UPDATE(gpuTextureSparseMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUSparseMemoryUsage()));
STAT_UPDATE(gpuSparseTextureEnabled, qApp->getGPUContext()->getBackend()->isTextureManagementSparseEnabled() ? 1 : 0); STAT_UPDATE(gpuSparseTextureEnabled, gpuContext->getBackend()->isTextureManagementSparseEnabled() ? 1 : 0);
STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory())); STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory()));
STAT_UPDATE(rectifiedTextureCount, (int)RECTIFIED_TEXTURE_COUNT.load()); STAT_UPDATE(rectifiedTextureCount, (int)RECTIFIED_TEXTURE_COUNT.load());
STAT_UPDATE(decimatedTextureCount, (int)DECIMATED_TEXTURE_COUNT.load()); STAT_UPDATE(decimatedTextureCount, (int)DECIMATED_TEXTURE_COUNT.load());

View file

@ -101,6 +101,8 @@ class Stats : public QQuickItem {
STATS_PROPERTY(int, gpuTextureSparseMemory, 0) STATS_PROPERTY(int, gpuTextureSparseMemory, 0)
STATS_PROPERTY(int, gpuSparseTextureEnabled, 0) STATS_PROPERTY(int, gpuSparseTextureEnabled, 0)
STATS_PROPERTY(int, gpuFreeMemory, 0) STATS_PROPERTY(int, gpuFreeMemory, 0)
STATS_PROPERTY(float, gpuFrameTime, 0)
STATS_PROPERTY(float, batchFrameTime, 0)
public: public:
static Stats* getInstance(); static Stats* getInstance();
@ -198,6 +200,8 @@ signals:
void gpuTextureSparseMemoryChanged(); void gpuTextureSparseMemoryChanged();
void gpuSparseTextureEnabledChanged(); void gpuSparseTextureEnabledChanged();
void gpuFreeMemoryChanged(); void gpuFreeMemoryChanged();
void gpuFrameTimeChanged();
void batchFrameTimeChanged();
void rectifiedTextureCountChanged(); void rectifiedTextureCountChanged();
void decimatedTextureCountChanged(); void decimatedTextureCountChanged();

View file

@ -34,6 +34,10 @@ void Context::beginFrame(const glm::mat4& renderPose) {
_frameActive = true; _frameActive = true;
_currentFrame = std::make_shared<Frame>(); _currentFrame = std::make_shared<Frame>();
_currentFrame->pose = renderPose; _currentFrame->pose = renderPose;
if (!_frameRangeTimer) {
_frameRangeTimer = std::make_shared<RangeTimer>();
}
} }
void Context::appendFrameBatch(Batch& batch) { void Context::appendFrameBatch(Batch& batch) {
@ -73,10 +77,18 @@ void Context::executeFrame(const FramePointer& frame) const {
consumeFrameUpdates(frame); consumeFrameUpdates(frame);
_backend->setStereoState(frame->stereoState); _backend->setStereoState(frame->stereoState);
{ {
Batch beginBatch;
_frameRangeTimer->begin(beginBatch);
_backend->render(beginBatch);
// Execute the frame rendering commands // Execute the frame rendering commands
for (auto& batch : frame->batches) { for (auto& batch : frame->batches) {
_backend->render(batch); _backend->render(batch);
} }
Batch endBatch;
_frameRangeTimer->end(endBatch);
_backend->render(endBatch);
} }
} }
@ -127,6 +139,20 @@ void Context::getStats(ContextStats& stats) const {
_backend->getStats(stats); _backend->getStats(stats);
} }
double Context::getFrameTimerGPUAverage() const {
if (_frameRangeTimer) {
return _frameRangeTimer->getGPUAverage();
}
return 0.0;
}
double Context::getFrameTimerBatchAverage() const {
if (_frameRangeTimer) {
return _frameRangeTimer->getBatchAverage();
}
return 0.0;
}
const Backend::TransformCamera& Backend::TransformCamera::recomputeDerived(const Transform& xformView) const { const Backend::TransformCamera& Backend::TransformCamera::recomputeDerived(const Transform& xformView) const {
_projectionInverse = glm::inverse(_projection); _projectionInverse = glm::inverse(_projection);
@ -183,6 +209,10 @@ Size Context::getFreeGPUMemory() {
return _freeGPUMemory.load(); return _freeGPUMemory.load();
} }
Size Context::getUsedGPUMemory() {
return getTextureGPUMemoryUsage() + getBufferGPUMemoryUsage();
};
void Context::incrementBufferGPUCount() { void Context::incrementBufferGPUCount() {
static std::atomic<uint32_t> max { 0 }; static std::atomic<uint32_t> max { 0 };
auto total = ++_bufferGPUCount; auto total = ++_bufferGPUCount;
@ -349,3 +379,5 @@ void Backend::updateTextureGPUFramebufferMemoryUsage(Resource::Size prevObjectSi
void Backend::updateTextureGPUSparseMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUSparseMemoryUsage(prevObjectSize, newObjectSize); } void Backend::updateTextureGPUSparseMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUSparseMemoryUsage(prevObjectSize, newObjectSize); }
void Backend::incrementTextureGPUTransferCount() { Context::incrementTextureGPUTransferCount(); } void Backend::incrementTextureGPUTransferCount() { Context::incrementTextureGPUTransferCount(); }
void Backend::decrementTextureGPUTransferCount() { Context::decrementTextureGPUTransferCount(); } void Backend::decrementTextureGPUTransferCount() { Context::decrementTextureGPUTransferCount(); }

View file

@ -205,12 +205,16 @@ public:
void getStats(ContextStats& stats) const; void getStats(ContextStats& stats) const;
double getFrameTimerGPUAverage() const;
double getFrameTimerBatchAverage() const;
static uint32_t getBufferGPUCount(); static uint32_t getBufferGPUCount();
static Size getBufferGPUMemoryUsage(); static Size getBufferGPUMemoryUsage();
static uint32_t getTextureGPUCount(); static uint32_t getTextureGPUCount();
static uint32_t getTextureGPUSparseCount(); static uint32_t getTextureGPUSparseCount();
static Size getFreeGPUMemory(); static Size getFreeGPUMemory();
static Size getUsedGPUMemory();
static Size getTextureGPUMemoryUsage(); static Size getTextureGPUMemoryUsage();
static Size getTextureGPUVirtualMemoryUsage(); static Size getTextureGPUVirtualMemoryUsage();
static Size getTextureGPUFramebufferMemoryUsage(); static Size getTextureGPUFramebufferMemoryUsage();
@ -223,8 +227,12 @@ protected:
std::shared_ptr<Backend> _backend; std::shared_ptr<Backend> _backend;
bool _frameActive { false }; bool _frameActive { false };
FramePointer _currentFrame; FramePointer _currentFrame;
RangeTimerPointer _frameRangeTimer;
StereoState _stereo; StereoState _stereo;
double getGPUAverage() const;
double getBatchAverage() const;
// This function can only be called by "static Shader::makeProgram()" // This function can only be called by "static Shader::makeProgram()"
// makeProgramShader(...) make a program shader ready to be used in a Batch. // makeProgramShader(...) make a program shader ready to be used in a Batch.
// It compiles the sub shaders, link them and defines the Slots and their bindings. // It compiles the sub shaders, link them and defines the Slots and their bindings.