From 30c8f01a25adf7941d55eb37fa3379000b907334 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 9 Jul 2018 14:14:29 +0100 Subject: [PATCH] Handle implementations on capture without ARB_vertex_binding --- renderdoc/driver/gl/gl_common.cpp | 17 ++++++++++-- renderdoc/driver/gl/gl_common.h | 1 + renderdoc/driver/gl/gl_driver.cpp | 3 +-- renderdoc/driver/gl/gl_initstate.cpp | 39 ++++++++++++++++++++++------ renderdoc/driver/gl/gl_manager.cpp | 3 +-- 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/renderdoc/driver/gl/gl_common.cpp b/renderdoc/driver/gl/gl_common.cpp index 678016b88..d02301c8d 100644 --- a/renderdoc/driver/gl/gl_common.cpp +++ b/renderdoc/driver/gl/gl_common.cpp @@ -507,7 +507,7 @@ void DoVendorChecks(GLPlatform &platform, GLWindowingData context) RDCEraseEl(VendorCheck); - if(GL.glGetError && GL.glGetIntegeri_v) + if(GL.glGetError && GL.glGetIntegeri_v && HasExt[ARB_vertex_attrib_binding]) { // clear all error flags. GLenum err = eGL_NONE; @@ -1332,11 +1332,24 @@ void ClearGLErrors() } } +GLint GetNumVertexBuffers() +{ + GLint numBindings = 16; + + // when the extension isn't present we pretend attribs == vertex buffers + if(HasExt[ARB_vertex_attrib_binding]) + GL.glGetIntegerv(eGL_MAX_VERTEX_ATTRIB_BINDINGS, &numBindings); + else + GL.glGetIntegerv(eGL_MAX_VERTEX_ATTRIBS, &numBindings); + + return numBindings; +} + GLuint GetBoundVertexBuffer(GLuint i) { GLuint buffer = 0; - if(VendorCheck[VendorCheck_AMD_vertex_buffer_query]) + if(VendorCheck[VendorCheck_AMD_vertex_buffer_query] || !HasExt[ARB_vertex_attrib_binding]) GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, (GLint *)&buffer); else GL.glGetIntegeri_v(eGL_VERTEX_BINDING_BUFFER, i, (GLint *)&buffer); diff --git a/renderdoc/driver/gl/gl_common.h b/renderdoc/driver/gl/gl_common.h index 4c566603f..31a724531 100644 --- a/renderdoc/driver/gl/gl_common.h +++ b/renderdoc/driver/gl/gl_common.h @@ -492,6 +492,7 @@ const char *SamplerString(GLenum smpenum); void ClearGLErrors(); GLuint GetBoundVertexBuffer(GLuint idx); +GLint GetNumVertexBuffers(); void GetBindpointMapping(GLuint curProg, int shadIdx, ShaderReflection *refl, ShaderBindpointMapping &mapping); diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index af18815a1..cd34e048c 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -4435,8 +4435,7 @@ void WrappedOpenGL::AddUsage(const DrawcallDescription &d) } // Vertex buffers and attributes - GLint numVBufferBindings = 16; - GL.glGetIntegerv(eGL_MAX_VERTEX_ATTRIB_BINDINGS, &numVBufferBindings); + GLint numVBufferBindings = GetNumVertexBuffers(); for(GLuint i = 0; i < (GLuint)numVBufferBindings; i++) { diff --git a/renderdoc/driver/gl/gl_initstate.cpp b/renderdoc/driver/gl/gl_initstate.cpp index 7def682e2..bccdf3130 100644 --- a/renderdoc/driver/gl/gl_initstate.cpp +++ b/renderdoc/driver/gl/gl_initstate.cpp @@ -325,23 +325,46 @@ void GLResourceManager::ContextPrepare_InitialState(GLResource res) { GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_ENABLED, (GLint *)&data.VertexAttribs[i].enabled); - GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_BINDING, (GLint *)&data.VertexAttribs[i].vbslot); - GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_RELATIVE_OFFSET, - (GLint *)&data.VertexAttribs[i].offset); GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_TYPE, (GLint *)&data.VertexAttribs[i].type); GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_NORMALIZED, (GLint *)&data.VertexAttribs[i].normalized); - GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_INTEGER, - (GLint *)&data.VertexAttribs[i].integer); + + // no extension for this, it just appeared in GL & GLES 3.0, along with glVertexAttribIPointer + if(GLCoreVersion >= 3.0) + GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_INTEGER, + (GLint *)&data.VertexAttribs[i].integer); + else + data.VertexAttribs[i].integer = 0; + GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_SIZE, (GLint *)&data.VertexAttribs[i].size); GLuint buffer = GetBoundVertexBuffer(i); data.VertexBuffers[i].Buffer = BufferRes(ctx, buffer); - GL.glGetIntegeri_v(eGL_VERTEX_BINDING_STRIDE, i, (GLint *)&data.VertexBuffers[i].Stride); - GL.glGetIntegeri_v(eGL_VERTEX_BINDING_OFFSET, i, (GLint *)&data.VertexBuffers[i].Offset); - GL.glGetIntegeri_v(eGL_VERTEX_BINDING_DIVISOR, i, (GLint *)&data.VertexBuffers[i].Divisor); + if(HasExt[ARB_vertex_attrib_binding]) + { + GL.glGetIntegeri_v(eGL_VERTEX_BINDING_STRIDE, i, (GLint *)&data.VertexBuffers[i].Stride); + GL.glGetIntegeri_v(eGL_VERTEX_BINDING_OFFSET, i, (GLint *)&data.VertexBuffers[i].Offset); + GL.glGetIntegeri_v(eGL_VERTEX_BINDING_DIVISOR, i, (GLint *)&data.VertexBuffers[i].Divisor); + + GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_RELATIVE_OFFSET, + (GLint *)&data.VertexAttribs[i].offset); + GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_BINDING, (GLint *)&data.VertexAttribs[i].vbslot); + } + else + { + GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_STRIDE, + (GLint *)&data.VertexBuffers[i].Stride); + GL.glGetVertexAttribiv(i, eGL_VERTEX_ATTRIB_ARRAY_DIVISOR, + (GLint *)&data.VertexBuffers[i].Divisor); + data.VertexBuffers[i].Offset = 0; + + void *ptr = NULL; + GL.glGetVertexAttribPointerv(i, eGL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr); + + data.VertexAttribs[i].offset = (uint32_t)(uintptr_t)ptr; + } } GLuint buffer = 0; diff --git a/renderdoc/driver/gl/gl_manager.cpp b/renderdoc/driver/gl/gl_manager.cpp index c1f850b2d..40c0fdbde 100644 --- a/renderdoc/driver/gl/gl_manager.cpp +++ b/renderdoc/driver/gl/gl_manager.cpp @@ -41,8 +41,7 @@ void GLResourceManager::MarkVAOReferenced(GLResource res, FrameRefType ref, bool MarkResourceFrameReferenced(res, ref == eFrameRef_Unknown ? eFrameRef_Unknown : eFrameRef_Read); - GLint numVBufferBindings = 16; - GL.glGetIntegerv(eGL_MAX_VERTEX_ATTRIB_BINDINGS, &numVBufferBindings); + GLint numVBufferBindings = GetNumVertexBuffers(); for(GLuint i = 0; i < (GLuint)numVBufferBindings; i++) {