Results 1 to 6 of 6

Thread: cpu at 100%

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    11

    cpu at 100%

    Even when I'm running the simplest examples of webGL like this:
    http://learningwebgl.com/lessons/lesson01/index.html
    my cpu reaches 100% load at the moment the page loads.
    I'm using Mozilla Firefox 3.7a1pre at Windows XP 32-bit with SP3 and hardware:
    cpu: AMD Turion 64 Mobile Technology MT-32
    graphics: GeForce Go 7300 256MB with driver 6.14.11.7948
    memory: 1,5 GB
    Where's the problem?

  2. #2
    Member Coolcat's Avatar
    Join Date
    Oct 2009
    Location
    NRW, Germany
    Posts
    75

    Re: cpu at 100%

    It's running at 30% CPU here on Intel Core 2 Quad (2.5 Ghz) with Geforce 9800 Pro.
    The reason is probably because there is a call
    Code :
    setInterval(drawScene, 15);
    That means it tries to redraw the scene every 15 ms or with 66 frames per second. Each frame it creates two JavaScript arrays with vertex data. Arrays in JavaScript are actually HashMaps, which means they are slow when using them just as arrays. These two "arrays" are converted into an CanvasFloatArray (true array) and are then uploaded to the graphics card into newly created VertexBufferObjects.

    That's just inefficient code
    You could try to create each VBO just once and reuse it every frame.

    However, when using an native compiled application (C++, ...) this would be much faster.

  3. #3
    Member
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    90

    Re: cpu at 100%

    Yup, Coolcat's right -- the code's not very efficient. It's a first lesson in WebGL and I figured simplicity was more important than speed

    In a later lesson, once I've started using JS objects to represent objects in the scene, then things should be a bit faster...

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    11

    Re: cpu at 100%

    I can't find the reference for CanvasFloatArray(). What is the return type of this function? Maybe we use this type rather than js arrays and skip casting those type due to CanvasFloatArray?

  5. #5
    Member
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    90

    Re: cpu at 100%

    CanvasFloatArray is a class rather than a function, and, as far as I can make out from the Firefox source, it doesn't have any useful methods. From http://mxr.mozilla.org/mozilla-centr...xtWebGL.idl#69, I've found:

    Code :
    interface nsICanvasFloatArray : nsICanvasArray
    {
    };

    and
    Code :
    interface nsICanvasArray : nsISupports
    {
       attribute unsigned long length;
     
       [noscript, notxpcom] unsigned long nativeType();
       [noscript, notxpcom] voidPtr nativePointer();
       [noscript, notxpcom] unsigned long nativeSize();
       [noscript, notxpcom] unsigned long nativeElementSize();
       [noscript, notxpcom] unsigned long nativeCount();
    };

    ...which would seem to imply that it's an almost completely opaque type from the JavaScript side (if I'm interpreting those "noscript" flags correctly). And running the following code:

    Code :
          for (var f in CanvasFloatArray([]))
            alert(f);

    Showed only one attribute, the length one that you'd expect from the IDL.

    So, nice idea but I don't think it'll work, at least in current versions of WebGL.

  6. #6
    Junior Member
    Join Date
    Oct 2009
    Posts
    11

    Re: cpu at 100%

    class of course, my mistake. thanks for the answers

Similar Threads

  1. when run on cpu or graphics card of cpu
    By prince in forum OpenCL
    Replies: 2
    Last Post: 01-20-2013, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •