summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2005-09-02 13:42:49 +0000
committerBrian Paul <[email protected]>2005-09-02 13:42:49 +0000
commit4fb995084e1b4b629667f09331adf060aa0fac4c (patch)
treeb8652385e0cc674b51aafa6191719536ea116757 /src/mesa/drivers
parent8cdf3729468aefb7c67c8ecd32fd850adbf6d351 (diff)
Prototype implementation of new GL_EXT_timer_query extension (not finalized yet).
Extends the query mechanism to query elapsed time while rendering.
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r--src/mesa/drivers/common/driverfuncs.c4
-rw-r--r--src/mesa/drivers/x11/glxheader.h1
-rw-r--r--src/mesa/drivers/x11/xm_api.c5
-rw-r--r--src/mesa/drivers/x11/xm_dd.c84
-rw-r--r--src/mesa/drivers/x11/xmesaP.h7
5 files changed, 95 insertions, 6 deletions
diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c
index c027123736f..f2e36b78452 100644
--- a/src/mesa/drivers/common/driverfuncs.c
+++ b/src/mesa/drivers/common/driverfuncs.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 6.3
+ * Version: 6.5
*
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
*
@@ -28,6 +28,7 @@
#include "buffers.h"
#include "context.h"
#include "framebuffer.h"
+#include "occlude.h"
#include "program.h"
#include "renderbuffer.h"
#include "texcompress.h"
@@ -210,6 +211,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
#endif
/* query objects */
+ driver->NewQueryObject = _mesa_new_query_object;
driver->BeginQuery = NULL;
driver->EndQuery = NULL;
diff --git a/src/mesa/drivers/x11/glxheader.h b/src/mesa/drivers/x11/glxheader.h
index 2533d504443..34b613a1bc4 100644
--- a/src/mesa/drivers/x11/glxheader.h
+++ b/src/mesa/drivers/x11/glxheader.h
@@ -51,6 +51,7 @@
# include <X11/extensions/XShm.h>
# endif
# include <GL/glx.h>
+# include <sys/time.h>
#endif
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index 4e71830afe5..ad9756bb90c 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -1689,13 +1689,16 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
_mesa_enable_1_4_extensions(mesaCtx);
_mesa_enable_1_5_extensions(mesaCtx);
_mesa_enable_2_0_extensions(mesaCtx);
-#if SWTC
+#if ENABLE_EXT_texure_compression_s3tc
if (c->Mesa_DXTn) {
_mesa_enable_extension(c, "GL_EXT_texture_compression_s3tc");
_mesa_enable_extension(c, "GL_S3_s3tc");
}
_mesa_enable_extension(c, "GL_3DFX_texture_compression_FXT1");
#endif
+#if ENABLE_EXT_timer_query
+ _mesa_enable_extension(c, "GL_EXT_timer_query");
+#endif
/* finish up xmesa context initializations */
c->swapbytes = CHECK_BYTE_ORDER(v) ? GL_FALSE : GL_TRUE;
diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c
index 7ab09d444d6..76dec19f531 100644
--- a/src/mesa/drivers/x11/xm_dd.c
+++ b/src/mesa/drivers/x11/xm_dd.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.3
+ * Version: 6.5
*
- * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -1130,6 +1130,78 @@ xmesa_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
}
+#if ENABLE_EXT_timer_query
+
+/*
+ * The GL_EXT_timer_query extension is not enabled for the XServer
+ * indirect renderer. Not sure about how/if wrapping of gettimeofday()
+ * is done, etc.
+ */
+
+struct xmesa_query_object
+{
+ struct gl_query_object Base;
+ struct timeval StartTime;
+};
+
+
+static struct gl_query_object *
+xmesa_new_query_object(GLcontext *ctx, GLuint id)
+{
+ struct xmesa_query_object *q = CALLOC_STRUCT(xmesa_query_object);
+ if (q) {
+ q->Base.Id = id;
+ q->Base.Ready = GL_TRUE;
+ }
+ return &q->Base;
+}
+
+
+static void
+xmesa_begin_query(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+{
+ if (target == GL_TIME_ELAPSED_EXT) {
+ struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
+ (void) gettimeofday(&xq->StartTime, NULL);
+ }
+}
+
+
+/**
+ * Return the difference between the two given times in microseconds.
+ */
+static unsigned int
+time_diff(const struct timeval *t0, const struct timeval *t1)
+{
+ time_t seconds0 = t0->tv_sec & 0xff; /* 0 .. 255 seconds */
+ time_t seconds1 = t1->tv_sec & 0xff; /* 0 .. 255 seconds */
+ suseconds_t useconds0 = seconds0 * 1000000 + t0->tv_usec;
+ suseconds_t useconds1 = seconds1 * 1000000 + t1->tv_usec;
+ return useconds1 - useconds0;
+}
+
+
+static void
+xmesa_end_query(GLcontext *ctx, GLenum target, struct gl_query_object *q)
+{
+ if (target == GL_TIME_ELAPSED_EXT) {
+ struct xmesa_query_object *xq = (struct xmesa_query_object *) q;
+ struct timeval endTime;
+ unsigned int dt;
+ (void) gettimeofday(&endTime, NULL);
+ dt = time_diff(&xq->StartTime, &endTime);
+ /* clamp if we'd overflow a 32-bit unsigned int */
+ if (dt >= 0xffffffffU / 1000U)
+ q->Result = 0xffffffffU;
+ else
+ q->Result = dt * 1000; /* result is in nanoseconds! */
+ }
+ q->Ready = GL_TRUE;
+}
+
+#endif /* ENABLE_timer_query */
+
+
/**
* Initialize the device driver function table with the functions
* we implement in this driver.
@@ -1162,11 +1234,17 @@ xmesa_init_driver_functions( XMesaVisual xmvisual,
}
#endif
driver->TestProxyTexImage = test_proxy_teximage;
-#if SWTC
+#if ENABLE_EXT_texure_compression_s3tc
driver->ChooseTextureFormat = choose_tex_format;
#else
(void) choose_tex_format;
#endif
+
+#if ENABLE_EXT_timer_query
+ driver->NewQueryObject = xmesa_new_query_object;
+ driver->BeginQuery = xmesa_begin_query;
+ driver->EndQuery = xmesa_end_query;
+#endif
}
diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h
index ee8ea2f574e..7030afaa119 100644
--- a/src/mesa/drivers/x11/xmesaP.h
+++ b/src/mesa/drivers/x11/xmesaP.h
@@ -539,7 +539,12 @@ extern GLboolean XMesaLoseCurrent(XMesaContext c);
extern void XMesaReset( void );
-#define SWTC 0 /* SW texture compression */
+#define ENABLE_EXT_texure_compression_s3tc 0 /* SW texture compression */
+#ifdef XFree86Server
+#define ENABLE_EXT_timer_query 0
+#else
+#define ENABLE_EXT_timer_query 1
+#endif
#endif