Jump to content
  • Advertisement
Sign in to follow this  
lomateron

optimization

This topic is 2464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 );
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!