From 24b26e3097fc781efd72f3a1507dba25aa9aa025 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 22 Mar 2016 19:18:46 -0700 Subject: [PATCH] first few elements --- libraries/gpu/src/gpu/Texture.cpp | 36 +++++++++++++++++++++++++++++-- libraries/gpu/src/gpu/Texture.h | 20 ++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 3f2415d240..8b219a55de 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -17,6 +17,30 @@ using namespace gpu; +std::atomic Texture::_textureSystemMemoryUsage; +std::atomic Texture::_textureVideoMemoryUsage; + +uint32_t Texture::getCurrentSystemMemoryUsage() { + return _textureSystemMemoryUsage.load(); +} +uint32_t Texture::getCurrentVideoMemoryUsage() { + return _textureVideoMemoryUsage.load(); +} + +void Texture::addSystemMemoryUsage(uint32_t memorySize) { + _textureSystemMemoryUsage.fetch_add(memorySize); +} +void Texture::subSystemMemoryUsage(uint32_t memorySize) { + _textureSystemMemoryUsage.fetch_sub(memorySize); +} + +void Texture::addVideoMemoryUsage(uint32_t memorySize) { + _textureVideoMemoryUsage.fetch_add(memorySize); +} +void Texture::subVideoMemoryUsage(uint32_t memorySize) { + _textureVideoMemoryUsage.fetch_sub(memorySize); +} + uint8 Texture::NUM_FACES_PER_TYPE[NUM_TYPES] = {1, 1, 1, 6}; Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) : @@ -28,6 +52,15 @@ Texture::Pixels::Pixels(const Element& format, Size size, const Byte* bytes) : Texture::Pixels::~Pixels() { } +Texture::Size Texture::Pixels::resize(Size pSize) { + return _sysmem.resize(pSize); +} + +void Texture::Pixels::notifyGPULoaded() { + _isGPULoaded = true; + _sysmem.resize(0); +} + void Texture::Storage::assignTexture(Texture* texture) { _texture = texture; if (_texture) { @@ -60,8 +93,7 @@ const Texture::PixelsPointer Texture::Storage::getMipFace(uint16 level, uint8 fa void Texture::Storage::notifyMipFaceGPULoaded(uint16 level, uint8 face) const { PixelsPointer mipFace = getMipFace(level, face); if (mipFace && (_type != TEX_CUBE)) { - mipFace->_isGPULoaded = true; - mipFace->_sysmem.resize(0); + mipFace->notifyGPULoaded(); } } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index e05dc84c25..106b179f69 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -15,6 +15,7 @@ #include //min max and more #include +#include #include @@ -138,8 +139,20 @@ protected: }; class Texture : public Resource { + static std::atomic _textureSystemMemoryUsage; + static std::atomic _textureVideoMemoryUsage; + + void addSystemMemoryUsage(uint32_t memorySize); + void subSystemMemoryUsage(uint32_t memorySize); + + void addVideoMemoryUsage(uint32_t memorySize); + void subVideoMemoryUsage(uint32_t memorySize); + public: + uint32_t getCurrentSystemMemoryUsage(); + uint32_t getCurrentVideoMemoryUsage(); + class Usage { public: enum FlagBit { @@ -194,8 +207,13 @@ public: Pixels(const Element& format, Size size, const Byte* bytes); ~Pixels(); - Sysmem _sysmem; + Size getSize() const { return _sysmem.getSize(); } + Size resize(Size pSize); + void notifyGPULoaded(); + + protected: Element _format; + Sysmem _sysmem; bool _isGPULoaded; }; typedef std::shared_ptr< Pixels > PixelsPointer;