From 3356486f277169db83eecb9cdda223695c756b75 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 17 May 2018 14:33:46 -0700 Subject: [PATCH] Fix populated texture size tracking --- .../gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp | 6 +++--- .../gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp | 2 +- .../gpu/gl45/GL45BackendVariableTexture.cpp | 18 +++++++++--------- .../src/gpu/gles/GLESBackendTexture.cpp | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 624cb4f656..00f7ae284f 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -338,8 +338,7 @@ Size GL41VariableAllocationTexture::copyMipsFromTexture() { amount += copyMipFaceFromTexture(sourceMip, targetMip, face); } } - - + incrementPopulatedSize(amount); return amount; } @@ -348,7 +347,6 @@ Size GL41VariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, ui withPreservedTexture([&] { amountCopied = Parent::copyMipFaceLinesFromTexture(mip, face, size, yOffset, internalFormat, format, type, sourceSize, sourcePointer); }); - incrementPopulatedSize(amountCopied); return amountCopied; } @@ -609,6 +607,8 @@ void GL41VariableAllocationTexture::populateTransferQueue(TransferQueue& pending // queue up the sampler and populated mip change for after the transfer has completed pendingTransfers.emplace(new TransferJob([=] { _populatedMip = sourceMip; + incrementPopulatedSize(_gpuObject.evalMipSize(sourceMip)); + sanityCheck(); syncSampler(); })); } while (sourceMip != _allocatedMip); diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index b0ae1296e9..558f221705 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -123,7 +123,7 @@ GLTexture* GL45Backend::syncGPUObject(const TexturePointer& texturePointer) { } void GL45Backend::initTextureManagementStage() { - GLBackend::initTextureManagementStage(); + GLBackend::initTextureManagementStage(); // enable the Sparse Texture on gl45 _textureManagement._sparseCapable = true; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index fe74336b2a..713b99fc77 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -54,7 +54,6 @@ const GL45Texture::Bindless& GL45VariableAllocationTexture::getBindless() const Size GL45VariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, uint8_t face, const uvec3& size, uint32_t yOffset, GLenum internalFormat, GLenum format, GLenum type, Size sourceSize, const void* sourcePointer) const { Size amountCopied = 0; amountCopied = Parent::copyMipFaceLinesFromTexture(mip, face, size, yOffset, internalFormat, format, type, sourceSize, sourcePointer); - incrementPopulatedSize(amountCopied); return amountCopied; } @@ -81,7 +80,6 @@ void GL45VariableAllocationTexture::copyTextureMipsInGPUMem(GLuint srcId, GLuint copyTexGPUMem(_gpuObject, _target, srcId, destId, numMips, srcMipOffset, destMipOffset, populatedMips); } - // Managed size resource textures using GL45ResourceTexture = GL45Backend::GL45ResourceTexture; @@ -132,6 +130,7 @@ Size GL45ResourceTexture::copyMipsFromTexture() { amount += copyMipFaceFromTexture(sourceMip, targetMip, face); } } + incrementPopulatedSize(amount); return amount; } @@ -139,7 +138,7 @@ void GL45ResourceTexture::syncSampler() const { Parent::syncSampler(); #if GPU_BINDLESS_TEXTURES if (!isBindless()) { - glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip); + glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip); } #else glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip); @@ -169,7 +168,7 @@ size_t GL45ResourceTexture::promote() { // allocate storage for new level allocateStorage(targetAllocatedMip); - + // copy pre-existing mips copyTextureMipsInGPUMem(oldId, _id, oldAllocatedMip, _allocatedMip, _populatedMip); @@ -230,14 +229,14 @@ size_t GL45ResourceTexture::demote() { // update the memory usage Backend::textureResourceGPUMemSize.update(oldSize, 0); - // Demoting unpopulate the memory delta + // Demoting unpopulate the memory delta if (oldPopulatedMip != _populatedMip) { auto numPopulatedDemoted = _populatedMip - oldPopulatedMip; Size amountUnpopulated = 0; for (int i = 0; i < numPopulatedDemoted; i++) { - amountUnpopulated += _gpuObject.evalMipSize(oldPopulatedMip + i); + amountUnpopulated += _gpuObject.evalMipSize(oldPopulatedMip + i); } - decrementPopulatedSize(amountUnpopulated); + decrementPopulatedSize(amountUnpopulated); } return (oldSize - _size); } @@ -268,12 +267,12 @@ void GL45ResourceTexture::populateTransferQueue(TransferQueue& pendingTransfers) continue; } - // break down the transfers into chunks so that no single transfer is + // break down the transfers into chunks so that no single transfer is // consuming more than X bandwidth // For compressed format, regions must be a multiple of the 4x4 tiles, so enforce 4 lines as the minimum block auto mipSize = _gpuObject.getStoredMipFaceSize(sourceMip, face); const auto lines = mipDimensions.y; - const uint32_t BLOCK_NUM_LINES { 4 }; + const uint32_t BLOCK_NUM_LINES{ 4 }; const auto numBlocks = (lines + (BLOCK_NUM_LINES - 1)) / BLOCK_NUM_LINES; auto bytesPerBlock = mipSize / numBlocks; Q_ASSERT(0 == (mipSize % lines)); @@ -289,6 +288,7 @@ void GL45ResourceTexture::populateTransferQueue(TransferQueue& pendingTransfers) // queue up the sampler and populated mip change for after the transfer has completed pendingTransfers.emplace(new TransferJob([=] { _populatedMip = sourceMip; + incrementPopulatedSize(_gpuObject.evalMipSize(sourceMip)); sanityCheck(); syncSampler(); })); diff --git a/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp b/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp index 2ffa421bc8..7419221889 100644 --- a/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp +++ b/libraries/gpu-gles/src/gpu/gles/GLESBackendTexture.cpp @@ -401,8 +401,7 @@ Size GLESVariableAllocationTexture::copyMipsFromTexture() { amount += copyMipFaceFromTexture(sourceMip, targetMip, face); } } - - + incrementPopulatedSize(amount); return amount; } @@ -411,7 +410,6 @@ Size GLESVariableAllocationTexture::copyMipFaceLinesFromTexture(uint16_t mip, ui withPreservedTexture([&] { amountCopied = Parent::copyMipFaceLinesFromTexture(mip, face, size, yOffset, internalFormat, format, type, sourceSize, sourcePointer); }); - incrementPopulatedSize(amountCopied); return amountCopied; } @@ -673,6 +671,8 @@ void GLESVariableAllocationTexture::populateTransferQueue(TransferJob::Queue& qu // queue up the sampler and populated mip change for after the transfer has completed queue.emplace(new TransferJob([=] { _populatedMip = sourceMip; + incrementPopulatedSize(_gpuObject.evalMipSize(sourceMip)); + sanityCheck(); syncSampler(); })); } while (sourceMip != _allocatedMip);