Jump to content
  • Advertisement
hiya83

DX11 DX11 Update textures every frame

This topic is 884 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

Hi,

 

I am trying to upload multiple (say n) textures (BC7) to the gpu each frame (there's data every frame read from CPU; there is no way around this), and I am trying to minimize this time as much as possible, was wondering if anyone has any insights other than what I've done:

 

- each texture is dynamic, have 2 copies (total 2n textures) and interchange between a cpu mapped (D3D11_MAP_WRITE_DISCARD) version to copy data into and gpu unmapped to use for render

- each texture has 2 corresponding resources, a default & a staging version (2n staging, 2n default), map with D3D11_MAP_WRITE and CopyResource (n times each) to default from staging

- have a staging & default texture2darray (array size = n, 2 staging, 2 default), call map D3D11_MAP_WRITE once per frame on staging, CopyResource once to copy and unmap once.

- I also want to try 3d textures, but the limitation of 2048x2048x2048 means i can't use it.

 

All of these are approximately the same times. Does anyone have thoughts on how I can hide/reduce this time?

I am aware GPU has compute/copy/3d engines (exposed in D12), but is there anyway to parallelize whatever unmap/copyresource is doing to a separate engine from the 3d engine on D11? If not any suggestions/thoughts?

 

Thanks

Share this post


Link to post
Share on other sites
Advertisement

Copying textures every frame from CPU to GPU memory will be bottlenecked by the bus-bandwidth, so, check out your target platform (e.g. PCI-E) bandwidth and do some theo-crafting about how many times you would be theoretically able to transfer your textures from CPU memory to GPU memory. If this would be an issue, try to re-think your approach.

 

Data transfer will use DMA most of the time, so you can hide this transfer costs (aka avoid stalling your pipeline) if you can get along with one or two frames delay. If this is the case, look into double/triple buffering.

 

Eventually try to reduce the transfered data, either update only parts, use some compression or do even packing/unpacking.

 

Why are 2048x2048x2048 limiting ? Do you need larger textures ? I mean, 2k^3 ~ 32GB for an RGBA texture without mipmaps.

Edited by Ashaman73

Share this post


Link to post
Share on other sites

I am not sure if PCIe is the problem, I have maybe 40MB per frame (with PCIe3.0 x16 for 32GB/s), and I am already double buffering (with a frame delay) to hide the memcpy operation. However, I was thinking earlier, it seems using staging/default approach, the time is not in the unmap, but copyresource. Does D11's CopyResource automatically use the Copy Engine and not stall the 3D Engine (if there is no dependency)? Or would I have to use D12 for that? I'll have to test that out with triple buffering and 2 frames delay I guess. :D

 

2048^3 is limiting cause my widths are > 2048 (height and depth are fine). 

Edited by hiya83

Share this post


Link to post
Share on other sites

D3D11 has no concept of a "copy engine", and so the driver is free to implement CopyResource however it wants as long as it has the correct behavior. It might implement it with an asynchronous DMA. it might not. It might even be doing the same thing for all 3 of your approaches.

 

When you say that all of your approaches are "approximately the same times", what do you mean by that? Are you measuring CPU timing? GPU timing?

Share this post


Link to post
Share on other sites

I am measuring GPU times. 

 

- in dynamic case, I put gpu ticks around unmap

- in default & staging case, unmap doesn't take time, but CopyResource is where the time is

- in default/staging with texture2darray, same as 2nd case. 

Share this post


Link to post
Share on other sites

- in default & staging case, unmap doesn't take time, but CopyResource is where the time is

Unmap will only trigger the upload, which, when done with DMA, will not involve the GPU. But CopyResource, when you try to access the memory block, will spent time in 

1. waiting until the data has been uploaded (=>stalling your pipeline)

2. actually copying your data

 

To measure the first delay try to use some fence and try to measure the time spend in waiting for the fence:

unmap buffer A -> fence A ->... -> start GPU timer -> wait for fence B -> end GPU timer -> CopyResource ->... ->  unmap buffer B -> fence B ->...

Share this post


Link to post
Share on other sites


I also want to try 3d textures, but the limitation of 2048x2048x2048 means i can't use it

Perhaps this is not a relevant suggestion, but is it possible to use a texture array instead of one big volume texture?

Edited by vanka78bg

Share this post


Link to post
Share on other sites

How much time exactly is your 40MiB copy operation currently taking with any of your methods?

2048^3 is limiting cause my widths are > 2048 (height and depth are fine).

Well, another limit is that you'd need a video card with over 8GiB of RAM, which pretty much limits your min-spec hardware to the US$999 GeForce GTX Titan X :wink: :lol:

Share this post


Link to post
Share on other sites

Unmap will only trigger the upload, which, when done with DMA, will not involve the GPU. But CopyResource, when you try to access the memory block, will spent time in 

 

To measure the first delay try to use some fence and try to measure the time spend in waiting for the fence:

 

Does that mean unmap for Dynamic Textures triggers some sort of copy from cpu-accessible gpu memory to default gpu memory internally since that takes about same time as unmap/copyresource for staging/default textures. 

Also possibly dumb question, how would you setup a memory fence on DX from the CPU?? There is no query for that, and everything seems to be implicit... 

 

 

Perhaps this is not a relevant suggestion, but is it possible to use a texture array instead of one big volume texture?

 

I did try texture arrays already, that was the 3rd thing I tried in my original post.. sorry if it was misleading.

 

 

How much time exactly is your 40MiB copy operation currently taking with any of your methods?

 

Well, another limit is that you'd need a video card with over 8GiB of RAM, which pretty much limits your min-spec hardware to the US$999 GeForce GTX Titan X :wink: :lol:

 

Hey sorry but not sure what you meant by how long 40MB copy operation is taking? If you mean the methods I've tried above, they are all in the upper 3 ms ballpark (3.6 - 3.9). 

Yea I am aware of the large memory video card, I am working on other forms of compression as well, but just want to get this down with BC7 for now :D

Edited by hiya83

Share this post


Link to post
Share on other sites

So tried the triple buffering approach hoping CopyResource is async dma, but it still stalls the gpu command. :(

 

Also since d11 device is free threaded, I tried to do something real "dumb" of creating another thread and just keep deleting old/creating new textures (with new content) on this other thread, hoping the texture creation/deletion is async from the gpu graphics engine, and that plan fell flat as well. Even though device is free threaded from the context, apparently creating/deleting resources still runs in same pipeline as the context commands. :( 

 

Any other thoughts/ideas would be appreciated.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!