0
\$\begingroup\$

I am trying to understand this. So I have a bunch of models that need to be rendered. Each model most likely has various "sub meshes" with their own diffuse, specular, etc textures. So for each of these models I have to loop through set the diffuse, specular, etc and then a draw call. Now lets say I do this a couple times for each model, and I have 100 models in a scene. Since my C++ code that sets these per model parameters is called by the CPU, doesn't it have to bus all that data to the GPU a ridiculous amount of times. Even if it doesn't and the GPU is caching, wouldn't the CPU still need to make several inquires to make sure the correct resources are cached? I am asking because I have a, single, high res model I am rendering and once textures are applied I drop from 1000 FPS to 70. This model has about 20 different textures, and isn't something that will be used in a game, solely using it to stress test and locate bottlenecks. Thanks!

\$\endgroup\$
0
\$\begingroup\$

Look into "Shader Constants Buffers" on DirectX and "Uniform Buffers" on OpenGL. These allow sending shader parameters all at once to the GPU and possibly reusing them every frames without having to resend them over the bus.

\$\endgroup\$
  • \$\begingroup\$ Yeah, that's basically what I am trying to figure out how to batch. I have a scenemanager that uses an octree to cull visibility, and adds visible items to a vector of priority queues (so I can control render order for opaque/transparent, post-processing effects, etc.) What I am struggling with is finding an efficient method to batch these by render context and texture context across a priority queue. \$\endgroup\$ – user3355098 Jan 5 '15 at 23:43
  • \$\begingroup\$ Group shader settings into a material object then sort render batches by material object. One easy way is to use a std::multimap<Material *, RenderBatch *> all render batches using the same material will be grouped on the same key (the material pointer). You can then iterate over the multimap and only update GPU states when the material (iterator->first) changes. \$\endgroup\$ – Stephane Hockenhull Jan 6 '15 at 0:24
2
\$\begingroup\$

It isn't entirely clear what you are asking. Setting shader parameters IS a bottleneck - that's why engines batch by material - textures, parameters, lights, etc. While CPUs and GPUs are efficient, in order to get the most out of rendering performance you have to think about these things.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.