Remix.run Logo
CrimsonCape 41 minutes ago

I see lots of shader related videos but to me the worst part of GPU code is that the setup is archaic and hard to understand.

Does anyone have a good resource for the stages such as:

- What kind of data formats do I design to pipe into the GPU? Describe like i'm five texcels, arrays, buffers, etc.

- describe the difference between the data formats of traditional 3D workflow and more modern compute shader data formats

- Now that I supplied data, obviously I want to supply transformations as well. Transforms are not commutative, so it implies there is sequential state in which transforms are applied which seems to contradict this whole article

- The above point is more abstractly part of "supplying data into the GPU at a later stage". Am I crossing the CPU-GPU boundary multiple times before a frame is complete? If so describe the process and how/why.

- There is some kind of global variable system in GPUs. explain it. List every variable reachable from a shader fragment program

dahart 15 minutes ago | parent [-]

You’re partly asking questions about APIs rather than questions about GPUs. It might help to identify any specific goals you have and any specific tools or APIs you intend to use.

In general, you can use just about any data format you want. Since GPUs are SIMT, it’s good to try to keep data access coherent in thread groups, that’s the high level summary. There are various APIs that come with formats ready for you. Depends on whether you’re talking textures, geometry, audio, fields, NN weights, etc., etc.

I’m not sure I understand what you mean about sequential state contradicting the article. Shaders don’t necessarily need to deal with transforms (though they can). Transforms in shaders are applied sequentially within each thread, and are still parallel across threads.

Crossing the CPU GPU boundary is an application specific question. You can do that as many times as you have the budget for. Crossing that boundary might imply synchronization, which can affect performance.

For global variables, you might be thinking of shader uniforms, but I can’t tell. Uniforms are not globals, they are constants passed separately to each thread, even when the value is the same for each thread. You can use globals in CUDA with atomic instructions that causes threads to block when another thread is accessing the global. That costs performance, so people will avoid it when possible.

I hope that helps. Answering these is a bigger question than just shaders, it’s more like understanding the pipeline and how GPUs work and knowing what APIs are available. An intro course to WebGL might be a good starting point.