Merge pull request #11288 from birarda/feat/bake-with-compression

enable compression in image library from Asset Server
This commit is contained in:
Clément Brisset 2017-09-12 14:08:03 -07:00 committed by GitHub
commit c1685d827e
5 changed files with 46 additions and 52 deletions

View file

@ -266,6 +266,18 @@ AssetServer::AssetServer(ReceivedMessage& message) :
_transferTaskPool(this), _transferTaskPool(this),
_bakingTaskPool(this) _bakingTaskPool(this)
{ {
// store the current state of image compression so we can reset it when this assignment is complete
_wasColorTextureCompressionEnabled = image::isColorTexturesCompressionEnabled();
_wasGrayscaleTextureCompressionEnabled = image::isGrayscaleTexturesCompressionEnabled();
_wasNormalTextureCompressionEnabled = image::isNormalTexturesCompressionEnabled();
_wasCubeTextureCompressionEnabled = image::isCubeTexturesCompressionEnabled();
// enable compression in image library
image::setColorTexturesCompressionEnabled(true);
image::setGrayscaleTexturesCompressionEnabled(true);
image::setNormalTexturesCompressionEnabled(true);
image::setCubeTexturesCompressionEnabled(true);
BAKEABLE_TEXTURE_EXTENSIONS = TextureBaker::getSupportedFormats(); BAKEABLE_TEXTURE_EXTENSIONS = TextureBaker::getSupportedFormats();
qDebug() << "Supported baking texture formats:" << BAKEABLE_MODEL_EXTENSIONS; qDebug() << "Supported baking texture formats:" << BAKEABLE_MODEL_EXTENSIONS;
@ -296,6 +308,14 @@ AssetServer::AssetServer(ReceivedMessage& message) :
#endif #endif
} }
void AssetServer::aboutToFinish() {
// re-set defaults in image library
image::setColorTexturesCompressionEnabled(_wasCubeTextureCompressionEnabled);
image::setGrayscaleTexturesCompressionEnabled(_wasGrayscaleTextureCompressionEnabled);
image::setNormalTexturesCompressionEnabled(_wasNormalTextureCompressionEnabled);
image::setCubeTexturesCompressionEnabled(_wasCubeTextureCompressionEnabled);
}
void AssetServer::run() { void AssetServer::run() {
qCDebug(asset_server) << "Waiting for connection to domain to request settings from domain-server."; qCDebug(asset_server) << "Waiting for connection to domain to request settings from domain-server.";
@ -1086,7 +1106,7 @@ bool AssetServer::renameMapping(AssetPath oldPath, AssetPath newPath) {
_fileMappings.erase(it); _fileMappings.erase(it);
// in case we're overwriting, keep the current destination mapping for potential rollback // in case we're overwriting, keep the current destination mapping for potential rollback
auto oldDestinationMapping = _fileMappings.find(newPath)->second; auto oldDestinationIt = _fileMappings.find(newPath);
if (!oldSourceMapping.isEmpty()) { if (!oldSourceMapping.isEmpty()) {
_fileMappings[newPath] = oldSourceMapping; _fileMappings[newPath] = oldSourceMapping;
@ -1100,9 +1120,9 @@ bool AssetServer::renameMapping(AssetPath oldPath, AssetPath newPath) {
// we couldn't persist the renamed mapping, rollback and return failure // we couldn't persist the renamed mapping, rollback and return failure
_fileMappings[oldPath] = oldSourceMapping; _fileMappings[oldPath] = oldSourceMapping;
if (!oldDestinationMapping.isNull()) { if (oldDestinationIt != _fileMappings.end()) {
// put back the overwritten mapping for the destination path // put back the overwritten mapping for the destination path
_fileMappings[newPath] = oldDestinationMapping; _fileMappings[newPath] = oldDestinationIt->second;
} else { } else {
// clear the new mapping // clear the new mapping
_fileMappings.erase(_fileMappings.find(newPath)); _fileMappings.erase(_fileMappings.find(newPath));
@ -1322,7 +1342,8 @@ bool AssetServer::setBakingEnabled(const AssetPathList& paths, bool enabled) {
auto bakedMapping = getBakeMapping(hash, bakedFilename); auto bakedMapping = getBakeMapping(hash, bakedFilename);
bool currentlyDisabled = (_fileMappings.value(bakedMapping) == hash); auto it = _fileMappings.find(bakedMapping);
bool currentlyDisabled = (it != _fileMappings.end() && it->second == hash);
if (enabled && currentlyDisabled) { if (enabled && currentlyDisabled) {
QStringList bakedMappings{ bakedMapping }; QStringList bakedMappings{ bakedMapping };

View file

@ -64,6 +64,8 @@ class AssetServer : public ThreadedAssignment {
public: public:
AssetServer(ReceivedMessage& message); AssetServer(ReceivedMessage& message);
void aboutToFinish() override;
public slots: public slots:
void run() override; void run() override;
@ -137,6 +139,11 @@ private:
QHash<AssetHash, std::shared_ptr<BakeAssetTask>> _pendingBakes; QHash<AssetHash, std::shared_ptr<BakeAssetTask>> _pendingBakes;
QThreadPool _bakingTaskPool; QThreadPool _bakingTaskPool;
bool _wasColorTextureCompressionEnabled { false };
bool _wasGrayscaleTextureCompressionEnabled { false };
bool _wasNormalTextureCompressionEnabled { false };
bool _wasCubeTextureCompressionEnabled { false };
}; };
#endif #endif

View file

@ -333,30 +333,6 @@ void setupPreferences() {
preferences->addPreference(preference); preferences->addPreference(preference);
} }
} }
{
auto getter = []()->bool { return image::isColorTexturesCompressionEnabled(); };
auto setter = [](bool value) { return image::setColorTexturesCompressionEnabled(value); };
auto preference = new CheckPreference(RENDER, "Compress Color Textures", getter, setter);
preferences->addPreference(preference);
}
{
auto getter = []()->bool { return image::isNormalTexturesCompressionEnabled(); };
auto setter = [](bool value) { return image::setNormalTexturesCompressionEnabled(value); };
auto preference = new CheckPreference(RENDER, "Compress Normal Textures", getter, setter);
preferences->addPreference(preference);
}
{
auto getter = []()->bool { return image::isGrayscaleTexturesCompressionEnabled(); };
auto setter = [](bool value) { return image::setGrayscaleTexturesCompressionEnabled(value); };
auto preference = new CheckPreference(RENDER, "Compress Grayscale Textures", getter, setter);
preferences->addPreference(preference);
}
{
auto getter = []()->bool { return image::isCubeTexturesCompressionEnabled(); };
auto setter = [](bool value) { return image::setCubeTexturesCompressionEnabled(value); };
auto preference = new CheckPreference(RENDER, "Compress Cube Textures", getter, setter);
preferences->addPreference(preference);
}
} }
{ {
static const QString RENDER("Networking"); static const QString RENDER("Networking");

View file

@ -22,7 +22,6 @@
#include <Profile.h> #include <Profile.h>
#include <StatTracker.h> #include <StatTracker.h>
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <SettingHandle.h>
#include "ImageLogging.h" #include "ImageLogging.h"
@ -30,18 +29,17 @@ using namespace gpu;
#define CPU_MIPMAPS 1 #define CPU_MIPMAPS 1
static std::mutex settingsMutex;
static Setting::Handle<bool> compressColorTextures("hifi.graphics.compressColorTextures", false);
static Setting::Handle<bool> compressNormalTextures("hifi.graphics.compressNormalTextures", false);
static Setting::Handle<bool> compressGrayscaleTextures("hifi.graphics.compressGrayscaleTextures", false);
static Setting::Handle<bool> compressCubeTextures("hifi.graphics.compressCubeTextures", false);
static const glm::uvec2 SPARSE_PAGE_SIZE(128); static const glm::uvec2 SPARSE_PAGE_SIZE(128);
static const glm::uvec2 MAX_TEXTURE_SIZE(4096); static const glm::uvec2 MAX_TEXTURE_SIZE(4096);
bool DEV_DECIMATE_TEXTURES = false; bool DEV_DECIMATE_TEXTURES = false;
std::atomic<size_t> DECIMATED_TEXTURE_COUNT{ 0 }; std::atomic<size_t> DECIMATED_TEXTURE_COUNT{ 0 };
std::atomic<size_t> RECTIFIED_TEXTURE_COUNT{ 0 }; std::atomic<size_t> RECTIFIED_TEXTURE_COUNT{ 0 };
static std::atomic<bool> compressColorTextures { false };
static std::atomic<bool> compressNormalTextures { false };
static std::atomic<bool> compressGrayscaleTextures { false };
static std::atomic<bool> compressCubeTextures { false };
bool needsSparseRectification(const glm::uvec2& size) { bool needsSparseRectification(const glm::uvec2& size) {
// Don't attempt to rectify small textures (textures less than the sparse page size in any dimension) // Don't attempt to rectify small textures (textures less than the sparse page size in any dimension)
if (glm::any(glm::lessThan(size, SPARSE_PAGE_SIZE))) { if (glm::any(glm::lessThan(size, SPARSE_PAGE_SIZE))) {
@ -150,8 +148,7 @@ gpu::TexturePointer TextureUsage::createCubeTextureFromImageWithoutIrradiance(co
bool isColorTexturesCompressionEnabled() { bool isColorTexturesCompressionEnabled() {
#if CPU_MIPMAPS #if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex); return compressColorTextures.load();
return compressColorTextures.get();
#else #else
return false; return false;
#endif #endif
@ -159,8 +156,7 @@ bool isColorTexturesCompressionEnabled() {
bool isNormalTexturesCompressionEnabled() { bool isNormalTexturesCompressionEnabled() {
#if CPU_MIPMAPS #if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex); return compressNormalTextures.load();
return compressNormalTextures.get();
#else #else
return false; return false;
#endif #endif
@ -168,8 +164,7 @@ bool isNormalTexturesCompressionEnabled() {
bool isGrayscaleTexturesCompressionEnabled() { bool isGrayscaleTexturesCompressionEnabled() {
#if CPU_MIPMAPS #if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex); return compressGrayscaleTextures.load();
return compressGrayscaleTextures.get();
#else #else
return false; return false;
#endif #endif
@ -177,31 +172,26 @@ bool isGrayscaleTexturesCompressionEnabled() {
bool isCubeTexturesCompressionEnabled() { bool isCubeTexturesCompressionEnabled() {
#if CPU_MIPMAPS #if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex); return compressCubeTextures.load();
return compressCubeTextures.get();
#else #else
return false; return false;
#endif #endif
} }
void setColorTexturesCompressionEnabled(bool enabled) { void setColorTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex); compressColorTextures.store(enabled);
compressColorTextures.set(enabled);
} }
void setNormalTexturesCompressionEnabled(bool enabled) { void setNormalTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex); compressNormalTextures.store(enabled);
compressNormalTextures.set(enabled);
} }
void setGrayscaleTexturesCompressionEnabled(bool enabled) { void setGrayscaleTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex); compressGrayscaleTextures.store(enabled);
compressGrayscaleTextures.set(enabled);
} }
void setCubeTexturesCompressionEnabled(bool enabled) { void setCubeTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex); compressCubeTextures.store(enabled);
compressCubeTextures.set(enabled);
} }

View file

@ -44,7 +44,7 @@ Oven::Oven(int argc, char* argv[]) :
parser.addHelpOption(); parser.addHelpOption();
parser.process(*this); parser.process(*this);
// enable compression in image library, except for cube maps // enable compression in image library
image::setColorTexturesCompressionEnabled(true); image::setColorTexturesCompressionEnabled(true);
image::setGrayscaleTexturesCompressionEnabled(true); image::setGrayscaleTexturesCompressionEnabled(true);
image::setNormalTexturesCompressionEnabled(true); image::setNormalTexturesCompressionEnabled(true);