From 59ee88ea99b6de592b32d635e097a759b7f70e23 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 15 Jan 2012 14:24:10 +0000 Subject: [PATCH] Distinguish linear pointers. --- glretrace.py | 18 +++++++++--------- retrace.py | 19 +++++++++++++++++-- retrace_stdc.cpp | 6 ++++++ specs/glapi.py | 2 +- specs/gltypes.py | 9 +++++++-- specs/stdapi.py | 38 ++++++++++++++++++++++++++++++++++++++ trace.py | 18 ++++++++++++++++++ 7 files changed, 96 insertions(+), 14 deletions(-) diff --git a/glretrace.py b/glretrace.py index 15ba092..e650c54 100644 --- a/glretrace.py +++ b/glretrace.py @@ -320,22 +320,22 @@ class GlRetracer(Retracer): print r' }' print ' }' - # Update buffer mappings + # Query the buffer length for whole buffer mappings if function.name in self.map_function_names: - print r' if (__result) {' - print r' unsigned long long __address = call.ret->toUIntPtr();' - if 'BufferRange' not in function.name: - print r' GLint length = 0;' + if 'length' in function.argNames(): + assert 'BufferRange' in function.name + else: + assert 'BufferRange' not in function.name + print r' GLint length = 0;' if function.name in ('glMapBuffer', 'glMapBufferOES'): print r' glGetBufferParameteriv(target, GL_BUFFER_SIZE, &length);' elif function.name == 'glMapBufferARB': - print r' glGetBufferParameterivARB(target, GL_BUFFER_SIZE_ARB, &length);' + print r' glGetBufferParameterivARB(target, GL_BUFFER_SIZE_ARB, &length);' elif function.name == 'glMapNamedBufferEXT': - print r' glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_SIZE, &length);' + print r' glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_SIZE, &length);' else: assert False - print r' retrace::addRegion(__address, __result, length);' - print r' }' + # Destroy the buffer mapping if function.name in self.unmap_function_names: print r' GLvoid *ptr = NULL;' if function.name == 'glUnmapBuffer': diff --git a/retrace.py b/retrace.py index 96a09ab..0e28d18 100644 --- a/retrace.py +++ b/retrace.py @@ -94,8 +94,15 @@ class ValueDeserializer(stdapi.Visitor): print ' %s = NULL;' % lvalue print ' }' + def visitIntPointer(self, pointer, lvalue, rvalue): + print ' %s = static_cast<%s>((%s).toPointer());' % (lvalue, pointer, rvalue) + + def visitLinearPointer(self, pointer, lvalue, rvalue): + print ' %s = static_cast<%s>(retrace::toPointer(%s));' % (lvalue, pointer, rvalue) + def visitHandle(self, handle, lvalue, rvalue): - OpaqueValueDeserializer().visit(handle.type, lvalue, rvalue); + #OpaqueValueDeserializer().visit(handle.type, lvalue, rvalue); + self.visit(handle.type, lvalue, rvalue); new_lvalue = lookupHandle(handle, lvalue) print ' if (retrace::verbosity >= 2) {' print ' std::cout << "%s " << size_t(%s) << " <- " << size_t(%s) << "\\n";' % (handle.name, lvalue, new_lvalue) @@ -155,6 +162,14 @@ class SwizzledValueRegistrator(stdapi.Visitor): finally: print ' }' + def visitIntPointer(self, pointer, lvalue, rvalue): + pass + + def visitLinearPointer(self, pointer, lvalue, rvalue): + assert pointer.size is not None + if pointer.size is not None: + print r' retrace::addRegion((%s).toUIntPtr(), %s, %s);' % (rvalue, lvalue, pointer.size) + def visitHandle(self, handle, lvalue, rvalue): print ' %s __orig_result;' % handle.type OpaqueValueDeserializer().visit(handle.type, '__orig_result', rvalue); @@ -251,7 +266,7 @@ class Retracer: visitor.visit(type, lvalue, rvalue) def invokeFunction(self, function): - arg_names = ", ".join([arg.name for arg in function.args]) + arg_names = ", ".join(function.argNames()) if function.type is not stdapi.Void: print ' %s __result;' % (function.type) print ' __result = %s(%s);' % (function.name, arg_names) diff --git a/retrace_stdc.cpp b/retrace_stdc.cpp index 59dcf4f..03c3865 100644 --- a/retrace_stdc.cpp +++ b/retrace_stdc.cpp @@ -77,6 +77,12 @@ upperBound(unsigned long long address) { void addRegion(unsigned long long address, void *buffer, unsigned long long size) { + if (!address) { + // Ignore NULL pointer + assert(!buffer); + return; + } + // Forget all regions that intersect this new one. if (0) { RegionMap::iterator start = lowerBound(address); diff --git a/specs/glapi.py b/specs/glapi.py index ee86b39..886da1c 100644 --- a/specs/glapi.py +++ b/specs/glapi.py @@ -2142,7 +2142,7 @@ glapi.addFunctions([ GlFunction(Void, "glPrimitiveRestartIndexNV", [(GLuint, "index")]), # GL_ATI_map_object_buffer - GlFunction(GLmap, "glMapObjectBufferATI", [(GLbuffer, "buffer")]), + GlFunction(GLpointer, "glMapObjectBufferATI", [(GLbuffer, "buffer")]), GlFunction(Void, "glUnmapObjectBufferATI", [(GLbuffer, "buffer")]), # GL_ATI_separate_stencil diff --git a/specs/gltypes.py b/specs/gltypes.py index 829f0d8..5ea201a 100644 --- a/specs/gltypes.py +++ b/specs/gltypes.py @@ -98,12 +98,17 @@ GLrenderbuffer = Handle("renderbuffer", GLuint) GLfragmentShaderATI = Handle("fragmentShaderATI", GLuint) GLarray = Handle("array", GLuint) GLregion = Handle("region", GLuint) -GLmap = GLpointer GLpipeline = Handle("pipeline", GLuint) GLsampler = Handle("sampler", GLuint) GLfeedback = Handle("feedback", GLuint) -GLsync_ = Opaque("GLsync") +# GL mappings are pointers to linear memory regions. +# +# The map length is not always available in the function prototype, and must be +# reconstructed from other state. +GLmap = LinearPointer(GLvoid, "length") + +GLsync_ = IntPointer("GLsync") GLsync = Handle("sync", GLsync_) GLenum = Enum("GLenum", [ diff --git a/specs/stdapi.py b/specs/stdapi.py index 35257a3..44d4680 100644 --- a/specs/stdapi.py +++ b/specs/stdapi.py @@ -127,6 +127,25 @@ class Pointer(Type): return visitor.visitPointer(self, *args, **kwargs) +class IntPointer(Type): + '''Integer encoded as a pointer.''' + + def visit(self, visitor, *args, **kwargs): + return visitor.visitIntPointer(self, *args, **kwargs) + + +class LinearPointer(Type): + '''Integer encoded as a pointer.''' + + def __init__(self, type, size = None): + Type.__init__(self, type.expr + " *", 'P' + type.tag) + self.type = type + self.size = size + + def visit(self, visitor, *args, **kwargs): + return visitor.visitLinearPointer(self, *args, **kwargs) + + class Handle(Type): def __init__(self, name, type, range=None, key=None): @@ -437,6 +456,12 @@ class Visitor: def visitPointer(self, pointer, *args, **kwargs): raise NotImplementedError + def visitIntPointer(self, pointer, *args, **kwargs): + raise NotImplementedError + + def visitLinearPointer(self, pointer, *args, **kwargs): + raise NotImplementedError + def visitHandle(self, handle, *args, **kwargs): raise NotImplementedError @@ -508,6 +533,13 @@ class Rebuilder(Visitor): type = self.visit(pointer.type) return Pointer(type) + def visitIntPointer(self, pointer): + return pointer + + def visitLinearPointer(self, pointer): + type = self.visit(pointer.type) + return LinearPointer(type, pointer.size) + def visitHandle(self, handle): type = self.visit(handle.type) return Handle(handle.name, type, range=handle.range, key=handle.key) @@ -571,6 +603,12 @@ class Collector(Visitor): def visitPointer(self, pointer): self.visit(pointer.type) + def visitIntPointer(self, pointer): + pass + + def visitLinearPointer(self, pointer): + self.visit(pointer.type) + def visitHandle(self, handle): self.visit(handle.type) diff --git a/trace.py b/trace.py index bb209e4..0e6a4e0 100644 --- a/trace.py +++ b/trace.py @@ -105,6 +105,12 @@ class ComplexValueSerializer(stdapi.OnceVisitor): def visitPointer(self, pointer): self.visit(pointer.type) + def visitIntPointer(self, pointer): + pass + + def visitLinearPointer(self, pointer): + self.visit(pointer.type) + def visitHandle(self, handle): self.visit(handle.type) @@ -201,6 +207,12 @@ class ValueSerializer(stdapi.Visitor): print ' trace::localWriter.writeNull();' print ' }' + def visitIntPointer(self, pointer, instance): + print ' trace::localWriter.writeOpaque((const void *)%s);' % instance + + def visitLinearPointer(self, pointer, instance): + print ' trace::localWriter.writeOpaque((const void *)%s);' % instance + def visitHandle(self, handle, instance): self.visit(handle.type, instance) @@ -257,6 +269,12 @@ class ValueWrapper(stdapi.Visitor): print " if (%s) {" % instance self.visit(pointer.type, "*" + instance) print " }" + + def visitIntPointer(self, pointer, instance): + pass + + def visitLinearPointer(self, pointer, instance): + pass def visitHandle(self, handle, instance): self.visit(handle.type, instance) -- 2.43.0