Jump to content
  • Advertisement
Sign in to follow this  
timfrombriz

What happens when I lock a surface in DirectX?

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

What happens when you lock a surface in DirectDraw?

I know it makes available a pointer to the pixel array and you tell it your done with unlock but..

If you have a surface created in video memory, does it provide a pointer to video memory or does it copy it system memory and provide a ptr for that?

I presume it would have to be in system memory, but in profiling ive done, locking the fullscreen vs locking a small rect area, the small rect area is slower? This indicates that memory must not be copied between the GPU memory and system memory otherwise it would show being faster.

On this presumption, why do you get a video memory pointer within the range of system memory (ie. 4Gb on 32bit systems).

I read that during lock/unlock, the system behaves differently and you should avoid certain things. Is this true? Can something explain what this is all about?

Do these behaviours apply to say SDL under Windows as well, thus being a hardware based thing, or is it specific to the graphics framework your working.

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
AFAIK To be able to Lock()/Unlock() you have to create the surfaces with the DYNAMIC flag. And when a resource is created with DYNAMIC flag it will be stored in a region of memory that is accessible to both the CPU and the GPU, so I think that when you Lock() a resource you simply set a flag said that it can't be accessed by the GPU and so on.

Share this post


Link to post
Share on other sites
This is entirely driver and hardware dependent (well, the driver will make the decision based on hardware capabilities). Generally speaking, there are a lot of ways to achieve this, but some are faster than others, so the driver attempts to choose the fastest based on what it knows (about hardware, semantics, usage, etc). There are certain logical constraints where blocking may occur on the CPU (lock to read - so if you do lock to read, make sure that it is read several frames later) or write (without discard or overwrite semantics). Apart from this, I would never make any assumptions about copying or obtaining direct pointers on any OS or any API.

Share this post


Link to post
Share on other sites
This is all very driver specific but generally speaking: You cannot get a video memory pointer in XP and earlier, you can in Vista and later but you probably won't. The driver and hardware use fairly complex formats internally which may need to be converted, and the resource you're locking may not be available besides. If you lock a rect, it has to make a solid block of memory containing only that rect, which pretty much forces a copy. If you don't specify the discard flag, then the driver may also have to copy memory back from the GPU so that the surface contents are what you expect. The safe assumption is that lock is always a pair of copies, once to read (if you don't discard) and once to write (may be altered by no overwrite flag).

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!