From 3a687217029e3b5de2ed427b53398749898f677a Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 21 Oct 2020 18:00:19 +0100 Subject: [PATCH] Allow repeated calls to CopyTex2DMSToArray on GL * Normally the function creates its output to enforce storage (for texture views) but repeated calls would break that, so we only create when the output texture ID is 0. --- renderdoc/driver/gl/gl_initstate.cpp | 1 + renderdoc/driver/gl/gl_msaa_array_conv.cpp | 47 +++++++++------------- renderdoc/driver/gl/gl_replay.cpp | 1 + 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/renderdoc/driver/gl/gl_initstate.cpp b/renderdoc/driver/gl/gl_initstate.cpp index 923e0fbd8..d6667d5dc 100644 --- a/renderdoc/driver/gl/gl_initstate.cpp +++ b/renderdoc/driver/gl/gl_initstate.cpp @@ -945,6 +945,7 @@ void GLResourceManager::PrepareTextureInitialContents(ResourceId liveid, Resourc GLuint msaaTex = tex; + tex = 0; m_Driver->CopyTex2DMSToArray(tex, msaaTex, details.width, details.height, details.depth, details.samples, details.internalFormat); diff --git a/renderdoc/driver/gl/gl_msaa_array_conv.cpp b/renderdoc/driver/gl/gl_msaa_array_conv.cpp index 85c92792d..377eb83f8 100644 --- a/renderdoc/driver/gl/gl_msaa_array_conv.cpp +++ b/renderdoc/driver/gl/gl_msaa_array_conv.cpp @@ -119,10 +119,17 @@ void WrappedOpenGL::CopyTex2DMSToArray(GLuint &destArray, GLuint srcMS, GLint wi intFormat = GetSizedFormat(intFormat); + bool needInit = false; + // create temporary texture array, which we'll initialise to be the width/height in same format, // with the same number of array slices as multi samples. - GL.glGenTextures(1, &destArray); - GL.glBindTexture(eGL_TEXTURE_2D_ARRAY, destArray); + if(destArray == 0) + { + GL.glGenTextures(1, &destArray); + GL.glBindTexture(eGL_TEXTURE_2D_ARRAY, destArray); + + needInit = true; + } bool failed = false; @@ -156,16 +163,20 @@ void WrappedOpenGL::CopyTex2DMSToArray(GLuint &destArray, GLuint srcMS, GLint wi { // create using the non-storage API which is always available, so the texture is at least valid // (but with undefined/empty contents). - GL.glTextureImage3DEXT(destArray, eGL_TEXTURE_2D_ARRAY, 0, intFormat, width, height, - arraySize * samples, 0, GetBaseFormat(intFormat), GetDataType(intFormat), - NULL); - GL.glTextureParameteriEXT(destArray, eGL_TEXTURE_2D_ARRAY, eGL_TEXTURE_MAX_LEVEL, 0); + if(needInit) + { + GL.glTextureImage3DEXT(destArray, eGL_TEXTURE_2D_ARRAY, 0, intFormat, width, height, + arraySize * samples, 0, GetBaseFormat(intFormat), + GetDataType(intFormat), NULL); + GL.glTextureParameteriEXT(destArray, eGL_TEXTURE_2D_ARRAY, eGL_TEXTURE_MAX_LEVEL, 0); + } return; } // initialise the texture using texture storage, as required for texture views. - GL.glTextureStorage3DEXT(destArray, eGL_TEXTURE_2D_ARRAY, 1, intFormat, width, height, - arraySize * samples); + if(needInit) + GL.glTextureStorage3DEXT(destArray, eGL_TEXTURE_2D_ARRAY, 1, intFormat, width, height, + arraySize * samples); if(IsDepthStencilFormat(intFormat)) { @@ -293,16 +304,6 @@ void WrappedOpenGL::CopyDepthTex2DMSToArray(GLuint &destArray, GLuint srcMS, GLi // depth aspect GL.glActiveTexture(eGL_TEXTURE0); GL.glBindTexture(eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, texs[1]); - GL.glTextureParameteriEXT(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_MIN_FILTER, - eGL_NEAREST); - GL.glTextureParameteriEXT(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_MAG_FILTER, - eGL_NEAREST); - GL.glTextureParameteriEXT(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_WRAP_S, - eGL_CLAMP_TO_EDGE); - GL.glTextureParameteriEXT(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_WRAP_T, - eGL_CLAMP_TO_EDGE); - GL.glTextureParameteriEXT(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_BASE_LEVEL, 0); - GL.glTextureParameteriEXT(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_MAX_LEVEL, 0); GL.glTextureParameteriEXT(texs[1], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_DEPTH_STENCIL_TEXTURE_MODE, eGL_DEPTH_COMPONENT); } @@ -312,16 +313,6 @@ void WrappedOpenGL::CopyDepthTex2DMSToArray(GLuint &destArray, GLuint srcMS, GLi // stencil aspect GL.glActiveTexture(eGL_TEXTURE1); GL.glBindTexture(eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, texs[2]); - GL.glTextureParameteriEXT(texs[2], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_MIN_FILTER, - eGL_NEAREST); - GL.glTextureParameteriEXT(texs[2], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_MAG_FILTER, - eGL_NEAREST); - GL.glTextureParameteriEXT(texs[2], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_WRAP_S, - eGL_CLAMP_TO_EDGE); - GL.glTextureParameteriEXT(texs[2], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_WRAP_T, - eGL_CLAMP_TO_EDGE); - GL.glTextureParameteriEXT(texs[2], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_BASE_LEVEL, 0); - GL.glTextureParameteriEXT(texs[2], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_TEXTURE_MAX_LEVEL, 0); GL.glTextureParameteriEXT(texs[2], eGL_TEXTURE_2D_MULTISAMPLE_ARRAY, eGL_DEPTH_STENCIL_TEXTURE_MODE, eGL_STENCIL_INDEX); } diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index 461878f38..59afdb525 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -2658,6 +2658,7 @@ void GLReplay::GetTextureData(ResourceId tex, const Subresource &sub, // copy multisampled texture to an array. This creates tempTex and returns it in that variable, // for us to own + tempTex = 0; m_pDriver->CopyTex2DMSToArray(tempTex, texname, width, height, arraysize, samples, intFormat); // CopyTex2DMSToArray is unwrapped, so register the resource here now