From ef12358cebd118955f74d68111ff678bb7b256a3 Mon Sep 17 00:00:00 2001 From: Baldur Karlsson Date: Wed, 14 Mar 2018 15:29:35 +0000 Subject: [PATCH] Hash all properties of mesh config that affect highlighting. Closes #918 --- renderdoc/replay/replay_driver.cpp | 38 ++++++++++++++++++++++++------ renderdoc/replay/replay_driver.h | 9 +++---- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/renderdoc/replay/replay_driver.cpp b/renderdoc/replay/replay_driver.cpp index 5bc352f12..7c19290a5 100644 --- a/renderdoc/replay/replay_driver.cpp +++ b/renderdoc/replay/replay_driver.cpp @@ -290,20 +290,44 @@ FloatVector HighlightCache::InterpretVertex(byte *data, uint32_t vert, const Mes return ret; } +uint64_t inthash(uint64_t val, uint64_t seed) +{ + return (seed << 5) + seed + val; /* hash * 33 + c */ +} + +uint64_t inthash(ResourceId id, uint64_t seed) +{ + uint64_t val = 0; + memcpy(&val, &id, sizeof(val)); + return (seed << 5) + seed + val; /* hash * 33 + c */ +} + void HighlightCache::CacheHighlightingData(uint32_t eventId, const MeshDisplay &cfg) { - if(EID != eventId || cfg.type != stage || cfg.position.vertexResourceId != buf || - cfg.position.vertexByteOffset != offs) + std::string ident; + + uint64_t newKey = 5381; + + // hash all the properties of cfg that we use + newKey = inthash(eventId, newKey); + newKey = inthash(cfg.position.indexByteStride, newKey); + newKey = inthash(cfg.position.numIndices, newKey); + newKey = inthash((uint64_t)cfg.type, newKey); + newKey = inthash((uint64_t)cfg.position.baseVertex, newKey); + newKey = inthash((uint64_t)cfg.position.topology, newKey); + newKey = inthash(cfg.position.vertexByteOffset, newKey); + newKey = inthash(cfg.position.vertexByteStride, newKey); + newKey = inthash(cfg.position.indexResourceId, newKey); + newKey = inthash(cfg.position.vertexResourceId, newKey); + + if(cacheKey != newKey) { - EID = eventId; - buf = cfg.position.vertexResourceId; - offs = cfg.position.vertexByteOffset; - stage = cfg.type; + cacheKey = newKey; uint32_t bytesize = cfg.position.indexByteStride; uint64_t maxIndex = cfg.position.numIndices - 1; - if(cfg.position.indexByteStride == 0 || stage == MeshDataStage::GSOut) + if(cfg.position.indexByteStride == 0 || cfg.type == MeshDataStage::GSOut) { indices.clear(); idxData = false; diff --git a/renderdoc/replay/replay_driver.h b/renderdoc/replay/replay_driver.h index 61723ee77..929945a1c 100644 --- a/renderdoc/replay/replay_driver.h +++ b/renderdoc/replay/replay_driver.h @@ -234,15 +234,12 @@ void PatchLineStripIndexBuffer(const DrawcallDescription *draw, uint8_t *idx8, u // mesh, not jumping back and forth much between meshes. struct HighlightCache { - HighlightCache() : EID(0), buf(), offs(0), stage(MeshDataStage::Unknown), idxData(false) {} + HighlightCache() : cacheKey(0), idxData(false) {} IRemoteDriver *driver = NULL; - uint32_t EID; - ResourceId buf; - uint64_t offs; - MeshDataStage stage; - bool idxData; + uint64_t cacheKey; + bool idxData; bytebuf vertexData; std::vector indices;