From ff44a460d66270d42db2191f2202c6ec9384de62 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 27 Oct 2014 11:40:52 -0700 Subject: [PATCH 1/4] Add NSIGHT Profiliing capability --- interface/CMakeLists.txt | 12 +++++++++--- interface/src/gpu/Batch.h | 17 +++++++++++++++++ interface/src/renderer/Model.cpp | 9 +++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 9c4eeff65b..194558e580 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -226,11 +226,17 @@ else (APPLE) if (WIN32) find_package(GLEW REQUIRED) include_directories(${GLEW_INCLUDE_DIRS}) - + # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) - - target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" wsock32.lib opengl32.lib) + + find_package(NSIGHT) + if (NSIGHT_FOUND) + include_directories(${NSIGHT_INCLUDE_DIRS}) + add_definitions(-DNSIGHT_FOUND) + endif () + + target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib) endif() endif (APPLE) diff --git a/interface/src/gpu/Batch.h b/interface/src/gpu/Batch.h index ad5246f9b6..cceb41be76 100644 --- a/interface/src/gpu/Batch.h +++ b/interface/src/gpu/Batch.h @@ -16,6 +16,23 @@ #include +#if defined(NSIGHT_FOUND) + #include "nvToolsExt.h" + class ProfileRange { + public: + ProfileRange(const char *name) { + nvtxRangePush(name); + } + ~ProfileRange() { + nvtxRangePop(); + } + }; + + #define PROFILE_SCOPE(name) ProfileRange profileRangeThis(name); +#else + #define PROFILE_SCOPE(name) +#endif + namespace gpu { class Batch; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 131c600dc1..c2893c79ce 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -395,6 +395,7 @@ void Model::setJointStates(QVector states) { } bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { + PROFILE_SCOPE(__FUNCTION__); // render the attachments foreach (Model* attachment, _attachments) { attachment->render(alpha, mode); @@ -560,8 +561,11 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0); // Render! - ::gpu::backend::renderBatch(batch); - batch.clear(); + { + PROFILE_SCOPE("render Batch"); + ::gpu::backend::renderBatch(batch); + batch.clear(); + } // restore all the default material settings Application::getInstance()->setupWorldLight(); @@ -1551,6 +1555,7 @@ void Model::segregateMeshGroups() { int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args) { + PROFILE_SCOPE(__FUNCTION__); bool dontCullOutOfViewMeshParts = Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); bool cullTooSmallMeshParts = !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); From 541e528e57c234e8c6a80de23ac26de411b87013 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 27 Oct 2014 11:41:39 -0700 Subject: [PATCH 2/4] Add NSIGHT Profiliing capability --- cmake/modules/FindNSIGHT.cmake | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 cmake/modules/FindNSIGHT.cmake diff --git a/cmake/modules/FindNSIGHT.cmake b/cmake/modules/FindNSIGHT.cmake new file mode 100644 index 0000000000..4df0686ebe --- /dev/null +++ b/cmake/modules/FindNSIGHT.cmake @@ -0,0 +1,49 @@ +# +# FindNSIGHT.cmake +# +# Try to find NSIGHT NvToolsExt library and include path. +# Once done this will define +# +# NSIGHT_FOUND +# NSIGHT_INCLUDE_DIRS +# NSIGHT_LIBRARIES +# +# Created on 10/27/2014 by Sam Gateau +# Copyright 2014 High Fidelity, Inc. +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# + +if (WIN32) + + find_path(NSIGHT_INCLUDE_DIRS + NAMES + nvToolsExt.h + PATH_SUFFIXES + include + PATHS + "C:/Program Files/NVIDIA Corporation/NvToolsExt") + + find_library(NSIGHT_LIBRARY_RELEASE nvToolsExt32_1 + PATH_SUFFIXES + "lib/Win32" "lib" + PATHS + "C:/Program Files/NVIDIA Corporation/NvToolsExt") + find_library(NSIGHT_LIBRARY_DEBUG nvToolsExt32_1 + PATH_SUFFIXES + "lib/Win32" "lib" + PATHS + "C:/Program Files/NVIDIA Corporation/NvToolsExt") + + include(SelectLibraryConfigurations) + select_library_configurations(NSIGHT) +endif () + +set(NSIGHT_LIBRARIES "${NSIGHT_LIBRARY}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(NSIGHT DEFAULT_MSG NSIGHT_INCLUDE_DIRS NSIGHT_LIBRARIES) + +mark_as_advanced(NSIGHT_INCLUDE_DIRS NSIGHT_LIBRARIES NSIGHT_SEARCH_DIRS) + From 89f9e5b01bd64ff69649e0d3ec735ac17e6ec1fe Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 27 Oct 2014 11:49:51 -0700 Subject: [PATCH 3/4] try to get more coherent names --- interface/src/gpu/Batch.h | 4 ++-- interface/src/renderer/Model.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/gpu/Batch.h b/interface/src/gpu/Batch.h index cceb41be76..b0bf30bae5 100644 --- a/interface/src/gpu/Batch.h +++ b/interface/src/gpu/Batch.h @@ -28,9 +28,9 @@ } }; - #define PROFILE_SCOPE(name) ProfileRange profileRangeThis(name); + #define PROFILE_RANGE(name) ProfileRange profileRangeThis(name); #else - #define PROFILE_SCOPE(name) +#define PROFILE_RANGE(name) #endif namespace gpu { diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index c2893c79ce..e949e9a811 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -395,7 +395,7 @@ void Model::setJointStates(QVector states) { } bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { - PROFILE_SCOPE(__FUNCTION__); + PROFILE_RANGE(__FUNCTION__); // render the attachments foreach (Model* attachment, _attachments) { attachment->render(alpha, mode); @@ -562,7 +562,7 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { // Render! { - PROFILE_SCOPE("render Batch"); + PROFILE_RANGE("render Batch"); ::gpu::backend::renderBatch(batch); batch.clear(); } @@ -1555,7 +1555,7 @@ void Model::segregateMeshGroups() { int Model::renderMeshes(gpu::Batch& batch, RenderMode mode, bool translucent, float alphaThreshold, bool hasTangents, bool hasSpecular, bool isSkinned, RenderArgs* args) { - PROFILE_SCOPE(__FUNCTION__); + PROFILE_RANGE(__FUNCTION__); bool dontCullOutOfViewMeshParts = Menu::getInstance()->isOptionChecked(MenuOption::DontCullOutOfViewMeshParts); bool cullTooSmallMeshParts = !Menu::getInstance()->isOptionChecked(MenuOption::DontCullTooSmallMeshParts); bool dontReduceMaterialSwitches = Menu::getInstance()->isOptionChecked(MenuOption::DontReduceMaterialSwitches); From fd514ccfc9fd14cc06b7204dca53c55ada9b8497 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 27 Oct 2014 14:47:31 -0700 Subject: [PATCH 4/4] Fixed the cmake so if NSIGHT is not available then no problem --- interface/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 194558e580..d9cf40baa3 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -230,13 +230,16 @@ else (APPLE) # we're using static GLEW, so define GLEW_STATIC add_definitions(-DGLEW_STATIC) + target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib) + + # 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 () - target_link_libraries(${TARGET_NAME} "${GLEW_LIBRARIES}" "${NSIGHT_LIBRARIES}" wsock32.lib opengl32.lib) endif() endif (APPLE)