From 6a39ad3b5aa1e1559fa7436cd2e85c3632d6db5f Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 3 Nov 2016 13:01:41 -0700 Subject: [PATCH 1/4] Prevent sparse texture on AMD gpus for now --- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 1 + libraries/gpu-gl/src/gpu/gl/GLBackend.h | 9 ++++++++ libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 4 ++++ .../src/gpu/gl45/GL45BackendTexture.cpp | 22 +++++++++++++++++-- libraries/gpu/src/gpu/Context.h | 4 ++-- libraries/gpu/src/gpu/Texture.h | 1 + 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 2e1084e581..3513d7a05b 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -56,6 +56,7 @@ BackendPointer GLBackend::createBackend() { } result->initInput(); result->initTransform(); + result->initTextureManagementStage(); INSTANCE = result.get(); void* voidInstance = &(*result); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.h b/libraries/gpu-gl/src/gpu/gl/GLBackend.h index f99d34393c..fad433d4a2 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.h @@ -176,6 +176,9 @@ public: virtual void releaseQuery(GLuint id) const; virtual void queueLambda(const std::function lambda) const; + bool isTextureManagementSparseEnabled() const { return (_textureManagement._sparseCapable && Texture::getEnableSparseTextures()); } + bool isTextureManagementIncrementalTransferEnabled() const { return (_textureManagement._incrementalTransferCapable && Texture::getEnableIncrementalTextureTransfers()); } + protected: void recycle() const override; @@ -364,6 +367,12 @@ protected: void resetStages(); + struct TextureManagementStageState { + bool _sparseCapable { false }; + bool _incrementalTransferCapable { false }; + } _textureManagement; + virtual void initTextureManagementStage() {} + typedef void (GLBackend::*CommandCall)(const Batch&, size_t); static CommandCall _commandCalls[Batch::NUM_COMMANDS]; friend class GLState; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index 059156b4a3..643d54af6a 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -32,6 +32,7 @@ public: static GLuint allocate(const Texture& texture); static const uint32_t DEFAULT_PAGE_DIMENSION = 128; static const uint32_t DEFAULT_MAX_SPARSE_LEVEL = 0xFFFF; + public: GL45Texture(const std::weak_ptr& backend, const Texture& texture, GLuint externalId); GL45Texture(const std::weak_ptr& backend, const Texture& texture, bool transferrable); @@ -132,6 +133,9 @@ protected: // Output stage void do_blit(const Batch& batch, size_t paramOffset) override; + + // Texture Management Stage + void initTextureManagementStage() override; }; } } diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 621c619954..07b4ca084d 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -148,6 +148,22 @@ uint32_t SparseInfo::getPageCount(const uvec3& dimensions) const { return pageCounts.x * pageCounts.y * pageCounts.z; } + + +void GL45Backend::initTextureManagementStage() { + + // enable the Sparse Texture on gl45 + _textureManagement._sparseCapable = true; + _textureManagement._incrementalTransferCapable = true; + + // But now let s refine the behavior based on vendor + std::string vendor { (const char*)glGetString(GL_VENDOR) }; + if ((vendor.compare("AMD") <= 0) || (vendor.compare("INTEL") <= 0)) { + qCDebug(gpugllogging, "GPU is sparse capable but force it off %s\n", vendor); + _textureManagement._sparseCapable = false; + } +} + using TransferState = GL45Backend::GL45Texture::TransferState; TransferState::TransferState(GL45Texture& texture) : texture(texture) { @@ -250,7 +266,8 @@ GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& GL45Texture::GL45Texture(const std::weak_ptr& backend, const Texture& texture, bool transferrable) : GLTexture(backend, texture, allocate(texture), transferrable), _sparseInfo(*this), _transferState(*this) { - if (_transferrable && Texture::getEnableSparseTextures()) { + auto theBackend = _backend.lock(); + if (_transferrable && theBackend && theBackend->isTextureManagementSparseEnabled()) { _sparseInfo.maybeMakeSparse(); if (_sparseInfo.sparse) { Backend::incrementTextureGPUSparseCount(); @@ -362,7 +379,8 @@ void GL45Texture::startTransfer() { } bool GL45Texture::continueTransfer() { - if (!Texture::getEnableIncrementalTextureTransfers()) { + auto backend = _backend.lock(); + if (!backend || !backend->isTextureManagementIncrementalTransferEnabled()) { size_t maxFace = GL_TEXTURE_CUBE_MAP == _target ? CUBE_NUM_FACES : 1; for (uint8_t face = 0; face < maxFace; ++face) { for (uint16_t mipLevel = _minMip; mipLevel <= _maxMip; ++mipLevel) { diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 763e91b3e4..56d1930c94 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -125,6 +125,7 @@ protected: friend class Context; ContextStats _stats; StereoState _stereo; + }; class Context { @@ -214,7 +215,7 @@ public: static Size getTextureGPUFramebufferMemoryUsage(); static Size getTextureGPUSparseMemoryUsage(); static uint32_t getTextureGPUTransferCount(); - + protected: Context(const Context& context); @@ -270,7 +271,6 @@ protected: static std::atomic _textureGPUFramebufferMemoryUsage; static std::atomic _textureGPUTransferCount; - friend class Backend; }; typedef std::shared_ptr ContextPointer; diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 0f1022a0c9..1eacb46d77 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -147,6 +147,7 @@ class Texture : public Resource { static std::atomic _enableSparseTextures; static std::atomic _enableIncrementalTextureTransfers; + public: static uint32_t getTextureCPUCount(); static Size getTextureCPUMemoryUsage(); From 4104aa62864fccdc84d8fc6d8d35bcbba58a02d7 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 3 Nov 2016 14:31:28 -0700 Subject: [PATCH 2/4] avoid warning? --- libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 07b4ca084d..1075c1407d 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -159,7 +159,7 @@ void GL45Backend::initTextureManagementStage() { // But now let s refine the behavior based on vendor std::string vendor { (const char*)glGetString(GL_VENDOR) }; if ((vendor.compare("AMD") <= 0) || (vendor.compare("INTEL") <= 0)) { - qCDebug(gpugllogging, "GPU is sparse capable but force it off %s\n", vendor); + qCDebug(gpugllogging) << "GPU is sparse capable but force it off, vendor = " << vendor.c_str(); _textureManagement._sparseCapable = false; } } From ce89f811f3db06536229415ffb86aac2064306e9 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 3 Nov 2016 14:35:44 -0700 Subject: [PATCH 3/4] better loggin of the sparse switch --- libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 1075c1407d..6e2e7ca62b 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -161,6 +161,8 @@ void GL45Backend::initTextureManagementStage() { if ((vendor.compare("AMD") <= 0) || (vendor.compare("INTEL") <= 0)) { qCDebug(gpugllogging) << "GPU is sparse capable but force it off, vendor = " << vendor.c_str(); _textureManagement._sparseCapable = false; + } else { + qCDebug(gpugllogging) << "GPU is sparse capable, vendor = " << vendor.c_str(); } } From 1086585559fe5017ee9664f8e26619bbf860c49b Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 3 Nov 2016 15:15:05 -0700 Subject: [PATCH 4/4] fixing the test to actually capture ati correctly and add the report to the ui --- interface/src/ui/Stats.cpp | 2 +- libraries/gpu-gl/src/gpu/gl/GLBackend.h | 4 ++-- libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp | 2 +- libraries/gpu/src/gpu/Context.h | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 11660a332d..05632cb1e6 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -302,7 +302,7 @@ void Stats::updateStats(bool force) { STAT_UPDATE(gpuTextureVirtualMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUVirtualMemoryUsage())); STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUFramebufferMemoryUsage())); STAT_UPDATE(gpuTextureSparseMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUSparseMemoryUsage())); - STAT_UPDATE(gpuSparseTextureEnabled, gpu::Texture::getEnableSparseTextures() ? 1 : 0); + STAT_UPDATE(gpuSparseTextureEnabled, qApp->getGPUContext()->getBackend()->isTextureManagementSparseEnabled() ? 1 : 0); STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory())); STAT_UPDATE(rectifiedTextureCount, (int)RECTIFIED_TEXTURE_COUNT.load()); STAT_UPDATE(decimatedTextureCount, (int)DECIMATED_TEXTURE_COUNT.load()); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.h b/libraries/gpu-gl/src/gpu/gl/GLBackend.h index fad433d4a2..1be279b375 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.h @@ -176,8 +176,8 @@ public: virtual void releaseQuery(GLuint id) const; virtual void queueLambda(const std::function lambda) const; - bool isTextureManagementSparseEnabled() const { return (_textureManagement._sparseCapable && Texture::getEnableSparseTextures()); } - bool isTextureManagementIncrementalTransferEnabled() const { return (_textureManagement._incrementalTransferCapable && Texture::getEnableIncrementalTextureTransfers()); } + bool isTextureManagementSparseEnabled() const override { return (_textureManagement._sparseCapable && Texture::getEnableSparseTextures()); } + bool isTextureManagementIncrementalTransferEnabled() const override { return (_textureManagement._incrementalTransferCapable && Texture::getEnableIncrementalTextureTransfers()); } protected: diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index 6e2e7ca62b..ac9a84513e 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -158,7 +158,7 @@ void GL45Backend::initTextureManagementStage() { // But now let s refine the behavior based on vendor std::string vendor { (const char*)glGetString(GL_VENDOR) }; - if ((vendor.compare("AMD") <= 0) || (vendor.compare("INTEL") <= 0)) { + if ((vendor.find("AMD") != std::string::npos) || (vendor.find("ATI") != std::string::npos) || (vendor.find("INTEL") != std::string::npos)) { qCDebug(gpugllogging) << "GPU is sparse capable but force it off, vendor = " << vendor.c_str(); _textureManagement._sparseCapable = false; } else { diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 56d1930c94..e174e9d728 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -85,7 +85,8 @@ public: void getStats(ContextStats& stats) const { stats = _stats; } - + virtual bool isTextureManagementSparseEnabled() const = 0; + virtual bool isTextureManagementIncrementalTransferEnabled() const = 0; // These should only be accessed by Backend implementation to repport the buffer and texture allocations, // they are NOT public calls @@ -215,7 +216,7 @@ public: static Size getTextureGPUFramebufferMemoryUsage(); static Size getTextureGPUSparseMemoryUsage(); static uint32_t getTextureGPUTransferCount(); - + protected: Context(const Context& context);