I am attempting to make a 3d game using SDL2 just to learn and have a bit of fun. I was wondering if there is any way to get SDL2 do calculations on GPU. I have read that SDL2 Textures uses GPU for calculation, but is there any way to get it to do calculations from my functions using GPU? For example, if I have a function multiplyVectorWithMatrix, and there is a bunch of additions going on in that function, how would I get SDL2 to do those additions using GPU rather than CPU?
\$\begingroup\$
\$\endgroup\$
5
-
2\$\begingroup\$ If you want to use the GPU for a "round trip": set up the data, send the data to the GPU, have the GPU do the calculations, then get the data again to use them for whatever your game require, you might be spending more time doing all the "non useful" stuff and you'll likely lose the performance gain offered by the GPU. \$\endgroup\$Vaillancourt– Vaillancourt ♦2020-10-02 16:17:04 +00:00Commented Oct 2, 2020 at 16:17
-
2\$\begingroup\$ You almost certainly do not want to incur a GPU synchronization, call, sync again, and read-back each time you do one matrix multiplication. Think of the GPU as a factory. If you need a million packages sent out, you submit a work order to it and then let it do its thing while you work on something else. You don't send a single package to the factory for them to lick the stamp for you and send it back each time. What you might be looking for are things like SIMD instructions that might help matrix math run faster on your CPU, and the library may already do that where feasible/appropriate. \$\endgroup\$DMGregory– DMGregory ♦2020-10-02 16:27:54 +00:00Commented Oct 2, 2020 at 16:27
-
2\$\begingroup\$ Note that SDL2 does not support 3D rendering itself, so unless you are writing a software renderer on the CPU, you are going to need something like OpenGL ontop of SDL2. \$\endgroup\$user35344– user353442020-10-02 16:45:32 +00:00Commented Oct 2, 2020 at 16:45
-
\$\begingroup\$ @Tyyppi_77 Yea, I was thinking of writing a software for 3d rendering using all the tools SDL2 provides, but I am just starting to learn so I will probably write bad code, so i just want it to be able to handle it. I don't want to work on something for weeks only for it to be a laggy mess \$\endgroup\$Apple_Banana– Apple_Banana2020-10-02 16:55:30 +00:00Commented Oct 2, 2020 at 16:55
-
2\$\begingroup\$ "I am just starting to learn" Just so you know, it will likely be laggy and messy, but maybe not where you think it will be. And that's all right, we've all been there :). When you're there, you'll know what parts of the code need to be fixed, and we'll be able to help finding an appropriate solution :) \$\endgroup\$Vaillancourt– Vaillancourt ♦2020-10-02 17:05:41 +00:00Commented Oct 2, 2020 at 17:05
Add a comment
|