d3d12: Fix alloc function
It may generate wrong result in very rare circumstance, although I never experienced it.
This commit is contained in:
@@ -137,26 +137,25 @@ struct DataHeap
|
|||||||
*/
|
*/
|
||||||
bool canAlloc(size_t size)
|
bool canAlloc(size_t size)
|
||||||
{
|
{
|
||||||
size_t putPos = m_putPos, getPos = m_getPos;
|
|
||||||
size_t allocSize = align(size, Alignment);
|
size_t allocSize = align(size, Alignment);
|
||||||
if (putPos + allocSize < m_size)
|
if (m_putPos + allocSize < m_size)
|
||||||
{
|
{
|
||||||
// range before get
|
// range before get
|
||||||
if (putPos + allocSize < getPos)
|
if (m_putPos + allocSize < m_getPos)
|
||||||
return true;
|
return true;
|
||||||
// range after get
|
// range after get
|
||||||
if (putPos > getPos)
|
if (m_putPos > m_getPos)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ..]....[..get..
|
// ..]....[..get..
|
||||||
if (putPos < getPos)
|
if (m_putPos < m_getPos)
|
||||||
return false;
|
return false;
|
||||||
// ..get..]...[...
|
// ..get..]...[...
|
||||||
// Actually all resources extending beyond heap space starts at 0
|
// Actually all resources extending beyond heap space starts at 0
|
||||||
if (allocSize > getPos)
|
if (allocSize > m_getPos)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -165,15 +164,16 @@ struct DataHeap
|
|||||||
size_t alloc(size_t size)
|
size_t alloc(size_t size)
|
||||||
{
|
{
|
||||||
assert(canAlloc(size));
|
assert(canAlloc(size));
|
||||||
size_t putPos = m_putPos;
|
size_t allocSize = align(size, Alignment);
|
||||||
if (putPos + size < m_size)
|
if (m_putPos + allocSize < m_size)
|
||||||
{
|
{
|
||||||
m_putPos += align(size, Alignment);
|
size_t oldPutPos = m_putPos;
|
||||||
return putPos;
|
m_putPos += allocSize;
|
||||||
|
return oldPutPos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_putPos = align(size, Alignment);
|
m_putPos = allocSize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user