Search code examples
graphicsgpucomputer-sciencehardware

On the shader code, why we can't read variables allocated in process memory(e.g. RAM)?


As far as I know, we can read only data in video memory.

So when we want to read data on process memory, we should copy the data to video memory by using Render Target or SSBO so the shader can read.

It's a quite loss of performance and code architecture I think.

I'm sure that there is some reason on there but, I can't find it out with my own force.

Why these things are happened?

And what should I learn to figure it out and understand whole of them?

I think the answer is on how GPU works and is designed for better performance.

But I don't have plenty of knowledge for these parts so want some help.


Solution

  • GPUs have their own memory which is designed for the needs of the GPU. It needs to have high bandwidth and low latency so that the GPU can achieve maximum efficiency. The needs of the GPU are for more than what is needed by a CPU.

    Hence one of the goals in any GPU programming is to get your data onto the GPU and have the GPU do as much processing as it can within its own memory. Moving data back and forth is expensive. Leaving the data on the GPU is cheap.