From d877e61038ad4401dfc96966a0b73882c9dd6092 Mon Sep 17 00:00:00 2001 From: dbp Date: Sat, 24 Sep 2016 20:26:33 +0300 Subject: [PATCH] 0027899: Visualization, Ray Tracing - Provide ability to rebuild GLSL shaders on the fly For debugging and performance analysis it is reasonable to provide the ability to rebuild ray tracing shaders on the fly. In this way, it will be possible to analyze the impact of different shaders modifications without re-launching and re-configuring the scene. This functionality can be used in the following way: > vrenderparams -rebuild --- src/Graphic3d/Graphic3d_RenderingParams.hxx | 2 + src/OpenGl/OpenGl_View.hxx | 3 +- src/OpenGl/OpenGl_View_Raytrace.cxx | 73 ++++++++++++-------- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 18 +++++ 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/src/Graphic3d/Graphic3d_RenderingParams.hxx b/src/Graphic3d/Graphic3d_RenderingParams.hxx index 687fe0623a..86f3389f83 100644 --- a/src/Graphic3d/Graphic3d_RenderingParams.hxx +++ b/src/Graphic3d/Graphic3d_RenderingParams.hxx @@ -63,6 +63,7 @@ public: CoherentPathTracingMode (Standard_False), AdaptiveScreenSampling (Standard_False), ShowSamplingTiles (Standard_False), + RebuildRayTracingShaders (Standard_False), // stereoscopic parameters StereoMode (Graphic3d_StereoMode_QuadBuffer), AnaglyphFilter (Anaglyph_RedCyan_Optimized), @@ -103,6 +104,7 @@ public: Standard_Boolean CoherentPathTracingMode; //!< enables/disables 'coherent' tracing mode (single RNG seed within 16x16 image blocks) Standard_Boolean AdaptiveScreenSampling; //!< enables/disables adaptive screen sampling mode for path tracing, FALSE by default Standard_Boolean ShowSamplingTiles; //!< enables/disables debug mode for adaptive screen sampling, FALSE by default + Standard_Boolean RebuildRayTracingShaders; //!< forces rebuilding ray tracing shaders at the next frame Graphic3d_StereoMode StereoMode; //!< stereoscopic output mode, Graphic3d_StereoMode_QuadBuffer by default Anaglyph AnaglyphFilter; //!< filter for anaglyph output, Anaglyph_RedCyan_Optimized by default diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 06a805323c..f23dd47f90 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -869,7 +869,8 @@ protected: //! @name methods related to ray-tracing Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext); //! Releases OpenGL/GLSL shader programs. - void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext); + void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext, + const Standard_Boolean theToRebuild = Standard_False); //! Updates auxiliary OpenGL frame buffers. Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX, diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index df86d0e608..ded7610498 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -1271,10 +1271,19 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context Standard_Boolean aToRebuildShaders = Standard_False; + if (myRenderParams.RebuildRayTracingShaders) // requires complete re-initialization + { + myRaytraceInitStatus = OpenGl_RT_NONE; + releaseRaytraceResources (theGlContext, Standard_True); + myRenderParams.RebuildRayTracingShaders = Standard_False; // clear rebuilding flag + } + if (myRaytraceInitStatus == OpenGl_RT_INIT) { if (!myIsRaytraceDataValid) + { return Standard_True; + } const Standard_Integer aRequiredStackSize = myRaytraceGeometry.TopLevelTreeDepth() + myRaytraceGeometry.BotLevelTreeDepth(); @@ -1385,6 +1394,8 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context if (myRaytraceInitStatus == OpenGl_RT_NONE) { + myAccumFrames = 0; // reject accumulated frames + if (!theGlContext->IsGlGreaterEqual (3, 1)) { return safeFailBack ("Ray-tracing requires OpenGL 3.1 and higher", theGlContext); @@ -1681,19 +1692,9 @@ inline void nullifyResource (const Handle(OpenGl_Context)& theGlContext, Handle( // function : releaseRaytraceResources // purpose : Releases OpenGL/GLSL shader programs // ======================================================================= -void OpenGl_View::releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext) +void OpenGl_View::releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext, const Standard_Boolean theToRebuild) { - myRaytraceFBO1[0]->Release (theGlContext.operator->()); - myRaytraceFBO1[1]->Release (theGlContext.operator->()); - myRaytraceFBO2[0]->Release (theGlContext.operator->()); - myRaytraceFBO2[1]->Release (theGlContext.operator->()); - - nullifyResource (theGlContext, myRaytraceOutputTexture[0]); - nullifyResource (theGlContext, myRaytraceOutputTexture[1]); - - nullifyResource (theGlContext, myRaytraceTileOffsetsTexture); - nullifyResource (theGlContext, myRaytraceVisualErrorTexture); - + // release shader resources nullifyResource (theGlContext, myRaytraceShader); nullifyResource (theGlContext, myPostFSAAShader); @@ -1701,24 +1702,38 @@ void OpenGl_View::releaseRaytraceResources (const Handle(OpenGl_Context)& theGlC nullifyResource (theGlContext, myPostFSAAProgram); nullifyResource (theGlContext, myOutImageProgram); - nullifyResource (theGlContext, mySceneNodeInfoTexture); - nullifyResource (theGlContext, mySceneMinPointTexture); - nullifyResource (theGlContext, mySceneMaxPointTexture); - - nullifyResource (theGlContext, myGeometryVertexTexture); - nullifyResource (theGlContext, myGeometryNormalTexture); - nullifyResource (theGlContext, myGeometryTexCrdTexture); - nullifyResource (theGlContext, myGeometryTriangTexture); - nullifyResource (theGlContext, mySceneTransformTexture); - - nullifyResource (theGlContext, myRaytraceLightSrcTexture); - nullifyResource (theGlContext, myRaytraceMaterialTexture); - - myRaytraceGeometry.ReleaseResources (theGlContext); - - if (myRaytraceScreenQuad.IsValid()) + if (!theToRebuild) // complete release { - myRaytraceScreenQuad.Release (theGlContext.operator->()); + myRaytraceFBO1[0]->Release (theGlContext.operator->()); + myRaytraceFBO1[1]->Release (theGlContext.operator->()); + myRaytraceFBO2[0]->Release (theGlContext.operator->()); + myRaytraceFBO2[1]->Release (theGlContext.operator->()); + + nullifyResource (theGlContext, myRaytraceOutputTexture[0]); + nullifyResource (theGlContext, myRaytraceOutputTexture[1]); + + nullifyResource (theGlContext, myRaytraceTileOffsetsTexture); + nullifyResource (theGlContext, myRaytraceVisualErrorTexture); + + nullifyResource (theGlContext, mySceneNodeInfoTexture); + nullifyResource (theGlContext, mySceneMinPointTexture); + nullifyResource (theGlContext, mySceneMaxPointTexture); + + nullifyResource (theGlContext, myGeometryVertexTexture); + nullifyResource (theGlContext, myGeometryNormalTexture); + nullifyResource (theGlContext, myGeometryTexCrdTexture); + nullifyResource (theGlContext, myGeometryTriangTexture); + nullifyResource (theGlContext, mySceneTransformTexture); + + nullifyResource (theGlContext, myRaytraceLightSrcTexture); + nullifyResource (theGlContext, myRaytraceMaterialTexture); + + myRaytraceGeometry.ReleaseResources (theGlContext); + + if (myRaytraceScreenQuad.IsValid ()) + { + myRaytraceScreenQuad.Release (theGlContext.operator->()); + } } } diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 2baaea1c53..e130388a59 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -8522,6 +8522,23 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI, return 1; } } + else if (aFlag == "-rebuildglsl" + || aFlag == "-rebuild") + { + if (toPrint) + { + theDI << (aParams.RebuildRayTracingShaders ? "on" : "off") << " "; + continue; + } + + Standard_Boolean toEnable = Standard_True; + if (++anArgIter < theArgNb + && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable)) + { + --anArgIter; + } + aParams.RebuildRayTracingShaders = toEnable; + } else { std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n"; @@ -9663,6 +9680,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "\n '-env on|off' Enables/disables environment map background" "\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)" "\n '-issd on|off' Shows screen sampling distribution in ISS mode" + "\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)" "\n '-shadingModel model' Controls shading model from enumeration" "\n color, flat, gouraud, phong" "\n '-resolution value' Sets a new pixels density (PPI), defines scaling factor for parameters like text size"