views:

551

answers:

2

I need to render some CPU generated images in Direct3D 9 and I'm not sure of the best way to get the texture data onto the graphics card as there seems to be a number of approaches.

My usage path goes along the following lines each frame

  1. Render a bunch of stuff with the textures
  2. Update a few parts of the texture (which may have been used by the previous renders)
  3. Render some more stuff with the texture
  4. Update another part of the texture
  5. and so on

Ive thought of a couple of ways to do this, however I'm not sure which one to go with. I considered benchmarking each method however I have no way to know if any results I get are representative of hardware in general, or only my hardware.

  • Which pool is best for a texture for this task?
  • Whats the best way to update this texture?
    1. Call LockRect and UnlockRect for each region I need to update
    2. Call LockRect and UnlockRect for the entire texture
    3. Call LockRect and UnlockRect for the entire texture with D3DLOCK_DISCARD and copy in a bitmap from RAM.
    4. Create a completely new texture each time I need to "update it"
    5. Use 1,2 or 3 to update a surface in D3DPOOL_SYSMEM, then UpdateSurface to update level 0 of my texture from this surface
    6. Same as 5 but specify RECT to cover the entire area I need
    7. Same as 5 but make multiple calls, one for each region I updated
    8. Probably yet another way to do this I haven't thought of yet...

It should be noted that the areas I'm updating are usually fairly small compared to the size of the entire texture, eg the texture may be 1024*1024 and I might want to update 5 or so 64*64 regions of it.

A: 
  • D3DPOOL_DEFAULT
  • D3DUSAGE_DYNAMIC
  • call LockRect and UnlockRect for each region you need to update

--> This is the fastest!

Benchmark will follow...

SuperPro
+1  A: 

If you need to update multiple areas, you should lock the whole texture and use the D3DLOCK_NO_DIRTY_UPDATE flag, then for each area call AddDirtyRect before unlocking.

This of course all depends on the size of the texture etc, for small texture it may be more efficient to copy the whole thing from ram.

croxmeister