GPU Accelerated JavaScript ?

Discussion in 'Learning Javascript' started by Jonforum, Jan 9, 2018.

  1. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,574
    Likes Received:
    1,339
    Location:
    Canada / Québec
    First Language:
    French
    Primarily Uses:
    RMMV
    hey guys what do you think about this ?
    https://github.com/gpujs/gpu.js
    can it be worth it for i game like rmmv?
    source:http://gpu.rocks/

    it seem to use Matrix multiplication written in gpu.js:
    // Create the GPU accelerated function from a kernel
    // function that computes a single element in the
    // 512 x 512 matrix (2D array). The kernel function
    // is run in a parallel manner in the GPU resulting
    // in very fast computations! (...sometimes)

    it seem to No variables captured by a closure but look great for masive update code
     
    Last edited: Feb 16, 2018
    #1
    peq42_ likes this.
  2. Leon Kennedy

    Leon Kennedy Restaff Novice Restaff

    Messages:
    613
    Likes Received:
    468
    Location:
    Chicago
    First Language:
    english
    Primarily Uses:
    RMMV
    Could be nice, a lot of reported issues with it though. But everything has issues.
     
    #2
  3. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,778
    Likes Received:
    9,445
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Not for graphical chips. I use a laptop with a chip and even a blank project gives me 30% gpu use due to WebGL. I can't imagine how much additional strain would this gpu acceleration put.
    Other than that I think GPU acceleration is great and should be implemented to MV once it stabilizes.
     
    Last edited: Jan 9, 2018
    #3
  4. Windows i7

    Windows i7 Veteran Veteran

    Messages:
    311
    Likes Received:
    926
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Is it integrated graphics? If so that's why. My GPU usage is around 2 to 3% (R9 Fury X video card)
     
    #4
  5. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,778
    Likes Received:
    9,445
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Graphical chips are always integrated graphics.
     
    #5
  6. Alastor01

    Alastor01 Veteran Veteran

    Messages:
    220
    Likes Received:
    255
    First Language:
    Russian
    Primarily Uses:
    N/A
    A good idea, but only for some people (or if you have the ability to switch it on / off). That would require use of dedicated GPUs. Surely will work nice for a desktop, like with GT 1050 / 1080 etc. But what about integrated GPUs, mobile PowerVR and Tegra chips? They don't have much juice at all and may be outdone even by a multi-core ARM in calculations with proper use of co-processors...
    But what is the point of using it even in a desktop? Cause you would probably have i5 / i7 / Ryzen 5 / Ryzen 7 as your CPU, which will process these calculations like nothing...
    I have GTx 1050 Ti with Ryzen5: when rendering scenes in Blender there is practically no difference in speed whether I use GPU (with CUDA) or CPU (with 12 threads): 1 to 1. So I believe there will be hardly any difference.
     
    #6
  7. Windows i7

    Windows i7 Veteran Veteran

    Messages:
    311
    Likes Received:
    926
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    No I mean is it a full video card, or is it IGP (Integrated Graphics Processor)? In my case, I have a full video card and my IGP is disabled. Some laptops also have video cards (sometimes called discrete graphics). One of the key differences is that IGPs usually rely on system memory instead of having their own VRAM.
     
    #7
  8. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,778
    Likes Received:
    9,445
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    @Alastor01 If you have a 4 GHz thread, then no, there won't be a difference. But MV doesn't support multithreading, so usually you have only 1 core available. And people often report lag issues even with intel i7 processors, so it's not like i7 is an automatic savior, and it can only increase if the upcoming windows update limits Intel CPU power too much.

    @Windows i7 IGP, since it's not a card.
     
    #8
    Alastor01 likes this.
  9. peq42_

    peq42_ Yeet Veteran

    Messages:
    452
    Likes Received:
    269
    Location:
    Brazil
    First Language:
    Portuguese(BR)
    Primarily Uses:
    RMMV
    Nah that's why. Your CPU and "GPU" share the same resources, so they will always be near to be overloaded once playing games. Probably you wouldn't lose any performance using that GPU.js, (since transfering the work to your GPU is the same as handling it on CPU).

    But for those who have a dedicated GPU, performance gain can be incredible, because a separated GPU will do the hard work(and by hard work, i mean: graphical things that MV forces CPU do handle).

    With that on desktop, maybe MV would finally be able to have bigger maps, more NPCs and stuff like that

    @Alastor01 What poryg said is right. MV uses just one core, and also doesn't share work with GPU as well as it could, so performance gain would still be huge for you and most of us.
     
    Last edited: Jan 9, 2018
    #9
    Alastor01 likes this.
  10. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,778
    Likes Received:
    9,445
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    @elpeleq42 If you change how textures are handled, you eliminate most of the work cpu does while it doesn't need to. Because loading through CPU is a necessary evil (due to encryption which most DLC require) and a lot of rendering is automatically passed on to GPU thanks to WebGL (if you use it. If not, then gpu acceleration might have a much bigger impact).
     
    #10
  11. MagicMagor

    MagicMagor Veteran Veteran

    Messages:
    201
    Likes Received:
    36
    First Language:
    German
    Don't expect huge performance boosts with this unless you need to multiply huge matrices (which in a game you typicaly don't).
    Matrix multiplication requires a lot of processing power (especially when the matrices become huge) and is a typical case for optimization but GPUs are also designed for fast vector-based math.
    If you use the GPU for a different kind of problem (say pathfinding) the performance boost you would gain might be lower. And that does not include the extra cost of transfering the data between cpu and gpu or the synchronization issues that arise when you go multi-threaded.
    Writing good multi-threaded code is hard and bad multi-threaded code is surely slower than good single-threaded code.

    Unless you find a very specific performance problem in your game, don't try to fix something which isn't broken.
     
    #11
    MushroomCake28 and Poryg like this.
  12. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    921
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    I think most people here are missing the point of what this would do. GPU.js wouldn't make games on systems with good GPUs to run as fast as the benchmarks might suggest at first. GPUs are good at doing the same thing thousands of times at the same time. it's why they're very good at drawing graphics: Each pixel is run on its own thread on the GPU, and they're all run at the same time with the same instructions, but differing data with regards to colors, textures, or other object-specific data.

    There's just no way for you game to run entirely on the GPU, which is what some people seem to think would happen. What the GPU would possibly help improve in MV games is repeated math operations on a lot of data, like moving thousands of objects differently, scaling them, and rotating them. All three of those things can happen in an MV game, but I don't think the tradeoff will make it worth it. To send data to the GPU for it to process, you're going to have overhead - the information has to be sent to the GPU across your motherboard. Then the GPU needs to be free so it can begin working on what it was sent. Then that information has to be sent back to the CPU and stored in RAM.

    The benchmarks for GPU.js use a 512x512 matrix. 2D applications like MV use a 3x3 matrix, or 9 elements, whereas the 512x512 matrix is 262,144 elements (or in percent, the 512x512 matrix is 16,384% the size of our 3x3 matrix). To get the same performance benefit, we'd need to be doing about 16.4 thousand matrix multiplcations at once. If an MV game has anywhere near 16,400 moving, rotating, and/or scaling objects at once, then you need to sit down and consider if what you're doing is really the only way it can be done, because that is simply ridiculous.

    If your computer has a compatible GPU and your browser is up to date (or you use the desktop client, which is up to date enough), then your GPU will already be used to handle drawing, which is a huge source of lag with applications. The amount of power it takes to render a picture with the CPU is high, but by offloading that to the GPU, you're already seeing performance improvements. You'd need to be doing a lot of complicated math for this to be worth it.


    tl;dr No, it's really not going to help much, unless you're trying to compute the 10 billionth digit of pi or something.
     
    #12
    waynee95, Alastor01 and Poryg like this.
  13. Alastor01

    Alastor01 Veteran Veteran

    Messages:
    220
    Likes Received:
    255
    First Language:
    Russian
    Primarily Uses:
    N/A
    Wait... It uses just one core, i.e one physical thread?? Not even 2? Gosh we are in 2018 now...
    The number one priority for speed should be multi-threading and not asking GPU to do what's its not supposed to do... All current gen CPUs have at least 2 cores and most have 2 threads per core. And they all have some kind of extensions for heavy math (even ancient ones). Intel / AMD / ARM are all multi-core now. PowerPC had 2 threads already ages ago. Heck they have been multi-core multi-threaded for ages, but we still have applications which use one core / thread
    Isn't it much easier to optimize the code for multi-threading than writing extensions for GPU? GPU should be doing rendering and DSP stuff. CPU should be doing all game logic.
     
    #13
  14. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,778
    Likes Received:
    9,445
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    @Alastor01 We are in 2018, however it doesn't matter how many cpu cores you have in regards to single threaded languages (and Javascript is single threaded), because only one logical cpu thread handles that single thread. The more logical cpu threads you have, the merrier, but unless you can execute code in multiple threads, it's completely useless.
    There is a way to implement some sort of multithreading in javascript, through web workers. These will be supported in MV from version 1.6 onwards though.
    But multithreading brings some trouble and actually, there is not that much use of it in MV, because web workers don't have access to global variables, cannot access DOM (because they are on the background) and can't communicate with each other except by means of json files. So pretty much the only way to use multithreading in MV would be to load files. Still better than nothing though.
     
    #14
    Alastor01 likes this.
  15. Alastor01

    Alastor01 Veteran Veteran

    Messages:
    220
    Likes Received:
    255
    First Language:
    Russian
    Primarily Uses:
    N/A
    Thanks @Poryg that answers my question perfect ;)
    I apologize if off topic!
     
    #15
  16. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,574
    Likes Received:
    1,339
    Location:
    Canada / Québec
    First Language:
    French
    Primarily Uses:
    RMMV
    rmmv, on my side, solicit all the core and can do multi thread instance.
    [​IMG]
    Performance counter values for threads are subject to error when threads are stopping and starting. Faulty values sometimes appear as large spikes in the data.
    some info here for pro and deep
    https://technet.microsoft.com/en-us/library/cc938598.aspx?f=255&MSPPError=-2147217396

    Some Intel CPUs have a feature called hyperthreading, which allows an operating system to see double the amount of logical cores per physical core. This allows the operating system to schedule and run double the amount of threads simultaneously, so in the case of the CPU I linked to above, there are four physical cores, but eight logical ones (so you can run eight threads simultaneously)

    I will probably try to see what I can remove in the core update.
    More deep i look in the update, more I find a lot of js very useless lound .call, apply. and bind.
     
    #16
  17. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    921
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    I'm late to the party, but JavaScript is, by nature, definition, and every implementation, a single-threaded language. Game.exe is a fully-fledged HTML5 web browser. That's where your extra threads are coming from. The game logic itself is single threaded.
     
    #17
    caethyril and Jonforum like this.

Share This Page