samizdatco / skia-canvas

A GPU-accelerated 2D graphics environment for Node.js
MIT License
1.67k stars 63 forks source link

GPU is enabled but it doesn't change the rendering speed. #127

Open remyLmnr opened 1 year ago

remyLmnr commented 1 year ago

Hello, we are trying to enable the GPU on skia-canvas but we don't see any difference in rendering speed. We are trying several type of canvas but we don't see any difference.

Context:

Skia-canvas auto detect the GPU and set .gpu as true.

Vulkaninfo:

Device Groups:
==============
Group 0:
    Properties:
        physicalDevices: count = 1
            Tesla T4 (ID: 0)
        subsetAllocation = 0

    Present Capabilities:
        Tesla T4 (ID: 0):
            Can present images from the following devices: count = 1
                Tesla T4 (ID: 0)
        Present modes: count = 1
            DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR

nvidia-smi:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.82.01    Driver Version: 470.82.01    CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla T4            Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   32C    P8     9W /  70W |   1348MiB / 15109MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

Thanks a lot for your work

omegascorp commented 1 year ago

Facing the same issue tested on 2 servers with GPU, and didn't manage to get any difference.

JesseRussell411 commented 1 year ago

same problem, using the .filter function to apply a blur. Does skia-canvas use the gpu for the blur filter?

JesseRussell411 commented 1 year ago

For reference

The way I'm applying the blur is like this:

context.filter = `blur(5.5px)`;
context.drawImage(canvas, 0, 0, canvas.width, canvas.height)
// canvas is the same canvas that the context belongs to, I'm drawing it onto itself
JesseRussell411 commented 1 year ago

I can add another computer

same problem

JesseRussell411 commented 1 year ago

Wait, my bad, it does use the gpu but only when I save the canvas to a file. It's still not any faster when using the gpu though, a little slower even. Also I do some manual pixel manipulation with getImageData and putImageData after the blurring and I don't see how that could be cached until the canvas is saved to file. So it kinda still seems like it's not using the gpu for the blur filter.

mpaperno commented 1 year ago

I also am having a hard time finding a benefit with GPU rendering enabled.

Not only is it not faster (which is going to depend on the GPU vs. CPU speed I suppose), but it also doesn't use any less CPU time and increases total system memory (RSS) use (and of course also uses VRAM and GPU time). The thread count also doubles, with no apparent benefit.

skia-canvas 1.0.1, NVIDIA RTX 2xxx and 3xxx with latest Studio drivers, Intel i7 and i9 brand CPUs, gen 8+.

(And yea GPU only kicks in when producing the final output, eg. canvas.toBuffer() or canvas.toFile(), etc. (also evident from looking at the Rust code, the drawing surface isn't actually created until Page.encoded_as() is called, which in turn only happens during output).)

Also there is the memory leak I reported earlier, and the strange hang-on-exit issue which is hard to recreate, all related to GPU usage.

In CPU-only mode, SC v1+ in general performs better than the previous versions, which of course is great and makes it worth using just for that. However seems like the GPU feature is maybe not quite ready for production and should be disabled by default.

And I don't mean to disparage, skia-canvas is great and much appreciated! Thanks!

-Max