Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track image data size independently of the pixelData array size #804

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cesium3DTilesSelection/src/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ int64_t Tile::computeByteSize() const noexcept {
bytes -= bufferViews[size_t(bufferView)].byteLength;
}

bytes += int64_t(image.cesium.pixelData.size());
// sizeBytes is set in TilesetContentManager::ContentKindSetter, if not
// sooner (e.g., by the renderer implementation).
bytes += image.cesium.sizeBytes;
}
}

Expand Down
10 changes: 10 additions & 0 deletions Cesium3DTilesSelection/src/TilesetContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ struct ContentKindSetter {
}

void operator()(CesiumGltf::Model&& model) {
for (CesiumGltf::Image& image : model.images) {
// If the image size hasn't been overridden, store the pixelData
// size now. We'll be adding this number to our total memory usage soon,
// and remove it when the tile is later unloaded, and we must use
// the same size in each case.
if (image.cesium.sizeBytes < 0) {
image.cesium.sizeBytes = int64_t(image.cesium.pixelData.size());
}
}

auto pRenderContent = std::make_unique<TileRenderContent>(std::move(model));
pRenderContent->setRenderResources(pRenderResources);
if (rasterOverlayDetails) {
Expand Down
17 changes: 16 additions & 1 deletion CesiumGltf/include/CesiumGltf/ImageCesium.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct CESIUMGLTF_API ImageCesium final {
* Otherwise, this buffer will store the compressed pixel data in the
* specified format.
*
* If mipOffsets is not empty, this buffer will contains multiple mips
* If mipPositions is not empty, this buffer will contains multiple mips
* back-to-back.
*
* When this is an uncompressed texture:
Expand All @@ -95,5 +95,20 @@ struct CESIUMGLTF_API ImageCesium final {
* | 4 | red, green, blue, alpha |
*/
std::vector<std::byte> pixelData;

/**
* @brief The effective size of this image, in bytes, for estimating resource
* usage for caching purposes.
*
* When this value is less than zero (the default), the size of this image
* should be assumed to equal the size of the {@link pixelData} array. When
* it is greater than or equal to zero, the specified size should be used
* instead. For example, the overridden size may account for:
* * The `pixelData` being cleared during the load process in order to save
* memory.
* * The cost of any renderer resources (e.g., GPU textures) created for
* this image.
*/
int64_t sizeBytes = -1;
};
} // namespace CesiumGltf
14 changes: 12 additions & 2 deletions CesiumRasterOverlays/src/RasterOverlayTileProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ RasterOverlayTileProvider::getTile(
void RasterOverlayTileProvider::removeTile(RasterOverlayTile* pTile) noexcept {
assert(pTile->getReferenceCount() == 0);

this->_tileDataBytes -= int64_t(pTile->getImage().pixelData.size());
this->_tileDataBytes -= pTile->getImage().sizeBytes;
}

CesiumAsync::Future<TileProviderAndTile>
Expand Down Expand Up @@ -343,7 +343,17 @@ CesiumAsync::Future<TileProviderAndTile> RasterOverlayTileProvider::doLoad(
: RasterOverlayTile::MoreDetailAvailable::No;
pTile->setState(result.state);

thiz->_tileDataBytes += int64_t(pTile->getImage().pixelData.size());
ImageCesium& imageCesium = pTile->getImage();

// If the image size hasn't been overridden, store the pixelData
// size now. We'll add this number to our total memory usage now,
// and remove it when the tile is later unloaded, and we must use
// the same size in each case.
if (imageCesium.sizeBytes < 0) {
imageCesium.sizeBytes = int64_t(imageCesium.pixelData.size());
}

thiz->_tileDataBytes += imageCesium.sizeBytes;

thiz->finalizeTileLoad(isThrottledLoad);

Expand Down
Loading