From 4f8f3a86566463bc331354fd8cfb46dd03a9d2fd Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 26 Apr 2017 18:50:28 -0700 Subject: [PATCH 01/19] debugging the mip not beeing copied correctly on 4.1 --- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 2 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 42 +++++++++++++++++-- libraries/image/src/image/Image.cpp | 4 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 1210112a78..c5c9b90eb2 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -48,7 +48,7 @@ BackendPointer GLBackend::createBackend() { // Where the gpuContext is initialized and where the TRUE Backend is created and assigned auto version = QOpenGLContextWrapper::currentContextVersion(); std::shared_ptr result; - if (!disableOpenGL45 && version >= 0x0405) { + if (false && !disableOpenGL45 && version >= 0x0405) { qCDebug(gpugllogging) << "Using OpenGL 4.5 backend"; result = std::make_shared(); } else { diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index bff5bf3f2c..54d3c87194 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -300,7 +300,7 @@ void GL41VariableAllocationTexture::promote() { // allocate storage for new level allocateStorage(_allocatedMip - std::min(_allocatedMip, 2)); - + /* withPreservedTexture([&] { GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); @@ -325,7 +325,24 @@ void GL41VariableAllocationTexture::promote() { glDeleteFramebuffers(1, &fbo); syncSampler(); - }); + });*/ + + uint16_t mips = _gpuObject.getNumMips(); + // copy pre-existing mips + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = mip - oldAllocatedMip; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } // destroy the old texture glDeleteTextures(1, &oldId); @@ -343,7 +360,7 @@ void GL41VariableAllocationTexture::demote() { uint16_t oldAllocatedMip = _allocatedMip; allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); - + /* withPreservedTexture([&] { GLuint fbo { 0 }; glCreateFramebuffers(1, &fbo); @@ -368,7 +385,24 @@ void GL41VariableAllocationTexture::demote() { glDeleteFramebuffers(1, &fbo); syncSampler(); - }); + });*/ + + // copy pre-existing mips + uint16_t mips = _gpuObject.getNumMips(); + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = targetMip + 1; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } // destroy the old texture diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index 707a2e4496..e60187d230 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -28,9 +28,9 @@ using namespace gpu; #define CPU_MIPMAPS 1 -#define COMPRESS_COLOR_TEXTURES 0 +#define COMPRESS_COLOR_TEXTURES 1 #define COMPRESS_NORMALMAP_TEXTURES 0 // Disable Normalmap compression for now -#define COMPRESS_GRAYSCALE_TEXTURES 0 +#define COMPRESS_GRAYSCALE_TEXTURES 1 #define COMPRESS_CUBEMAP_TEXTURES 0 // Disable Cubemap compression for now static const glm::uvec2 SPARSE_PAGE_SIZE(128); From d99f63588076820a36eff989adc7b036461fdd59 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Thu, 27 Apr 2017 02:08:48 -0700 Subject: [PATCH 02/19] still finding a good implementation for the compressed texel copy --- libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp | 14 ++ libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h | 2 + libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 1 + .../src/gpu/gl41/GL41BackendTexture.cpp | 165 +++++++++--------- 4 files changed, 102 insertions(+), 80 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp index b0c53caa1a..7f724cce65 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.cpp @@ -11,6 +11,20 @@ using namespace gpu; using namespace gpu::gl; +bool GLTexelFormat::isCompressed() const { + switch (internalFormat) { + case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: + case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + case GL_COMPRESSED_RED_RGTC1: + case GL_COMPRESSED_RG_RGTC2: + return true; + break; + default: + return false; + break; + } +} GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) { GLenum result = GL_RGBA8; diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h index 94ded3dc23..1edc10395c 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h @@ -18,6 +18,8 @@ public: GLenum format; GLenum type; + bool isCompressed() const; + static GLTexelFormat evalGLTexelFormat(const Element& dstFormat) { return evalGLTexelFormat(dstFormat, dstFormat); } diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index 19979a1778..94ded8b23d 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -109,6 +109,7 @@ public: Size size() const override { return _size; } Size _size { 0 }; + GLTexelFormat _texelFormat; }; class GL41ResourceTexture : public GL41VariableAllocationTexture { diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 0b03f8eec6..be820b66b6 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -240,7 +240,10 @@ GL41StrictResourceTexture::GL41StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : GL41Texture(backend, texture) { +GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr& backend, const Texture& texture) : + GL41Texture(backend, texture), + _texelFormat(GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), texture.getStoredMipFormat())) +{ auto mipLevels = texture.getNumMips(); _allocatedMip = mipLevels; _maxAllocatedMip = _populatedMip = mipLevels; @@ -321,49 +324,50 @@ void GL41VariableAllocationTexture::promote() { // allocate storage for new level allocateStorage(targetAllocatedMip); - /* + withPreservedTexture([&] { - GLuint fbo { 0 }; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - - uint16_t mips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = mip - oldAllocatedMip; - for (GLenum target : getFaceTargets(_target)) { - glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip); - (void)CHECK_GL_ERROR(); - glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); - (void)CHECK_GL_ERROR(); + if (false && _texelFormat.isCompressed()) { + uint16_t mips = _gpuObject.getNumMips(); + // copy pre-existing mips + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = mip - oldAllocatedMip; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } } + } else { + GLuint fbo { 0 }; + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + + uint16_t mips = _gpuObject.getNumMips(); + // copy pre-existing mips + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = mip - oldAllocatedMip; + for (GLenum target : getFaceTargets(_target)) { + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip); + (void)CHECK_GL_ERROR(); + glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); + (void)CHECK_GL_ERROR(); + } + } + + // destroy the transfer framebuffer + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glDeleteFramebuffers(1, &fbo); } - - // destroy the transfer framebuffer - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glDeleteFramebuffers(1, &fbo); - syncSampler(); - });*/ - - uint16_t mips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = mip - oldAllocatedMip; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } + }); // destroy the old texture glDeleteTextures(1, &oldId); @@ -381,50 +385,51 @@ void GL41VariableAllocationTexture::demote() { uint16_t oldAllocatedMip = _allocatedMip; allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); - /* + withPreservedTexture([&] { - GLuint fbo { 0 }; - glCreateFramebuffers(1, &fbo); - glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - - uint16_t mips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = mip - oldAllocatedMip; - for (GLenum target : getFaceTargets(_target)) { - glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip); - (void)CHECK_GL_ERROR(); - glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); - (void)CHECK_GL_ERROR(); + if (_texelFormat.isCompressed()) { + + // copy pre-existing mips + uint16_t mips = _gpuObject.getNumMips(); + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = targetMip + 1; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } } + } else { + GLuint fbo { 0 }; + glCreateFramebuffers(1, &fbo); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + + uint16_t mips = _gpuObject.getNumMips(); + // copy pre-existing mips + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = targetMip + 1; + for (GLenum target : getFaceTargets(_target)) { + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip); + (void)CHECK_GL_ERROR(); + glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); + (void)CHECK_GL_ERROR(); + } + } + + // destroy the transfer framebuffer + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glDeleteFramebuffers(1, &fbo); } - - // destroy the transfer framebuffer - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glDeleteFramebuffers(1, &fbo); - syncSampler(); - });*/ - - // copy pre-existing mips - uint16_t mips = _gpuObject.getNumMips(); - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = targetMip + 1; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } - + }); // destroy the old texture glDeleteTextures(1, &oldId); From 69a90d6f861f5c6667f174168d8a4a058abef24e Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 27 Apr 2017 11:24:09 -0700 Subject: [PATCH 03/19] work in progress --- libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 5 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 66 ++++++++++++------- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index 94ded8b23d..ef409d37f4 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -37,8 +37,9 @@ class GL41Backend : public GLBackend { public: static const GLint TRANSFORM_OBJECT_SLOT { 31 }; static const GLint RESOURCE_TRANSFER_TEX_UNIT { 32 }; - static const GLint RESOURCE_BUFFER_TEXBUF_TEX_UNIT { 33 }; - static const GLint RESOURCE_BUFFER_SLOT0_TEX_UNIT { 34 }; + static const GLint RESOURCE_TRANSFER_EXTRA_TEX_UNIT { 33 }; + static const GLint RESOURCE_BUFFER_TEXBUF_TEX_UNIT { 34 }; + static const GLint RESOURCE_BUFFER_SLOT0_TEX_UNIT { 35 }; explicit GL41Backend(bool syncCache) : Parent(syncCache) {} GL41Backend() : Parent() {} diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index be820b66b6..d9fa2ad067 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -386,28 +386,47 @@ void GL41VariableAllocationTexture::demote() { allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); - withPreservedTexture([&] { - if (_texelFormat.isCompressed()) { - - // copy pre-existing mips - uint16_t mips = _gpuObject.getNumMips(); - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = targetMip + 1; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } + if (_texelFormat.isCompressed()) { + GLuint pbo { 0 }; + glGenBuffers(1, &pbo); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); + glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); + + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); + glBindTexture(_target, oldId); + + glGetTexLevelParameteriv(_target, sourceMip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size); + + // copy pre-existing mips + uint16_t mips = _gpuObject.getNumMips(); + for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = targetMip + 1; + GLint size { 0 }; + GLint internalFormat; + glGetTexLevelParameteriv(_target, sourceMip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size); + + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); } - } else { + } + + + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glDeleteBuffers(1, &pbo); + + } else { + withPreservedTexture([&] { GLuint fbo { 0 }; - glCreateFramebuffers(1, &fbo); + glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); uint16_t mips = _gpuObject.getNumMips(); @@ -427,9 +446,10 @@ void GL41VariableAllocationTexture::demote() { // destroy the transfer framebuffer glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fbo); - } - syncSampler(); - }); + + syncSampler(); + }); + } // destroy the old texture glDeleteTextures(1, &oldId); From 7c15609136372e27696a0f3c64f87c9f542b13d3 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 27 Apr 2017 17:28:10 -0700 Subject: [PATCH 04/19] Fixing the broken texture copy (during texture streaming) for compressed format in GL41Backend --- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 2 +- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 3 +- libraries/gpu-gl/src/gpu/gl/GLTexture.h | 1 + libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 1 - .../src/gpu/gl41/GL41BackendTexture.cpp | 192 ++++++++++++++---- libraries/gpu/src/gpu/Texture.cpp | 8 +- libraries/gpu/src/gpu/Texture.h | 4 +- 7 files changed, 160 insertions(+), 51 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index c5c9b90eb2..1210112a78 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -48,7 +48,7 @@ BackendPointer GLBackend::createBackend() { // Where the gpuContext is initialized and where the TRUE Backend is created and assigned auto version = QOpenGLContextWrapper::currentContextVersion(); std::shared_ptr result; - if (false && !disableOpenGL45 && version >= 0x0405) { + if (!disableOpenGL45 && version >= 0x0405) { qCDebug(gpugllogging) << "Using OpenGL 4.5 backend"; result = std::make_shared(); } else { diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 7f075a1698..95815993c2 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -102,7 +102,8 @@ const std::vector& GLTexture::getFaceTargets(GLenum target) { GLTexture::GLTexture(const std::weak_ptr& backend, const Texture& texture, GLuint id) : GLObject(backend, texture, id), _source(texture.source()), - _target(getGLTextureType(texture)) + _target(getGLTextureType(texture)), + _texelFormat(GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), texture.getStoredMipFormat())) { Backend::setGPUObject(texture, this); } diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.h b/libraries/gpu-gl/src/gpu/gl/GLTexture.h index e0b8a63a99..99df5d94cf 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.h @@ -153,6 +153,7 @@ public: const GLuint& _texture { _id }; const std::string _source; const GLenum _target; + GLTexelFormat _texelFormat; static const std::vector& getFaceTargets(GLenum textureType); static uint8_t getFaceCount(GLenum textureType); diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index ef409d37f4..3662253a66 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -110,7 +110,6 @@ public: Size size() const override { return _size; } Size _size { 0 }; - GLTexelFormat _texelFormat; }; class GL41ResourceTexture : public GL41VariableAllocationTexture { diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index d9fa2ad067..f199d210b3 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -241,8 +241,7 @@ GL41StrictResourceTexture::GL41StrictResourceTexture(const std::weak_ptr& backend, const Texture& texture) : - GL41Texture(backend, texture), - _texelFormat(GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), texture.getStoredMipFormat())) + GL41Texture(backend, texture) { auto mipLevels = texture.getNumMips(); _allocatedMip = mipLevels; @@ -325,25 +324,87 @@ void GL41VariableAllocationTexture::promote() { // allocate storage for new level allocateStorage(targetAllocatedMip); - withPreservedTexture([&] { - if (false && _texelFormat.isCompressed()) { - uint16_t mips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = mip - oldAllocatedMip; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); + if (_texelFormat.isCompressed()) { + GLuint pbo { 0 }; + glGenBuffers(1, &pbo); + glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); + uint16_t numMips = _gpuObject.getNumMips(); + struct MipDesc { + GLint _faceSize; + GLint _size; + GLint _offset; + gpu::Vec3u _dims; + }; + std::vector sourceMips(numMips); + + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); + glBindTexture(_target, oldId); + const auto& faceTargets = getFaceTargets(_target); + GLint internalFormat { 0 }; + (void)CHECK_GL_ERROR(); + + // Collect the mip description from the source texture + GLint bufferOffset { 0 }; + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + sourceMip._dims = _gpuObject.evalMipDimensions(mip); + + uint16_t sourceLevel = mip - oldAllocatedMip; + + // Grab internal format once + if (internalFormat == 0) { + glGetTexLevelParameteriv(faceTargets[0], sourceLevel, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); + } + + // Collect the size of the first face, and then compute the total size offset needed for this mip level + glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); + sourceMip._size = faceTargets.size() * sourceMip._faceSize; + sourceMip._offset = bufferOffset; + bufferOffset += sourceMip._size; + } + (void)CHECK_GL_ERROR(); + + // Allocate the PBO to accomodate for all the mips to copy + glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); + (void)CHECK_GL_ERROR(); + + // Transfer from source texture to pbo + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + + uint16_t sourceLevel = mip - oldAllocatedMip; + + for (GLint f = 0; f < faceTargets.size(); f++) { + glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + } + (void)CHECK_GL_ERROR(); + + } + + // Now populate the new texture from the pbo + glBindTexture(_target, 0); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); + + withPreservedTexture([&] { + // Transfer from pbo to new texture + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + + uint16_t destLevel = mip - _allocatedMip; + + for (GLint f = 0; f < faceTargets.size(); f++) { + glCompressedTexSubImage2D(faceTargets[f], destLevel, 0, 0, sourceMip._dims.x, sourceMip._dims.y, internalFormat, + sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); } } - } else { + syncSampler(); + }); + + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + glDeleteBuffers(1, &pbo); + } else { + withPreservedTexture([&] { GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); @@ -365,9 +426,10 @@ void GL41VariableAllocationTexture::promote() { // destroy the transfer framebuffer glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fbo); - } - syncSampler(); - }); + + syncSampler(); + }); + } // destroy the old texture glDeleteTextures(1, &oldId); @@ -383,44 +445,86 @@ void GL41VariableAllocationTexture::demote() { auto oldSize = _size; const_cast(_id) = allocate(_gpuObject); uint16_t oldAllocatedMip = _allocatedMip; + uint16_t oldPopulatedMip = _populatedMip; allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); if (_texelFormat.isCompressed()) { GLuint pbo { 0 }; glGenBuffers(1, &pbo); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); + uint16_t numMips = _gpuObject.getNumMips(); + struct MipDesc { + GLint _faceSize; + GLint _size; + GLint _offset; + gpu::Vec3u _dims; + }; + std::vector sourceMips(numMips); glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); glBindTexture(_target, oldId); + const auto& faceTargets = getFaceTargets(_target); + GLint internalFormat { 0 }; - glGetTexLevelParameteriv(_target, sourceMip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size); + // Collect the mip description from the source texture + GLint bufferOffset { 0 }; + for (uint16_t mip = oldPopulatedMip; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + sourceMip._dims = _gpuObject.evalMipDimensions(mip); - // copy pre-existing mips - uint16_t mips = _gpuObject.getNumMips(); - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = targetMip + 1; - GLint size { 0 }; - GLint internalFormat; - glGetTexLevelParameteriv(_target, sourceMip, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size); + uint16_t sourceLevel = mip - oldAllocatedMip; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); + // Grab internal format once + if (internalFormat != 0) { + glGetTexLevelParameteriv(faceTargets[0], sourceLevel, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); } + + // Collect the size of the first face, and then compute the total size offset needed for this mip level + glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); + sourceMip._size = faceTargets.size() * sourceMip._faceSize; + sourceMip._offset = bufferOffset; + bufferOffset += sourceMip._size; + } + (void)CHECK_GL_ERROR(); + + // Allocate the PBO to accomodate for all the mips to copy + glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); + (void)CHECK_GL_ERROR(); + + // Transfer from source texture to pbo + for (uint16_t mip = oldPopulatedMip; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + + uint16_t sourceLevel = mip - oldAllocatedMip; + + for (GLint f = 0; f < faceTargets.size(); f++) { + glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (sourceMip._offset + f * sourceMip._faceSize)); + } + (void)CHECK_GL_ERROR(); } + // Now populate the new texture from the pbo + glBindTexture(_target, 0); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); + + withPreservedTexture([&] { + // Transfer from pbo to new texture + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + + uint16_t destLevel = mip - _allocatedMip; + + for (GLint f = 0; f < faceTargets.size(); f++) { + glCompressedTexSubImage2D(faceTargets[f], destLevel, 0, 0, sourceMip._dims.x, sourceMip._dims.y, internalFormat, + sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + } + } + syncSampler(); + }); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glDeleteBuffers(1, &pbo); } else { @@ -429,9 +533,9 @@ void GL41VariableAllocationTexture::demote() { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - uint16_t mips = _gpuObject.getNumMips(); + uint16_t numMips = _gpuObject.getNumMips(); // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { auto mipDimensions = _gpuObject.evalMipDimensions(mip); uint16_t targetMip = mip - _allocatedMip; uint16_t sourceMip = targetMip + 1; diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 3e6ed166a7..353bcbc8f1 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -407,8 +407,12 @@ void Texture::setStoredMipFormat(const Element& format) { _storage->setFormat(format); } -const Element& Texture::getStoredMipFormat() const { - return _storage->getFormat(); +const Element Texture::getStoredMipFormat() const { + if (_storage) { + return _storage->getFormat(); + } else { + return Element(); + } } void Texture::assignStoredMip(uint16 level, Size size, const Byte* bytes) { diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 9b23b4e695..21a1b0ec57 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -372,7 +372,7 @@ public: bool isColorRenderTarget() const; bool isDepthStencilRenderTarget() const; - const Element& getTexelFormat() const { return _texelFormat; } + const Element getTexelFormat() const { return _texelFormat; } Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); } uint16 getWidth() const { return _width; } @@ -468,7 +468,7 @@ public: // Mip storage format is constant across all mips void setStoredMipFormat(const Element& format); - const Element& getStoredMipFormat() const; + const Element getStoredMipFormat() const; // Manually allocate the mips down until the specified maxMip // this is just allocating the sysmem version of it From d7dfab6405c4362b13a1b3bd743461ee4942b743 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 27 Apr 2017 17:31:46 -0700 Subject: [PATCH 05/19] Fixing the broken texture copy (during texture streaming) for compressed format in GL41Backend --- libraries/image/src/image/Image.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/image/src/image/Image.cpp b/libraries/image/src/image/Image.cpp index e60187d230..707a2e4496 100644 --- a/libraries/image/src/image/Image.cpp +++ b/libraries/image/src/image/Image.cpp @@ -28,9 +28,9 @@ using namespace gpu; #define CPU_MIPMAPS 1 -#define COMPRESS_COLOR_TEXTURES 1 +#define COMPRESS_COLOR_TEXTURES 0 #define COMPRESS_NORMALMAP_TEXTURES 0 // Disable Normalmap compression for now -#define COMPRESS_GRAYSCALE_TEXTURES 1 +#define COMPRESS_GRAYSCALE_TEXTURES 0 #define COMPRESS_CUBEMAP_TEXTURES 0 // Disable Cubemap compression for now static const glm::uvec2 SPARSE_PAGE_SIZE(128); From 8240c3f76112d9c1b300eb50211886dda732ef3e Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 27 Apr 2017 18:05:52 -0700 Subject: [PATCH 06/19] Fixing the spam issue triggered by the external textures, removed 2 warnings --- libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h | 3 +++ libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 2 +- libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp | 4 ++-- libraries/gpu/src/gpu/Texture.cpp | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h index 1edc10395c..8f37f6b604 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTexelFormat.h @@ -18,6 +18,9 @@ public: GLenum format; GLenum type; + GLTexelFormat(GLenum glinternalFormat, GLenum glformat, GLenum gltype) : internalFormat(glinternalFormat), format(glformat), type(gltype) {} + GLTexelFormat(GLenum glinternalFormat) : internalFormat(glinternalFormat) {} + bool isCompressed() const; static GLTexelFormat evalGLTexelFormat(const Element& dstFormat) { diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 95815993c2..05c194405b 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -103,7 +103,7 @@ GLTexture::GLTexture(const std::weak_ptr& backend, const Texture& tex GLObject(backend, texture, id), _source(texture.source()), _target(getGLTextureType(texture)), - _texelFormat(GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), texture.getStoredMipFormat())) + _texelFormat(GLTexelFormat::evalGLTexelFormatInternal(texture.getTexelFormat())) { Backend::setGPUObject(texture, this); } diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index f199d210b3..1f2cb20d04 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -358,7 +358,7 @@ void GL41VariableAllocationTexture::promote() { // Collect the size of the first face, and then compute the total size offset needed for this mip level glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); - sourceMip._size = faceTargets.size() * sourceMip._faceSize; + sourceMip._size = (GLint) faceTargets.size() * sourceMip._faceSize; sourceMip._offset = bufferOffset; bufferOffset += sourceMip._size; } @@ -482,7 +482,7 @@ void GL41VariableAllocationTexture::demote() { // Collect the size of the first face, and then compute the total size offset needed for this mip level glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); - sourceMip._size = faceTargets.size() * sourceMip._faceSize; + sourceMip._size = (GLint) faceTargets.size() * sourceMip._faceSize; sourceMip._offset = bufferOffset; bufferOffset += sourceMip._size; } diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 353bcbc8f1..b12ae5bc97 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -216,6 +216,7 @@ void Texture::MemoryStorage::assignMipFaceData(uint16 level, uint8 face, const s TexturePointer Texture::createExternal(const ExternalRecycler& recycler, const Sampler& sampler) { TexturePointer tex = std::make_shared(TextureUsageType::EXTERNAL); tex->_type = TEX_2D; + tex->_texelFormat = Element::COLOR_RGBA_32; tex->_maxMipLevel = 0; tex->_sampler = sampler; tex->setExternalRecycler(recycler); From d0fa8fe88713ae4be7ad3e7662280cffca788758 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 28 Apr 2017 12:26:44 -0700 Subject: [PATCH 07/19] Debuging the bad transfers... --- .../gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 1f2cb20d04..fdc151e20b 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -386,7 +386,9 @@ void GL41VariableAllocationTexture::promote() { glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); - withPreservedTexture([&] { + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); + glBindTexture(_target, _texture); + // Transfer from pbo to new texture for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { auto& sourceMip = sourceMips[mip]; @@ -394,12 +396,13 @@ void GL41VariableAllocationTexture::promote() { uint16_t destLevel = mip - _allocatedMip; for (GLint f = 0; f < faceTargets.size(); f++) { - glCompressedTexSubImage2D(faceTargets[f], destLevel, 0, 0, sourceMip._dims.x, sourceMip._dims.y, internalFormat, + glCompressedTexImage2D(faceTargets[f], destLevel, internalFormat, sourceMip._dims.x, sourceMip._dims.y, 0, sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); } } syncSampler(); - }); + + glBindTexture(_target, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); @@ -445,7 +448,6 @@ void GL41VariableAllocationTexture::demote() { auto oldSize = _size; const_cast(_id) = allocate(_gpuObject); uint16_t oldAllocatedMip = _allocatedMip; - uint16_t oldPopulatedMip = _populatedMip; allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); @@ -469,7 +471,7 @@ void GL41VariableAllocationTexture::demote() { // Collect the mip description from the source texture GLint bufferOffset { 0 }; - for (uint16_t mip = oldPopulatedMip; mip < numMips; ++mip) { + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { auto& sourceMip = sourceMips[mip]; sourceMip._dims = _gpuObject.evalMipDimensions(mip); @@ -493,7 +495,7 @@ void GL41VariableAllocationTexture::demote() { (void)CHECK_GL_ERROR(); // Transfer from source texture to pbo - for (uint16_t mip = oldPopulatedMip; mip < numMips; ++mip) { + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { auto& sourceMip = sourceMips[mip]; uint16_t sourceLevel = mip - oldAllocatedMip; @@ -517,7 +519,7 @@ void GL41VariableAllocationTexture::demote() { uint16_t destLevel = mip - _allocatedMip; for (GLint f = 0; f < faceTargets.size(); f++) { - glCompressedTexSubImage2D(faceTargets[f], destLevel, 0, 0, sourceMip._dims.x, sourceMip._dims.y, internalFormat, + glCompressedTexImage2D(faceTargets[f], destLevel, internalFormat, sourceMip._dims.x, sourceMip._dims.y, 0, sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); } } From bfe8bc7593b0710864a041333aecc8757de1550c Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 28 Apr 2017 16:52:43 -0700 Subject: [PATCH 08/19] Adding the 45 codepath for debug --- .../src/gpu/gl41/GL41BackendTexture.cpp | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index fdc151e20b..06fc5ca7c6 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -325,6 +325,27 @@ void GL41VariableAllocationTexture::promote() { allocateStorage(targetAllocatedMip); if (_texelFormat.isCompressed()) { +#if defined(USE_45IMAGECOPY_PROMOTE) + withPreservedTexture([&] { + uint16_t numMips = _gpuObject.getNumMips(); + // copy pre-existing mips + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = mip - oldAllocatedMip; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } + syncSampler(); + }); +#else GLuint pbo { 0 }; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); @@ -406,6 +427,7 @@ void GL41VariableAllocationTexture::promote() { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); +#endif } else { withPreservedTexture([&] { GLuint fbo { 0 }; @@ -452,6 +474,27 @@ void GL41VariableAllocationTexture::demote() { _populatedMip = std::max(_populatedMip, _allocatedMip); if (_texelFormat.isCompressed()) { +#if defined(USE_45IMAGECOPY_DEMOTE) + withPreservedTexture([&] { + uint16_t numMips = _gpuObject.getNumMips(); + // copy pre-existing mips + for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { + auto mipDimensions = _gpuObject.evalMipDimensions(mip); + uint16_t targetMip = mip - _allocatedMip; + uint16_t sourceMip = targetMip + 1; + auto faces = getFaceCount(_target); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + oldId, _target, sourceMip, 0, 0, face, + _id, _target, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } + syncSampler(); + }); +#else GLuint pbo { 0 }; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); @@ -528,7 +571,7 @@ void GL41VariableAllocationTexture::demote() { glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); - +#endif } else { withPreservedTexture([&] { GLuint fbo { 0 }; From 04895864b5f9c3fc543ac71584fe3f393b2605a4 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 28 Apr 2017 17:34:15 -0700 Subject: [PATCH 09/19] Factorizing the code... --- .../src/gpu/gl41/GL41BackendTexture.cpp | 237 +++++++----------- 1 file changed, 85 insertions(+), 152 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 06fc5ca7c6..8c249fc652 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -308,6 +308,87 @@ void GL41VariableAllocationTexture::syncSampler() const { }); } + +void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { + GLuint pbo { 0 }; + glGenBuffers(1, &pbo); + glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); + struct MipDesc { + GLint _faceSize; + GLint _size; + GLint _offset; + GLint _width; + GLint _height; + }; + std::vector sourceMips(numMips); + + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); + glBindTexture(texTarget, srcId); + const auto& faceTargets = GLTexture::getFaceTargets(texTarget); + GLint internalFormat { 0 }; + + // Collect the mip description from the source texture + GLint bufferOffset { 0 }; + for (uint16_t mip = populatedMips; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + + uint16_t sourceLevel = mip - srcAllocatedMip; + + // Grab internal format once + if (internalFormat != 0) { + glGetTexLevelParameteriv(faceTargets[0], sourceLevel, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); + } + + // Collect the size of the first face, and then compute the total size offset needed for this mip level + + glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_WIDTH, &sourceMip._width); + glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_HEIGHT, &sourceMip._height); + glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); + sourceMip._size = (GLint)faceTargets.size() * sourceMip._faceSize; + sourceMip._offset = bufferOffset; + bufferOffset += sourceMip._size; + } + (void)CHECK_GL_ERROR(); + + // Allocate the PBO to accomodate for all the mips to copy + glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); + (void)CHECK_GL_ERROR(); + + // Transfer from source texture to pbo + for (uint16_t mip = populatedMips; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + + uint16_t sourceLevel = mip - srcAllocatedMip; + + for (GLint f = 0; f < faceTargets.size(); f++) { + glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + } + (void)CHECK_GL_ERROR(); + } + + // Now populate the new texture from the pbo + glBindTexture(texTarget, 0); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); + + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); + + // Transfer from pbo to new texture + for (uint16_t mip = populatedMips; mip < numMips; ++mip) { + auto& sourceMip = sourceMips[mip]; + + uint16_t destLevel = mip - destAllocatedMip; + + for (GLint f = 0; f < faceTargets.size(); f++) { + glCompressedTexImage2D(faceTargets[f], destLevel, internalFormat, sourceMip._width, sourceMip._height, 0, + sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + } + } + + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + glDeleteBuffers(1, &pbo); +} + void GL41VariableAllocationTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); Q_ASSERT(_allocatedMip > 0); @@ -346,87 +427,11 @@ void GL41VariableAllocationTexture::promote() { syncSampler(); }); #else - GLuint pbo { 0 }; - glGenBuffers(1, &pbo); - glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); uint16_t numMips = _gpuObject.getNumMips(); - struct MipDesc { - GLint _faceSize; - GLint _size; - GLint _offset; - gpu::Vec3u _dims; - }; - std::vector sourceMips(numMips); - - glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); - glBindTexture(_target, oldId); - const auto& faceTargets = getFaceTargets(_target); - GLint internalFormat { 0 }; - (void)CHECK_GL_ERROR(); - - // Collect the mip description from the source texture - GLint bufferOffset { 0 }; - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto& sourceMip = sourceMips[mip]; - sourceMip._dims = _gpuObject.evalMipDimensions(mip); - - uint16_t sourceLevel = mip - oldAllocatedMip; - - // Grab internal format once - if (internalFormat == 0) { - glGetTexLevelParameteriv(faceTargets[0], sourceLevel, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); - } - - // Collect the size of the first face, and then compute the total size offset needed for this mip level - glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); - sourceMip._size = (GLint) faceTargets.size() * sourceMip._faceSize; - sourceMip._offset = bufferOffset; - bufferOffset += sourceMip._size; - } - (void)CHECK_GL_ERROR(); - - // Allocate the PBO to accomodate for all the mips to copy - glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); - (void)CHECK_GL_ERROR(); - - // Transfer from source texture to pbo - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto& sourceMip = sourceMips[mip]; - - uint16_t sourceLevel = mip - oldAllocatedMip; - - for (GLint f = 0; f < faceTargets.size(); f++) { - glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*)(sourceMip._offset + f * sourceMip._faceSize)); - } - (void)CHECK_GL_ERROR(); - - } - - // Now populate the new texture from the pbo - glBindTexture(_target, 0); - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); - - glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); - glBindTexture(_target, _texture); - - // Transfer from pbo to new texture - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto& sourceMip = sourceMips[mip]; - - uint16_t destLevel = mip - _allocatedMip; - - for (GLint f = 0; f < faceTargets.size(); f++) { - glCompressedTexImage2D(faceTargets[f], destLevel, internalFormat, sourceMip._dims.x, sourceMip._dims.y, 0, - sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); - } - } + withPreservedTexture([&] { + copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); - - glBindTexture(_target, 0); - - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - glDeleteBuffers(1, &pbo); + }); #endif } else { withPreservedTexture([&] { @@ -495,82 +500,11 @@ void GL41VariableAllocationTexture::demote() { syncSampler(); }); #else - GLuint pbo { 0 }; - glGenBuffers(1, &pbo); - glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); uint16_t numMips = _gpuObject.getNumMips(); - struct MipDesc { - GLint _faceSize; - GLint _size; - GLint _offset; - gpu::Vec3u _dims; - }; - std::vector sourceMips(numMips); - - glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); - glBindTexture(_target, oldId); - const auto& faceTargets = getFaceTargets(_target); - GLint internalFormat { 0 }; - - // Collect the mip description from the source texture - GLint bufferOffset { 0 }; - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto& sourceMip = sourceMips[mip]; - sourceMip._dims = _gpuObject.evalMipDimensions(mip); - - uint16_t sourceLevel = mip - oldAllocatedMip; - - // Grab internal format once - if (internalFormat != 0) { - glGetTexLevelParameteriv(faceTargets[0], sourceLevel, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); - } - - // Collect the size of the first face, and then compute the total size offset needed for this mip level - glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); - sourceMip._size = (GLint) faceTargets.size() * sourceMip._faceSize; - sourceMip._offset = bufferOffset; - bufferOffset += sourceMip._size; - } - (void)CHECK_GL_ERROR(); - - // Allocate the PBO to accomodate for all the mips to copy - glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); - (void)CHECK_GL_ERROR(); - - // Transfer from source texture to pbo - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto& sourceMip = sourceMips[mip]; - - uint16_t sourceLevel = mip - oldAllocatedMip; - - for (GLint f = 0; f < faceTargets.size(); f++) { - glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (sourceMip._offset + f * sourceMip._faceSize)); - } - (void)CHECK_GL_ERROR(); - } - - // Now populate the new texture from the pbo - glBindTexture(_target, 0); - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); - withPreservedTexture([&] { - // Transfer from pbo to new texture - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto& sourceMip = sourceMips[mip]; - - uint16_t destLevel = mip - _allocatedMip; - - for (GLint f = 0; f < faceTargets.size(); f++) { - glCompressedTexImage2D(faceTargets[f], destLevel, internalFormat, sourceMip._dims.x, sourceMip._dims.y, 0, - sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); - } - } + copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); }); - - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - glDeleteBuffers(1, &pbo); #endif } else { withPreservedTexture([&] { @@ -668,4 +602,3 @@ GL41ResourceTexture::GL41ResourceTexture(const std::weak_ptr& backend GL41ResourceTexture::~GL41ResourceTexture() { } - From 3abd9f21e80c35f5185b4a830e03b679a7d6a798 Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Mon, 1 May 2017 13:50:19 -0700 Subject: [PATCH 10/19] Debugging without understanding... --- libraries/gl/src/gl/Context.cpp | 4 +- .../src/gpu/gl41/GL41BackendTexture.cpp | 47 ++++++++++++++++--- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/libraries/gl/src/gl/Context.cpp b/libraries/gl/src/gl/Context.cpp index f7e08e607b..64d7dd635b 100644 --- a/libraries/gl/src/gl/Context.cpp +++ b/libraries/gl/src/gl/Context.cpp @@ -307,12 +307,12 @@ void Context::create() { qApp->setProperty(hifi::properties::gl::PRIMARY_CONTEXT, QVariant::fromValue((void*)PRIMARY)); } - if (enableDebugLogger) { + // if (enableDebugLogger) { makeCurrent(); glDebugMessageCallback(debugMessageCallback, NULL); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); doneCurrent(); - } + // } } #endif diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 8c249fc652..31fcf5b2d1 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -309,6 +309,30 @@ void GL41VariableAllocationTexture::syncSampler() const { } +void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { + GLuint fbo { 0 }; + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + + uint16_t mips = numMips; + // copy pre-existing mips + for (uint16_t mip = populatedMips; mip < mips; ++mip) { + auto mipDimensions = texture.evalMipDimensions(mip); + uint16_t targetMip = mip - destAllocatedMip; + uint16_t sourceMip = mip - srcAllocatedMip; + for (GLenum target : GLTexture::getFaceTargets(texTarget)) { + glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, srcId, sourceMip); + (void)CHECK_GL_ERROR(); + glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); + (void)CHECK_GL_ERROR(); + } + } + + // destroy the transfer framebuffer + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glDeleteFramebuffers(1, &fbo); +} + void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { GLuint pbo { 0 }; glGenBuffers(1, &pbo); @@ -347,12 +371,14 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint sourceMip._size = (GLint)faceTargets.size() * sourceMip._faceSize; sourceMip._offset = bufferOffset; bufferOffset += sourceMip._size; + gpu::gl::checkGLError(); } (void)CHECK_GL_ERROR(); // Allocate the PBO to accomodate for all the mips to copy glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); (void)CHECK_GL_ERROR(); + gpu::gl::checkGLError(); // Transfer from source texture to pbo for (uint16_t mip = populatedMips; mip < numMips; ++mip) { @@ -364,6 +390,7 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*)(sourceMip._offset + f * sourceMip._faceSize)); } (void)CHECK_GL_ERROR(); + gpu::gl::checkGLError(); } // Now populate the new texture from the pbo @@ -380,8 +407,9 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint uint16_t destLevel = mip - destAllocatedMip; for (GLint f = 0; f < faceTargets.size(); f++) { - glCompressedTexImage2D(faceTargets[f], destLevel, internalFormat, sourceMip._width, sourceMip._height, 0, + glCompressedTexSubImage2D(faceTargets[f], destLevel,0, 0, sourceMip._width, sourceMip._height, internalFormat, sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + gpu::gl::checkGLError(); } } @@ -405,6 +433,8 @@ void GL41VariableAllocationTexture::promote() { // allocate storage for new level allocateStorage(targetAllocatedMip); + uint16_t numMips = _gpuObject.getNumMips(); + if (_texelFormat.isCompressed()) { #if defined(USE_45IMAGECOPY_PROMOTE) withPreservedTexture([&] { @@ -427,7 +457,6 @@ void GL41VariableAllocationTexture::promote() { syncSampler(); }); #else - uint16_t numMips = _gpuObject.getNumMips(); withPreservedTexture([&] { copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); @@ -435,7 +464,8 @@ void GL41VariableAllocationTexture::promote() { #endif } else { withPreservedTexture([&] { - GLuint fbo { 0 }; + copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + /* GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); @@ -456,7 +486,7 @@ void GL41VariableAllocationTexture::promote() { // destroy the transfer framebuffer glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fbo); - + */ syncSampler(); }); } @@ -478,6 +508,8 @@ void GL41VariableAllocationTexture::demote() { allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); + uint16_t numMips = _gpuObject.getNumMips(); + if (_texelFormat.isCompressed()) { #if defined(USE_45IMAGECOPY_DEMOTE) withPreservedTexture([&] { @@ -500,7 +532,6 @@ void GL41VariableAllocationTexture::demote() { syncSampler(); }); #else - uint16_t numMips = _gpuObject.getNumMips(); withPreservedTexture([&] { copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); @@ -508,7 +539,9 @@ void GL41VariableAllocationTexture::demote() { #endif } else { withPreservedTexture([&] { - GLuint fbo { 0 }; + copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + + /* GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); @@ -529,7 +562,7 @@ void GL41VariableAllocationTexture::demote() { // destroy the transfer framebuffer glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glDeleteFramebuffers(1, &fbo); - +*/ syncSampler(); }); } From f81d01f179bd8eb1ff4760893e17f461e5b5c078 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 1 May 2017 14:13:59 -0700 Subject: [PATCH 11/19] Prevent possible crash in texture buffering thread --- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 10 +++++++++- libraries/gpu-gl/src/gpu/gl/GLTexture.h | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 7f075a1698..e85e74ce73 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -150,6 +150,7 @@ GLExternalTexture::~GLExternalTexture() { // Variable sized textures using MemoryPressureState = GLVariableAllocationSupport::MemoryPressureState; using WorkQueue = GLVariableAllocationSupport::WorkQueue; +using TransferJobPointer = GLVariableAllocationSupport::TransferJobPointer; std::list GLVariableAllocationSupport::_memoryManagedTextures; MemoryPressureState GLVariableAllocationSupport::_memoryPressureState { MemoryPressureState::Idle }; @@ -159,6 +160,7 @@ WorkQueue GLVariableAllocationSupport::_transferQueue; WorkQueue GLVariableAllocationSupport::_promoteQueue; WorkQueue GLVariableAllocationSupport::_demoteQueue; TexturePointer GLVariableAllocationSupport::_currentTransferTexture; +TransferJobPointer GLVariableAllocationSupport::_currentTransferJob; size_t GLVariableAllocationSupport::_frameTexturesCreated { 0 }; #define OVERSUBSCRIBED_PRESSURE_VALUE 0.95f @@ -553,9 +555,15 @@ void GLVariableAllocationSupport::executeNextTransfer(const TexturePointer& curr if (!_pendingTransfers.empty()) { // Keeping hold of a strong pointer during the transfer ensures that the transfer thread cannot try to access a destroyed texture _currentTransferTexture = currentTexture; - if (_pendingTransfers.front()->tryTransfer()) { + // Keeping hold of a strong pointer to the transfer job ensures that if the pending transfer queue is rebuilt, the transfer job + // doesn't leave scope, causing a crash in the buffering thread + _currentTransferJob = _pendingTransfers.front(); + // transfer jobs use asynchronous buffering of the texture data because it may involve disk IO, so we execute a try here to determine if the buffering + // is complete + if (_currentTransferJob->tryTransfer()) { _pendingTransfers.pop(); _currentTransferTexture.reset(); + _currentTransferJob.reset(); } } } diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.h b/libraries/gpu-gl/src/gpu/gl/GLTexture.h index e0b8a63a99..2603b36b21 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.h +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.h @@ -86,7 +86,8 @@ public: void transfer(); }; - using TransferQueue = std::queue>; + using TransferJobPointer = std::shared_ptr; + using TransferQueue = std::queue; static MemoryPressureState _memoryPressureState; public: @@ -100,6 +101,7 @@ protected: static WorkQueue _promoteQueue; static WorkQueue _demoteQueue; static TexturePointer _currentTransferTexture; + static TransferJobPointer _currentTransferJob; static const uvec3 INITIAL_MIP_TRANSFER_DIMENSIONS; static const uvec3 MAX_TRANSFER_DIMENSIONS; static const size_t MAX_TRANSFER_SIZE; From 8b62fad85eaadd7b1a96b859d03157e447ddc9fd Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 1 May 2017 18:19:07 -0700 Subject: [PATCH 12/19] TRying to test with sysmem and still doesn;t work --- .../src/gpu/gl41/GL41BackendTexture.cpp | 147 ++++++------------ 1 file changed, 47 insertions(+), 100 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 31fcf5b2d1..e52c2398f9 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -333,10 +333,23 @@ void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GL glDeleteFramebuffers(1, &fbo); } -void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { - GLuint pbo { 0 }; - glGenBuffers(1, &pbo); - glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); +void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { +#ifdef USE_GL45_COPYIMAGE + for (uint16_t mip = populatedMips; mip < numMips; ++mip) { + auto mipDimensions = texture.evalMipDimensions(mip); + uint16_t targetMip = mip - destAllocatedMip; + uint16_t sourceMip = mip - srcAllocatedMip; + auto faces = GLTexture::getFaceCount(texTarget); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + srcId, texTarget, sourceMip, 0, 0, face, + destId, texTarget, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } +#else struct MipDesc { GLint _faceSize; GLint _size; @@ -346,7 +359,9 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint }; std::vector sourceMips(numMips); - glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); + std::vector bytes; + + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); glBindTexture(texTarget, srcId); const auto& faceTargets = GLTexture::getFaceTargets(texTarget); GLint internalFormat { 0 }; @@ -364,9 +379,12 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint } // Collect the size of the first face, and then compute the total size offset needed for this mip level + auto mipDimensions = texture.evalMipDimensions(sourceLevel); + sourceMip._width = mipDimensions.x; + sourceMip._height = mipDimensions.y; - glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_WIDTH, &sourceMip._width); - glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_HEIGHT, &sourceMip._height); + // glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_WIDTH, &sourceMip._width); + // glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_HEIGHT, &sourceMip._height); glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); sourceMip._size = (GLint)faceTargets.size() * sourceMip._faceSize; sourceMip._offset = bufferOffset; @@ -376,9 +394,21 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint (void)CHECK_GL_ERROR(); // Allocate the PBO to accomodate for all the mips to copy +#ifdef USE_PBO + GLvoid* pboPointer = 0; + GLuint pbo { 0 }; + glGenBuffers(1, &pbo); + glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); (void)CHECK_GL_ERROR(); gpu::gl::checkGLError(); +#else + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + bytes.resize(bufferOffset); + auto pboPointer = bytes.data(); +#endif + // Transfer from source texture to pbo for (uint16_t mip = populatedMips; mip < numMips; ++mip) { @@ -387,7 +417,7 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint uint16_t sourceLevel = mip - srcAllocatedMip; for (GLint f = 0; f < faceTargets.size(); f++) { - glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (pboPointer + (sourceMip._offset + f * sourceMip._faceSize))); } (void)CHECK_GL_ERROR(); gpu::gl::checkGLError(); @@ -395,10 +425,13 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint // Now populate the new texture from the pbo glBindTexture(texTarget, 0); +#ifdef USE_PBO glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); +#endif glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); + glBindTexture(texTarget, destId); // Transfer from pbo to new texture for (uint16_t mip = populatedMips; mip < numMips; ++mip) { @@ -408,13 +441,16 @@ void copyCompressedTexGPUMem(GLenum texTarget, GLuint srcId, GLuint destId, uint for (GLint f = 0; f < faceTargets.size(); f++) { glCompressedTexSubImage2D(faceTargets[f], destLevel,0, 0, sourceMip._width, sourceMip._height, internalFormat, - sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + sourceMip._faceSize, (void*)(pboPointer + (sourceMip._offset + f * sourceMip._faceSize))); gpu::gl::checkGLError(); } } +#ifdef USE_PBO glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); +#endif +#endif } void GL41VariableAllocationTexture::promote() { @@ -436,57 +472,13 @@ void GL41VariableAllocationTexture::promote() { uint16_t numMips = _gpuObject.getNumMips(); if (_texelFormat.isCompressed()) { -#if defined(USE_45IMAGECOPY_PROMOTE) withPreservedTexture([&] { - uint16_t numMips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = mip - oldAllocatedMip; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } + copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); }); -#else - withPreservedTexture([&] { - copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - syncSampler(); - }); -#endif } else { withPreservedTexture([&] { copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - /* GLuint fbo { 0 }; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - - uint16_t mips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = mip - oldAllocatedMip; - for (GLenum target : getFaceTargets(_target)) { - glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip); - (void)CHECK_GL_ERROR(); - glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); - (void)CHECK_GL_ERROR(); - } - } - - // destroy the transfer framebuffer - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glDeleteFramebuffers(1, &fbo); - */ syncSampler(); }); } @@ -511,58 +503,13 @@ void GL41VariableAllocationTexture::demote() { uint16_t numMips = _gpuObject.getNumMips(); if (_texelFormat.isCompressed()) { -#if defined(USE_45IMAGECOPY_DEMOTE) withPreservedTexture([&] { - uint16_t numMips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = targetMip + 1; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } + copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); syncSampler(); }); -#else - withPreservedTexture([&] { - copyCompressedTexGPUMem(_target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - syncSampler(); - }); -#endif } else { withPreservedTexture([&] { copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - - /* GLuint fbo { 0 }; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - - uint16_t numMips = _gpuObject.getNumMips(); - // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < numMips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = targetMip + 1; - for (GLenum target : getFaceTargets(_target)) { - glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip); - (void)CHECK_GL_ERROR(); - glCopyTexSubImage2D(target, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y); - (void)CHECK_GL_ERROR(); - } - } - - // destroy the transfer framebuffer - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - glDeleteFramebuffers(1, &fbo); -*/ syncSampler(); }); } From 54ace01cd6f962f1b43faed541e2f24510cf470d Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Tue, 2 May 2017 00:32:32 -0700 Subject: [PATCH 13/19] Factorizing the code on both 45 and 41 backend --- .../src/gpu/gl41/GL41BackendTexture.cpp | 46 +++++++------- .../gpu/gl45/GL45BackendVariableTexture.cpp | 63 ++++++++++--------- 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index e52c2398f9..114f61dfc9 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -374,17 +374,18 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui uint16_t sourceLevel = mip - srcAllocatedMip; // Grab internal format once - if (internalFormat != 0) { + if (internalFormat == 0) { glGetTexLevelParameteriv(faceTargets[0], sourceLevel, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat); } // Collect the size of the first face, and then compute the total size offset needed for this mip level - auto mipDimensions = texture.evalMipDimensions(sourceLevel); + auto mipDimensions = texture.evalMipDimensions(mip); sourceMip._width = mipDimensions.x; sourceMip._height = mipDimensions.y; - - // glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_WIDTH, &sourceMip._width); - // glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_HEIGHT, &sourceMip._height); +#ifdef DEBUG_COPY + glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_WIDTH, &sourceMip._width); + glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_HEIGHT, &sourceMip._height); +#endif glGetTexLevelParameteriv(faceTargets.front(), sourceLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sourceMip._faceSize); sourceMip._size = (GLint)faceTargets.size() * sourceMip._faceSize; sourceMip._offset = bufferOffset; @@ -394,21 +395,12 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui (void)CHECK_GL_ERROR(); // Allocate the PBO to accomodate for all the mips to copy -#ifdef USE_PBO - GLvoid* pboPointer = 0; + GLint pboPointer = 0; GLuint pbo { 0 }; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); (void)CHECK_GL_ERROR(); - gpu::gl::checkGLError(); -#else - glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - bytes.resize(bufferOffset); - auto pboPointer = bytes.data(); -#endif - // Transfer from source texture to pbo for (uint16_t mip = populatedMips; mip < numMips; ++mip) { @@ -417,18 +409,15 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui uint16_t sourceLevel = mip - srcAllocatedMip; for (GLint f = 0; f < faceTargets.size(); f++) { - glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (pboPointer + (sourceMip._offset + f * sourceMip._faceSize))); + glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (pboPointer + (sourceMip._offset + f * sourceMip._faceSize))); } (void)CHECK_GL_ERROR(); - gpu::gl::checkGLError(); } // Now populate the new texture from the pbo glBindTexture(texTarget, 0); -#ifdef USE_PBO glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); -#endif glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); glBindTexture(texTarget, destId); @@ -440,17 +429,21 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui uint16_t destLevel = mip - destAllocatedMip; for (GLint f = 0; f < faceTargets.size(); f++) { - glCompressedTexSubImage2D(faceTargets[f], destLevel,0, 0, sourceMip._width, sourceMip._height, internalFormat, +#ifdef DEBUG_COPY + GLint destWidth, destHeight, destSize; + glGetTexLevelParameteriv(faceTargets.front(), destLevel, GL_TEXTURE_WIDTH, &destWidth); + glGetTexLevelParameteriv(faceTargets.front(), destLevel, GL_TEXTURE_HEIGHT, &destHeight); + glGetTexLevelParameteriv(faceTargets.front(), destLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &destSize); +#endif + glCompressedTexSubImage2D(faceTargets[f], destLevel, 0, 0, sourceMip._width, sourceMip._height, internalFormat, sourceMip._faceSize, (void*)(pboPointer + (sourceMip._offset + f * sourceMip._faceSize))); gpu::gl::checkGLError(); } } -#ifdef USE_PBO glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); #endif -#endif } void GL41VariableAllocationTexture::promote() { @@ -462,15 +455,16 @@ void GL41VariableAllocationTexture::promote() { GLuint oldId = _id; auto oldSize = _size; + uint16_t oldAllocatedMip = _allocatedMip; + // create new texture const_cast(_id) = allocate(_gpuObject); - uint16_t oldAllocatedMip = _allocatedMip; // allocate storage for new level allocateStorage(targetAllocatedMip); + // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - if (_texelFormat.isCompressed()) { withPreservedTexture([&] { copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); @@ -495,13 +489,15 @@ void GL41VariableAllocationTexture::demote() { Q_ASSERT(_allocatedMip < _maxAllocatedMip); auto oldId = _id; auto oldSize = _size; + + // allocate new texture const_cast(_id) = allocate(_gpuObject); uint16_t oldAllocatedMip = _allocatedMip; allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); + // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - if (_texelFormat.isCompressed()) { withPreservedTexture([&] { copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 92d820e5f0..3381fa8cce 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -97,6 +97,24 @@ void GL45ResourceTexture::syncSampler() const { glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip); } + +void copyTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { + for (uint16_t mip = populatedMips; mip < numMips; ++mip) { + auto mipDimensions = texture.evalMipDimensions(mip); + uint16_t targetMip = mip - destAllocatedMip; + uint16_t sourceMip = mip - srcAllocatedMip; + auto faces = GLTexture::getFaceCount(texTarget); + for (uint8_t face = 0; face < faces; ++face) { + glCopyImageSubData( + srcId, texTarget, sourceMip, 0, 0, face, + destId, texTarget, targetMip, 0, 0, face, + mipDimensions.x, mipDimensions.y, 1 + ); + (void)CHECK_GL_ERROR(); + } + } +} + void GL45ResourceTexture::promote() { PROFILE_RANGE(render_gpu_gl, __FUNCTION__); Q_ASSERT(_allocatedMip > 0); @@ -106,27 +124,18 @@ void GL45ResourceTexture::promote() { GLuint oldId = _id; auto oldSize = _size; + uint16_t oldAllocatedMip = _allocatedMip; + // create new texture const_cast(_id) = allocate(_gpuObject); - uint16_t oldAllocatedMip = _allocatedMip; + // allocate storage for new level allocateStorage(targetAllocatedMip); - uint16_t mips = _gpuObject.getNumMips(); + // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = mip - oldAllocatedMip; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } + uint16_t numMips = _gpuObject.getNumMips(); + copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + // destroy the old texture glDeleteTextures(1, &oldId); // update the memory usage @@ -140,25 +149,17 @@ void GL45ResourceTexture::demote() { Q_ASSERT(_allocatedMip < _maxAllocatedMip); auto oldId = _id; auto oldSize = _size; + + // allocate new texture const_cast(_id) = allocate(_gpuObject); + uint16_t oldAllocatedMip = _allocatedMip; allocateStorage(_allocatedMip + 1); _populatedMip = std::max(_populatedMip, _allocatedMip); - uint16_t mips = _gpuObject.getNumMips(); + // copy pre-existing mips - for (uint16_t mip = _populatedMip; mip < mips; ++mip) { - auto mipDimensions = _gpuObject.evalMipDimensions(mip); - uint16_t targetMip = mip - _allocatedMip; - uint16_t sourceMip = targetMip + 1; - auto faces = getFaceCount(_target); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - oldId, _target, sourceMip, 0, 0, face, - _id, _target, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } + uint16_t numMips = _gpuObject.getNumMips(); + copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + // destroy the old texture glDeleteTextures(1, &oldId); // update the memory usage From 32d675c82bee798b8d8e25ed9c98c19ddd2d19d1 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 2 May 2017 11:46:51 -0700 Subject: [PATCH 14/19] Clean up the new code and adress review comments --- libraries/gl/src/gl/Context.cpp | 4 +-- libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp | 2 ++ libraries/gpu-gl/src/gpu/gl41/GL41Backend.h | 3 +++ .../src/gpu/gl41/GL41BackendTexture.cpp | 26 +++++-------------- libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp | 2 ++ libraries/gpu-gl/src/gpu/gl45/GL45Backend.h | 3 +++ .../gpu/gl45/GL45BackendVariableTexture.cpp | 4 +-- libraries/gpu/src/gpu/Context.cpp | 4 +++ libraries/gpu/src/gpu/Context.h | 5 ++++ libraries/gpu/src/gpu/Texture.cpp | 2 +- libraries/gpu/src/gpu/Texture.h | 6 ++--- 11 files changed, 33 insertions(+), 28 deletions(-) diff --git a/libraries/gl/src/gl/Context.cpp b/libraries/gl/src/gl/Context.cpp index 64d7dd635b..f7e08e607b 100644 --- a/libraries/gl/src/gl/Context.cpp +++ b/libraries/gl/src/gl/Context.cpp @@ -307,12 +307,12 @@ void Context::create() { qApp->setProperty(hifi::properties::gl::PRIMARY_CONTEXT, QVariant::fromValue((void*)PRIMARY)); } - // if (enableDebugLogger) { + if (enableDebugLogger) { makeCurrent(); glDebugMessageCallback(debugMessageCallback, NULL); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); doneCurrent(); - // } + } } #endif diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp index a87d0ad6b8..32bfb777a8 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.cpp @@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl41logging, "hifi.gpu.gl41") using namespace gpu; using namespace gpu::gl41; +const std::string GL41Backend::GL41_VERSION { "GL41" }; + void GL41Backend::do_draw(const Batch& batch, size_t paramOffset) { Primitive primitiveType = (Primitive)batch._params[paramOffset + 2]._uint; GLenum mode = gl::PRIMITIVE_TO_GL[primitiveType]; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h index 3662253a66..4caa29574c 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h +++ b/libraries/gpu-gl/src/gpu/gl41/GL41Backend.h @@ -44,6 +44,9 @@ public: explicit GL41Backend(bool syncCache) : Parent(syncCache) {} GL41Backend() : Parent() {} + static const std::string GL41_VERSION; + const std::string& getVersion() const override { return GL41_VERSION; } + class GL41Texture : public GLTexture { using Parent = GLTexture; friend class GL41Backend; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 114f61dfc9..87df109d16 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -310,6 +310,8 @@ void GL41VariableAllocationTexture::syncSampler() const { void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { + // DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT + GLuint fbo { 0 }; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); @@ -334,22 +336,8 @@ void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GL } void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { -#ifdef USE_GL45_COPYIMAGE - for (uint16_t mip = populatedMips; mip < numMips; ++mip) { - auto mipDimensions = texture.evalMipDimensions(mip); - uint16_t targetMip = mip - destAllocatedMip; - uint16_t sourceMip = mip - srcAllocatedMip; - auto faces = GLTexture::getFaceCount(texTarget); - for (uint8_t face = 0; face < faces; ++face) { - glCopyImageSubData( - srcId, texTarget, sourceMip, 0, 0, face, - destId, texTarget, targetMip, 0, 0, face, - mipDimensions.x, mipDimensions.y, 1 - ); - (void)CHECK_GL_ERROR(); - } - } -#else + // DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT + struct MipDesc { GLint _faceSize; GLint _size; @@ -361,7 +349,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui std::vector bytes; - glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); + glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_EXTRA_TEX_UNIT); glBindTexture(texTarget, srcId); const auto& faceTargets = GLTexture::getFaceTargets(texTarget); GLint internalFormat { 0 }; @@ -399,7 +387,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui GLuint pbo { 0 }; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); - glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STREAM_COPY); + glBufferData(GL_PIXEL_PACK_BUFFER, bufferOffset, nullptr, GL_STATIC_COPY); (void)CHECK_GL_ERROR(); // Transfer from source texture to pbo @@ -420,7 +408,6 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); glActiveTexture(GL_TEXTURE0 + GL41Backend::RESOURCE_TRANSFER_TEX_UNIT); - glBindTexture(texTarget, destId); // Transfer from pbo to new texture for (uint16_t mip = populatedMips; mip < numMips; ++mip) { @@ -443,7 +430,6 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glDeleteBuffers(1, &pbo); -#endif } void GL41VariableAllocationTexture::promote() { diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp index c9d1fb1b2f..c119e27d5b 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.cpp @@ -18,6 +18,8 @@ Q_LOGGING_CATEGORY(gpugl45logging, "hifi.gpu.gl45") using namespace gpu; using namespace gpu::gl45; +const std::string GL45Backend::GL45_VERSION { "GL45" }; + void GL45Backend::recycle() const { Parent::recycle(); } diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index dbedd81c76..8319e61382 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -41,6 +41,9 @@ public: explicit GL45Backend(bool syncCache) : Parent(syncCache) {} GL45Backend() : Parent() {} + static const std::string GL45_VERSION; + const std::string& getVersion() const override { return GL45_VERSION; } + class GL45Texture : public GLTexture { using Parent = GLTexture; friend class GL45Backend; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 3381fa8cce..6ea8d15704 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -134,7 +134,7 @@ void GL45ResourceTexture::promote() { // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); @@ -158,7 +158,7 @@ void GL45ResourceTexture::demote() { // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - copyTexGPUMem(_gpuObject, _target, _id, oldId, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); + copyTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); // destroy the old texture glDeleteTextures(1, &oldId); diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 0030b2fa88..78fef0af59 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -50,6 +50,10 @@ Context::Context(const Context& context) { Context::~Context() { } +const std::string& Context::getBackendVersion() const { + return _backend->getVersion(); +} + void Context::beginFrame(const glm::mat4& renderPose) { assert(!_frameActive); _frameActive = true; diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index b56255f862..c4b9453df3 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -54,6 +54,9 @@ class Backend { public: virtual~ Backend() {}; + + virtual const std::string& getVersion() const = 0; + void setStereoState(const StereoState& stereo) { _stereo = stereo; } virtual void render(const Batch& batch) = 0; @@ -153,6 +156,8 @@ public: Context(); ~Context(); + const std::string& getBackendVersion() const; + void beginFrame(const glm::mat4& renderPose = glm::mat4()); void appendFrameBatch(Batch& batch); FramePointer endFrame(); diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index b12ae5bc97..0f84d2a3c9 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -408,7 +408,7 @@ void Texture::setStoredMipFormat(const Element& format) { _storage->setFormat(format); } -const Element Texture::getStoredMipFormat() const { +Element Texture::getStoredMipFormat() const { if (_storage) { return _storage->getFormat(); } else { diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 21a1b0ec57..924c1ee148 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -285,7 +285,7 @@ public: Stamp bumpStamp() { return ++_stamp; } void setFormat(const Element& format) { _format = format; } - const Element& getFormat() const { return _format; } + Element getFormat() const { return _format; } private: Stamp _stamp { 0 }; @@ -372,7 +372,7 @@ public: bool isColorRenderTarget() const; bool isDepthStencilRenderTarget() const; - const Element getTexelFormat() const { return _texelFormat; } + Element getTexelFormat() const { return _texelFormat; } Vec3u getDimensions() const { return Vec3u(_width, _height, _depth); } uint16 getWidth() const { return _width; } @@ -468,7 +468,7 @@ public: // Mip storage format is constant across all mips void setStoredMipFormat(const Element& format); - const Element getStoredMipFormat() const; + Element getStoredMipFormat() const; // Manually allocate the mips down until the specified maxMip // this is just allocating the sysmem version of it From 41f0b1682ed2a7fdb228208a3a7cfafe57cdabd5 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 2 May 2017 14:45:41 -0700 Subject: [PATCH 15/19] Fixing warnings too --- .../src/gpu/gl41/GL41BackendTexture.cpp | 54 +++++++++---------- .../gpu/gl45/GL45BackendVariableTexture.cpp | 6 +-- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 87df109d16..796abda5a3 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -309,7 +309,7 @@ void GL41VariableAllocationTexture::syncSampler() const { } -void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { +void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) { // DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT GLuint fbo { 0 }; @@ -320,8 +320,8 @@ void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GL // copy pre-existing mips for (uint16_t mip = populatedMips; mip < mips; ++mip) { auto mipDimensions = texture.evalMipDimensions(mip); - uint16_t targetMip = mip - destAllocatedMip; - uint16_t sourceMip = mip - srcAllocatedMip; + uint16_t targetMip = mip - destMipOffset; + uint16_t sourceMip = mip - srcMipOffset; for (GLenum target : GLTexture::getFaceTargets(texTarget)) { glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, srcId, sourceMip); (void)CHECK_GL_ERROR(); @@ -335,7 +335,7 @@ void copyUncompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GL glDeleteFramebuffers(1, &fbo); } -void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { +void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) { // DestID must be bound to the GL41Backend::RESOURCE_TRANSFER_TEX_UNIT struct MipDesc { @@ -359,7 +359,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui for (uint16_t mip = populatedMips; mip < numMips; ++mip) { auto& sourceMip = sourceMips[mip]; - uint16_t sourceLevel = mip - srcAllocatedMip; + uint16_t sourceLevel = mip - srcMipOffset; // Grab internal format once if (internalFormat == 0) { @@ -383,7 +383,6 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui (void)CHECK_GL_ERROR(); // Allocate the PBO to accomodate for all the mips to copy - GLint pboPointer = 0; GLuint pbo { 0 }; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); @@ -394,10 +393,10 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui for (uint16_t mip = populatedMips; mip < numMips; ++mip) { auto& sourceMip = sourceMips[mip]; - uint16_t sourceLevel = mip - srcAllocatedMip; + uint16_t sourceLevel = mip - srcMipOffset; - for (GLint f = 0; f < faceTargets.size(); f++) { - glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (pboPointer + (sourceMip._offset + f * sourceMip._faceSize))); + for (GLuint f = 0; f < faceTargets.size(); f++) { + glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (sourceMip._offset + f * sourceMip._faceSize)); } (void)CHECK_GL_ERROR(); } @@ -413,9 +412,9 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui for (uint16_t mip = populatedMips; mip < numMips; ++mip) { auto& sourceMip = sourceMips[mip]; - uint16_t destLevel = mip - destAllocatedMip; + uint16_t destLevel = mip - destMipOffset; - for (GLint f = 0; f < faceTargets.size(); f++) { + for (GLuint f = 0; f < faceTargets.size(); f++) { #ifdef DEBUG_COPY GLint destWidth, destHeight, destSize; glGetTexLevelParameteriv(faceTargets.front(), destLevel, GL_TEXTURE_WIDTH, &destWidth); @@ -423,7 +422,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui glGetTexLevelParameteriv(faceTargets.front(), destLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &destSize); #endif glCompressedTexSubImage2D(faceTargets[f], destLevel, 0, 0, sourceMip._width, sourceMip._height, internalFormat, - sourceMip._faceSize, (void*)(pboPointer + (sourceMip._offset + f * sourceMip._faceSize))); + sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); gpu::gl::checkGLError(); } } @@ -451,17 +450,14 @@ void GL41VariableAllocationTexture::promote() { // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - if (_texelFormat.isCompressed()) { - withPreservedTexture([&] { + withPreservedTexture([&] { + if (_texelFormat.isCompressed()) { copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - syncSampler(); - }); - } else { - withPreservedTexture([&] { + } else { copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - syncSampler(); - }); - } + } + syncSampler(); + }); // destroy the old texture glDeleteTextures(1, &oldId); @@ -484,17 +480,15 @@ void GL41VariableAllocationTexture::demote() { // copy pre-existing mips uint16_t numMips = _gpuObject.getNumMips(); - if (_texelFormat.isCompressed()) { - withPreservedTexture([&] { + withPreservedTexture([&] { + if (_texelFormat.isCompressed()) { copyCompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - syncSampler(); - }); - } else { - withPreservedTexture([&] { + } else { copyUncompressedTexGPUMem(_gpuObject, _target, oldId, _id, numMips, oldAllocatedMip, _allocatedMip, _populatedMip); - syncSampler(); - }); - } + } + syncSampler(); + }); + // destroy the old texture glDeleteTextures(1, &oldId); diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 6ea8d15704..4f40f47085 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -98,11 +98,11 @@ void GL45ResourceTexture::syncSampler() const { } -void copyTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcAllocatedMip, uint16_t destAllocatedMip, uint16_t populatedMips) { +void copyTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLuint srcId, GLuint destId, uint16_t numMips, uint16_t srcMipOffset, uint16_t destMipOffset, uint16_t populatedMips) { for (uint16_t mip = populatedMips; mip < numMips; ++mip) { auto mipDimensions = texture.evalMipDimensions(mip); - uint16_t targetMip = mip - destAllocatedMip; - uint16_t sourceMip = mip - srcAllocatedMip; + uint16_t targetMip = mip - destMipOffset; + uint16_t sourceMip = mip - srcMipOffset; auto faces = GLTexture::getFaceCount(texTarget); for (uint8_t face = 0; face < faces; ++face) { glCopyImageSubData( From dc50db7ee5f0fa59d68f4604b96af6dcb31416a3 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 2 May 2017 16:27:28 -0700 Subject: [PATCH 16/19] One more warning from gcc --- libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 796abda5a3..527b503571 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -395,7 +395,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui uint16_t sourceLevel = mip - srcMipOffset; - for (GLuint f = 0; f < faceTargets.size(); f++) { + for (GLint f = 0; f < (GLint)faceTargets.size(); f++) { glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (sourceMip._offset + f * sourceMip._faceSize)); } (void)CHECK_GL_ERROR(); @@ -414,7 +414,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui uint16_t destLevel = mip - destMipOffset; - for (GLuint f = 0; f < faceTargets.size(); f++) { + for (GLint f = 0; f < (GLint)faceTargets.size(); f++) { #ifdef DEBUG_COPY GLint destWidth, destHeight, destSize; glGetTexLevelParameteriv(faceTargets.front(), destLevel, GL_TEXTURE_WIDTH, &destWidth); From 0ecf599267f76c0a71dfea3bccd8bfbc22942b32 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 2 May 2017 17:19:22 -0700 Subject: [PATCH 17/19] Adressing the warning --- libraries/gpu-gl/src/gpu/gl/GLShared.h | 2 ++ libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLShared.h b/libraries/gpu-gl/src/gpu/gl/GLShared.h index 22f63363d1..1b898e5c22 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLShared.h +++ b/libraries/gpu-gl/src/gpu/gl/GLShared.h @@ -18,6 +18,8 @@ Q_DECLARE_LOGGING_CATEGORY(gpugllogging) Q_DECLARE_LOGGING_CATEGORY(trace_render_gpu_gl) Q_DECLARE_LOGGING_CATEGORY(trace_render_gpu_gl_detail) +#define BUFFER_OFFSET(bytes) ((GLubyte*) nullptr + (bytes)) + namespace gpu { namespace gl { // Create a fence and inject a GPU wait on the fence diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp index 527b503571..c2cef5a21e 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendTexture.cpp @@ -396,7 +396,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui uint16_t sourceLevel = mip - srcMipOffset; for (GLint f = 0; f < (GLint)faceTargets.size(); f++) { - glGetCompressedTexImage(faceTargets[f], sourceLevel, (void*) (sourceMip._offset + f * sourceMip._faceSize)); + glGetCompressedTexImage(faceTargets[f], sourceLevel, BUFFER_OFFSET(sourceMip._offset + f * sourceMip._faceSize)); } (void)CHECK_GL_ERROR(); } @@ -422,7 +422,7 @@ void copyCompressedTexGPUMem(const gpu::Texture& texture, GLenum texTarget, GLui glGetTexLevelParameteriv(faceTargets.front(), destLevel, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &destSize); #endif glCompressedTexSubImage2D(faceTargets[f], destLevel, 0, 0, sourceMip._width, sourceMip._height, internalFormat, - sourceMip._faceSize, (void*)(sourceMip._offset + f * sourceMip._faceSize)); + sourceMip._faceSize, BUFFER_OFFSET(sourceMip._offset + f * sourceMip._faceSize)); gpu::gl::checkGLError(); } } From 07d3e482cf0d7e0a15a830f497bcde8240ab1a29 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 3 May 2017 15:40:39 -0700 Subject: [PATCH 18/19] ARG --- interface/src/Application.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index 86b2335e62..385aa0a286 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -139,7 +139,7 @@ public: Present = DisplayPlugin::Present, Paint = Present + 1, Idle = Paint + 1, - Lambda = Paint + 1 + Lambda = Idle + 1 }; // FIXME? Empty methods, do we still need them? From 4d49ae5b098eef9d8e6e83f389ea46b74b0a288c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 3 May 2017 15:41:00 -0700 Subject: [PATCH 19/19] Remove the +1s --- interface/src/Application.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index 385aa0a286..367d878dd4 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -137,9 +137,9 @@ public: enum Event { Present = DisplayPlugin::Present, - Paint = Present + 1, - Idle = Paint + 1, - Lambda = Idle + 1 + Paint, + Idle, + Lambda }; // FIXME? Empty methods, do we still need them?