From 7a0288bf56b5ae7c7bb1f7de99fccc397bec5f47 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Sat, 2 May 2015 22:33:33 -0700 Subject: [PATCH] fix issue with btDbvt::collideOCL, related to memmove (needs further testing) only enable OpenCL demo if flag --enable_experimental_opencl is passed to ExampleBrowser --- docs/latex/intro.tex | 7 +++-- examples/ExampleBrowser/ExampleEntries.cpp | 20 +++++++++----- .../ExampleBrowser/OpenGLExampleBrowser.cpp | 27 ++++++++++++++----- examples/ExampleBrowser/main.cpp | 1 - examples/OpenGLWindow/MacOpenGLWindow.mm | 4 +-- .../BroadphaseCollision/btDbvt.h | 12 ++++++--- 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/docs/latex/intro.tex b/docs/latex/intro.tex index 56e26a15d..6502c1b29 100644 --- a/docs/latex/intro.tex +++ b/docs/latex/intro.tex @@ -25,10 +25,13 @@ Bullet Physics is a professional open source collision detection, rigid body and \subsection{New in Bullet 2.83} \begin{itemize} - \item New ExampleBrowser, replacing the standalone demos. See \path{examples/ExampleBrowser}. - \item Import of Universal Robot Description Files (URDF). See \path{examples/Importers/ImportURDFDemo}. + \item New ExampleBrowser, replacing the standalone demos. Not all demos have been ported over yet, it will happen in upcoming releases. It is recommended to use an OpenGL 3+ system, although there is limited OpenGL 2 fallback. See \path{examples/ExampleBrowser}. + \item Import of Universal Robot Description Files (URDF). See \path{examples/Importers/ImportURDFDemo}. You can use File-Open in the ExampleBrowser. \item Improved support for btMultiBody with multi-degree of freedom mobilizers, thanks to Jakub Stepien. See \path{examples/MultiBody/MultiDofDemo}. \item New btGeneric6DofSpring2Constraint, replacing the old generic 6dof constraint, thanks to Gabor PUHR and Tamas Umenhoffer. See \path{examples/Dof6Spring2Setup} + \item OpenCL demo integrated in the ExampleBrowser. The demo is disabled by default, because it only works on high-end desktop GPU systems with compatible up-to-date OpenCL 1.1+ driver. Use $--enable\_experimental\_opencl$ command-line argument in the ExampleBrowser. + + \end{itemize} \subsection{New in Bullet 2.82} \begin{itemize} diff --git a/examples/ExampleBrowser/ExampleEntries.cpp b/examples/ExampleBrowser/ExampleEntries.cpp index 372a9f6f1..f442619a2 100644 --- a/examples/ExampleBrowser/ExampleEntries.cpp +++ b/examples/ExampleBrowser/ExampleEntries.cpp @@ -63,18 +63,22 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(0,"API"), - ExampleEntry(1,"Basic Example","Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application.", BasicExampleCreateFunc), + ExampleEntry(1,"Basic Example","Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application. Press W for wireframe, A to show AABBs, I to suspend/restart physics simulation. ", BasicExampleCreateFunc), + + ExampleEntry(1,"Constraints","Show the use of the various constraints in Bullet. Press the L key to visualize the constraint limits. Press the C key to visualize the constraint frames.", + AllConstraintCreateFunc), + + ExampleEntry(1,"Motorized Hinge","Use of a btHingeConstraint. You can adjust the first slider to change the target velocity, and the second slider to adjust the maximum impulse applied to reach the target velocity. Note that the hinge angle can reach beyond -360 and 360 degrees.", ConstraintCreateFunc), + +// ExampleEntry(0,"What's new in 2.83"), + + ExampleEntry(1,"6DofSpring2","Show the use of the btGeneric6DofSpring2Constraint. This is a replacement of the btGeneric6DofSpringConstraint, it has various improvements. This includes improved spring implementation and better control over the restitution (bounce) when the constraint hits its limits.", + Dof6Spring2CreateFunc), ExampleEntry(1,"Gyroscopic", "Show the Dzhanibekov effect using various settings of the gyroscopic term. You can select the gyroscopic term computation using btRigidBody::setFlags, with arguments BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT (using explicit integration, which adds energy and can lead to explosions), BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD, BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY. If you don't set any of these flags, there is no gyroscopic term used.", GyroscopicCreateFunc), - ExampleEntry(1,"Planar 2D","Show the use of 2D collision shapes and rigid body simulation. The collision shape is wrapped into a btConvex2dShape. The rigid bodies are restricted in a plane using the 'setAngularFactor' and 'setLinearFactor' API call.",Planar2DCreateFunc), - ExampleEntry(1,"6DofSpring2","Show the use of the btGeneric6DofSpring2Constraint.", - Dof6Spring2CreateFunc), - ExampleEntry(1,"Constraints","Show the use of the various constraints in Bullet.", - AllConstraintCreateFunc), - ExampleEntry(1,"Motorized Hinge","Use of a btHingeConstraint. You can adjust the first slider to change the target velocity, and the second slider to adjust the maximum impulse applied to reach the target velocity. Note that the hinge angle can reach beyond -360 and 360 degrees.", ConstraintCreateFunc), ExampleEntry(0,"MultiBody"), ExampleEntry(1,"MultiDofCreateFunc","Create a basic btMultiBody with 3-DOF spherical joints (mobilizers). The demo uses a fixed base or a floating base at restart.", MultiDofCreateFunc), @@ -168,6 +172,8 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(1,"Voronoi Fracture", "Automatically create a compound rigid body using voronoi tesselation. Individual parts are modeled as rigid bodies using a btConvexHullShape.", VoronoiFractureCreateFunc), + ExampleEntry(1,"Planar 2D","Show the use of 2D collision shapes and rigid body simulation. The collision shape is wrapped into a btConvex2dShape. The rigid bodies are restricted in a plane using the 'setAngularFactor' and 'setLinearFactor' API call.",Planar2DCreateFunc), + ExampleEntry(1,"Implicit Cloth", "Cloth simulation using implicit integration, by Stan Melax. The cloth is only attached at the corners. Note the stability using a large time step even with high stiffness.", ImplicitClothCreateFunc), diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index 0edb10bba..ce75cf208 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -73,9 +73,9 @@ extern bool gDisableDeactivation; int gPreferredOpenCLDeviceIndex=-1; int gPreferredOpenCLPlatformIndex=-1; -int gGpuArraySizeX=25; -int gGpuArraySizeY=25; -int gGpuArraySizeZ=25; +int gGpuArraySizeX=15; +int gGpuArraySizeY=15; +int gGpuArraySizeZ=15; //#include //unsigned int fp_control_state = _controlfp(_EM_INEXACT, _MCW_EM); @@ -375,13 +375,15 @@ void MyStatusBarPrintf(const char* msg) } -void MyStatusBarWarning(const char* msg) +void MyStatusBarError(const char* msg) { printf("Warning: %s\n", msg); if (gui) { bool isLeft = false; gui->setStatusBarMessage(msg,isLeft); + gui->textOutput(msg); + gui->forceUpdateScrollBars(); } } @@ -583,6 +585,17 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) { b3CommandLineArgs args(argc,argv); + + ///The OpenCL rigid body pipeline is experimental and + ///most OpenCL drivers and OpenCL compilers have issues with our kernels. + ///If you have a high-end desktop GPU such as AMD 7970 or better, or NVIDIA GTX 680 with up-to-date drivers + ///you could give it a try + if (args.CheckCmdLineFlag("enable_experimental_opencl")) + { + gAllExamples->initOpenCLExampleEntries(); + } + + int width = 1024; int height=768; @@ -599,7 +612,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) if (sUseOpenGL2 ) { char title[1024]; - sprintf(title,"%s using OpenGL2 fallback. %s", appTitle,optMode); + sprintf(title,"%s using limited OpenGL2 fallback. %s", appTitle,optMode); s_app = new SimpleOpenGL2App(title,width,height); s_app->m_renderer = new SimpleOpenGL2Renderer(width,height); } else @@ -630,9 +643,9 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) s_app->m_renderer->getActiveCamera()->setCameraPitch(0); s_app->m_renderer->getActiveCamera()->setCameraTargetPosition(0,0,0); - b3SetCustomWarningMessageFunc(MyStatusBarWarning); - //b3SetCustomPrintfFunc(MyStatusBarPrintf); + b3SetCustomWarningMessageFunc(MyGuiPrintf); b3SetCustomPrintfFunc(MyGuiPrintf); + b3SetCustomErrorMessageFunc(MyStatusBarError); assert(glGetError()==GL_NO_ERROR); diff --git a/examples/ExampleBrowser/main.cpp b/examples/ExampleBrowser/main.cpp index 50b94d6b4..f1e103e76 100644 --- a/examples/ExampleBrowser/main.cpp +++ b/examples/ExampleBrowser/main.cpp @@ -20,7 +20,6 @@ int main(int argc, char* argv[]) ExampleEntries examples; examples.initExampleEntries(); - examples.initOpenCLExampleEntries(); ExampleBrowserInterface* exampleBrowser = new DefaultBrowser(&examples); bool init = exampleBrowser->init(argc,argv); diff --git a/examples/OpenGLWindow/MacOpenGLWindow.mm b/examples/OpenGLWindow/MacOpenGLWindow.mm index b2c120db9..544cf2a37 100644 --- a/examples/OpenGLWindow/MacOpenGLWindow.mm +++ b/examples/OpenGLWindow/MacOpenGLWindow.mm @@ -822,7 +822,7 @@ void MacOpenGLWindow::startRendering() uint32 virtualKeycode = [event keyCode]; int keycode = getAsciiCodeFromVirtualKeycode(virtualKeycode); - printf("keycode = %d\n", keycode); + // printf("keycode = %d\n", keycode); if (m_keyboardCallback) { @@ -839,7 +839,7 @@ void MacOpenGLWindow::startRendering() uint32 virtualKeycode = [event keyCode]; int keycode = getAsciiCodeFromVirtualKeycode(virtualKeycode); - printf("keycode = %d\n", keycode); + //printf("keycode = %d\n", keycode); if (m_keyboardCallback) { diff --git a/src/BulletCollision/BroadphaseCollision/btDbvt.h b/src/BulletCollision/BroadphaseCollision/btDbvt.h index b64936844..f578aae01 100644 --- a/src/BulletCollision/BroadphaseCollision/btDbvt.h +++ b/src/BulletCollision/BroadphaseCollision/btDbvt.h @@ -1193,17 +1193,23 @@ inline void btDbvt::collideOCL( const btDbvtNode* root, /* Insert 0 */ j=nearest(&stack[0],&stock[0],nes[q].value,0,stack.size()); stack.push_back(0); + + //void * memmove ( void * destination, const void * source, size_t num ); + #if DBVT_USE_MEMMOVE - memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1)); + memmove(&stack[j],&stack[j-1],sizeof(int)*(stack.size()-j-1)); #else - for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1]; + for(int k=stack.size()-1;k>j;--k) + { + stack[k]=stack[k-1]; + } #endif stack[j]=allocate(ifree,stock,nes[q]); /* Insert 1 */ j=nearest(&stack[0],&stock[0],nes[1-q].value,j,stack.size()); stack.push_back(0); #if DBVT_USE_MEMMOVE - memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1)); + memmove(&stack[j],&stack[j-1],sizeof(int)*(stack.size()-j-1)); #else for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1]; #endif