{"action":"created","comment":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/80285987","id":80285987,"diff_hunk":"@@ -139,63 +247,103 @@ GLuint GL45Backend::getTextureID(const TexturePointer& texture, bool transfer) {\n }\n \n GL45Texture::GL45Texture(const std::weak_ptr<GLBackend>& backend, const Texture& texture, bool transferrable)\n-    : GLTexture(backend, texture, allocate(texture), transferrable), _transferState(*this) {\n+    : GLTexture(backend, texture, allocate(texture), transferrable), _sparseInfo(*this), _transferState(*this) {\n \n-#if SPARSE_TEXTURES\n-    if (transferrable) {\n-        glTextureParameteri(_id, GL_TEXTURE_SPARSE_ARB, GL_TRUE);\n+    if (enableSparseTextures && _transferrable) {\n+        _sparseInfo.maybeMakeSparse();\n     }\n-#endif\n }\n \n-GL45Texture::GL45Texture(const std::weak_ptr<GLBackend>& backend, const Texture& texture, GLTexture* original)\n-    : GLTexture(backend, texture, allocate(texture), original), _transferState(*this) { }\n-\n GL45Texture::~GL45Texture() {\n-    // FIXME do we need to explicitly deallocate the virtual memory here?\n-    //if (_transferrable) {\n-    //    for (uint16_t mipLevel = 0; mipLevel < usedMipLevels(); ++i) {\n-    //        glTexturePageCommitmentEXT(_id, mipLevel, offset.x, offset.y, offset.z, size.x, size.y, size.z, GL_TRUE);\n-    //    }\n-    //}\n+    qCDebug(gpugl45logging) << \"Destroying texture \" << _id << \" from source \" << _source.c_str();\n+    if (_sparseInfo._sparse) {\n+        // Remove this texture from the candidate list of derezzable textures\n+        {\n+            auto mipLevels = usedMipLevels();\n+            Lock lock(texturesByMipCountsMutex);\n+            if (texturesByMipCounts.count(mipLevels)) {\n+                auto& textures = texturesByMipCounts[mipLevels];\n+                textures.erase(this);\n+                if (textures.empty()) {\n+                    texturesByMipCounts.erase(mipLevels);\n+                }\n+            }\n+        }\n+\n+        // Experimenation suggests that allocating sparse textures on one context/thread and deallocating \n+        // them on another is buggy.  So for sparse textures we need to queue a lambda with the deallocation \n+        // callls to the transfer thread\n+        auto id = _id;\n+        // Set the class _id to 0 so we don't try to double delete\n+        const_cast<GLuint&>(_id) = 0;\n+        std::list<std::function<void()>> destructionFunctions;\n+        \n+        uint8_t maxFace = (uint8_t)((_target == GL_TEXTURE_CUBE_MAP) ? GLTexture::CUBE_NUM_FACES : 1);\n+        auto maxSparseMip = std::min<uint16_t>(_maxMip, _sparseInfo._maxSparseLevel);\n+        for (uint16_t mipLevel = _minMip; mipLevel <= maxSparseMip; ++mipLevel) {\n+            auto mipDimensions = _gpuObject.evalMipDimensions(mipLevel);\n+            destructionFunctions.push_back([id, maxFace, mipLevel, mipDimensions] {\n+                glTexturePageCommitmentEXT(id, mipLevel, 0, 0, 0, mipDimensions.x, mipDimensions.y, maxFace, GL_FALSE);\n+            });\n+\n+            auto deallocatedPages = _sparseInfo.getPageCount(mipDimensions) * maxFace;\n+            assert(deallocatedPages <= _allocatedPages);\n+            _allocatedPages -= deallocatedPages;\n+        }\n+\n+        if (0 != _allocatedPages) {\n+            qCWarning(gpugl45logging) << \"Allocated pages remaining \" << _id << \" \" << _allocatedPages;\n+        }\n+\n+        auto size = _size;\n+        _textureTransferHelper->queueExecution([id, size, destructionFunctions] {\n+            for (auto function : destructionFunctions) {\n+                function();\n+            }\n+            glDeleteTextures(1, &id);\n+            Backend::decrementTextureGPUCount();\n+            Backend::updateTextureGPUMemoryUsage(size, 0);\n+        });\n+    }\n }\n \n void GL45Texture::withPreservedTexture(std::function<void()> f) const {","path":"libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp","position":273,"original_position":273,"commit_id":"3cf6d143d734d0258b3c0ea174cf361f4a4621ea","original_commit_id":"3cf6d143d734d0258b3c0ea174cf361f4a4621ea","user":{"login":"jherico","id":1533642,"avatar_url":"https://avatars.githubusercontent.com/u/1533642?v=3","gravatar_id":"","url":"https://api.github.com/users/jherico","html_url":"https://github.com/jherico","followers_url":"https://api.github.com/users/jherico/followers","following_url":"https://api.github.com/users/jherico/following{/other_user}","gists_url":"https://api.github.com/users/jherico/gists{/gist_id}","starred_url":"https://api.github.com/users/jherico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jherico/subscriptions","organizations_url":"https://api.github.com/users/jherico/orgs","repos_url":"https://api.github.com/users/jherico/repos","events_url":"https://api.github.com/users/jherico/events{/privacy}","received_events_url":"https://api.github.com/users/jherico/received_events","type":"User","site_admin":false},"body":"The point of the `withPreservedTexture` code is so that you can execute something without disturbing the bound texture for future calls.  it doesn't do something special for cubemaps, it just has to do one thing for 2D texture and another for cubemaps, because they're different binding points.  However all the 4.5 stuff is done with DSA functions, so they don't ever actually bind a texture, so there's nothing to restore.  Hence the GL45 version doesn't do anything.","created_at":"2016-09-23T17:11:05Z","updated_at":"2016-09-23T17:11:05Z","html_url":"https://github.com/highfidelity/hifi/pull/8594#discussion_r80285987","pull_request_url":"https://api.github.com/repos/highfidelity/hifi/pulls/8594","_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/80285987"},"html":{"href":"https://github.com/highfidelity/hifi/pull/8594#discussion_r80285987"},"pull_request":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/8594"}}},"pull_request":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/8594","id":85135947,"html_url":"https://github.com/highfidelity/hifi/pull/8594","diff_url":"https://github.com/highfidelity/hifi/pull/8594.diff","patch_url":"https://github.com/highfidelity/hifi/pull/8594.patch","issue_url":"https://api.github.com/repos/highfidelity/hifi/issues/8594","number":8594,"state":"open","locked":false,"title":"Dynamic texture resolution","user":{"login":"jherico","id":1533642,"avatar_url":"https://avatars.githubusercontent.com/u/1533642?v=3","gravatar_id":"","url":"https://api.github.com/users/jherico","html_url":"https://github.com/jherico","followers_url":"https://api.github.com/users/jherico/followers","following_url":"https://api.github.com/users/jherico/following{/other_user}","gists_url":"https://api.github.com/users/jherico/gists{/gist_id}","starred_url":"https://api.github.com/users/jherico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jherico/subscriptions","organizations_url":"https://api.github.com/users/jherico/orgs","repos_url":"https://api.github.com/users/jherico/repos","events_url":"https://api.github.com/users/jherico/events{/privacy}","received_events_url":"https://api.github.com/users/jherico/received_events","type":"User","site_admin":false},"body":"Automatically lower the resolution of high memory textures when texture memory is being over-committed. \r\n\r\n## Testing\r\n\r\nEnter a content-heavy scene like dev-playa.  Let the content completely load (and potentially look around to ensure all the content is loaded, not just the current view frustum.  Then go into the `Developer` -> `Render` -> `Maximum Texture Memory` menu and set the memory to 256 MB.  Notice that the textures applied to content immediately become fuzzier and less detailed.  Additionally, you can load the renderStats.js script and see that the GPU texture memory has dropped to a much lower level, presumably less than 256 MB.\r\n\r\nNote, restoring the texture memory setting to automatic will not have any visual effect until the scene is reloaded.\r\n\r\n\r\n\r\nCan some more people test this that have an AMD and i5 machines. ","created_at":"2016-09-13T22:18:52Z","updated_at":"2016-09-23T17:11:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b575e5580a54d243c9d63440e04f12793da825df","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/highfidelity/hifi/pulls/8594/commits","review_comments_url":"https://api.github.com/repos/highfidelity/hifi/pulls/8594/comments","review_comment_url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/highfidelity/hifi/issues/8594/comments","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/3cf6d143d734d0258b3c0ea174cf361f4a4621ea","head":{"label":"jherico:texture_derez","ref":"texture_derez","sha":"3cf6d143d734d0258b3c0ea174cf361f4a4621ea","user":{"login":"jherico","id":1533642,"avatar_url":"https://avatars.githubusercontent.com/u/1533642?v=3","gravatar_id":"","url":"https://api.github.com/users/jherico","html_url":"https://github.com/jherico","followers_url":"https://api.github.com/users/jherico/followers","following_url":"https://api.github.com/users/jherico/following{/other_user}","gists_url":"https://api.github.com/users/jherico/gists{/gist_id}","starred_url":"https://api.github.com/users/jherico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jherico/subscriptions","organizations_url":"https://api.github.com/users/jherico/orgs","repos_url":"https://api.github.com/users/jherico/repos","events_url":"https://api.github.com/users/jherico/events{/privacy}","received_events_url":"https://api.github.com/users/jherico/received_events","type":"User","site_admin":false},"repo":{"id":29566286,"name":"hifi","full_name":"jherico/hifi","owner":{"login":"jherico","id":1533642,"avatar_url":"https://avatars.githubusercontent.com/u/1533642?v=3","gravatar_id":"","url":"https://api.github.com/users/jherico","html_url":"https://github.com/jherico","followers_url":"https://api.github.com/users/jherico/followers","following_url":"https://api.github.com/users/jherico/following{/other_user}","gists_url":"https://api.github.com/users/jherico/gists{/gist_id}","starred_url":"https://api.github.com/users/jherico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jherico/subscriptions","organizations_url":"https://api.github.com/users/jherico/orgs","repos_url":"https://api.github.com/users/jherico/repos","events_url":"https://api.github.com/users/jherico/events{/privacy}","received_events_url":"https://api.github.com/users/jherico/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jherico/hifi","description":"Open, decentralized virtual worlds using sensors to control avatars and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.io/jobs  Documentation at http://docs.highfidelity.io  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":true,"url":"https://api.github.com/repos/jherico/hifi","forks_url":"https://api.github.com/repos/jherico/hifi/forks","keys_url":"https://api.github.com/repos/jherico/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jherico/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jherico/hifi/teams","hooks_url":"https://api.github.com/repos/jherico/hifi/hooks","issue_events_url":"https://api.github.com/repos/jherico/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/jherico/hifi/events","assignees_url":"https://api.github.com/repos/jherico/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/jherico/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/jherico/hifi/tags","blobs_url":"https://api.github.com/repos/jherico/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jherico/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jherico/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/jherico/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jherico/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/jherico/hifi/languages","stargazers_url":"https://api.github.com/repos/jherico/hifi/stargazers","contributors_url":"https://api.github.com/repos/jherico/hifi/contributors","subscribers_url":"https://api.github.com/repos/jherico/hifi/subscribers","subscription_url":"https://api.github.com/repos/jherico/hifi/subscription","commits_url":"https://api.github.com/repos/jherico/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/jherico/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/jherico/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/jherico/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/jherico/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/jherico/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jherico/hifi/merges","archive_url":"https://api.github.com/repos/jherico/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jherico/hifi/downloads","issues_url":"https://api.github.com/repos/jherico/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/jherico/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/jherico/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/jherico/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jherico/hifi/labels{/name}","releases_url":"https://api.github.com/repos/jherico/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/jherico/hifi/deployments","created_at":"2015-01-21T02:11:03Z","updated_at":"2016-07-15T08:47:38Z","pushed_at":"2016-09-23T01:44:18Z","git_url":"git://github.com/jherico/hifi.git","ssh_url":"git@github.com:jherico/hifi.git","clone_url":"https://github.com/jherico/hifi.git","svn_url":"https://github.com/jherico/hifi","homepage":"","size":231554,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"highfidelity:master","ref":"master","sha":"2be961ef103e2e51ee5ddc69939fa9705f377211","user":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"repo":{"id":5372872,"name":"hifi","full_name":"highfidelity/hifi","owner":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/highfidelity/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":false,"url":"https://api.github.com/repos/highfidelity/hifi","forks_url":"https://api.github.com/repos/highfidelity/hifi/forks","keys_url":"https://api.github.com/repos/highfidelity/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/highfidelity/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/highfidelity/hifi/teams","hooks_url":"https://api.github.com/repos/highfidelity/hifi/hooks","issue_events_url":"https://api.github.com/repos/highfidelity/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/highfidelity/hifi/events","assignees_url":"https://api.github.com/repos/highfidelity/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/highfidelity/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/highfidelity/hifi/tags","blobs_url":"https://api.github.com/repos/highfidelity/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/highfidelity/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/highfidelity/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/highfidelity/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/highfidelity/hifi/languages","stargazers_url":"https://api.github.com/repos/highfidelity/hifi/stargazers","contributors_url":"https://api.github.com/repos/highfidelity/hifi/contributors","subscribers_url":"https://api.github.com/repos/highfidelity/hifi/subscribers","subscription_url":"https://api.github.com/repos/highfidelity/hifi/subscription","commits_url":"https://api.github.com/repos/highfidelity/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/highfidelity/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/highfidelity/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/highfidelity/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/highfidelity/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/highfidelity/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/highfidelity/hifi/merges","archive_url":"https://api.github.com/repos/highfidelity/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/highfidelity/hifi/downloads","issues_url":"https://api.github.com/repos/highfidelity/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/highfidelity/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/highfidelity/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/highfidelity/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/highfidelity/hifi/labels{/name}","releases_url":"https://api.github.com/repos/highfidelity/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/highfidelity/hifi/deployments","created_at":"2012-08-10T18:26:22Z","updated_at":"2016-09-23T16:52:05Z","pushed_at":"2016-09-23T16:58:12Z","git_url":"git://github.com/highfidelity/hifi.git","ssh_url":"git@github.com:highfidelity/hifi.git","clone_url":"https://github.com/highfidelity/hifi.git","svn_url":"https://github.com/highfidelity/hifi","homepage":"","size":280568,"stargazers_count":435,"watchers_count":435,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":253,"mirror_url":null,"open_issues_count":46,"forks":253,"open_issues":46,"watchers":435,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/8594"},"html":{"href":"https://github.com/highfidelity/hifi/pull/8594"},"issue":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/8594"},"comments":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/8594/comments"},"review_comments":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/8594/comments"},"review_comment":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/8594/commits"},"statuses":{"href":"https://api.github.com/repos/highfidelity/hifi/statuses/3cf6d143d734d0258b3c0ea174cf361f4a4621ea"}}}}
{"actor":{"display_login":"jherico"}}