Implement proper out-of-bounds value filling for vulkan post-vs fetch

This commit is contained in:
baldurk
2021-04-23 19:07:31 +01:00
parent 659c75319b
commit e78a48bfc3
3 changed files with 43 additions and 6 deletions
+32 -6
View File
@@ -2079,30 +2079,49 @@ void VulkanReplay::FetchVSOut(uint32_t eventId, VulkanRenderState &state)
vkr = m_pDriver->vkBindBufferMemory(dev, vbuffers[attr].buf, vbuffers[attr].mem, 0);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
byte *compactedData = NULL;
vkr = m_pDriver->vkMapMemory(m_Device, vbuffers[attr].mem, 0, VK_WHOLE_SIZE, 0,
(void **)&compactedData);
byte *dst = NULL;
vkr =
m_pDriver->vkMapMemory(m_Device, vbuffers[attr].mem, 0, VK_WHOLE_SIZE, 0, (void **)&dst);
RDCASSERTEQUAL(vkr, VK_SUCCESS);
if(compactedData && origVBEnd)
const byte *dstBase = dst;
(void)dstBase;
const byte *dstEnd = dst + bufInfo.size;
if(dst)
{
FloatVector defaultValue(0.0f, 0.0f, 0.0f, 1.0f);
if(fmt.compType == CompType::UInt || fmt.compType == CompType::SInt || fmt.compCount == 4)
defaultValue.w = 0.0f;
const byte *src = origVBBegin;
byte *dst = compactedData;
const byte *dstEnd = dst + bufInfo.size;
// fast memcpy compaction case for regular 32-bit types. Any type like R32G32B32 or so on
// can be memcpy'd into place and read, since we discard any unused components and there's
// no re-interpretation needed.
if(fmt.type == ResourceFormatType::Regular && fmt.compByteWidth == 4)
{
size_t expandedComponentBytes = sizeof(FloatVector) - origElemSize;
while(src < origVBEnd && dst < dstEnd)
{
if(expandedComponentBytes > 0)
memcpy(dst + origElemSize, ((byte *)&defaultValue) + origElemSize,
expandedComponentBytes);
memcpy(dst, src, origElemSize);
// advance by the *destination* element size of 16 bytes
dst += elemSize;
src += stride;
}
// fill the rest with default values
while(dst < dstEnd)
{
memcpy(dst, &defaultValue, sizeof(FloatVector));
dst += elemSize;
}
}
else
{
@@ -2203,6 +2222,13 @@ void VulkanReplay::FetchVSOut(uint32_t eventId, VulkanRenderState &state)
dst += sizeof(FloatVector);
src += stride;
}
// fill the rest with default values
while(dst < dstEnd)
{
memcpy(dst, &defaultValue, sizeof(FloatVector));
dst += elemSize;
}
}
}
}
+3
View File
@@ -308,6 +308,9 @@ FloatVector DecodeFormattedComponents(const ResourceFormat &fmt, const byte *dat
{
FloatVector ret(0.0f, 0.0f, 0.0f, 1.0f);
if(fmt.compType == CompType::UInt || fmt.compType == CompType::SInt || fmt.compCount == 4)
ret.w = 0.0f;
const uint64_t dummy = 0;
if(!data)
data = (const byte *)&dummy;
+8
View File
@@ -587,6 +587,10 @@ FloatVector HighlightCache::InterpretVertex(const byte *data, uint32_t vert, con
{
FloatVector ret(0.0f, 0.0f, 0.0f, 1.0f);
if(cfg.position.format.compType == CompType::UInt ||
cfg.position.format.compType == CompType::SInt || cfg.position.format.compCount == 4)
ret.w = 0.0f;
if(useidx && idxData)
{
if(vert >= (uint32_t)indices.size())
@@ -623,6 +627,10 @@ FloatVector HighlightCache::InterpretVertex(const byte *data, uint32_t vert,
if(data + fmt.ElementSize() > end)
{
valid = false;
if(fmt.compType == CompType::UInt || fmt.compType == CompType::SInt || fmt.compCount == 4)
return FloatVector(0.0f, 0.0f, 0.0f, 0.0f);
return FloatVector(0.0f, 0.0f, 0.0f, 1.0f);
}