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),
_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();
qDebug() << "Supported baking texture formats:" << BAKEABLE_MODEL_EXTENSIONS;
@ -296,6 +308,14 @@ AssetServer::AssetServer(ReceivedMessage& message) :
#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() {
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);
// 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()) {
_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
_fileMappings[oldPath] = oldSourceMapping;
if (!oldDestinationMapping.isNull()) {
if (oldDestinationIt != _fileMappings.end()) {
// put back the overwritten mapping for the destination path
_fileMappings[newPath] = oldDestinationMapping;
_fileMappings[newPath] = oldDestinationIt->second;
} else {
// clear the new mapping
_fileMappings.erase(_fileMappings.find(newPath));
@ -1322,7 +1342,8 @@ bool AssetServer::setBakingEnabled(const AssetPathList& paths, bool enabled) {
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) {
QStringList bakedMappings{ bakedMapping };

View file

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

View file

@ -333,30 +333,6 @@ void setupPreferences() {
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");

View file

@ -22,7 +22,6 @@
#include <Profile.h>
#include <StatTracker.h>
#include <GLMHelpers.h>
#include <SettingHandle.h>
#include "ImageLogging.h"
@ -30,18 +29,17 @@ using namespace gpu;
#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 MAX_TEXTURE_SIZE(4096);
bool DEV_DECIMATE_TEXTURES = false;
std::atomic<size_t> DECIMATED_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) {
// 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))) {
@ -150,8 +148,7 @@ gpu::TexturePointer TextureUsage::createCubeTextureFromImageWithoutIrradiance(co
bool isColorTexturesCompressionEnabled() {
#if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex);
return compressColorTextures.get();
return compressColorTextures.load();
#else
return false;
#endif
@ -159,8 +156,7 @@ bool isColorTexturesCompressionEnabled() {
bool isNormalTexturesCompressionEnabled() {
#if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex);
return compressNormalTextures.get();
return compressNormalTextures.load();
#else
return false;
#endif
@ -168,8 +164,7 @@ bool isNormalTexturesCompressionEnabled() {
bool isGrayscaleTexturesCompressionEnabled() {
#if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex);
return compressGrayscaleTextures.get();
return compressGrayscaleTextures.load();
#else
return false;
#endif
@ -177,31 +172,26 @@ bool isGrayscaleTexturesCompressionEnabled() {
bool isCubeTexturesCompressionEnabled() {
#if CPU_MIPMAPS
std::lock_guard<std::mutex> guard(settingsMutex);
return compressCubeTextures.get();
return compressCubeTextures.load();
#else
return false;
#endif
}
void setColorTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex);
compressColorTextures.set(enabled);
compressColorTextures.store(enabled);
}
void setNormalTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex);
compressNormalTextures.set(enabled);
compressNormalTextures.store(enabled);
}
void setGrayscaleTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex);
compressGrayscaleTextures.set(enabled);
compressGrayscaleTextures.store(enabled);
}
void setCubeTexturesCompressionEnabled(bool enabled) {
std::lock_guard<std::mutex> guard(settingsMutex);
compressCubeTextures.set(enabled);
compressCubeTextures.store(enabled);
}

View file

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