Used GCC's __builtin_expect when available. Change the way code is
generated for commands that can use RenderLarge packets. Tweak the code for __glXFlushRenderBuffer slightly.
This commit is contained in:
@@ -1263,23 +1263,23 @@ CARD8 __glXSetupForCommand(Display *dpy)
|
|||||||
return priv->majorOpcode;
|
return priv->majorOpcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
** Flush the drawing command transport buffer.
|
* Flush the drawing command transport buffer.
|
||||||
*/
|
*
|
||||||
|
* \param ctx Context whose transport buffer is to be flushed.
|
||||||
|
* \param pc Pointer to first unused buffer location.
|
||||||
|
*
|
||||||
|
* \todo
|
||||||
|
* Modify this function to use \c ctx->pc instead of the explicit
|
||||||
|
* \c pc parameter.
|
||||||
|
*/
|
||||||
GLubyte *__glXFlushRenderBuffer(__GLXcontext *ctx, GLubyte *pc)
|
GLubyte *__glXFlushRenderBuffer(__GLXcontext *ctx, GLubyte *pc)
|
||||||
{
|
{
|
||||||
Display *dpy;
|
Display * const dpy = ctx->currentDpy;
|
||||||
xGLXRenderReq *req;
|
xGLXRenderReq *req;
|
||||||
GLint size;
|
const GLint size = pc - ctx->buf;
|
||||||
|
|
||||||
if (!(dpy = ctx->currentDpy)) {
|
if ( (dpy != NULL) && (size > 0) ) {
|
||||||
/* Using the dummy context */
|
|
||||||
ctx->pc = ctx->buf;
|
|
||||||
return ctx->pc;
|
|
||||||
}
|
|
||||||
|
|
||||||
size = pc - ctx->buf;
|
|
||||||
if (size) {
|
|
||||||
/* Send the entire buffer as an X request */
|
/* Send the entire buffer as an X request */
|
||||||
LockDisplay(dpy);
|
LockDisplay(dpy);
|
||||||
GetReq(GLXRender,req);
|
GetReq(GLXRender,req);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -56,6 +56,10 @@ class PrintGlxProtoStubs(glX_XML.GlxProto):
|
|||||||
glX_XML.printFastcall()
|
glX_XML.printFastcall()
|
||||||
glX_XML.printNoinline()
|
glX_XML.printNoinline()
|
||||||
print ''
|
print ''
|
||||||
|
print '#if !defined __GNUC__ || __GNUC__ < 3'
|
||||||
|
print '# define __builtin_expect(x, y) x'
|
||||||
|
print '#endif'
|
||||||
|
print ''
|
||||||
print '/* If the size and opcode values are known at compile-time, this will, on'
|
print '/* If the size and opcode values are known at compile-time, this will, on'
|
||||||
print ' * x86 at least, emit them with a single instruction.'
|
print ' * x86 at least, emit them with a single instruction.'
|
||||||
print ' */'
|
print ' */'
|
||||||
@@ -91,7 +95,7 @@ read_reply( Display *dpy, size_t size, void * dest, GLboolean reply_is_always_ar
|
|||||||
|
|
||||||
#define X_GLXSingle 0
|
#define X_GLXSingle 0
|
||||||
|
|
||||||
static NOINLINE GLubyte *
|
static NOINLINE FASTCALL GLubyte *
|
||||||
setup_single_request( __GLXcontext * gc, GLint sop, GLint cmdlen )
|
setup_single_request( __GLXcontext * gc, GLint sop, GLint cmdlen )
|
||||||
{
|
{
|
||||||
xGLXSingleReq * req;
|
xGLXSingleReq * req;
|
||||||
@@ -106,7 +110,7 @@ setup_single_request( __GLXcontext * gc, GLint sop, GLint cmdlen )
|
|||||||
return (GLubyte *)(req) + sz_xGLXSingleReq;
|
return (GLubyte *)(req) + sz_xGLXSingleReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NOINLINE GLubyte *
|
static NOINLINE FASTCALL GLubyte *
|
||||||
setup_vendor_request( __GLXcontext * gc, GLint code, GLint vop, GLint cmdlen )
|
setup_vendor_request( __GLXcontext * gc, GLint code, GLint vop, GLint cmdlen )
|
||||||
{
|
{
|
||||||
xGLXVendorPrivateReq * req;
|
xGLXVendorPrivateReq * req;
|
||||||
@@ -147,7 +151,7 @@ generic_%u_byte( GLint rop, const void * ptr )
|
|||||||
emit_header(gc->pc, rop, cmdlen);
|
emit_header(gc->pc, rop, cmdlen);
|
||||||
(void) memcpy((void *)(gc->pc + 4), ptr, %u);
|
(void) memcpy((void *)(gc->pc + 4), ptr, %u);
|
||||||
gc->pc += cmdlen;
|
gc->pc += cmdlen;
|
||||||
if (gc->pc > gc->limit) { (void) __glXFlushRenderBuffer(gc, gc->pc); }
|
if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }
|
||||||
}
|
}
|
||||||
""" % (n, n + 4, n)
|
""" % (n, n + 4, n)
|
||||||
|
|
||||||
@@ -189,7 +193,21 @@ generic_%u_byte( GLint rop, const void * ptr )
|
|||||||
self.common_func_print_just_header(f)
|
self.common_func_print_just_header(f)
|
||||||
|
|
||||||
print ' __GLXcontext * const gc = __glXGetCurrentContext();'
|
print ' __GLXcontext * const gc = __glXGetCurrentContext();'
|
||||||
|
|
||||||
|
# The only reason that single and vendor private commands need
|
||||||
|
# a variable called 'dpy' is becuase they use the SyncHandle
|
||||||
|
# macro. For whatever brain-dead reason, that macro is hard-
|
||||||
|
# coded to use a variable called 'dpy' instead of taking a
|
||||||
|
# parameter.
|
||||||
|
|
||||||
|
if not f.glx_rop:
|
||||||
print ' Display * const dpy = gc->currentDpy;'
|
print ' Display * const dpy = gc->currentDpy;'
|
||||||
|
skip_condition = "dpy != NULL"
|
||||||
|
elif f.can_be_large:
|
||||||
|
skip_condition = "gc->currentDpy != NULL"
|
||||||
|
else:
|
||||||
|
skip_condition = None
|
||||||
|
|
||||||
|
|
||||||
if f.fn_return_type != 'void':
|
if f.fn_return_type != 'void':
|
||||||
print ' %s retval = (%s) 0;' % (f.fn_return_type, f.fn_return_type)
|
print ' %s retval = (%s) 0;' % (f.fn_return_type, f.fn_return_type)
|
||||||
@@ -199,26 +217,23 @@ generic_%u_byte( GLint rop, const void * ptr )
|
|||||||
|
|
||||||
print ' const GLuint cmdlen = %s;' % (f.command_length())
|
print ' const GLuint cmdlen = %s;' % (f.command_length())
|
||||||
|
|
||||||
if f.counter != None:
|
if f.counter:
|
||||||
print ' if (%s < 0) %s' % (f.counter, f.return_string())
|
if skip_condition:
|
||||||
|
skip_condition = "(%s >= 0) && (%s)" % (f.counter, skip_condition)
|
||||||
if f.can_be_large:
|
|
||||||
print ' if (dpy == NULL) return;'
|
|
||||||
print ' if ( ((gc->pc + cmdlen) > gc->bufEnd)'
|
|
||||||
print ' || (cmdlen > gc->maxSmallRenderCommandSize)) {'
|
|
||||||
print ' (void) __glXFlushRenderBuffer(gc, gc->pc);'
|
|
||||||
print ' }'
|
|
||||||
else:
|
else:
|
||||||
print ' (void) dpy;'
|
skip_condition = "%s >= 0" % (f.counter)
|
||||||
|
|
||||||
return
|
|
||||||
|
if skip_condition:
|
||||||
|
print ' if (__builtin_expect(%s, 1)) {' % (skip_condition)
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def printSingleFunction(self, f):
|
def printSingleFunction(self, f):
|
||||||
self.common_func_print_header(f)
|
self.common_func_print_header(f)
|
||||||
|
|
||||||
print ' if (dpy != NULL) {'
|
|
||||||
|
|
||||||
if f.fn_parameters != []:
|
if f.fn_parameters != []:
|
||||||
pc_decl = "GLubyte const * pc ="
|
pc_decl = "GLubyte const * pc ="
|
||||||
else:
|
else:
|
||||||
@@ -249,9 +264,9 @@ generic_%u_byte( GLint rop, const void * ptr )
|
|||||||
else:
|
else:
|
||||||
aa = "GL_FALSE"
|
aa = "GL_FALSE"
|
||||||
|
|
||||||
print " %s read_reply(gc->currentDpy, %s, %s, %s);" % (return_str, output_size, output_str, aa)
|
print " %s read_reply(dpy, %s, %s, %s);" % (return_str, output_size, output_str, aa)
|
||||||
|
|
||||||
print ' UnlockDisplay(gc->currentDpy); SyncHandle();'
|
print ' UnlockDisplay(dpy); SyncHandle();'
|
||||||
print ' }'
|
print ' }'
|
||||||
print ' %s' % f.return_string()
|
print ' %s' % f.return_string()
|
||||||
print '}'
|
print '}'
|
||||||
@@ -278,33 +293,41 @@ generic_%u_byte( GLint rop, const void * ptr )
|
|||||||
print ''
|
print ''
|
||||||
return
|
return
|
||||||
|
|
||||||
self.common_func_print_header(f)
|
if self.common_func_print_header(f):
|
||||||
|
|
||||||
if f.can_be_large:
|
|
||||||
print ' if (cmdlen <= gc->maxSmallRenderCommandSize) {'
|
|
||||||
indent = " "
|
indent = " "
|
||||||
|
trailer = " }"
|
||||||
else:
|
else:
|
||||||
indent = ""
|
indent = ""
|
||||||
|
trailer = None
|
||||||
|
|
||||||
|
if f.can_be_large:
|
||||||
|
print '%s if (cmdlen <= gc->maxSmallRenderCommandSize) {' % (indent)
|
||||||
|
print '%s if ( (gc->pc + cmdlen) > gc->bufEnd ) {' % (indent)
|
||||||
|
print '%s (void) __glXFlushRenderBuffer(gc, gc->pc);' % (indent)
|
||||||
|
print '%s }' % (indent)
|
||||||
|
indent += " "
|
||||||
|
|
||||||
print '%s emit_header(gc->pc, %s, cmdlen);' % (indent, f.opcode_real_name())
|
print '%s emit_header(gc->pc, %s, cmdlen);' % (indent, f.opcode_real_name())
|
||||||
|
|
||||||
self.common_emit_args(f, "gc->pc", indent, 4, 0)
|
self.common_emit_args(f, "gc->pc", indent, 4, 0)
|
||||||
print '%s gc->pc += cmdlen;' % (indent)
|
print '%s gc->pc += cmdlen;' % (indent)
|
||||||
print '%s if (gc->pc > gc->limit) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' % (indent)
|
print '%s if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }' % (indent)
|
||||||
|
|
||||||
if f.can_be_large:
|
if f.can_be_large:
|
||||||
print ' }'
|
print '%s}' % (indent)
|
||||||
print ' else {'
|
print '%selse {' % (indent)
|
||||||
print ' const GLint op = %s;' % (f.opcode_real_name())
|
print '%s const GLint op = %s;' % (indent, f.opcode_real_name())
|
||||||
print ' const GLuint cmdlenLarge = cmdlen + 4;'
|
print '%s const GLuint cmdlenLarge = cmdlen + 4;' % (indent)
|
||||||
print ' (void) memcpy((void *)(gc->pc + 0), (void *)(&op), 4);'
|
print '%s GLubyte * const pc = __glXFlushRenderBuffer(gc, gc->pc);' % (indent)
|
||||||
print ' (void) memcpy((void *)(gc->pc + 4), (void *)(&cmdlenLarge), 4);'
|
print '%s (void) memcpy((void *)(pc + 0), (void *)(&op), 4);' % (indent)
|
||||||
offset = self.common_emit_args(f, "gc->pc", indent, 8, 1)
|
print '%s (void) memcpy((void *)(pc + 4), (void *)(&cmdlenLarge), 4);' % (indent)
|
||||||
|
offset = self.common_emit_args(f, "pc", indent, 8, 1)
|
||||||
|
|
||||||
p = f.variable_length_parameter()
|
p = f.variable_length_parameter()
|
||||||
print ' __glXSendLargeCommand(gc, gc->pc, %u, %s, %s);' % (offset + 8, p.name, p.size_string())
|
print '%s __glXSendLargeCommand(gc, pc, %u, %s, %s);' % (indent, offset + 8, p.name, p.size_string())
|
||||||
print ' }'
|
print '%s}' % (indent)
|
||||||
|
|
||||||
|
if trailer: print trailer
|
||||||
print '}'
|
print '}'
|
||||||
print ''
|
print ''
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user