From owner-freebsd-threads@FreeBSD.ORG Tue Jun 17 09:19:02 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1CED237B407 for ; Tue, 17 Jun 2003 09:19:02 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id E169543F75 for ; Tue, 17 Jun 2003 09:19:00 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mail.pcnet.com (8.12.8/8.12.1) with ESMTP id h5HGImXh023336; Tue, 17 Jun 2003 12:18:48 -0400 (EDT) Date: Tue, 17 Jun 2003 12:18:48 -0400 (EDT) From: Daniel Eischen X-Sender: eischen@pcnet5.pcnet.com To: Gareth Hughes In-Reply-To: <2D32959E172B8F4D9B02F68266BE421401A6D7E7@mail-sc-3.nvidia.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: threads@freebsd.org cc: zander@mail.minion.de cc: 'Julian Elischer' cc: Andy Ritger cc: 'Daniel Eischen' Subject: RE: NVIDIA and TLS X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jun 2003 16:19:02 -0000 On Mon, 16 Jun 2003, Gareth Hughes wrote: > Umm, you clearly don't understand what I've been talking about. > Upon entry into libGL, i.e. when an OpenGL API entrypoint is > called by the application, things like the current context or > current dispatch table are fetched from thread-local storage. > Internally, we pass these pointers around as required. > > So, we might have something like this: > > void glBegin(GLenum mode) > { > // Grab the current dispatch pointer from TLS > __GLdispatch *dispatch = GET_CURRENT_DISPATCH(); > > // Call into the driver backend > dispatch->Begin(mode) > } > > or, in x86 assembly: > > glBegin: > mov %gs:__gl_dispatch@ntpoff, %eax > jmp *__begin_offset(%eax) > > (note that Andy mentioned this example in his original email) > > This would jump to a function inside the driver like this: > > void __internal_Begin(GLenum mode) > { > __GLcontext *ctx = GET_CURRENT_CONTEXT(); > > do_something(ctx, ...); > do_something_else(ctx, ...); > // and so on > } But you have at least 2 levels of "get current thread" context: one in the openGl entry point (GET_CURRENT_DISPATCH()) and another in the driver (GET_CURRENT_CONTEXT()). If you are going to get some TLS in the OpenGL entry point, then make it the only TLS thingy you'll ever need. Hang all your stuff off the one TLS context and pass it (or parts of it) around to other consumers. So the driver gets called as follows: void __internal_Begin(GLenum mode, __GLcontext *ctx) { do_something(ctx, ...); do_something_else(ctx, ...); // and so on } Now when somebody comes up with thread-safe OpenGL and you have glBegin_r(GLctx *ctx, GLenum mode), you are golden: glBegin_r(GLctx *ctx, GLenum mode) { __GLdispatch *dispatch = ctx->dispatch; __GLcontext *glctx = ctx->glctx; dispatch->Begin(glctx, mode); } > Once we're inside the driver, we know what the current context > or other thread-local variable's value is. Two critical > points: > > 1) We have to fetch the value from TLS at least once per entry > into the driver. Pass what you need to the driver. You needn't have to fetch any TLS in the driver because the only way to the driver is from the OpenGL entry point -- unless I'm missing something. -- Dan Eischen