Access GPU Memory

Hi,

I am new to SDL2, how do I know if I am using CPU RAM or GPU RAM if I want to display a simple full HD image on the screen?

At what point does SDL2 uses GPU RAM? Is it during Window creation or during Rendering?

Regards
Siva

If you use SDL_Surface, its data is stored in universal RAM (heap) and is directly accessed by the CPU. You can read pixel data from it, you can modify pixels, or you can render it on another surface. However, rendering is done by the CPU (software rendering), so it is not very efficient.

However, if you use SDL_Texture then most of its data is stored in VRAM (GPU RAM). There is no direct access to texture pixel data, but you can transfer pixel data to RAM, modify it, and send it to VRAM (mainly for write). Another way to modify the texture content are shaders, i.e. mini-programs executed on the GPU side. Texture-on-texture rendering is performed on the GPU side (using API such as DirectX, OpenGL, Vulkan, Metal), which is hundreds of times faster than software rendering, and also much more functional.

Just when you use SDL instructions that allocate data in VRAM and use it (e.g. creating textures, loading them from file/memory, texture-on-texture rendering etc.). I don’t know if I should answer that question — maybe someone else will chime in.

Why are you interested in this?

1 Like

furious-programming:

Thanks, you explanation is very clear. Now I understand what I need to do.

Thanks
Siva