ID3D11Buffer question...

Started by
7 comments, last by Hodgman 11 years, 3 months ago

When a ID3D11Buffer is created, is a .bytewidth(from desc) sized block of memory reserved? Is it dependant on the flags for creation?

Advertisement

1) Yes.

2) Yes. Check on MSDN how bytewidth depends on D3D11_BIND_CONSTANT_BUFFER.

How do I work out exactly where the memory is reserved.... video, agp or ram & how much is available (is this something we keep track of or can dx tell us how much is left)?

When mapping the buffer for writing (e.g dynamic with write access) I'm assuming this is agp memory. If I map with D3D11_MAP_WRITE_DISCARD it writes to a different memory location if I'm not mistaken (as the gpu may still be using the previous block of memory)? If that's the case... how can the memory be reserved?

I'm just thinking about memory limitations and ensuring my app doesn't exceed them... though I cannot find much information on how to go about this.

First thing, that your memory mapping will depend on is if your device is created by DriverType as HARDWARE or REFERENCE.

Assuming it's HAL, memory allocations happen on GPU.

AGP is just a channel. It's purpose is more like registers.

Refer to this link for further clarity --> http://gamedev.stackexchange.com/questions/18026/directx11-how-do-i-manage-and-update-multiple-shader-constant-buffers

I'm still confused regarding everything in my previous post lol.

I'm getting the impression AGP is reserved RAM that increases/decreases dynamically as needed? So the vertex buffer i created as dynamic with cpu write access points to a block of memory there... always, so at minimum there is .bytewidth memory reserved. But If I map the buffer with D3D11_MAP_WRITE_DISCARD there are now two blocks of memory reserved of bytewidth size?

That 2 blocks of memory is because of the dynamic usage nature of D3D11_MAP_WRITE_DISCARD.

I am guessing that it always appends the same chunk of memory to the originally requested one, for catering to the needs of D3D11_MAP_WRITE_DISCARD.

And again, AGP is just a channel that provides direct access to main memory. There is no memory allocation happening on AGP.

"AGP memory" is a fairly old term (from when GPU's generally used an AGP-port, instead of a PCIe port).
It's basically refers to regular "main memory" that the OS has allowed the GPU to access over the AGP/PCI channel. This type of memory means you can quickly update it from the CPU (as it's just regular RAM), but the GPU can also access it as if it were GPU-RAM (aka video RAM), albiet it will be a bit slower than reading from local GPU-RAM, depending on the AGP/PCI bus speeds.

The way D3D/GL are made, you can never actually know where your buffers are stored. They might be stored in main memory, or in "AGP memory" (AKA GPU-accessible main memory) or in GPU-memory. All you can do is give the API/Driver the appropriate hints (e.g. DYNAMIC, READ_ONLY, etc) and hope that the driver allocates your memory in the appropriate place. Also, on PC, there's really no reliable way to measure the amount of available RAM in any of these places either, and tell exactly how much RAM your buffers are using.


For the next part, keep in mind that the GPU/CPU are not synchronized. All D3D/GL commands to the GPU are sent through a pipe, which typically has a lot of latency (e.g. 10-100ms). Whenever you ask the GPU to do something, it will do it some time in the future.

When you map a resource that's being used by the GPU -- e.g. 1. put data in buffer, 2. draw from buffer, 3. put new data in same buffer, 4. draw from buffer -- the driver has two choices once the CPU gets up to #3:

1) It introduces a sync point. The CPU stops and waits for the first "draw" (#2) to be complete, and then maps the buffer. This could stall the CPU for dozens of milliseconds.

2) It creates another internal allocation for that buffer, which the CPU writes to during #3. From your code, you still just have the one handle to the buffer, but internally, there can be any number of versions of the buffer "in the pipe", on their way to being consumed by the GPU. Some time after the GPU executes #2, the allocation from #1 will be freed/recycled automatically by the driver.

Specifying a "DISCARD" hint will help the driver choose option 2.

Tyvvm for your explanation. So it is probably best to use D3D11_MAP_WRITE_NO_OVERWRITE if the buffer has not been filled entirely and write to the unused parts of the buffer... attempting to avoid the sync points?

Yes, the NO_OVERWRITE hint gives the driver a 3rd option -- just give the application access to the buffer without syncing or creating extra allocations -- however, the results are undefined if you disobey the hint and do actually overwrite existing data ;)

This topic is closed to new replies.

Advertisement