Why Microsoft put restriction for locking Depth Buffer with Format other than D16_Lockable and D32_Lockable in DirectX9 runtime?

StackOverflow https://stackoverflow.com/questions/23316666

  •  10-07-2023
  •  | 
  •  

Question

E.g we can't lock depth buffer with format D24S8 using DX9 API LockRect(), however using the same API we can lock depth buffer with format D16_Lockable and D32_Lockable.

Was it helpful?

Solution

Many GPUs will not keep a memory linear depth buffer around at all for best performance. It might be just a span buffer, an optimized swizzled buffer, or some kind of tree. This helps the GPU a lot. But if you were to lock such a buffer the GPU would have to convert it to a linear buffer which might be costly. So by getting a lockable buffer to begin with, you tell the GPU to skip all those tricks and build a linear buffer from the start.

Implementations might still be different, but that is the idea behind having an API choice between lockable and not. It allows the driver to optimize for each case.

By saying "D24S8" you tell the drive what you expect the buffer to do in precision, features and rendering. It is then free to implement it in any weird way. By saying "Lockable" you tell it to skip optimization that would hurt memory mapped readback later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top