optimization

Started by
11 comments, last by lomateron 12 years ago
Hello i am a starter that already knows a lot, hohoho. I have a for() loop that goest 1000 times callying draw() method, each one draws a tetrahedron. The program stars with 0 tetrahedron, each time i make a click i shoot a tetrahedron in the direction you are watching, each one has its own gravity so each time i shoot the program gets COOL er, no collision is there, the max number of tetrahedrons can be whatever you want, all physics runs on GPU using textures as positions and velocitiess.
Ok back to the point, i wana know if someone can tell me unknown rare ways of optimising the 1000 loop. O maybe there is no way? i mean, i really dont know about CPU threads, this can be stupid, but can you call the draw() with different threads at the same time.
Dont get suck but the last thing i said, i wanna know if there is any way.
Advertisement
You'll probably have to post the code for your loop. Drawing 1000 objects shouldn't take more than a few milliseconds. Have you timed/profiled this loop yet to see if it is worth optimising it?
the method just does this
for(int kl=0;kl<numPres;kl++)
{
g_pSetPVariable->SetFloat((float)kl); // set the position of the position of the tethrehedron
g_pTechnique2->GetPassByIndex( 0 )->Apply( 0 );
g_pd3dDevice->DrawIndexed( 12, 0, 0 );
}
If your positions are already on the GPU you should be able to draw all of them using instancing with only one call and no loop required at all, so do have a look into instancing.

Even without instancing you should be able to hardcode a object ID your vertex buffer and use that to grab the textcoord you need from your GPU updated "position texture".. this also will allow you to draw all in one call.

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

ok, i am watching the sample called instancing10. I have seen that sample runs very very slow and it is very simple, just some meshes with textures and runs very sloooow.
The last thing you writote, i didnt underestand it, too advance hoho, hardcode object IDs, that sounds familiar, i will have to read mmore.... thanks.
Now i know how to use instancing but there is a problem, When i am in IASetVertexBuffers() i need a ( ID3D10Buffer* pVB[2]; ) where

pVB[0] = commonly used vector buffer with the tetrahedron info
pVB[1] = info where only the different positions of the tetrahedron will be

So pVB[1] just accepts ID3D10Buffer* buffers types, but i have the positions of tetrahedrons in ID3D10Texture2D* buffer, so i am stuck there.

I will want to know more about the last thing kunos wrote, that i could leave instancing ----"Even without instancing you should be able to hardcode a object ID your vertex buffer and use that to grab the textcoord you need from your GPU updated "position texture".. this also will allow you to draw all in one call"---
I didnt undestand that.
Instead of using a 2nd vertex buffer to store the positions, you can make a texture-coordinate out of SV_InstanceID in order to read the positions from your texture.
wait right now the program works but with the loop i posted, and the positions of the tetrahedrons in a ID3D10Texture2D*.
So then i knew about instancing but i couldnt use it because of what i posted, so when you say "Instead of using a 2nd vertex buffer to store the positions....." the program is working like i said.
I want to know another way of making that loop faster, so i want to understand what kunos wrote in his last paragraph.
Instead of using a 2nd vertex buffer to store the positions, you can make a texture-coordinate out of SV_InstanceID in order to read the positions from your texture...
... and still render the object using "instancing". So, you render the object once, but using instancing so that the one draw-call actually causes the object to be rendered 1000 times at once.
Then, inside your vertex shader you can use SV_InstanceID to tell which one of those 1000 objects is currently being transformed -- i.e. [font=courier new,courier,monospace]SV_InstanceID[/font] replaces your "[font=courier new,courier,monospace]kl[/font]" variable.
the tetrahedron model is in the center of the world by defaul, when i run the normal drawIndexed() method i change its position using the shader variable "kl" you saw, and every loop a new tetrahedron will be draw i a diferent position of the render target image, thats possible because every loop i can change the "kl" varible, now with the drawIndexedInstanced()method I dont understand how i could change the SV_InstanceID variable for every tetrahedron, that way you told me, can you explain me more what is that texture-coordinate.

The way my program works is that all the positions that will have the tetrahedrons i will draw are in a texture with dimensions
N`tetrahedrons X 2
the 2 is because in the upper row of pixels i put the velocities and in the bottom row i put the positions.
That texture is modified, rendering to it in a process that is not related with the drawing of the tetrahedrons.

This topic is closed to new replies.

Advertisement