From cage at katamail.com Sun Mar 10 13:35:04 2013 From: cage at katamail.com (cage) Date: Sun, 10 Mar 2013 14:35:04 +0100 Subject: [cl-opengl-devel] slow interpolation issues Message-ID: <20130310133504.GA25029@ponyo> Hello, I have written an MD2 3d mesh loader, everything works fine except for the animations. Because the model save only the key frame for each animation the loader must interpolate the vertex position of the mesh to get a smooth animation. My solution was to save the triangles vertices in a gl-array for each frame an then doing linear interpolation, something like that: (defun lerp-gl-array (a b c count interpolation-factor) (dotimes (i count) (setf (gl:glaref c i) (alexandria:lerp interpolation-factor (gl:glaref a i) (gl:glaref b i))))) but it seem to be too slow as shown by the SBCL profiler seconds | gc | consed | calls | sec/call | name ----------------------------------------------------------- 264.554 | 8.189 | 8,307,049,792 | 2,870 | 0.092179 | CL-GL-UTILS:LERP-GL-ARRAY ----------------------------------------------------------- 264.554 | 8.189 | 8,307,049,792 | 2,870 | | Total is this my fault? Any idea how can I improve performance? Thank you. C. -- source code published is licensed under the "Simplified BSD License" From 00003b at gmail.com Sun Mar 10 23:24:34 2013 From: 00003b at gmail.com (Bart Botta) Date: Sun, 10 Mar 2013 18:24:34 -0500 Subject: [cl-opengl-devel] slow interpolation issues In-Reply-To: <20130310133504.GA25029@ponyo> References: <20130310133504.GA25029@ponyo> Message-ID: On Sun, Mar 10, 2013 at 8:35 AM, cage wrote: > (defun lerp-gl-array (a b c count interpolation-factor) > (dotimes (i count) > (setf (gl:glaref c i) > (alexandria:lerp interpolation-factor (gl:glaref a i) (gl:glaref b > i))))) > > is this my fault? Any idea how can I improve performance? > Most of the problem is https://github.com/3b/cl-opengl/issues/27 (glaref and (setf glaref) are slow). Another problem is that the compiler doesn't know what types the values are, so has to call generic math routines instead of using CPU ops directly. Storing the source arrays as specialized lisp arrays, and declaring types (and/or check-type) would help with both problems, though writing to the gl-array would still be slow until that bug is fixed. You could work around the bug by using cffi:mem-aref directly instead of glaref, or if you are using shaders, you could just do the interpolation on the GPU. -b- -------------- next part -------------- An HTML attachment was scrubbed... URL: From cage at katamail.com Mon Mar 11 09:38:14 2013 From: cage at katamail.com (cage) Date: Mon, 11 Mar 2013 10:38:14 +0100 Subject: [cl-opengl-devel] slow interpolation issues In-Reply-To: References: <20130310133504.GA25029@ponyo> Message-ID: <20130311093814.GA27797@ponyo> On Sun, Mar 10, 2013 at 06:24:34PM -0500, Bart Botta wrote: Hi, thank you for your reply! [...] > Most of the problem is https://github.com/3b/cl-opengl/issues/27 (glaref > and (setf glaref) are slow). > > Another problem is that the compiler doesn't know what types the values > are, so has to call generic math routines instead of using CPU ops directly. > > Storing the source arrays as specialized lisp arrays, and declaring types > (and/or check-type) would help with both problems, though writing to the > gl-array would still be slow until that bug is fixed. You could work around > the bug by using cffi:mem-aref directly instead of glaref, I have just replaced all glaref calls with: (cffi:mem-aref (gl::gl-array-pointer array) :float offset) and the results are surprisingly good! seconds | gc | consed | calls | sec/call | name ---------------------------------------------------- 3.924 | 0.000 | 0 | 2,500 | 0.001569 | CL-GL-UTILS:LERP-GL-ARRAY ---------------------------------------------------- 3.924 | 0.000 | 0 | 2,500 | | Total > or if you are > using shaders, you could just do the interpolation on the GPU. That's a good idea indeed! My fault is that i still stick with the old fixed pipeline opengl paradigm. Thank you for your help! C.