Sign in to follow this  

"Don't read from a subresource mapped for writing" ...

Recommended Posts

At least thats what MSDN tells you for mapping DX11-resources (https://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx).

 

Now, how hard can this really be? I mean, why would I read from a buffer that I only intend on writing to? Thats just ridiculous (discount the example about generated assembly).

 

Then theres this:

SpriteVertex* pBuffer = m_pMapped + m_nextFreeID;

pBuffer->leftPos = vPosition.x;
pBuffer->rightPos = pBuffer->leftPos + vSize.x;
pBuffer->topPos = -vPosition.y;
pBuffer->bottomPos = -pBuffer->rightPos - vSize.y;

You should probably be able to spot the problem right away, but I had this exact code for over 2(!) years, until my profiler recently showed a decent amount of time spent on those two lines. Quess DRY is not always your best bet. :/

 

Did you fall for something similar?

Share this post


Link to post
Share on other sites

Thats just ridiculous (discount the example about generated assembly).

 

It gets worse:  https://fgiesen.wordpress.com/2013/01/29/write-combining-is-not-your-friend/

 

There's a couple of additional strong recommendations:  Always write sequentially, and don't leave any holes.  IIRC violating the latter rule can even result in a cacheline read by the CPU on at least one arch - although I can't find a proper source/docs for that.

 

My golden rule now is:  Always use memcpy.  Always.  For the entire buffer.  *Always*.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this