From debc787eb9f0ec11b403e2243d5fb76c1e67fa61 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 25 Feb 2015 17:29:55 +0000 Subject: [PATCH] Check fast path for compressed pixel unpack requiring block dims * The unpack parameters are ignored for compressed images unless the compressed width, height, depth and size parameters are set (whichever are required for the given unpack param). So we roll this into our calculation of the fast path, which means that we only use them in UnpackCompressed if they are valid. --- renderdoc/driver/gl/gl_renderstate.cpp | 38 ++++++++++++++++++- renderdoc/driver/gl/gl_renderstate.h | 4 +- .../driver/gl/wrappers/gl_texture_funcs.cpp | 12 +++--- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/renderdoc/driver/gl/gl_renderstate.cpp b/renderdoc/driver/gl/gl_renderstate.cpp index e046d8acd..c655047ec 100644 --- a/renderdoc/driver/gl/gl_renderstate.cpp +++ b/renderdoc/driver/gl/gl_renderstate.cpp @@ -83,7 +83,43 @@ bool PixelUnpackState::FastPath(GLsizei width, GLsizei height, GLsizei depth, GL if(height > 0 && imageheight > 0 && height < imageheight) return false; - if(dataformat != eGL_NONE && alignment > (int32_t)GetByteSize(1, 1, 1, dataformat, basetype)) + if(alignment > (int32_t)GetByteSize(1, 1, 1, dataformat, basetype)) + return false; + + return true; +} + +bool PixelUnpackState::FastPathCompressed(GLsizei width, GLsizei height, GLsizei depth) +{ + // compressedBlockSize and compressedBlockWidth must be set for any of the unpack params to be used + // if they are 0, all of the unpack params are ignored, so we go through the fast path (no unpacking) + if(compressedBlockSize == 0 || compressedBlockWidth == 0) + return true; + + if(skipPixels) + return false; + + if(width > 0 && rowlength > 0 && width < rowlength) + return false; + + // the below two unpack params require compressedBlockHeight to be set so if we haven't "failed" to + // hit the fast path, none of the other params make a difference as they're ignored and we go through + // the fast path (no unpacking) + if(compressedBlockHeight == 0) + return true; + + if(height > 0 && skipRows) + return false; + + if(height > 0 && imageheight > 0 && height < imageheight) + return false; + + // the final unpack param requires compressedBlockDepth to be set, as above if it's 0 then we can + // just go straight through the fast path (no unpacking) + if(compressedBlockDepth == 0) + return true; + + if(depth > 0 && skipImages) return false; return true; diff --git a/renderdoc/driver/gl/gl_renderstate.h b/renderdoc/driver/gl/gl_renderstate.h index abc473885..d8448bd9d 100644 --- a/renderdoc/driver/gl/gl_renderstate.h +++ b/renderdoc/driver/gl/gl_renderstate.h @@ -44,7 +44,9 @@ struct PixelUnpackState void Fetch(const GLHookSet *funcs, bool compressed); void Apply(const GLHookSet *funcs, bool compressed); - bool FastPath(GLsizei width, GLsizei height, GLsizei depth, GLenum dataformat=eGL_NONE, GLenum basetype=eGL_NONE); + bool FastPath(GLsizei width, GLsizei height, GLsizei depth, GLenum dataformat, GLenum basetype); + bool FastPathCompressed(GLsizei width, GLsizei height, GLsizei depth); + byte *Unpack(byte *pixels, GLsizei width, GLsizei height, GLsizei depth, GLenum dataformat, GLenum basetype); byte *UnpackCompressed(byte *pixels, GLsizei width, GLsizei height, GLsizei depth, GLsizei &imageSize); }; diff --git a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp index 77f13042a..5009297d0 100644 --- a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp +++ b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp @@ -2039,7 +2039,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureImage1DEXT(GLuint texture, GLen { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, 0, 0)) + if(unpack.FastPathCompressed(Width, 0, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, 0, 0, imageSize); @@ -2199,7 +2199,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureImage2DEXT(GLuint texture, GLen { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, 0)) + if(unpack.FastPathCompressed(Width, Height, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, 0, imageSize); @@ -2383,7 +2383,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureImage3DEXT(GLuint texture, GLen { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, Depth)) + if(unpack.FastPathCompressed(Width, Height, Depth)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, Depth, imageSize); @@ -3689,7 +3689,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureSubImage1DEXT(GLuint texture, G { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, 0, 0)) + if(unpack.FastPathCompressed(Width, 0, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, 0, 0, imageSize); @@ -3817,7 +3817,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureSubImage2DEXT(GLuint texture, G { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, 0)) + if(unpack.FastPathCompressed(Width, Height, 0)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, 0, imageSize); @@ -3947,7 +3947,7 @@ bool WrappedOpenGL::Serialise_glCompressedTextureSubImage3DEXT(GLuint texture, G { PixelUnpackState unpack; unpack.Fetch(&m_Real, true); - if(unpack.FastPath(Width, Height, Depth)) + if(unpack.FastPathCompressed(Width, Height, Depth)) srcPixels = (byte *)pixels; else srcPixels = unpackedPixels = unpack.UnpackCompressed((byte *)pixels, Width, Height, Depth, imageSize);