nouveau: Always render offscreen, emulate front buffer rendering.

This commit is contained in:
Ben Skeggs
2007-08-13 20:38:10 +10:00
parent b7c93de6d7
commit fef3dcbee6
13 changed files with 109 additions and 129 deletions
+15 -10
View File
@@ -315,19 +315,23 @@ GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv )
return GL_TRUE;
}
static void nouveauDoSwapBuffers(nouveauContextPtr nmesa,
__DRIdrawablePrivate *dPriv)
void
nouveauDoSwapBuffers(nouveauContextPtr nmesa, __DRIdrawablePrivate *dPriv)
{
struct gl_framebuffer *fb;
nouveau_renderbuffer *src, *dst;
nouveauScreenPtr screen = dPriv->driScreenPriv->private;
nouveau_renderbuffer_t *src;
drm_clip_rect_t *box;
int nbox, i;
fb = (struct gl_framebuffer *)dPriv->driverPrivate;
dst = (nouveau_renderbuffer*)
fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
src = (nouveau_renderbuffer*)
fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
if (fb->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT) {
src = (nouveau_renderbuffer_t *)
fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
} else {
src = (nouveau_renderbuffer_t *)
fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
}
#ifdef ALLOW_MULTI_SUBCHANNEL
LOCK_HARDWARE(nmesa);
@@ -341,9 +345,10 @@ static void nouveauDoSwapBuffers(nouveauContextPtr nmesa,
OUT_RING (6); /* X8R8G8B8 */
else
OUT_RING (4); /* R5G6B5 */
OUT_RING ((dst->pitch << 16) | src->pitch);
OUT_RING (src->offset);
OUT_RING (dst->offset);
OUT_RING(((screen->frontPitch * screen->fbFormat) << 16) |
src->pitch);
OUT_RING(src->offset);
OUT_RING(screen->frontOffset);
}
for (i=0; i<nbox; i++, box++) {
@@ -83,8 +83,8 @@ typedef struct nouveau_hw_func_t {
GLboolean (*InitCard)(struct nouveau_context *);
/* Update buffer offset/pitch/format */
GLboolean (*BindBuffers)(struct nouveau_context *, int num_color,
nouveau_renderbuffer **color,
nouveau_renderbuffer *depth);
nouveau_renderbuffer_t **color,
nouveau_renderbuffer_t *depth);
/* Update anything that depends on the window position/size */
void (*WindowMoved)(struct nouveau_context *);
} nouveau_hw_func;
@@ -223,6 +223,9 @@ extern GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
extern GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv );
extern void nouveauDoSwapBuffers(nouveauContextPtr nmesa,
__DRIdrawablePrivate *dPriv);
extern void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv);
extern void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
@@ -117,6 +117,9 @@ static const GLubyte *nouveauGetString( GLcontext *ctx, GLenum name )
static void nouveauFlush( GLcontext *ctx )
{
nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
if (ctx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT)
nouveauDoSwapBuffers(nmesa, nmesa->driDrawable);
FIRE_RING();
}
@@ -124,6 +127,7 @@ static void nouveauFlush( GLcontext *ctx )
static void nouveauFinish( GLcontext *ctx )
{
nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
nouveauFlush( ctx );
nouveauWaitForIdle( nmesa );
}
+56 -70
View File
@@ -11,7 +11,7 @@
#include "nouveau_reg.h"
static GLboolean
nouveau_renderbuffer_pixelformat(nouveau_renderbuffer * nrb,
nouveau_renderbuffer_pixelformat(nouveau_renderbuffer_t * nrb,
GLenum internalFormat)
{
nrb->mesa.InternalFormat = internalFormat;
@@ -84,7 +84,7 @@ nouveau_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
GLenum internalFormat,
GLuint width, GLuint height)
{
nouveau_renderbuffer *nrb = (nouveau_renderbuffer *) rb;
nouveau_renderbuffer_t *nrb = (nouveau_renderbuffer_t *) rb;
if (!nouveau_renderbuffer_pixelformat(nrb, internalFormat)) {
fprintf(stderr, "%s: unknown internalFormat\n", __func__);
@@ -93,7 +93,7 @@ nouveau_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
/* If this buffer isn't statically alloc'd, we may need to ask the
* drm for more memory */
if (!nrb->dPriv && (rb->Width != width || rb->Height != height)) {
if (rb->Width != width || rb->Height != height) {
GLuint pitch;
/* align pitches to 64 bytes */
@@ -116,62 +116,48 @@ nouveau_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
rb->Width = width;
rb->Height = height;
rb->InternalFormat = internalFormat;
nouveauSpanSetFunctions(nrb);
return GL_TRUE;
}
static void nouveau_renderbuffer_delete(struct gl_renderbuffer *rb)
static void
nouveau_renderbuffer_delete(struct gl_renderbuffer *rb)
{
GET_CURRENT_CONTEXT(ctx);
nouveau_renderbuffer *nrb = (nouveau_renderbuffer *) rb;
nouveau_renderbuffer_t *nrb = (nouveau_renderbuffer_t *) rb;
if (nrb->mem)
nouveau_mem_free(ctx, nrb->mem);
FREE(nrb);
}
nouveau_renderbuffer *nouveau_renderbuffer_new(GLenum internalFormat,
GLvoid * map, GLuint offset,
GLuint pitch,
__DRIdrawablePrivate *
dPriv)
nouveau_renderbuffer_t *
nouveau_renderbuffer_new(GLenum internalFormat)
{
nouveau_renderbuffer *nrb;
nouveau_renderbuffer_t *nrb;
nrb = CALLOC_STRUCT(nouveau_renderbuffer_t);
if (nrb) {
_mesa_init_renderbuffer(&nrb->mesa, 0);
nrb = CALLOC_STRUCT(nouveau_renderbuffer);
if (!nrb)
return NULL;
nouveau_renderbuffer_pixelformat(nrb, internalFormat);
_mesa_init_renderbuffer(&nrb->mesa, 0);
nrb->mesa.AllocStorage = nouveau_renderbuffer_storage;
nrb->mesa.Delete = nouveau_renderbuffer_delete;
nrb->dPriv = dPriv;
nrb->offset = offset;
nrb->pitch = pitch;
nrb->map = map;
if (!nouveau_renderbuffer_pixelformat(nrb, internalFormat)) {
fprintf(stderr, "%s: unknown internalFormat\n", __func__);
return GL_FALSE;
}
nrb->mesa.AllocStorage = nouveau_renderbuffer_storage;
nrb->mesa.Delete = nouveau_renderbuffer_delete;
return nrb;
}
static void
nouveau_cliprects_drawable_set(nouveauContextPtr nmesa,
nouveau_renderbuffer * nrb)
{
__DRIdrawablePrivate *dPriv = nrb->dPriv;
nmesa->numClipRects = dPriv->numClipRects;
nmesa->pClipRects = dPriv->pClipRects;
nmesa->drawX = dPriv->x;
nmesa->drawY = dPriv->y;
nmesa->drawW = dPriv->w;
nmesa->drawH = dPriv->h;
}
static void
nouveau_cliprects_renderbuffer_set(nouveauContextPtr nmesa,
nouveau_renderbuffer * nrb)
nouveau_renderbuffer_t * nrb)
{
nmesa->numClipRects = 1;
nmesa->pClipRects = &nmesa->osClipRect;
@@ -185,19 +171,18 @@ nouveau_cliprects_renderbuffer_set(nouveauContextPtr nmesa,
nmesa->drawH = nrb->mesa.Height;
}
void nouveau_window_moved(GLcontext * ctx)
void
nouveau_window_moved(GLcontext * ctx)
{
nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
nouveau_renderbuffer *nrb;
nouveau_renderbuffer_t *nrb;
nrb = (nouveau_renderbuffer *)ctx->DrawBuffer->_ColorDrawBuffers[0][0];
nrb = (nouveau_renderbuffer_t *)
ctx->DrawBuffer->_ColorDrawBuffers[0][0];
if (!nrb)
return;
if (!nrb->dPriv)
nouveau_cliprects_renderbuffer_set(nmesa, nrb);
else
nouveau_cliprects_drawable_set(nmesa, nrb);
nouveau_cliprects_renderbuffer_set(nmesa, nrb);
/* Viewport depends on window size/position, nouveauCalcViewport
* will take care of calling the hw-specific WindowMoved
@@ -210,20 +195,20 @@ void nouveau_window_moved(GLcontext * ctx)
}
GLboolean
nouveau_build_framebuffer(GLcontext * ctx, struct gl_framebuffer *fb)
nouveau_build_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
{
nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx);
nouveau_renderbuffer *color[MAX_DRAW_BUFFERS];
nouveau_renderbuffer *depth;
nouveau_renderbuffer_t *color[MAX_DRAW_BUFFERS];
nouveau_renderbuffer_t *depth;
_mesa_update_framebuffer(ctx);
_mesa_update_draw_buffer_bounds(ctx);
color[0] = (nouveau_renderbuffer *) fb->_ColorDrawBuffers[0][0];
color[0] = (nouveau_renderbuffer_t *) fb->_ColorDrawBuffers[0][0];
if (fb->_DepthBuffer && fb->_DepthBuffer->Wrapped)
depth = (nouveau_renderbuffer *) fb->_DepthBuffer->Wrapped;
depth = (nouveau_renderbuffer_t *) fb->_DepthBuffer->Wrapped;
else
depth = (nouveau_renderbuffer *) fb->_DepthBuffer;
depth = (nouveau_renderbuffer_t *) fb->_DepthBuffer;
if (!nmesa->hw_func.BindBuffers(nmesa, 1, color, depth))
return GL_FALSE;
@@ -232,34 +217,36 @@ nouveau_build_framebuffer(GLcontext * ctx, struct gl_framebuffer *fb)
return GL_TRUE;
}
static void nouveauDrawBuffer(GLcontext * ctx, GLenum buffer)
static void
nouveauDrawBuffer(GLcontext *ctx, GLenum buffer)
{
nouveau_build_framebuffer(ctx, ctx->DrawBuffer);
}
static struct gl_framebuffer *nouveauNewFramebuffer(GLcontext * ctx,
GLuint name)
static struct gl_framebuffer *
nouveauNewFramebuffer(GLcontext *ctx, GLuint name)
{
return _mesa_new_framebuffer(ctx, name);
}
static struct gl_renderbuffer *nouveauNewRenderbuffer(GLcontext * ctx,
GLuint name)
static struct gl_renderbuffer *
nouveauNewRenderbuffer(GLcontext *ctx, GLuint name)
{
nouveau_renderbuffer *nrb;
nouveau_renderbuffer_t *nrb;
nrb = CALLOC_STRUCT(nouveau_renderbuffer_t);
if (nrb) {
_mesa_init_renderbuffer(&nrb->mesa, name);
nrb = CALLOC_STRUCT(nouveau_renderbuffer);
if (!nrb)
return NULL;
nrb->mesa.AllocStorage = nouveau_renderbuffer_storage;
nrb->mesa.Delete = nouveau_renderbuffer_delete;
}
_mesa_init_renderbuffer(&nrb->mesa, name);
nrb->mesa.AllocStorage = nouveau_renderbuffer_storage;
nrb->mesa.Delete = nouveau_renderbuffer_delete;
return &nrb->mesa;
}
static void
nouveauBindFramebuffer(GLcontext * ctx, GLenum target,
nouveauBindFramebuffer(GLcontext *ctx, GLenum target,
struct gl_framebuffer *fb,
struct gl_framebuffer *fbread)
{
@@ -269,18 +256,15 @@ nouveauBindFramebuffer(GLcontext * ctx, GLenum target,
}
static void
nouveauFramebufferRenderbuffer(GLcontext * ctx,
struct gl_framebuffer *fb,
GLenum attachment,
struct gl_renderbuffer *rb)
nouveauFramebufferRenderbuffer(GLcontext *ctx, struct gl_framebuffer *fb,
GLenum attachment, struct gl_renderbuffer *rb)
{
_mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
nouveau_build_framebuffer(ctx, fb);
}
static void
nouveauRenderTexture(GLcontext * ctx,
struct gl_framebuffer *fb,
nouveauRenderTexture(GLcontext * ctx, struct gl_framebuffer *fb,
struct gl_renderbuffer_attachment *att)
{
}
@@ -291,7 +275,8 @@ nouveauFinishRenderTexture(GLcontext * ctx,
{
}
void nouveauInitBufferFuncs(struct dd_function_table *func)
void
nouveauInitBufferFuncs(struct dd_function_table *func)
{
func->DrawBuffer = nouveauDrawBuffer;
@@ -302,3 +287,4 @@ void nouveauInitBufferFuncs(struct dd_function_table *func)
func->RenderTexture = nouveauRenderTexture;
func->FinishRenderTexture = nouveauFinishRenderTexture;
}
+4 -9
View File
@@ -8,9 +8,8 @@
#include "nouveau_mem.h"
typedef struct nouveau_renderbuffer_t {
typedef struct nouveau_renderbuffer {
struct gl_renderbuffer mesa; /* must be first! */
__DRIdrawablePrivate *dPriv;
nouveau_mem *mem;
void *map;
@@ -18,17 +17,13 @@ typedef struct nouveau_renderbuffer_t {
int cpp;
uint32_t offset;
uint32_t pitch;
} nouveau_renderbuffer;
} nouveau_renderbuffer_t;
extern nouveau_renderbuffer *nouveau_renderbuffer_new(GLenum internalFormat,
GLvoid *map,
GLuint offset,
GLuint pitch,
__DRIdrawablePrivate *);
extern nouveau_renderbuffer_t *nouveau_renderbuffer_new(GLenum internalFormat);
extern void nouveau_window_moved(GLcontext *);
extern GLboolean nouveau_build_framebuffer(GLcontext *,
struct gl_framebuffer *);
extern nouveau_renderbuffer *nouveau_current_draw_buffer(GLcontext *);
extern nouveau_renderbuffer_t *nouveau_current_draw_buffer(GLcontext *);
extern void nouveauInitBufferFuncs(struct dd_function_table *);
+8 -19
View File
@@ -132,10 +132,11 @@ nouveauCreateBuffer(__DRIscreenPrivate *driScrnPriv,
GLboolean isPixmap)
{
nouveauScreenPtr screen = (nouveauScreenPtr) driScrnPriv->private;
nouveau_renderbuffer *nrb;
nouveau_renderbuffer_t *nrb;
struct gl_framebuffer *fb;
const GLboolean swAccum = mesaVis->accumRedBits > 0;
const GLboolean swStencil = mesaVis->stencilBits > 0 && mesaVis->depthBits != 24;
const GLboolean swStencil = (mesaVis->stencilBits > 0 &&
mesaVis->depthBits != 24);
GLenum color_format = screen->fbFormat == 4 ? GL_RGBA8 : GL_RGB5;
if (isPixmap)
@@ -146,37 +147,25 @@ nouveauCreateBuffer(__DRIscreenPrivate *driScrnPriv,
return GL_FALSE;
/* Front buffer */
nrb = nouveau_renderbuffer_new(color_format,
driScrnPriv->pFB + screen->frontOffset,
screen->frontOffset,
screen->frontPitch * screen->fbFormat,
driDrawPriv);
nouveauSpanSetFunctions(nrb, mesaVis);
nrb = nouveau_renderbuffer_new(color_format);
_mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &nrb->mesa);
if (mesaVis->doubleBufferMode) {
nrb = nouveau_renderbuffer_new(color_format, NULL, 0, 0, NULL);
nouveauSpanSetFunctions(nrb, mesaVis);
nrb = nouveau_renderbuffer_new(color_format);
_mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &nrb->mesa);
}
if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) {
nrb = nouveau_renderbuffer_new(GL_DEPTH24_STENCIL8_EXT, NULL,
0, 0, NULL);
nouveauSpanSetFunctions(nrb, mesaVis);
nrb = nouveau_renderbuffer_new(GL_DEPTH24_STENCIL8_EXT);
_mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa);
_mesa_add_renderbuffer(fb, BUFFER_STENCIL, &nrb->mesa);
} else
if (mesaVis->depthBits == 24) {
nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT24, NULL,
0, 0, NULL);
nouveauSpanSetFunctions(nrb, mesaVis);
nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT24);
_mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa);
} else
if (mesaVis->depthBits == 16) {
nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT16, NULL,
0, 0, NULL);
nouveauSpanSetFunctions(nrb, mesaVis);
nrb = nouveau_renderbuffer_new(GL_DEPTH_COMPONENT16);
_mesa_add_renderbuffer(fb, BUFFER_DEPTH, &nrb->mesa);
}
+3 -5
View File
@@ -37,8 +37,6 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#define HAVE_HW_STENCIL_SPANS 0
#define HAVE_HW_STENCIL_PIXELS 0
static char *fake_span[1280*1024*4];
#define HW_CLIPLOOP() \
do { \
int _nc = nmesa->numClipRects; \
@@ -50,11 +48,10 @@ static char *fake_span[1280*1024*4];
#define LOCAL_VARS \
nouveauContextPtr nmesa = NOUVEAU_CONTEXT(ctx); \
nouveau_renderbuffer *nrb = (nouveau_renderbuffer *)rb; \
nouveau_renderbuffer_t *nrb = (nouveau_renderbuffer_t *)rb; \
GLuint height = nrb->mesa.Height; \
GLubyte *map = (GLubyte *)(nrb->map ? nrb->map : nrb->mem->map) + \
(nmesa->drawY * nrb->pitch) + (nmesa->drawX * nrb->cpp); \
map = fake_span; \
GLuint p; \
(void) p;
@@ -119,10 +116,11 @@ void nouveauSpanInitFunctions( GLcontext *ctx )
* Plug in the Get/Put routines for the given driRenderbuffer.
*/
void
nouveauSpanSetFunctions(nouveau_renderbuffer *nrb, const GLvisual *vis)
nouveauSpanSetFunctions(nouveau_renderbuffer_t *nrb)
{
if (nrb->mesa._ActualFormat == GL_RGBA8)
nouveauInitPointers_ARGB8888(&nrb->mesa);
else // if (nrb->mesa._ActualFormat == GL_RGB5)
nouveauInitPointers_RGB565(&nrb->mesa);
}
+2 -2
View File
@@ -32,8 +32,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "drirenderbuffer.h"
#include "nouveau_fbo.h"
extern void nouveauSpanInitFunctions( GLcontext *ctx );
extern void nouveauSpanSetFunctions(nouveau_renderbuffer *nrb, const GLvisual *vis);
extern void nouveauSpanInitFunctions(GLcontext *ctx);
extern void nouveauSpanSetFunctions(nouveau_renderbuffer_t *nrb);
#endif /* __NOUVEAU_SPAN_H__ */
+2 -2
View File
@@ -451,8 +451,8 @@ static GLboolean nv04InitCard(nouveauContextPtr nmesa)
/* Update buffer offset/pitch/format */
static GLboolean nv04BindBuffers(nouveauContextPtr nmesa, int num_color,
nouveau_renderbuffer **color,
nouveau_renderbuffer *depth)
nouveau_renderbuffer_t **color,
nouveau_renderbuffer_t *depth)
{
GLuint x, y, w, h;
uint32_t depth_pitch=(depth?depth->pitch:0+15)&~15+16;
+2 -2
View File
@@ -709,8 +709,8 @@ static GLboolean nv10InitCard(nouveauContextPtr nmesa)
/* Update buffer offset/pitch/format */
static GLboolean nv10BindBuffers(nouveauContextPtr nmesa, int num_color,
nouveau_renderbuffer **color,
nouveau_renderbuffer *depth)
nouveau_renderbuffer_t **color,
nouveau_renderbuffer_t *depth)
{
GLuint x, y, w, h;
GLuint pitch, format, depth_pitch;
+2 -2
View File
@@ -728,8 +728,8 @@ static GLboolean nv20InitCard(nouveauContextPtr nmesa)
/* Update buffer offset/pitch/format */
static GLboolean nv20BindBuffers(nouveauContextPtr nmesa, int num_color,
nouveau_renderbuffer **color,
nouveau_renderbuffer *depth)
nouveau_renderbuffer_t **color,
nouveau_renderbuffer_t *depth)
{
GLuint x, y, w, h;
GLuint pitch, format, depth_pitch;
+3 -3
View File
@@ -905,9 +905,9 @@ static GLboolean nv40InitCard(nouveauContextPtr nmesa)
return GL_TRUE;
}
static GLboolean nv30BindBuffers(nouveauContextPtr nmesa, int num_color,
nouveau_renderbuffer **color,
nouveau_renderbuffer *depth)
static GLboolean
nv30BindBuffers(nouveauContextPtr nmesa, int num_color,
nouveau_renderbuffer_t **color, nouveau_renderbuffer_t *depth)
{
GLuint x, y, w, h;
+3 -3
View File
@@ -584,9 +584,9 @@ static GLboolean nv50InitCard(nouveauContextPtr nmesa)
return GL_FALSE;
}
static GLboolean nv50BindBuffers(nouveauContextPtr nmesa, int num_color,
nouveau_renderbuffer **color,
nouveau_renderbuffer *depth)
static GLboolean
nv50BindBuffers(nouveauContextPtr nmesa, int num_color,
nouveau_renderbuffer_t **color, nouveau_renderbuffer_t *depth)
{
return GL_FALSE;
}