From 9649fe45e4ea9d1d98ed9ee3068eb657d24e15bb Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 6 Jul 2015 15:45:26 -0700 Subject: [PATCH 1/2] fix a bad paintRainbow function in the shader... --- libraries/render/src/render/drawItemStatus.slv | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/render/src/render/drawItemStatus.slv b/libraries/render/src/render/drawItemStatus.slv index 9e2b4919ff..106a5684bb 100644 --- a/libraries/render/src/render/drawItemStatus.slv +++ b/libraries/render/src/render/drawItemStatus.slv @@ -22,10 +22,10 @@ uniform vec3 inBoundPos; uniform vec3 inBoundDim; uniform ivec4 inStatus; -vec3 paintRainbow(float nv) { - float v = nv * 5.f; +vec3 paintRainbow(float normalizedHue) { + float v = normalizedHue * 6.f; if (v < 0.f) { - return vec3(0.f, 0.f, 0.f); + return vec3(1.f, 0.f, 0.f); } else if (v < 1.f) { return vec3(1.f, v, 0.f); } else if (v < 2.f) { @@ -36,8 +36,10 @@ vec3 paintRainbow(float nv) { return vec3(0.f, 1.f - (v-3.f), 1.f ); } else if (v < 5.f) { return vec3((v-4.f), 0.f, 1.f ); + } else if (v < 6.f) { + return vec3(1.f, 0.f, 1.f - (v-5.f)); } else { - return vec3(1.f, 1.f, 1.f); + return vec3(1.f, 0.f, 0.f); } } From f992e875b452c900d43037d35c3493f145b38230 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 8 Jul 2015 14:25:13 -0700 Subject: [PATCH 2/2] Adding intrsumentation for nsight and hiding the nsight specific code in cpp --- interface/src/Application.cpp | 2 +- interface/src/GLCanvas.cpp | 1 + .../src/RenderableModelEntityItem.cpp | 1 + libraries/gpu/src/gpu/Batch.cpp | 11 ++++++++++ libraries/gpu/src/gpu/Batch.h | 10 ++-------- libraries/gpu/src/gpu/Context.cpp | 2 ++ libraries/render-utils/src/Model.cpp | 20 +++++++++++++++---- libraries/render/CMakeLists.txt | 14 ++++++++++++- libraries/render/src/render/Scene.cpp | 2 ++ 9 files changed, 49 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c1397beb28..46e127b1b3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1182,7 +1182,6 @@ bool Application::event(QEvent* event) { } bool Application::eventFilter(QObject* object, QEvent* event) { - if (event->type() == QEvent::ShortcutOverride) { if (DependencyManager::get()->shouldSwallowShortcut(event)) { event->accept(); @@ -1787,6 +1786,7 @@ void Application::checkFPS() { } void Application::idle() { + PROFILE_RANGE(__FUNCTION__); static SimpleAverage interIdleDurations; static uint64_t lastIdleEnd{ 0 }; diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index 0eda678fa9..aff7c75cc9 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -58,6 +58,7 @@ void GLCanvas::initializeGL() { } void GLCanvas::paintGL() { + PROFILE_RANGE(__FUNCTION__); if (!_throttleRendering && !Application::getInstance()->getWindow()->isMinimized()) { Application::getInstance()->paintGL(); } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index ae1c97f07f..85b7bafc78 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -161,6 +161,7 @@ namespace render { template <> void payloadRender(const RenderableModelEntityItemMeta::Pointer& payload, RenderArgs* args) { if (args) { if (payload && payload->entity) { + PROFILE_RANGE("MetaModelRender"); payload->entity->render(args); } } diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index ee028e79e6..98d7b70db8 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -12,6 +12,17 @@ #include +#if defined(NSIGHT_FOUND) +#include "nvToolsExt.h" + +ProfileRange::ProfileRange(const char *name) { + nvtxRangePush(name); +} +ProfileRange::~ProfileRange() { + nvtxRangePop(); +} +#endif + #define ADD_COMMAND(call) _commands.push_back(COMMAND_##call); _commandOffsets.push_back(_params.size()); using namespace gpu; diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 835e872b4a..5583294aba 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -26,17 +26,11 @@ #include "Framebuffer.h" #if defined(NSIGHT_FOUND) - #include "nvToolsExt.h" class ProfileRange { public: - ProfileRange(const char *name) { - nvtxRangePush(name); - } - ~ProfileRange() { - nvtxRangePop(); - } + ProfileRange(const char *name); + ~ProfileRange(); }; - #define PROFILE_RANGE(name) ProfileRange profileRangeThis(name); #else #define PROFILE_RANGE(name) diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 9cc6bb3cd7..51335f78df 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -33,9 +33,11 @@ bool Context::makeProgram(Shader& shader, const Shader::BindingSet& bindings) { } void Context::render(Batch& batch) { + PROFILE_RANGE(__FUNCTION__); _backend->render(batch); } void Context::syncCache() { + PROFILE_RANGE(__FUNCTION__); _backend->syncCache(); } \ No newline at end of file diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 1b94c70e57..03140c4dfb 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -417,6 +417,7 @@ void Model::reset() { } bool Model::updateGeometry() { + PROFILE_RANGE(__FUNCTION__); bool needFullUpdate = false; bool needToRebuild = false; @@ -690,6 +691,7 @@ void Model::recalculateMeshPartOffsets() { // entity-scripts to call. I think it would be best to do the picking once-per-frame (in cpu, or gpu if possible) // and then the calls use the most recent such result. void Model::recalculateMeshBoxes(bool pickAgainstTriangles) { + PROFILE_RANGE(__FUNCTION__); bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid; if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded || (!_calculatedMeshPartBoxesValid && pickAgainstTriangles) ) { @@ -1281,6 +1283,7 @@ Blender::Blender(Model* model, int blendNumber, const QWeakPointer vertices, normals; if (!_model.isNull()) { int offset = 0; @@ -1392,6 +1395,7 @@ void Model::snapToRegistrationPoint() { } void Model::simulate(float deltaTime, bool fullUpdate) { + PROFILE_RANGE(__FUNCTION__); fullUpdate = updateGeometry() || fullUpdate || (_scaleToFit && !_scaledToFit) || (_snapModelToRegistrationPoint && !_snappedToRegistrationPoint); @@ -1829,6 +1833,7 @@ void Model::setupBatchTransform(gpu::Batch& batch, RenderArgs* args) { } AABox Model::getPartBounds(int meshIndex, int partIndex) { + if (meshIndex < _meshStates.size()) { const MeshState& state = _meshStates.at(meshIndex); bool isSkinned = state.clusterMatrices.size() > 1; @@ -1859,6 +1864,7 @@ AABox Model::getPartBounds(int meshIndex, int partIndex) { } void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool translucent) { + // PROFILE_RANGE(__FUNCTION__); PerformanceTimer perfTimer("Model::renderPart"); if (!_readyWhenAdded) { return; // bail asap @@ -1933,7 +1939,9 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran pickPrograms(batch, mode, translucentMesh, alphaThreshold, hasLightmap, hasTangents, hasSpecular, isSkinned, wireframe, args, locations); - updateVisibleJointStates(); + { + updateVisibleJointStates(); + } // if our index is ever out of range for either meshes or networkMeshes, then skip it, and set our _meshGroupsKnown // to false to rebuild out mesh groups. @@ -2076,9 +2084,13 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran } } - _mutex.lock(); - qint64 offset = _calculatedMeshPartOffset[QPair(meshIndex, partIndex)]; - _mutex.unlock(); + qint64 offset; + { + // FIXME_STUTTER: We should n't have any lock here + _mutex.lock(); + offset = _calculatedMeshPartOffset[QPair(meshIndex, partIndex)]; + _mutex.unlock(); + } if (part.quadIndices.size() > 0) { batch.drawIndexed(gpu::QUADS, part.quadIndices.size(), offset); diff --git a/libraries/render/CMakeLists.txt b/libraries/render/CMakeLists.txt index ee99eb00b9..4d2be949e6 100644 --- a/libraries/render/CMakeLists.txt +++ b/libraries/render/CMakeLists.txt @@ -9,4 +9,16 @@ add_dependency_external_projects(glm) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) -link_hifi_libraries(shared gpu model) \ No newline at end of file +link_hifi_libraries(shared gpu model) + +if (WIN32) + if (USE_NSIGHT) + # try to find the Nsight package and add it to the build if we find it + find_package(NSIGHT) + if (NSIGHT_FOUND) + include_directories(${NSIGHT_INCLUDE_DIRS}) + add_definitions(-DNSIGHT_FOUND) + target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") + endif () + endif() +endif (WIN32) \ No newline at end of file diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index a7145af4b5..268f2b6841 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -11,6 +11,7 @@ #include "Scene.h" #include +#include "gpu/Batch.h" using namespace render; @@ -167,6 +168,7 @@ void consolidateChangeQueue(PendingChangesQueue& queue, PendingChanges& singleBa } void Scene::processPendingChangesQueue() { + PROFILE_RANGE(__FUNCTION__); _changeQueueMutex.lock(); PendingChanges consolidatedPendingChanges; consolidateChangeQueue(_changeQueue, consolidatedPendingChanges);