# "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 on other sites

Mines not a bug, but a massive performance hit.....

I had this set on a GPU only texture.

D3D11.CpuAccessFlags.Write

Wondered why my frame rate dipped by 25%.....

##### Share on other sites

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

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*.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628735
• Total Posts
2984449

• 25
• 11
• 10
• 16
• 14