Make rendering stats thread safe [Core feature] (#4059)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Adrian Cojocaru <adrian.cojocaru92@yahoo.com>
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
Alex Cristici
2026-01-21 02:49:45 +02:00
committed by GitHub
parent 4fab83669a
commit a8622a3a4f
5 changed files with 65 additions and 34 deletions

View File

@@ -224,8 +224,10 @@ void Texture2D::uploadSubRegion(const void* pixelData,
context.enqueueDeletion(std::move(function));
}
context.renderingStats().numTextureUpdates++;
context.renderingStats().textureUpdateBytes += bufferInfo.size;
context.threadSafeAccessRenderingStats([&](gfx::RenderingStats& stats) {
stats.numTextureUpdates++;
stats.textureUpdateBytes += bufferInfo.size;
});
}
vk::Format Texture2D::vulkanFormat(const gfx::TexturePixelType pixel, gfx::TextureChannelDataType channel) {
@@ -385,9 +387,11 @@ void Texture2D::createTexture() {
imageLayout = imageCreateInfo.initialLayout;
}
context.renderingStats().numCreatedTextures++;
context.renderingStats().numActiveTextures++;
context.renderingStats().memTextures += getDataSize();
context.threadSafeAccessRenderingStats([&](gfx::RenderingStats& stats) {
stats.numCreatedTextures++;
stats.numActiveTextures++;
stats.memTextures += getDataSize();
});
textureDirty = false;
lastModified = util::MonotonicTimer::now();
@@ -431,8 +435,10 @@ void Texture2D::destroyTexture() {
imageLayout = vk::ImageLayout::eUndefined;
context.renderingStats().numActiveTextures--;
context.renderingStats().memTextures -= Texture2D::getDataSize();
context.threadSafeAccessRenderingStats([&](gfx::RenderingStats& stats) {
stats.numActiveTextures--;
stats.memTextures -= Texture2D::getDataSize();
});
}
}